akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, W[100], L[100], R[100], res;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> W[i];
	}
	L[0] = W[0];
	for (int i = 1; i < N; ++i) {
		L[i] = L[i - 1] + W[i];
	}
	R[N - 1] = W[N - 1];
	for (int i = N - 2; i >= 0; --i) {
		R[i] = R[i + 1] + W[i];
	}
	res = intmax;
	for (int i = 0; i < N - 1; ++i) {
		res = min(res, abs(L[i] - R[i + 1]));
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    int n, len;
    char s[10005];
    scanf("%d", &n);
    scanf("%s", s);
    len = strlen(s);
    for(int i = 0; i < len; i++){
        s[i] += n;
        if(s[i] > 'Z'){
            s[i] = s[i] -('Z' - 'A' + 1);
        }
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#l = list(map(int, input().split()))

n,k = map(int, input().split())

ans = 0
while 1:
    n = n // k
    ans += 1
    if (n == 0):
        break

print(ans)


Measured memory_bytes: 9072
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
const int maxn = 200005;

int n,K,a[maxn];
struct BIT {
  int c[maxn];
  int lowbit(int x) {
    return x&(-x);
  }
  void add(int pos) {
    while(pos<maxn) {
      c[pos]++;
      pos+=lowbit(pos);
    }
  }
  int sum(int pos) {
    int ret=0;
    while(pos>0) {
      ret+=c[pos];
      pos-=lowbit(pos);
    }
    return ret;
  }
} bit;
ll sum[maxn];
int idx[maxn];
bool cmp(int x,int y) {
  if(sum[x]==sum[y])return x>y;
  return sum[x]>sum[y];
}

int main() {
#ifdef suiyuan2009
  freopen("in.cpp","r",stdin);
#endif
  cin>>n>>K;
  for(int i=1; i<=n; i++) {
    cin>>a[i];
    sum[i]=sum[i-1]+a[i];
  }
  for(int i=1; i<=n; i++)sum[i]-=i*(ll)K;
  for(int i=1; i<=n; i++)idx[i]=i;
  sort(idx+1,idx+n+1,cmp);
  ll ret=0;
  for(int i=1;i<=n;i++){
    int tt=idx[i];
    ret+=bit.sum(n)-bit.sum(tt);
    bit.add(tt);
  }
  for(int i=1;i<=n;i++)if(sum[i]>=0)ret++;
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 4096
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

const int mod = 1'000'000'007;

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int a[209];

const int N = 100'009;

int f[N];
int nf[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  reverse(a, a + n);
  memset(f, 0, sizeof f);
  f[m] = 1;
  for (int i = 0; i < n; ++i) {
    memset(nf, 0, sizeof nf);
    for (int j = 0; j <= m; ++j) {
      add(nf[j % a[i]], f[j]);
      add(nf[j], mul(f[j], max(0, n - (i + 1))));
    }
    memcpy(f, nf, sizeof f);
  }
  int ans = 0;
  for (int i = 0; i <= m; ++i) {
    add(ans, mul(f[i], i));
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;


int main() {
  for (int N; cin >> N, N != 0; ) {
    int grid[21][21];
    rep(i, 21) rep(j, 21) grid[i][j] = 0;

    rep(i, N) {
      int x, y; cin >> x >> y;
      grid[y][x] = 1;
    }

    int x = 10, y = 10;
    int ans = 0;

    int M; cin >> M;
    rep(i, M) {
      char D;
      int L;
      cin >> D >> L;

      int d;
      if (D == 'N') d = 0;
      if (D == 'E') d = 1;
      if (D == 'S') d = 2;
      if (D == 'W') d = 3;
      int dx[] = {0, 1, 0, -1};
      int dy[] = {1, 0, -1, 0};

      rep(i, L) {
        x += dx[d];
        y += dy[d];

        ans += grid[y][x];
        grid[y][x] = 0;
      }
    }

    if (ans == N) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  
  return 0;
}

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

int main(void){
   ll N,L;
   cin>>N>>L;
   ll sum=0;
   rep(0,i,N){
       sum+=i+L;
   }
   ll min=1000;
   ll ans;
   rep(0,i,N){
       ll sum0=0;
       rep(0,j,N){
           if(i!=j)sum0+=j+L;
       }
       //cout<<sum0<<endl;
        if(min>abs(sum-sum0)){
            min=abs(sum-sum0);
            ans=sum0;
        }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
a = []
for _ in range(H):
    a.append(input())
queue = deque([])
dist = [[-1 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            queue.append([i,j])
            dist[i][j] = 0
dh = [0, 0, 1, -1]
dw = [1, -1, 0, 0]
while len(queue) != 0:
    now = queue.popleft()
    h = now[0]
    w = now[1]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if nh < 0 or nw < 0 or nh >= H or nw >= W:
            continue
        elif dist[nh][nw] == -1:
            dist[nh][nw] = dist[h][w] +1
            queue.append([nh, nw])
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dist[i][j])
print(ans)

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

int main() {
  int N, D;
  cin >> N >> D;
  int ans = 0;
  rep(i, 0, N) {
    int x, y;
    cin >> x >> y;
    if (sqrt(pow(x, 2) + pow(y, 2)) <= D) ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3676
import bisect
from collections import defaultdict

S=input()
T=input()

def solve():
    obj=defaultdict(list)
    for i,s in enumerate(S):
        obj[s].append(i)

    result=1
    mx=-1
    for t in T:
        flag=True

        if not obj[t]:
            return -1

        
        bi_pos=bisect.bisect_right(obj[t],mx)
        if bi_pos==len(obj[t]):
            pos=-1
            mx=obj[t][0]
            result+=1
        else:
            pos=obj[t][bi_pos]
            mx=pos

    if pos==-1:
        pos=obj[t][0]
    return len(S)*(result-1)+pos+1
print(solve())


Measured memory_bytes: 45936
import java.util.Scanner;

public class Main {

	public static void main(String[] aggs){

	Scanner stdIn = new Scanner(System.in);
	int N = stdIn.nextInt();
	int X = stdIn.nextInt();
	int T = stdIn.nextInt();

	int i=0;
	int t=0;

	for(i=0;i<N;i=i+X) {
		t=t+T;
	}

	System.out.println(t);

	}
}


Measured memory_bytes: 26904
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

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

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

  int a, b;
  cin >> a >> b;

  int current = 1;
  int count = 0;

  rep(i, 20) {
    if (current >= b) {
      cout << count << endl;
      break;
    } else {
      current += a - 1;
      count++;
    }
  }

  return 0;
}


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

#define pi acos(-1)
using namespace std;
int main(){
   string s,t;
    cin >> s >> t;
    for(int i=0;i<s.size(); i++){
       if(s[i]!=t[i]){
            cout << "No" << endl;
            return 0;
           }
    }
        cout << "Yes" << endl;    
        return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main() {
  int n;
  while(cin >> n) {
    if(n == 0) {
      break;
    }

    int ans = 0;
    for(int i = 1; i <= n; i++) {
      int j = i;
      while(j % 5 == 0) {
        ans++;
        j = j / 5;
      }
    }

    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

#define ll long long

class UnionFind {
 public:
	vector < int >parent;

	 UnionFind(int n) {
		parent = vector < int >(n, -1);
	} int root(int a) {
		if (parent[a] < 0) {
			return a;
		}
		return parent[a] = root(parent[a]);
	}

	int size(int a) {
		return -parent[root(a)];
	}

	bool connect(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b) {
			return false;
		}
		if (size(a) < size(b)) {
			swap(a, b);
		}

		parent[a] += parent[b];
		parent[b] = a;

		return true;
	}
};

int main()
{
	int N;
	cin >> N;
	vector < pair < pair < ll, ll >, int >>x(N), y(N);

	for (int i = 0; i < N; i++) {
		ll xx, yy;
		cin >> xx >> yy;
		x[i] = make_pair(make_pair(xx, yy), i);
		y[i] = make_pair(make_pair(yy, xx), i);
	}

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	priority_queue < pair < ll, pair < int, int >>>q;

	for (int i = 0; i < N - 1; i++) {
		ll fs = abs(x[i].first.first - x[i + 1].first.first);
		ll sc = abs(x[i].first.second - x[i + 1].first.second);
		q.push( {
		       -min(fs, sc), {
		       x[i].second, x[i + 1].second}});

		fs = abs(y[i].first.first - y[i + 1].first.first);
		sc = abs(y[i].first.second - y[i + 1].first.second);
		q.push( {
		       -min(fs, sc), {
		       y[i].second, y[i + 1].second}});
	}

	ll ans = 0;

	UnionFind uni(N);

	while (!q.empty()) {
		pair < ll, pair < int, int >>nq;
		nq = q.top();
		q.pop();
		ll cost = -nq.first;
		int i = nq.second.first, j = nq.second.second;
		if (uni.connect(i, j)) {
			ans += cost;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 11120
#include<stdio.h>

int main(void){
        char s[110];
        int i=-1;

        while(~++i){
                scanf("%s", s);
                if(s[0]=='0') break;

                int j=0, a=0, b=0;
                while(++j){
                        if(s[j]=='A') a++;
                        else if(s[j]=='B') b++;
                        else break;
                }

                if(a>b) a++;
                else b++;

                printf("%d %d\n", a, b);
        }
        return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	const int INF = 1<<28;
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a= {1}, dp(n+4, INF);
	int z = 6;
	while(z<=n){ a.push_back(z); z*=6; }
	z=9;
	while(z<=n){ a.push_back(z); z*=9; }
	dp[0] = 0;
	for(auto x: a) rep(j, n) if(dp[j]<INF){
		if(j+x <= n) dp[j+x] = min(dp[j+x], dp[j]+1);
	}
	cout <<dp[n] <<"\n";
	return 0;
}


Measured memory_bytes: 640
import numpy as np

W,H,N=map(int,input().split())
T=[list(map(int,input().split())) for i in range(1,N+1)]

result=np.zeros((H,W))

for i in range(0,N):
    x,y,a=T[i]

    if a==1:
        result[:,:x]=1

    elif a==2:
        result[:,x:]=1

    elif a==3:
        result[:y,:]=1

    elif a==4:
        result[y:,:]=1
    
print(np.count_nonzero(result==0))

Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 998244353;
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) {
        int x;
        cin >> x;
        a[x - 1] = i + 1;
    }
    for(auto e: a)
        cout << e << " ";
} 

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	double n, m, d;
	cin >> n >> m >> d;

	double ans;
	if(d == 0){
		ans = 1.0 * n * (m - 1) / (n * n);
	}else{
		ans = 1.0 * 2 * (n - d) * (m - 1) / (n * n);
	}

	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<list>
#include<set>
using namespace std;

int n;

vector<int> fenech(1000001,-1);
vector<int> sunuke(1000001,-1);
set<int> se;

void dfs(int c,int depth,vector<vector<int> >& tree, vector<int>& memo){
	if(memo[c] != -1) return;
	memo[c] = depth;

	for(int i=0;i<tree[c].size();++i){
		int next = tree[c][i];
		dfs(next,depth+1,tree,memo);
	}
}


int main(){
	cin >> n;
	vector<vector<int> > tree(n+1);

	int a,b;
	for(int i=1;i<n;++i){
		cin >> a >> b;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	se.insert(1);
	dfs(1,0,tree,fenech);
	se.clear();
	se.insert(n);
	dfs(n,0,tree,sunuke);

	int nfenech = 0;
	int nsunuke = 0;

	for(int i=1;i<=n;++i){
		if(fenech[i] <= sunuke[i]){
			nfenech++;
		}else{
			nsunuke++;
		}
	}

	if(nfenech > nsunuke) cout << "Fennec" <<endl;
	else cout << "Snuke" <<endl;
	
	return 0;
}




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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll X, Y;
    cin >> X >> Y;
    int ans = 0;
    while(X <= Y){
        ans++;
        X = X * 2;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  string a,b;
  cin >> a >> b;
  if(a.size()>b.size()) cout << "GREATER" << endl;
  else if(a.size()<b.size()) cout << "LESS" << endl;
  
  else{
    for(int i=0;i<a.size();i++){
      if(a[i]>b[i]){
        cout << "GREATER" << endl;
        return 0;
      }
      else if (a[i]<b[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define ll long long 
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//typedef long long  MOD=1000000009;
ll MOD=998244353;
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll lcm(ll x, ll y) {ll res = (x * y) / __gcd(x, y); return res;}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}

void iofoj(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}


void solution()
{
    ll k,i,j,h,m,w,n;
    string a,b;
    cin>>a>>b;
    n=a.length();
    m=b.length();
    ll ans=1000000000000000;
    for(i=0;i+m<=n;i++)
    {
        ll sum=0;
        k=i;
        for(j=0;j<m;j++)
        {
            if(a[k]!=b[j])sum++;
            k++;
        }
        ans=min(ans,sum);
    }
    cout<<ans;
}

int main(){
    fio
    //iofoj();
    // ll t;
    // cin>>t;
    // while(t--)
    solution();
    return 0; 
}





Measured memory_bytes: 3648
A, B, K = map(int, input().split())

ans = []

if B - A + 1 > 2*K:
    ans += list(range(A, A + K))
    ans += list(range(B - K + 1, B + 1))

else:
    ans = list(range(A, B+1))
    
print(*ans, sep = "\n")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long answer = 0;
    if (A + B > C * 2)
    {
        if(X>Y){
            answer = Y * 2 * C + (X - Y) * A;
        }else{
            answer = X * 2 * C + (Y - X) * B;
        }
    }else{
        answer = X * A + Y * B;
    }
    if(X>Y){
        if(X*2*C<answer){
            answer = X * 2 * C;
        }
    }else{
        if(Y*2*C<answer){
            answer = Y * 2 * C;
        }
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 384
from itertools import combinations
from functools import reduce
from operator import mul
def prime_dec(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(n)
  return table

n = int(input())
ps = prime_dec(n)
ps = [1] if len(ps) == 0 else ps
ps_com = []
for i in range(len(ps)):    
    ps_com += set(combinations(ps, i+1))
divs = [reduce(mul, k) for k in ps_com if not len(k) == 0]
divs_twin = [(k, int(n/k)) for k in divs]
divs_twin = set(divs_twin)
divs_twin_len = [max(len(str(k[0])) ,len(str(k[1])))  for k in divs_twin]

print(min(divs_twin_len))



Measured memory_bytes: 4316
#pragma gcc optimize("Ofast")

#include "bits/stdc++.h"
using namespace std;
typedef int64_t lld;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<int,pll> pip;
typedef pair<pll,int> ppi;
typedef pair<lld,pll> plp;
typedef pair<pll,lld> ppl;
typedef pair<pll,pll> ppp;
template<typename T>
using maxHeap = priority_queue<T,vector<T>,less<T>>;
template<typename T>
using minHeap = priority_queue<T,vector<T>,greater<T>>;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
inline void input(int &_x) {
    _x = 0;
    int _tmp = 1; char _tc = getchar();
    while((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
    if(_tc == '-') _tc = getchar(), _tmp = -1;
    while(_tc >= '0' && _tc <= '9') _x = _x*10+(_tc-48), _tc = getchar();
    _x *= _tmp;
}
inline void output(int _x) {
    char _buff[20]; int _f = 0;
    if(_x == 0)putchar('0');
    while(_x > 0)
    {
        _buff[_f++] = _x%10+'0';
        _x /= 10;
    }
    for(_f-=1; _f >= 0; _f--)
        putchar(_buff[_f]);
    putchar('\n');
}
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
     return _out(s,c.begin(),c.end());
 }
#ifdef erd1
    #define pprint(x) cerr<<__PRETTY_FUNCTION__<<":"<<__LINE__<<" - "<<(#x)<<"="<<(x)<<endl
#else
    #define pprint(x)
#endif

// code starts here
const int N = 300;
int dp[N+2][N+2]={}, rep[N*2+2][N+2]={};
vector<string> v;
signed main(){
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        v.pb(s);
    }
    for(int i = 0; i < h; i++)dp[h+1][i] = dp[i][h+1] = 2000000000;
    int ans = 0;
    for(int i = 0; i < w-1; i++){
        for(int diff = -h+1; diff<h; diff++){
            for(int j = max(diff, 0); j < h+min(diff, 0); j++){
                rep[diff+h][j+1] = rep[diff+h][j] + (v[j][i] == v[j-diff][i+1]);
                //assert(rep[diff+h][j+1] < INT_MAX-2000000000);
            }
        }
        for(int l = h; l>=0; l--){
            for(int r = h; r>=0; r--){
                dp[l][r] = min(dp[l+1][r]+rep[l+1-r+h][l+1], dp[l][r+1]+rep[l-r-1+h][l]);
                assert(rep[l+1-r+h][l+1] < INT_MAX-2000000000);
                assert(rep[l-r-1+h][l]< INT_MAX-2000000000);
                //assert(dp[l][r] < 2000000000);
            }
        }
        ans += dp[0][0];
    }

    cout << ans << endl;
}


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

int main(){
    int n,d,x;
    cin >> n >> d >> x;
    vector<int> a(n);
    int i,j;
    for(i=0; i<n; i++)
        cin >> a.at(i);
    int chocolate=x;

    for(i=0; i<n; i++){
        chocolate+=(d-1)/a.at(i)+1;
    }

    cout << chocolate << endl;

}

Measured memory_bytes: 3600
function Main(arg: string) {
  const input = arg.split('\n')[0];
  const length = input.length;
  const a = check(input);
  const b = check(input.substr(0, (length  -1)/2 ));
  const c = check(input.substr((length +3)/2 - 1));
  console.log(a && b && c ? 'Yes': 'No');
}


function check(str: string) {
  const length = str.length;
  for (let i = 0; i < Math.floor(length / 2); i++) {
    if (str.charAt(i) !== str.charAt(length - i - 1))return false;
  }
  return true;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  vector<ll>a(N);
  vector<bool>ans(N,false);
  ll M=0;
  
  rep(i,N){
    cin>>a[i];
  }
  
  for(ll i=N-1;i>=0;i--){
    ll sum=0;
    ll num=N/(i+1)-1;
    
for(ll j=0;j<=num;j++){
  if(ans[i+1+(i+1)*j-1]){
sum++;
  }

}

    if(sum%2!=a[i]){
      ans[i]=true;
      M++;
    }
  }
cout<<M<<endl;
  
  rep(i,N){
    if(ans[i]){
      cout<<i+1<<" ";
    }
  }
cout<<endl;

}

Measured memory_bytes: 2560
trial = int(input())
for t in range(trial):
    money = int(input())
    year = int(input())
    cond = int(input())
    answer = 0
    
    for c in range(cond):
        initial = money
        bank = [float(n) for n in input().split(" ")]
        if bank[0] == 0:
            interest = 0
            for y in range(year):
                interest += int(initial * bank[1])
                initial -= bank[2]
            else:
                #print(interest + initial)
                if answer < interest + initial:
                    answer = int(interest + initial)
        else:
            for y in range(year):
                initial = initial + int(initial * bank[1] )
                initial -= bank[2]
            else:
                #print(initial)
                if answer < initial:
                    answer = int(initial)
    else:
        print(answer)

Measured memory_bytes: 7664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}



  


int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep (i,s.size()){
    if (s[i]==s[i+1]){
      cnt++;
      if (s[i+1]=='1'){
        s[i+1]='0';
      }
      else s[i+1]='1';
    }
  }
  cout << cnt << endl;
}




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

int main()
{
	char ar[4];
	char ar1[4];
    for(int i = 0; i < 3; ++i)
	{
		cin >> ar[i];
	}
	ar1[0] = ar[0];
	for (int i = 0; i < 3; ++i)
	{
		cin >> ar[i];
	}
	ar1[1] = ar[1];
	for (int i = 0; i < 3; ++i)
	{
		cin >> ar[i];
	}
	ar1[2] = ar[2];

	for (int i = 0; i < 3; ++i)
	{
		cout << ar1[i];
	}
	cout << endl;

}


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

using namespace std;

int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    for(int i=0;i<=k;i++){
        int yz = s-i;
        if(yz<0){break;}
        for(int j=0;j<=k;j++){
            int z = yz-j;
            if(z<0){break;}
            if(0<=z && z<=k){ans++;}
        }
    }
    cout << ans << "\n";

}


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

int main(){
  int N, T;
  cin >> N >> T;
  int cost=1000000000;
  int res=N;

  for (int i = 0; i < N; i++) {
    int c, t;
    cin >> c >> t;
    if(t<=T){
      if(cost>c){
        cost=c;
        res=i;
      }
    }
  }
  if(res==N) cout << "TLE" << endl;
  else{
    cout << cost << endl;
  }
}


Measured memory_bytes: 256
use strict;
use warnings;
use utf8;

use feature qw/say/;

my $n = <>;
my @a = split(/\s+/, <>);

my %cnt; $cnt{$_} = ($cnt{$_} // 0) + 1 for (@a);
my ($first, $second) = sort { $b <=> $a } grep { $cnt{$_} >= 2 } (keys %cnt);

say !defined $first   ? 0
  : $cnt{$first} >= 4 ? $first * $first
                      : $first * ($second // 0);

Measured memory_bytes: 28140
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

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

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n)
  cin >> a[i];
  multiset<ll> s(ALL(a));
  map<ll, ll> m;
  for (ll i = 0; i < a.size(); i++)
  {
    if (m.find(a[i]) == m.end())
    {
      m[a[i]] = 1;
    }
    else
    {
      m[a[i]]++;
    }
  }
  ll tmp = a[0];
  ll c = 0;
  ll tmpc = -1;
  for (ll i = 1; i < a.size(); i++)
  {
    ll b = a[i];
    //auto it = s.find(tmp ^ b);
    ll num = m[tmp ^ b];
    if (num != 0)
    {
      //ll cnt = s.erase(tmp);
      //m[tmp]--;
      //s.erase(b);
      m[b]--;
      //cnt = s.erase(tmp ^ b);
      //m[tmp ^ b]--;
      tmpc = tmp ^ b;
      c = tmp;
      tmp = b;
      break;
    }
  }
  if (tmpc == -1)
  {
    cout << "No" << endl;

    return 0;
  }
  for (ll i = 0; i < a.size() - 1; i++)
  {
    //auto it = s.find(tmp ^ c);
    ll num = m[tmp ^ c];
    if (num == 0)
    {
      cout << "No" << endl;
      return 0;
    }
    else
    {
      //ll cnt = s.erase(tmp ^ c);
      m[tmp ^ c]--;
      ll tmp2 = c;
      c = tmp;
      tmp = tmp ^ tmp2;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <algorithm>//sort
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  string S, T;
  int A, B;
  string U;
  cin >> S >> T >> A >> B >> U;
  if(U == S)cout << A - 1 << " " <<  B << endl;
  else cout << A << " " << B - 1 << endl;
}


Measured memory_bytes: 384
n=int(input())
a=[[0 for i in range(n)]for j in range(n)]
for i in range(n):
    v=list(input().split())
    for j in range(len(v)):
        v[j]=int(v[j])
    x=2
    for k in range(v[1]):
        a[i][v[x+k]-1]=1
#print(a)

stack=[]
v=[]
d=[0]*n
f=[0]*n
t=1

while len(v)<n:
    for i in range(n):
        if i+1 not in v:
            stack.append(i+1)
            d[i]=t
            break
        else: pass
        
    while len(stack)!=0:
        for i in range(n):
            if a[stack[-1]-1][i]==1 and stack[-1]-1!=i and i+1 not in v and i+1 not in stack:
                stack.append(i+1)
                t+=1
                d[i]=t
                break
            elif i==n-1:
                t+=1
                f[stack[-1]-1]=t
                v.append(stack.pop())
            else: pass
            #print("i=",i)
            #print("stack ",stack)
            #print("v ",v)
    t+=1
#print("d=",d," f=",f)
for i in range(n):
    print(i+1,d[i],f[i])



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s;
  cin>>s;
  ll n=s.size();

  bool flag=false;
  if(s[0]=='0' || s[n-1]=='1')
    flag=true;

  for(ll i=0; i+1<=n-(i+1); i++){
    ll l=i;
    ll r=n-(i+1)-1;
    if(s[l]!=s[r])
      flag=true;
  }

  if(flag){
    cout<<-1<<endl;
    return 0;
  }


  vpl edge;
  ll last=0;
  ll now=1;
  REP(i,n-1){
    if(s[i]=='1'){
      edge.push_back(pll(last,now));
      last=now;
      now++;
    }
    else{
      edge.push_back(pll(last,now));
      now++;
    }
  }

  for(auto e:edge)
    cout<<e.FI+1<<" "<<e.SE+1<<endl;
}



Measured memory_bytes: 5432
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> P;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  int N, W;
  int w[105];
  int v[105];
  int dp[105][10005];

  cin >> N >> W;

  rep(i, N) { cin >> v[i] >> w[i]; }

  rep(i, W) { dp[0][i] = 0; }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      if (w[i] > j) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 998244353;
const int maxn = 3e5 + 5;

void go() {
    int n;
    cin >> n;
    int ans = 0;
    int x = 0;
    f1(n) {
        int v;
        cin >> v;
        if (v == i) {
            if (!x) {
                x = 1;
                ans++;
            }
            else {
                x = 0;
            }
        }
        else {
            x = 0;
        }
    }
    cout << ans << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        go();
    }
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>

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

using namespace std;

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


Measured memory_bytes: 256
from collections import Counter

n=int(input())
a=list(map(int, input().split()))
A=Counter(a)
A_most = A.most_common()
d=[]
for i in A_most:
    if i[1]>=4:
        d.append(i[0])
        d.append(i[0])
    elif i[1]>=2:
        d.append(i[0])
d=sorted(d)
print(d[-1]*d[-2] if len(d)>0 else 0)

Measured memory_bytes: 21668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;

    double r = 0;
    for (int i = 1; i <= n; i++) {
        double t = 1;
        int a = i;
        while (a < k) a *= 2, t *= 0.5;
        r += t;
    }

    printf("%.12f\n", r / n);

    return 0;
}

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

using namespace std;

const int N = 1e6;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
char readChar()
{
    char result = getchar();
    while (isspace(result)) {
        result = getchar();
    }
    return result;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r)
{
    return uniform_int_distribution<int>(l, r)(rng);
}
main() {
    int n = readInt();
    int d = (n + 1) / 2;
    printf("%.6f", 1.0 * d / n);
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

# In[10]:


N = int(input())
S = input()


# In[11]:


count = []
for i in range(1,N):
    left = S[:i]
    right = S[i:]
#     print(set(left), set(right), set(left)&set(right))
#     print(len(set(left)&set(right)))
    count.append(len(set(left)&set(right)))
print(max(count))


# In[ ]:






Measured memory_bytes: 2940
lis = []
ans = 0
for i in range(5):
    a = int(input())
    amari = a%10
    if a%10 == 0:
        amari = 10
    lis.append([a, 10-amari])
lis = sorted(lis, key=lambda x:x[1])
#print(lis)
for i in range(4):
    ans += lis[i][0] + lis[i][1]
    #print(ans)
ans += lis[4][0]
print(ans)

Measured memory_bytes: 38384
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n\r\t', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

get_i_to_x_rbtree0(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 0, T2, T).

get_i_to_x_rbtree1(N, T) :-
    rb_empty(T2),
    get_i_to_x_rbtree(N, 1, T2, T).

get_i_to_x_rbtree(0, _, T, T).
get_i_to_x_rbtree(N, I, T2, T) :-
    get_number(X),
    rb_insert(T2, I, X, T3),    
    N2 is N - 1,
    I2 is I + 1,
    get_i_to_x_rbtree(N2, I2, T3, T).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)

    orは!忘れに注意(末尾再帰なら直前)
*/

/* [L,R) */
range_list(L, R, []) :- L >= R, !.
range_list(L, R, [L|Xs]) :- L2 is L + 1, range_list(L2, R, Xs).

d(0, 0).
d(X, Y) :- X2 is X div 10, d(X2, Y2), Y is Y2 + 1, !.

f([], S, S).
f([X|Xs], S, Z) :- g(X, S, S2), f(Xs, S2, Z).

g(X, S, S2) :- d(X, D), D mod 2 =:= 1, S2 is S + 1, !.
g(_, S, S).

main :-
    get_number(N),
    range_list(1, N+1, Xs),
    f(Xs, 0, Z),
    writeln(Z).

    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 12652
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map(String::toLong)
    val sum = aList.sum()
    val ansList = Array(n) { 0L }

    var x1 = 0L
    for (i in 0 until n) {
        x1 += if (i % 2 == 0) aList[i] else -aList[i]
    }
    ansList[0]= x1
    for(i in 0 until n-1){
        ansList[i+1] = (aList[i] - ansList[i]/2)*2
    }
    println(ansList.joinToString(" "))
}


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

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

class Sol{
	public void Solve(){
		
		Array.Sort(A);
		Array.Reverse(A);
		bool[] sig = new bool[N];
		for(int i=0;i<N;i++){
			sig[i] = A[i] >= 0;
		}
		
		if(sig[0] == false || sig[1] == false){
			long ans = A[0];
			for(int i=1;i<N;i++){
				ans -= A[i];
			}
			var sb = new StringBuilder();
			sb.AppendLine(ans.ToString());
			long v = A[0];
			for(int i=1;i<N;i++){
				sb.AppendLine(String.Format("{0} {1}",v, A[i]));
				v -= A[i];
			}
			Console.Write(sb.ToString());
		} else {
			long l = A[0];
			long r = A[N-1];
			for(int i=1;i<N-1;i++){
				if(sig[i]) r -= A[i];
				else l -= A[i];
			}
			long ans = l - r;
			
			var sb = new StringBuilder();
			sb.AppendLine(ans.ToString());
			
			l = A[0];
			r = A[N-1];
			for(int i=1;i<N-1;i++){
				if(sig[i]){
					sb.AppendLine(String.Format("{0} {1}",r,A[i]));
					r -= A[i];
				} else {
					sb.AppendLine(String.Format("{0} {1}",l,A[i]));
					l -= A[i];
				}
			}
			sb.AppendLine(String.Format("{0} {1}",l,r));
			Console.Write(sb.ToString());
		}
		
		
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 33228
#include <iostream>

using namespace std;

int gcd(int,int);

int main(void){
    int i,j,k,n;
    long long sum=0;
    cin >> n;
    for(i=1;i<=n;i++)
        for(j=1;j<=n;j++)
            for(k=1;k<=n;k++)
                sum += gcd(gcd(i,j),k);
    cout << sum;
    // cout << gcd(9,12);
    return 0;
}

int gcd(int x,int y){
    int z;
    while(z=x%y){
        x=y;
        y=z;
    }
    return y;
}


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

int main(){
string s,t;
int count =0,max = 0,ls,lt;
cin >> s >> t;

// cout << t.size() << endl;

ls = s.size();
lt = t.size();

for(int i=0;i < ls-lt+1;i++){
  for(int j = 0;j < lt;j++){
    // cout << j << endl;
    if(s[i + j] == t[j]) {
      count += 1; 
      // cout << i <<' ' << j << endl;
    }
    
  }
  if(count > max){
      max = count;
    }
    count = 0;
}

cout << lt - max << endl;
  return 0;
}

Measured memory_bytes: 3612
N,M=gets.split(" ").map &:to_i
arr =[]
N.times do |n|
  a, b = gets.split(" ").map(&:to_i)
  arr << [a,b]
end
#puts arr
arr.sort_by! do |item|
  item[0]
end

ans = 0
nokori = M
arr.each do |a,b|
  #puts "ans : #{ans} nokonri: #{nokori}"
  break if nokori == 0
  if b >= nokori
    ans += (a*nokori)
    nokori -= nokori
  else
    ans += (a*b)
    nokori -= b
  end
end
#puts "arr : #{arr}"
#puts "ans : #{ans}"

puts ans

Measured memory_bytes: 12664
import sys
input=sys.stdin.readline

cnt=[0]*30
n=int(input())
a=[int(i) for i in input().split()]
for i in a:
    x=(bin(i)[2:])[::-1]
    for j,k in enumerate(x):
        if k=="1":
            cnt[j]=(cnt[j]+1)%2

print("No" if any(cnt) else "Yes")

Measured memory_bytes: 57328
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑



ll n, k[55], l[55], ans = INF;
int main() {
	cin >> n;
	if (n == 1) { cout << 1 << endl; return 0; }
	for (int i = 0; i < n; ++i) { cin >> k[i] >> l[i]; }

	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			ll mon = 0;
			for (int kk = 0; kk < n; ++kk) {
				for (int ll = 0; ll < n; ++ll) {
					if (k[j] - k[i] == k[ll] - k[kk] && l[j] - l[i] == l[ll] - l[kk]) { ++mon; }
				}
			}
			ans = min(ans, n - mon);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n,i,I;
float h,w,b,B;
main(){
	for(;scanf("%d",&n),n;){
		B=1e9;
		for(;n--;){
			scanf("%d%f%f",&i,&h,&w);
			h/=100;
			b=fabs(w/h/h-22);
			if(b<B||b==B&&i<I)
				B=b,I=i;
		}
		printf("%d\n",I);
	}
	exit(0);
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int nums[7];
int main(){
	int n, num;
	while(cin >> n && n){
		fill(nums, nums + 7, 0);
		rep(i, n){
			cin >> num;
			if(num < 10) nums[0]++;
			else if(num < 20) nums[1]++;
			else if(num < 30) nums[2]++;
			else if(num < 40) nums[3]++;
			else if(num < 50) nums[4]++;
			else if(num < 60) nums[5]++;
			else nums[6]++;
		}
		rep(i, 7) cout << nums[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, P;
  cin >> n >> P;
  vector<int> ifac(n + 1);
  ifac[1] = 1;
  for (int i = 2; i <= n; ++i)
    ifac[i] = -(P / i) * (ll)ifac[P % i] % P + P;
  ifac[0] = 1;
  for (int i = 1; i <= n; ++i)
    ifac[i] = ifac[i - 1] * (ll)ifac[i] % P;

  vector<vector<int>> stirling2(n + 2, vector<int>(n + 2));
  stirling2[0][0] = 1;
  for (int i = 1; i <= n + 1; ++i)
    for (int j = 1; j <= i; ++j)
      stirling2[i][j] = (stirling2[i - 1][j - 1] + stirling2[i - 1][j] * (ll)j) % P;
  vector<int> pw2(n + 1), ppw2(n * n + 1);
  pw2[0] = 2;
  for (int i = 1; i <= n; ++i)
    pw2[i] = pw2[i - 1] * (ll)pw2[i - 1] % P;
  ppw2[0] = 1;
  for (int i = 1; i <= n * n; ++i)
    ppw2[i] = (ppw2[i - 1] << 1) % P;
  int ans = 0;
  for (int k = 0; k <= n; ++k)
    for (int i = 0; i <= n; ++i) {
      int coe = (stirling2[n - i][k + 1] * (k + 1LL) + stirling2[n - i][k]) % P * ifac[n - i] % P;
      if ((n - i) & 1) coe = (P - coe) % P;
      ans = (ans + coe * (ll)pw2[i] % P * ppw2[i * k] % P * ifac[i]) % P;
    }
  for (int i = 1; i <= n; ++i)
    ans = ans * (ll)i % P;
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 72704
#include <stdio.h>

int main(void){
    int a,b,k;
    scanf("%d" "%d",&a,&b);
    if((a+b)%2==0){
        k=(a+b)/2;
        printf("%d",k);
    }else{
        printf("IMPOSSIBLE");
    }
    return (0);
    
}

Measured memory_bytes: 128