akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];

int main(){
  int N,L ;
  cin >> N >> L ;
  vector<string> S(N) ;
  cinf(N,S) ;
  sort(S.begin() , S.end()) ;
  for(int i=0;i<N;i++)
    cout << S[i] ;
  cout << endl;
}
  


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a,b,c,l[10],m,i,j,k;
  cin >> n >> a >> b >> c;
  for(i=0;i<n;i++){
    cin >> l[i];
  }
  int ans=2000000000;
  for(i=1;i<(1<<n);i++){
    for(j=1;j<(1<<n);j++){
      for(k=1;k<(1<<n);k++){
        if((i&j)!=0 || (k&j)!=0 || (i&k)!=0){
          continue;
        }
        int sum1=0,sum=0,x=0;
        for(m=0;m<n;m++){
          if(i&(1<<m)){
            sum+=10;
            sum1+=l[m];
            x=1;
          }
        }
        if(x==1){
          sum-=10;
        }
        sum+=abs(a-sum1);
        sum1=0,x=0;
        for(m=0;m<n;m++){
          if(j&(1<<m)){
            sum+=10;
            sum1+=l[m];
            x=1;
          }
        }
        if(x==1){
          sum-=10;
        }
        sum+=abs(b-sum1);
        sum1=0,x=0;
        for(m=0;m<n;m++){
          if(k&(1<<m)){
            sum+=10;
            sum1+=l[m];
            x=1;
          }
        }
        if(x==1){
          sum-=10;
        }
        sum+=abs(c-sum1);
        if(ans>sum){
          ans=sum;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static boolean[] prime = new boolean[50001];
	static int n;
	public static void main(String[] args) {
		make_prime();
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		return true;
	}
	
	static void solve(){
		int res = 0;
		for(int i = 2; i <= n/2; i++){
			if(prime[i] && prime[n - i]){
				res++;
			}
		}
		System.out.println(res);
	}
	
	static void make_prime(){
		Arrays.fill(prime, true);
		prime[0] = false;
		prime[1] = false;
		for(int i = 2; i < prime.length; i++){
			if(prime[i]){
				for(int j = 2*i; j < prime.length; j += i){
					prime[j] = false;
				}
			}
		}
	}

}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int calculate_digits_total(int x) {
	int digits_total = 0;
	while (x) {
		digits_total += x % 10;
		x /= 10;
	}

	return digits_total;
}


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

	vector<LL> L(N+1);
	L[0] = 2;
	L[1] = 1;
	for (int i = 2; i <= N; i++) {
		L[i] = L[i - 1] + L[i - 2];
	}
	cout << L[N] << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
robots = []
for _ in range(N):
    x, l = map(int, input().split())
    robots.append((x-l, x+l))
robots = sorted(robots, key=lambda x: x[1])

x_max = -10**10
ans = 0
for s, t in robots:
    if s < x_max:
        continue
    ans += 1
    x_max = t
print(ans)

Measured memory_bytes: 19028
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(s,x);
  REP(i,s.size()){
    if(i >= x) break;
    if(s[i]!='1'){
      OUT(s[i]);
      return 0;
    }
  }
  OUT(1);
}

Measured memory_bytes: 256
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}



Measured memory_bytes: 1368
import Control.Applicative

main :: IO ()
main = do
  ns <- map words . lines
        <$> getContents
  mapM_ (print . f) ns

f :: [String] -> Int
f (x:y:_) = gcd' (read x) (read y)

gcd' :: Int -> Int -> Int
gcd' x y = go (max x y) (min x y)
  where
    go a b 
      | b == 0 = a
      | otherwise = go b (a `mod` b)

Measured memory_bytes: 3908
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n;
pa a[N];
ll s,pre[N];

inline int Find(int x,int pos){
	int l=1,r=n,ans=0;
	while (l<=r){
		int mid=l+r>>1;
		if (pre[mid]-(pos<=mid)*max(a[pos].fi,a[pos].se)>=s-x) ans=mid,r=mid-1;
			else l=mid+1;
	}
	return ans;
}

inline PA min(PA a,PA b){
	if ((__int128)a.fi*b.se<(__int128)a.se*b.fi) return a;
	return b;
}

int main(){
	n=read();
	For(i,1,n) a[i].fi=read(),a[i].se=read(),s+=a[i].fi;
	sort(a+1,a+1+n,[](pa a,pa b){
		return max(a.fi,a.se)>max(b.fi,b.se);
	});
	For(i,1,n) pre[i]=pre[i-1]+max(a[i].fi,a[i].se);
	PA ans=mp(1000000000,1);
	For(i,1,n){
		int ret=Find(a[i].se,i);
		if (ret==0) continue;
		ll p=s-(pre[ret]-max(a[i].fi,a[i].se)*(i<=ret));
		if (p<0) continue;
		if (i<=ret) --ret;
		ans=min(ans,mp(1ll*ret*a[i].se+p,a[i].se));
	}
	ans.se*=n,ans.fi=ans.se-ans.fi;
	if (ans.fi<=0) return puts("0 1"),0;
	ll g=__gcd(ans.fi,ans.se);
	printf("%lld %lld\n",ans.fi/g,ans.se/g);
}

Measured memory_bytes: 5360
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll x,y,z,k;cin >> x >>y >>z >>k;
    vl a(x),b(y),c(z);
    rep(i,x)cin >> a[i];
    rep(i,y)cin >> b[i];
    rep(i,z)cin >> c[i];
    sort(all(a));sort(all(b));sort(all(c));
    rev(all(a));rev(all(b));rev(all(c));
    priority_queue<pl,vpl,less<pl>> que;
    unordered_map<ll,ll> ma;
    que.push({a[0]+b[0]+c[0],0});
    ma.ins({0,1});
    rep(i,k){
        pl p=que.top();
        ll num=p.se;
        que.pop();
        cout << p.fi <<endl;
        rep(i,3){
            ll d=pow(1000,i);
            if(ma.count(num+d))continue;
            ma.ins({num+d,1});
            ll qq=d+num;
            ll one=qq%1000;
            qq/=1000;
            ll two=qq%1000;
            qq/=1000;
            if(one>=x||two>=y||qq>=z)continue;
            que.push(mp(a[one]+b[two]+c[qq],num+d));
        }
    }
}

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

int N;
const int MAX_N = 200005;
int as[MAX_N];
int ac[MAX_N], bcc[MAX_N];
std::vector<std::pair<int, int>> bccc;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    as[i] = v;
    ac[v]++;
  }
  for (int i = 0; i < N; ++i) {
    int v;
    scanf("%d", &v);
    bcc[v]++;
  }
  for (int i = 0; i < MAX_N; ++i) {
    if (bcc[i]) bccc.push_back({i, bcc[i]});
  }
  bool doable = true;
  for (auto& kv: bccc) {
    if (kv.second + ac[kv.first] > N) {
      doable = false;
      break;
    }
  }
  if (!doable) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  std::vector<int> ans;
  while (1) {
    auto bc = bccc;
    std::random_shuffle(bc.begin(), bc.end());
    auto iter = bc.begin();
    ans.clear();
    int idx = 0;
    while (bc.size()) {
      int to_remove = -1;
      if (iter->first == as[idx]) {
        iter++;
        if (bc.size() == 1) break;
        if (iter == bc.end()) iter = bc.begin();
      }
      while (as[idx] != iter->first) {
        idx++;
        iter->second--;
        ans.push_back(iter->first);
        if (iter->second == 0) {
          to_remove = iter->first;
          break;
        }
      }
      if (to_remove >= 0) {
        std::swap(*iter, *(--bc.end()));
        bc.pop_back();
        iter = bc.begin();
      }
    }
    if (ans.size() == N) break;
  }
  for (int i : ans) printf("%d ", i);
  printf("\n");
}


Measured memory_bytes: 10428
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

int a[1000000], b[1000000];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n){
		scanf("%lld", &a[i]);
		b[i] = a[i];
	}
	sort(b, b+n);
	int mn = b[n/2-1], mx = b[n/2];
	rep(i,n){
		if(a[i] <= mn)printf("%lld\n", mx);
		else printf("%lld\n", mn);
	}
	return 0;
}


Measured memory_bytes: 7808
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define endl "\n"
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
using namespace std;

void solve()
{
    ll n;
    cin>>n;
    if(n%2 == 0)
    {
        cout<<"-1";
        return ;
    }
    ll k = 7;
    ll cnt = 1;
    while(true)
    {
        if(k%n == 0)
        {
            cout<<cnt;
            break;
        }
        if(cnt > n)
        {
            cout<<"-1";
            break;
        }
        k = (k%n)*10 +7;
        ++cnt;
    }
}
int main()
{
    hs;
    ll t;
    t=1;

    for (int i=1; i<=t; i++)
    {
        solve();
    }
}




Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
	double r, are, circ, pi;
	scanf("%lf¥n", &r);
	pi = 3.141592653589;
	are = pi*r*r;
	circ = 2 * pi*r;
	printf("%f %f", are, circ);
	return 0;
}


Measured memory_bytes: 2692
matrix = []
H, W = map(int, input().split())
for h in range(H):
    matrix.append(list(input()))

for i in range(H):
    for j in range(W):
        if matrix[i][j] == '#': continue
        cnt = 0
        if H > i - 1 >= 0 and W > j - 1 >= 0:
            if matrix[i - 1][j - 1] == '#':
                cnt += 1
        if H > i - 1 >= 0 and W > j >= 0:
            if matrix[i - 1][j] == '#':
                cnt += 1
        if H > i - 1 >= 0 and W > j + 1 >= 0:
            if matrix[i - 1][j + 1] == '#':
                cnt += 1
        if H > i >= 0 and W > j - 1 >= 0:
            if matrix[i][j - 1] == '#':
                cnt += 1
        if H > i >= 0 and W > j + 1 >= 0:
            if matrix[i][j + 1] == '#':
                cnt += 1
        if H > i + 1 >= 0 and W > j - 1 >= 0:
            if matrix[i + 1][j - 1] == '#':
                cnt += 1
        if H > i + 1 >= 0 and W > j >= 0:
            if matrix[i + 1][j] == '#':
                cnt += 1
        if H > i + 1 >= 0 and W > j + 1 >= 0:
            if matrix[i + 1][j + 1] == '#':
                cnt += 1
        matrix[i][j] = cnt

for h in range(H):
    r = ''
    for w in range(W):
        r += str(matrix[h][w])
    print(r)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;



void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  rep(i,n) {
    ll a;
    cin >> a;
    a--;
    sum += a;
  }
  cout << sum << endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>
#include<float.h>

#define NUM 100001

int step(int n, int i, int m, int *ans){
	if(i==-1) return 0;
	else if (i==0) return 1;
	else if (ans[i] != -1) return ans[i];
	else return ans[i] = (step(n, i - 1, m, ans) + step(n, i - 2, m, ans)) % 1000000007;
}

int main(){
	int n, m, ans[NUM], a;
	scanf("%d%d\n", &n, &m);
	for(int i=0; i<n+1; i++){
		ans[i] = -1;
	}
	for(int i=0; i<m; i++){
		scanf("%d", &a);
		ans[a] = 0;
	}
	printf("%d\n", step(n, n, m, ans));
	return 0;
}

Measured memory_bytes: 6784
import math
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n,x = list(map(int, input().split()))
pos = list(map(int, input().split()))

pos.append(x)
pos.sort()

dist = []
for i in range(len(pos)-1):
    dist.append(pos[i+1]-pos[i])

print(gcd_list(dist))

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

int main()
{
  int i;

  while(cin >> i && i != 0){
    int a[32];
    int n = 32;
    for (int j = 0; j < i; j++){
      cin >> a[j];
    }
    int j = 0;
    while (n > 0){
      n -= (n - 1) % 5;
      cout << n << endl;
      n -= a[j++];
      if (j == i) j = 0;
      if (n < 0) n = 0;
      cout << n << endl;
    }
  }
}

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

using namespace std;

int N;
long long A[200005];

long long kanashisa(int b) {
    long long ret = 0;
    for (int i = 0; i < N; i++) {
        ret += abs(A[i]-(b+i+1));
    }
    return ret;
}

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

    long long l = -2e9;
    long long r = 1e9;
 
    while (r - l >= 3) {
        long long m0 = (l * 2 + r) / 3;
        long long m1 = (l + r * 2) / 3;
 
        if (kanashisa(m0) < kanashisa(m1)) {
            r = m1;
        } else {
            l = m0;
        }
    }

    long long ans;

    for (int i = -10; i <= 10; i++) {
        long long cur = kanashisa(l+i);
 
        if (i == -10) { ans = cur; }
        else { ans = min(ans, cur); }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  cin>>n;
  int cnt=0;
  int now=0;
  int front=0;
  int rear=n-1;
  char ns[100];
  while(cnt<20){
    printf("%d\n",now);
    fflush(stdout);
    char str[100];
    scanf(" %s",str);
    if(strcmp(str,"Vacant")==0)break;
    if(cnt==0){
      now=(front+rear)/2;
      strcpy(ns,str);
    }else{
      if(strcmp(str,"Female")==0){
	if((now-front)%2==0){
	  if(strcmp(ns,"Female")==0){
	    strcpy(ns,"Female");
	    front=now;
	  }else{
	    //strcpy(ns,"Male");
	    rear=now;
	  }
	}else{
	  if(strcmp(ns,"Female")==0){
	    //strcpy(ns,"Female");
	    rear=now;
	  }else{
	    strcpy(ns,"Female");
	    front=now;
	  }
	}
      }else{
	if((now-front)%2==0){
	  if(strcmp(ns,"Female")==0){
	    //strcpy(ns,"Female");
	    rear=now;
	  }else{
	    strcpy(ns,"Male");
	    front=now;
	  }
	}else{
	  if(strcmp(ns,"Female")==0){
	    strcpy(ns,"Male");
	    front=now;
	  }else{
	    //strcpy(ns,"Male");
	    rear=now;
	  }
	}
      }
      if(rear-front==1)now=rear;
      else now=(front+rear)/2;
    }
    cnt++;
  }
  return 0;
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
#define int long long
signed main(){
  int X;
  cin >> X;
  for(int i = 0;i < 1000;i++){
    for(int j = 0;j < 1000;j++){
      if(i*i*i*i*i - j*j*j*j*j == X){cout << i << " " << j;return 0;}
      i *= -1;
      if(i*i*i*i*i - j*j*j*j*j == X){cout << i << " " << j;return 0;}
      j *= -1;
      if(i*i*i*i*i - j*j*j*j*j == X){cout << i << " " << j;return 0;}
      i *= -1;
      if(i*i*i*i*i - j*j*j*j*j == X){cout << i << " " << j;return 0;}
      j *= -1;
    }
  }
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
vector<pair<int,int>> vp;
pair<int,int> pp;
vector<int> vv,vv1;
map<int,int> mp;
int mat[502][502];
int main()
{
    string s,ss;
    cin>>s>>ss;
    int ln1 = s.size();
    int ln2 = ss.size();
    int dp[ln1+2][ln2+1];

    for(int i=0; i<=ln1; i++){
        for(int j=0; j<=ln2; j++){
            if(i==0 || j==0)dp[i][j]=0;
            else if(s[i-1]==ss[j-1]){
                dp[i][j] = 1+dp[i-1][j-1];
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int ln = dp[ln1][ln2];
    int ln3 = ln;
    char ara[ln];
    int i = ln1,j=ln2,k=0;
    while(i!=0 and j!=0){
        if(s[i-1] == ss[j-1]){
            ara[ln-1] = s[i-1];
            i--,j--,ln--;
        }
        else if(dp[i][j-1]>=dp[i-1][j]){
            j--;
        }else i--;
    }
    for(int i=0; i<ln3; i++)cout<<ara[i];
    cout<<"\n";
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;

	vector<tuple<string, int, int>> restraunt(N);
	for (int i = 0; i < N; ++i) {
		string S;
		int P;
		cin >> S >> P;
		restraunt[i] = make_tuple(S, 100 - P, i + 1);
	}

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

	for (int i = 0; i < N; ++i) {
		cout << get<2>(restraunt[i]) << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
	#define dbg(x) cout << #x << " : " << x << endl;
#else 
	#define dbg(x)
#endif

#define int long long
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	
bool cmp(const pii &a, const pii & b) {
	return (a.second - a.first) < (b.second - b.first);
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int s = 0;
    vpii pl;
    vpii mn;
    int n;
    cin >> n;
    fi(0, n) {
    	str st;
    	cin >> st;
    	pii cur = {0, 0};
    	fx(x, st) {
    		if (x == '(')
    			++cur.second;
    		else
    			--cur.second;
    		mine(cur.first, cur.second);
    	}
    	if (cur.second >= 0)
    		pl.push_back(cur);
    	else
    		mn.push_back(cur);
    } 
    sort(all(pl));
    //cout << "pl :\n";
    while (!pl.empty()) {
    	//cout << pl.back().first << ' ' << pl.back().second << '\n';
    	if (s + pl.back().first < 0) {
    		cout << "No\n";
    		return 0;
    	}
    	s += pl.back().second;
    	pl.pop_back();
    }
    sort(all(mn), cmp);
    while (!mn.empty()) {
    	if (s + mn.back().first < 0) {
    		cout << "No\n";
    		return 0;
    	}
    	s += mn.back().second;
    	mn.pop_back();
    }
    cout << (s == 0 ? "Yes\n" : "No\n");
}

Measured memory_bytes: 18996
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		map<ll, int> m;
		ll x, pre = -1, maxn = -1, squ = -1;
		for (int i = 0; i < n; i++)
		{
			scanf("%lld", &x);
			m[x]++;
		}
		for (map<ll,int>::iterator it = m.begin(); it!=m.end(); it++)
		{
			if (it->second>1&&it->first>maxn)
			{
				pre = maxn;
				maxn=it->first;
			}
			if (it->second>3&&it->first>squ) squ = it->first;
		}
		ll rec = maxn*pre, squre = squ*squ;
		if ((~maxn||~pre)||~squ) printf("%lld\n", rec>squre?rec:squre);
		else printf("0\n");
	}
}


Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << ((a + b) * h) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        final int MOD = (int)1e9+7;
        
        int n = Integer.parseInt(sc.next());
        long k = Long.parseLong(sc.next());
        
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        Inversion in = new Inversion();
        int[] zaatu = in.zaatu(a);
        int[] revzaatu = new int[n];
        for(int i=0; i<n; i++){
            revzaatu[n-i-1] = zaatu[i];
        }
        long nt = in.inv(zaatu, MOD);
        long rv = in.inv(revzaatu, MOD);
        
        //System.out.println(nt + " : " + rv);
        //
        long s = (k+1)%MOD*(k%MOD)/2%MOD;
        long t = (k-1)%MOD*(k%MOD)/2%MOD;
        
        long ans1 = s*nt%MOD;
        long ans2 = t*rv%MOD;
        
        System.out.println((ans1+ans2)%MOD);
    }
}

class Inversion{
    public long inv(int[] a, int mod){
        long cnt = 0;
        int size = a.length;
        BinaryIndexedTree bit = new BinaryIndexedTree(size);
        
        for(int i=0; i<size; i++){
            int p = a[i];
            bit.add(p, 1);
            cnt += i + 1 - bit.sum(p);
            cnt %= mod;
        }
        return cnt;
    }
    
    //座圧(1-indexed)
    //使うとよい
    public int[] zaatu(int[] a){
        ArrayList<Integer> b = new ArrayList<>();
        for(int tmp : a){
            b.add(tmp);
        }
        
        b = new ArrayList<Integer>(new HashSet<>(b));
        Collections.sort(b);
        
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i=0; i<b.size(); i++){
            map.put(b.get(i), i);
        }
        
        int[] c = new int[a.length];
        for(int i=0; i<a.length; i++){
            c[i] = map.get(a[i])+1;
        }
        
        return c;
    }
}

class BinaryIndexedTree{
    int size;
    long[] tree;
    
    public BinaryIndexedTree(int n){
        this.size = n;
        this.tree = new long[n+1];
    }
    
    public long sum(int i){
        long s = 0L;
        while(0<i){
            s += tree[i];
            i -= i & -i;
        }
        return s;
    }
    
    public void add(int i, int x){
        while(i<=size){
            tree[i] += x;
            i += i & -i;
        }
    }
}


Measured memory_bytes: 24708
#include<iostream>
#include<string>
#include<algorithm>

typedef long long ll;
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a * b < c * d) {
		cout << c * d << endl;
	}
	if (a * b > c * d) {
		cout << a * b << endl;
	}
	if (a * b == c * d) {
		cout << a * b << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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

	ll N, M, K;
	string S;

	cin >> N >> S;

	ll W = 0;
	ll B = 0;

	rep(i, N) {
		if (S[i] == '.')W++;
		if (S[i] == '#')B++;
	}

	ll min = W;
	B = 0;

	rep(i, N) {
		if (S[i] == '.')W--;
		if (S[i] == '#')B++;
		if (min > (W + B)) {
			min = (W + B);
		}
	}


	cout << min << endl;


	
	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int h = 999983;
const int mod = 1e9+7;
char w[500005];
LL p[500005], val[500005];
vector<int> v[500005];
LL check(int s, int e){
    return (val[e]-val[s-1]+mod)%mod*p[500000-e]%mod;
}

bool check2(int s, int e){
    int l = e-s+1;
    for(int i=0;i<v[l].size();i++){
        int d = v[l][i];
        if(check(s, e-d) != check(s+d, e)) continue;
        return 0;
    }
    return 1;
}

int main(){
    scanf("%s", w+1);
    int n = strlen(w+1);
    bool ok = 1;
    for(int i=2;i<=n;i++){
        if(w[i] != w[i-1]) ok = 0;
    }
    if(ok){
        printf("%d\n1\n", n);
        return 0;
    }
    p[0] = 1;
    for(int i=1;i<=500000;i++) p[i] = p[i-1]*h%mod;
    for(int i=1;i<=n;i++) val[i] = (val[i-1] + p[i]*w[i])%mod;
    for(int i=1;i<=n;i++) for(int j=i+i;j<=n;j+=i) v[j].push_back(i);
    if(check2(1, n)){
        printf("1\n1\n");
        return 0;
    }
    int ans = 0;
    for(int i=1;i<n;i++){
        if(check2(1, i) && check2(i+1, n)) ans++;
    }
    printf("2\n%d\n", ans);
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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 ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    double a,b,x;cin>>a>>b>>x;
    double v=a*a*b;
    if(v/2<=x){
        double h=x/a/a;
        double y=2*(b-h);
        cout<<fixed<<setprecision(10)<<180/acos(-1)*atan(y/a)<<endl;
    }
    else{
        double A=x/a,t;
        t=2*A/b;
        cout<<fixed<<setprecision(10)<<180/acos(-1)*atan(b/t)<<endl;
    }
}

Measured memory_bytes: 384
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    def rec(s):
        if int(s) > N:
            return 0
        ans = 0
        if all(c in s for c in '357'):
            ans += 1
        for c in '357':
            ans += rec(s + c)
        return ans

    ans = rec('0')
    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
c = {}

for i in range(3):
    ci0,ci1,ci2 = list(map(int,input().split()))
    c[(i,0)] = ci0 
    c[(i,1)] = ci1
    c[(i,2)] = ci2


for ai in range(101):
    a = {0:ai}
    b ={}
    
    for i in range(3):
        for j in range(3):
            if (i in a) and (j in b):
                if a[i]+b[j] != c[(i,j)]:
                    break
                else:
                    pass
            elif (i in a) and (not j in b):
                b[j] = c[(i,j)] - a[i]
            elif (not i in a) and (j in b):
                a[i] = c[(i,j)] - b[j]
            if i==2 and j==2:
                print('Yes')
                exit()
        else:
            continue
        break

print('No')
                
            

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

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

void solve() {
    int N; cin >> N;
    vector<int> v(N + 1);
    mfor(i, 0, N - 2) {
        int A; cin >> A;
        v[A]++;
    }
    mfor(i, 1, N)
        cout << v[i] << '\n';
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>

static const int MAX = 200000;
static const int MAX_INT = 2147483647;

int A[MAX+2];
int L[MAX/2+2], R[MAX / 2 + 2];
long long sum=0;

void merge(int A[], int left, int mid, int right)
{
	int n1, n2, i, j;
	n1 = mid - left;
	n2 = right - mid;
	for (i = 0; i < n1; i++)
	{
		L[i] = A[i + left];
	}

	for (i = 0; i < n2; i++)
	{
		R[i] = A[i + mid];
	}
	L[n1] = MAX_INT;
	R[n2] = MAX_INT;
	i = j = 0;
	for (int k = left; k < right; k++)
	{
		if (L[i] <= R[j])
			A[k] = L[i++];
		else
		{
			sum += n1 - i;
			A[k] = R[j++];
		}
	}
	
}

void mergeSort(int A[], int left, int right)
{
	int mid;
	if (left + 1 < right)
	{
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main()
{
	int n, i;

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

	mergeSort(A, 0, n);

	printf("%lld\n", sum);

	return 0;
}


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

#define all(v) begin(v), end(v)
#define endl '\n';
#define int long long
#define pii pair<int, int>

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

    int a[6];
    for (int i = 1; i <= 5; i++) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << i << endl;
            return 0;
        }
    }

}

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

#define ll long long
#define pb push_back
#define vi vector<int>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);

int main() {
    fastio;

    int n;
    cin >> n;
    int A[n];
    int sum = 0;
    FOR(i, 0, n) {
        cin >> A[i];
        sum += A[i];
    }
    int size = sizeOf(A);
    sort(A, A + size);
    int i = 0;
    while (sum % 10 == 0 && i < n) {
        if (A[i] % 10 != 0) {
            sum -= A[i];
        }
        i++;
    }
    if (sum % 10 != 0) {
        cout << sum << "\n";
    } else {
        cout << 0 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Bot{
    int x = 1, y = 1 , dir = 0;
    private int width, height;
     
    private int[][] xy = {
            {0,1},{1,0},{0,-1},{-1,0}
    };
     
    public Bot(int w, int h) {
        width = w;
        height = h;
    }
     
     
    public void  forward(int step){
        x += xy[dir][0]*step;
        y += xy[dir][1]*step;
        beProperly();
    }
     
    public void backward(int step){
        x -= xy[dir][0]*step;
        y -= xy[dir][1]*step;
        beProperly();
    }
     
    public void right(){
        dir = (dir+1)%4;
    }
     
    public void left(){
        if(--dir == -1) dir = 3;
    }
     
    private void beProperly(){
        if(x > width) x = width;
        if(y > height) y = height;
        if(x < 1) x = 1;
        if(y < 1) y = 1;
    }
}
 
 
public class Main {
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);
 
        while(true){
            int w = sn.nextInt(), h = sn.nextInt();
            if(w == 0 && h == 0) break;
            Bot bot = new Bot(w, h);
            while(true){
 
                String cmd = sn.nextLine();
                String[] go = cmd.split(" ");
                String dir;
                 
                if(go.length == 2){
                    int step = new Integer(go[1]);
                    if(go[0].equals("FORWARD")) bot.forward(step);
                    else if(go[0].equals("BACKWARD")) bot.backward(step);
                } else{
                     
                    if(go[0].equals("RIGHT")) bot.right();
                    else if(go[0].equals("LEFT")) bot.left();
                    else if(go[0].equals("STOP")) break;
                }
            }
            System.out.println(bot.x+" "+bot.y);
        }      
    }
}

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

const int N = 200005;
int dp[N], vet[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++){
		scanf("%d", &vet[i]);
	}
	int mx = -1;
	for (int i=n-2; i>=0; i--){
		dp[i] = max(vet[i+1], dp[i+1]);
	}
	for (int i=0; i<n; i++){
		printf("%d\n", max(mx, dp[i]));
		mx = max(vet[i], mx);
	}
}


Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

ll gcd(ll n, ll m){

    if(m > n)  return gcd(m, n);

    ll r = n % m;
    if(r == 0) return m;
    else       return gcd(m, r);
}

ll lcm(ll n, ll m){
    return n / gcd(n, m) * m;
}


int main(){

    ll n, m; cin >> n >> m;

    string s, t; cin >> s >> t;

    if(n > m){
        swap(n, m);
        swap(s, t);
    }

    ll l = lcm(n, m);
    ll dn = l/n;
    ll dm = l/m;
    ll d = lcm(dn, dm);

    bool okflag = true;
    ll now = 0;
    while(now < l){

        if(s[now/dn] != t[now/dm]){
            okflag = false;
            break;
        }

        now += d;
    }

    cout << (okflag ? l : -1) << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef struct{
  long long first,second;
  long long place;
}PA;
vector<PA> vec;

void east(int n,long long place){
  if(vec[n].second == 1){
    vec[n].place = place;
    east(n-1,place);
  }
}

void west(int n,long long place){
  if(vec[n].second == 2){
    vec[n].place = place;
    west(n+1,place);
  }
}

int main(){
  int n,q,b,c;
  long long t,a;
      
  scanf("%d %lld %d",&n,&t,&q);
  
  for(int i=0;i<n;i++){
    scanf("%lld %d",&a,&b);
    vec.push_back( (PA){a,b,LLONG_MAX});
  }
  
  for(int i=0;i<n-1;i++){
    if( vec[i].second == 1 && vec[i+1].second == 2){
      vec[i].place = (vec[i].first+vec[i+1].first)/2;
      east(i-1,vec[i].place);
      west(i+1,vec[i].place);
    }
  }

  for(int i=0;i<q;i++){
    scanf("%d",&c);
    c--;
    
    if(vec[c].place == LLONG_MAX || llabs(vec[c].first-vec[c].place) > t){
      if(vec[c].second == 1) cout << vec[c].first+t << endl;
      if(vec[c].second == 2) cout << vec[c].first-t << endl;
    } else cout << vec[c].place << endl;
  }
  return (0);
}

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

using ll=long long;
const int inf=100000000;

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//(x,y) int型配列x[y]の受け取り

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) xの絶対値

int fact(int x){
  if (x == 1) return 1;
  return x*fact(x-1);
}//(x) x!

int fib(int x){
  if (x <= 2) return x;
  int a[x];
  a[0]=1;
  a[1]=2;
  for (int i=2;i<x;i++){
    a[i]=a[i-1]+a[i-2];
  }
  return a[x-1];
}//(x) フィボナッチ数列のx番目

int div1(ll x){
  return x%1000000007;
}

main(){
    int a=in();
    string s;
    cin >> s;
    if (a<3200) cout << "red" << endl;
    else cout << s << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
	char a[17];
	char s[]="CODEFESTIVAL2016";;
	int b;
	scanf("%s", a);
	for (int i = 0; i < 16; i++){
		if(a[i] != s[i]) b++;
	}
	printf("%d", b);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
  int w,h;

  while(true){
    cin >> w >> h;

    if((w==0) && (h==0))
      break;

    for(int i=0;i<w;i++){
      for(int j=0;j<h;j++){
	if((i%2==0) && (j%2==0))
	  cout << '#';
	else if((i%2==1) && (j%2==1))
	  cout << "#";
	else
	  cout << '.';
      }
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int digit(ll n) {
    int cnt = 0;
    while (n)
        n /= 10, cnt++;
    return cnt;
}

int main() {
    ll N;
    cin >> N;
    for (int i = sqrt(N); i >= 1; --i) {
        if (N % i)
            continue;
        cout << max(digit(i), digit(N / i)) << endl;
        break;
    }
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  
  //first trial
  if (a >= b) {
    ans += a;
    a -= 1;
  }
  else {
    ans += b;
    b -= 1;
  }
  
  //second trial
  if (a >= b) {
     ans += a;
  }
  else {
     ans += b;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(time(NULL));

const int D = 365, N = 26;
int d;
ll c[N+1];
ll s[D+1][N+1];
ll last[N];
int contest[D];

ll calc(int idx, int x) {
	ll ans = 0;
	ll l = idx-1, r = idx+1;
	ll len, len2;
	while(l > 0 && contest[l] != contest[idx]) l--;
	len = idx - l;
	while(r <= d && contest[r] != contest[idx]) r++;
	len2 = r - idx;
	ans -= s[idx][contest[idx]];
	ans -= c[contest[idx]] * len * len2;
	ll tmp = contest[idx];
	contest[idx] = x;

	l = idx-1, r = idx+1;
	while(l > 0 && contest[l] != contest[idx]) l--;
	len = idx - l;
	while(r <= d && contest[r] != contest[idx]) r++;
	len2 = r - idx;
	ans += s[idx][x];
	ans += c[x] * len * len2;
	contest[idx] = tmp;
	return ans;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> d;
	for(int i = 1; i <= N; i++)
		cin >> c[i];
	for(int i = 1; i <= d; i++) {
		for(int j = 1; j <= N; j++)
			cin >> s[i][j];
	}
	memset(last, 0, sizeof last);
	ll ans = 0;
	for(int i = 1; i <= d; i++) {
		ll penalty = 0;
		for(int j = 1; j <= 26; j++)
			penalty += c[j] * (last[j] - i);
		ll best = -1, idx = -1;
		for(int j = 1; j <= 26; j++) {
			ll cur = s[i][j] - penalty + c[j] * (i - last[j]);
			if(best < cur)
				best = cur, idx = j;
		}
		last[idx] = i;
		ans += best;
		contest[i] = idx;
	}

	for(int i = 0; i < 3000000; i++) {
		int idx = rng() % d + 1;
		int to = rng() % N + 1;
		while(to == contest[idx]) to = rng() % N + 1;
		ll change = calc(idx, to);
		if(change > 0) {
			contest[idx] = to;
			ans += change;
		}
	}

	for(int i = 1; i <= d; i++)
		cout << contest[i] << '\n';

	return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF=INT_MAX;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))



int main(){
	int N;
	while(cin>>N){
		if(N==0)break;
		
		vector< vector<int> > stage( N, vector<int>(N+1,0) );
		REP(i,N)REP(j,N+1){
			cin>>stage[i][j];
		}
		vector<int> dp(1<<N, INF);
		dp[0] = 0;
		REP(bits,1<<N){//??¨????????¶???????????????
			REP(i,N){
				if(bits&(1<<i))continue;//??????????????¢??????
				int cost=stage[i][0];
				REP(j,N){
					if((bits&(1<<j))==0)continue;//?????????
					cost=min(cost,stage[i][j+1]);
				}
				int now=(bits|(1<<i));
				dp[now]=min(dp[now],dp[bits]+cost);
			}
		}
		cout<<dp[(1<<N)-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1476