akhauriyash/Code-Regression huggingface dataset:
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<long long> A;
#define ivt(A,n,p) vector<long long> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair

const int mod=1e9+7;

int main()
{
    // #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
    //    //freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
    fio;
    ll n;
    cin>>n;
    ll a[n];
    forin(i,0,n-1)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    ll sum=0;
    ll k=n;
    k--;
    sum+=a[n-1];
    //ll k=n;
    k--;
    ll pp=n-2;
    forin(i,1,k/2)
    {
        sum+=2*a[pp];
        pp--;
    }
    if(k%2)
    {
        sum+=a[pp];
    }
    ol(sum);
}

Measured memory_bytes: 5216
#include <iostream>
using namespace std;
int main() {
    int h, w;
    while(1){
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
#include<iostream>

using namespace std;

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

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - AtCoder *** Contest
            string line = Console.ReadLine().TrimEnd();
            string s = line.Substring(8, 1);

            Console.WriteLine("A{0}C", s);
        }
                               
        static IEnumerable<List<T>> ReadLines<T>(int count = 0, char separator = ' ')
        {
            //[summary]コンソールの値を読み込んで、List<T>のコレクションを返却

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string line = Console.ReadLine().TrimEnd();
                count = int.Parse(line);
            }

            for (int i = 0; i < count; i++)
            {
                //コンソールを1行読み込み
                string line = Console.ReadLine().TrimEnd();

                //char型のときは1文字ずつに分割
                if (typeof(T) == typeof(char))
                {
                    var list = line.ToCharArray().ToList();
                    yield return (List<T>)(object)list;
                }
                else
                {
                    //読み込んだ値を"separator"で区切る
                    var list = line.Split(separator).ToList();

                    //int型のときは数値に変換
                    if (typeof(T) == typeof(int))
                    {
                        var numbers = list.ConvertAll(int.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else if (typeof(T) == typeof(long))
                    {
                        var numbers = list.ConvertAll(long.Parse);
                        yield return (List<T>)(object)numbers;
                    }
                    else
                    {
                        yield return (List<T>)(object)list;
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(){
  int n = 0;
  int h[100] = {};
  int matrix[100]={};
  int i = 0;
  int j = 0;
  long cnt = 0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  for(i=1;i<=100;i++){
    for(j=0;j<n;j++){
      if(h[j] >= i){
        matrix[j] = 1;
      }else{
        matrix[j] = 0;
      }
    }
    if(n!=1){
      for(j=0;j<n-1;j++){
        if(matrix[j] == 0 && matrix[j+1] == 1 || (matrix[0] == 1 && j == 0)){
          cnt++;
        }
      }
    }else{
      cnt = h[0];
    }
  }
  printf("%ld",cnt);
  return 0;
}

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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int n = s.Length;
			int bCount = 0;
			long ans = 0;
			for (int i = 0; i < n; i++) {
				if (s[i] == 'B') {
					++bCount;
				} else {
					ans += bCount;
				}
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 13240
n = int(input())
a = list(map(int, input().split()))

def cumsum(s):
    n = len(s)
    cs = [0] * (n+1)
    for i in range(n):
        cs[i+1] = cs[i] + s[i]
    return cs

a.sort()
acum = cumsum(a)
ans = 1

for i in range(n-2, -1, -1):
    if (acum[i+1] - acum[0]) * 2 < a[i+1]: break
    ans += 1

print(ans)


Measured memory_bytes: 14304
# AOJ 1058 Winter Bells
# Python3 2018.7.7 bal4u

import heapq
INF = 0x7fffffff

def dijkstra(V, to, start):
	dist, path = [INF]*V, [0]*V
	Q = []
	dist[start], path[start] = 0, 1
	heapq.heappush(Q, (0, start))
	while Q:
		t, s = heapq.heappop(Q)
		if dist[s] < t: continue
		for e, cost in to[s]:
			nt = t + cost
			if dist[e] < nt: continue
			if dist[e] > nt:
				path[e] = 0
				dist[e] = nt
				heapq.heappush(Q, (nt, e))
			path[e] += path[s]
	return [dist, path]
	
while True:
	n, m, p = map(int, input().split())
	if n == 0: break
	to = [[] for i in range(n)]
	for i in range(m):
		a, b, c = map(int, input().split())
		to[a].append((b, c))
		to[b].append((a, c))
	dist1, path1 = dijkstra(n, to, 0)
	dist2, path2 = dijkstra(n, to, n-1)
	for i in range(p):
		c = int(input())
		if dist1[c]+dist2[c] == dist2[0]:
			print((path1[c]*path2[c])/path2[0])
		else: print(0)
	print()


Measured memory_bytes: 6224
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,k=parseMap(split(readline()))
    ans=0
    for b in 1:n
        # n=pb+r (0<=r<b)とする
        p,r=n÷b,n%b
        
        # a:0->nのときa%bはそれぞれ(0,1,...,b-1)がp個 + (0,1,...,r)
        # 前者の条件を満たすaの数はp*max(0,b-k)
        # 後者の条件を満たすaの数はmax(0,r-k+1)
        # この二つを足し算してやる
        ans+=p*max(0,b-k)+max(0,r-k+1)
    end

    # a=0の場合を含んでいるので、k=0のとき答えが大きくなってしまう
    if k==0
        ans-=n
    end
    println(ans)
end
main()

Measured memory_bytes: 164560
x, y = gets.chomp.split(' ')
a = %w[1 3 5 7 8 10 12]
b = %w[4 6 9 11]
c = %w[2]
if a.include?(x) == a.include?(y) && b.include?(x) == b.include?(y) && c.include?(x) == c.include?(y)
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#define R register
#define Max(_A, _B) (_A > _B ? _A : _B)
#define Min(_A, _B) (_A < _B ? _A : _B)

const long long Inf = 1ll << 55;
int n, k, a[500010], b[500010], l[500010], r[500010], rr[1000010];
long long v[1 << 21], t[1 << 21];
void Pd(int u, R int begin, R int end)
{
	if(~t[u])
	{
		R int mid = begin + end >> 1;
		v[u << 1] = t[u] - rr[mid];
		t[u << 1] = t[u];
		v[u << 1 | 1] = t[u] - rr[end];
		t[u << 1 | 1] = t[u];
		t[u] = -1;
	}
}
void Pu(R int u){ v[u] = Min(v[u << 1], v[u << 1 | 1]); }
long long Query(R int u, R int begin, R int end, R int l, R int r)
{
	if(l <= begin && end <= r) 
	{
		R long long tmp = v[u]; v[u] = Inf;
		t[u] = Inf;
		return tmp;
	}
	Pd(u, begin, end);
	R int mid = begin + end >> 1; R long long t1 = Inf, t2 = Inf;
	if(l <= mid) t1 = Query(u << 1, begin, mid, l, r);
	if(r > mid) t2 = Query(u << 1 | 1, mid + 1, end, l, r);
	Pu(u);
	return Min(t1, t2);
}
void Modify(R int u, R int begin, R int end, R int l, R int r, R long long val)
{
	if(l > r) return ;
	if(l <= begin && end <= r)
	{
		v[u] = val - rr[end];
		t[u] = val;
		return ;
	}
	Pd(u, begin, end);
	R int mid = begin + end >> 1;
	if(l <= mid) Modify(u << 1, begin, mid, l, r, val);
	if(r > mid) Modify(u << 1 | 1, mid + 1, end, l, r, val);
	Pu(u);
}
long long GetAns(R int u, R int begin, R int end)
{
	if(begin == end || ~t[u]) return v[u] + rr[end];
	R int mid = begin + end >> 1;
	R long long t1 = Inf, t2 = Inf;
	t1 = GetAns(u << 1, begin, mid);
	t2 = GetAns(u << 1 | 1, mid + 1, end);
	return Min(t1, t2);
}
void Init(R int u, R int begin, R int end)
{
	t[u] = -1; v[u] = -rr[end];
	if(begin == end) return ;
	R int mid = begin + end >> 1;
	Init(u << 1, begin, mid);
	Init(u << 1 | 1, mid + 1, end);
}
int *d[1000010], tot, cnt; 
bool cmp(R int *i, R int *j){ return *i < *j; }
int main()
{
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d %d", &a[i], &b[i]);
	R long long sum = 0;
	for(int i = 1; i <= n; ++i)
	{
		sum += a[i];
		if(b[i] == 1)
		{
			if(a[i] << 1 > k){ puts("-1"); return 0; }
			r[++cnt] = (k - (sum << 1) % k) % k;
			l[cnt] = (k - ((sum - a[i]) << 1) % k) % k;
		}
	}
	for(int i = 1; i <= n; ++i) d[++tot] = &r[i], d[++tot] = &l[i];
	a[n + 1] = k - 1; d[++tot] = &a[n + 1];
	a[n + 2] = 0; d[++tot] = &a[n + 2];
	std::sort(d + 1, d + 1 + tot, cmp);
	R int hhh = 0, last = -1;
	for(int i = 1; i <= tot; ++i) 
		if(*d[i] != last){ rr[++hhh] = last = *d[i]; *d[i] = hhh; }
		else *d[i] = hhh;
	Init(1, 1, hhh);
	for(int i = 1; i <= cnt; ++i)
	{
		if(l[i] > r[i])
		{
			R long long t = Query(1, 1, hhh, r[i] + 1, l[i]) + rr[l[i]];
		//	Modify(1, 1, hhh, r[i] + 1, l[i] - 1, Inf);
			Modify(1, 1, hhh, l[i], l[i], t);
		}
		else
		{
			R long long t1 = Query(1, 1, hhh, 1, l[i]) + rr[l[i]];
			R long long t2 = Query(1, 1, hhh, r[i] + 1, hhh) + rr[l[i]] + k;
		//	Modify(1, 1, hhh, 1, l[i] - 1, Inf);
		//	Modify(1, 1, hhh, r[i] + 1, hhh, Inf);
			Modify(1, 1, hhh, l[i], l[i], Min(t1, t2));
		}
	}
	printf("%lld\n", GetAns(1, 1, hhh) + (sum << 1));
	return 0;
}

Measured memory_bytes: 22144
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
  int x;
  cin >> x;
  int s, a;
  s = x / 100;
  a = x % 100;
  int ans = 0;
  if(s*5 >= a) ans = 1;
  printf("%d\n", ans);
  
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;
using ll = long long int;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll allsum = 0;
    for(ll i = 0; i < N; ++i){
        cin >> A[i];
        allsum += A[i];
    }
    allsum /= 2;
    ll const diff = N / 2 + 1;

    vector<ll> B(N+1);
    for(ll i = 0; i < N; ++i){
        B[i] = A[(i * 2) % N];
    }
    B[N] = B[0];

    ll sum = 0;
    for(ll i = 0; i < diff; ++i){
        sum += B[i];
    }
    vector<ll> ans(N);
    for(ll i = 0; i < diff; ++i){
        ans[i * 2] = sum - allsum;
        sum = sum - B[i] + B[diff + i];
    }
    for(ll i = 0; i < diff - 1; ++i){
        ans[i * 2 + 1] = B[i] - ans[i * 2];
    }

    for(auto v : ans){
        cout << v * 2 << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3712
N = int(input())
L = sorted(list(map(int,input().split())))
ans = 0
for k in range(2,len(L)):
    for j in range(1,k):
        for i in range(0,j):
            if L[i] + L[j] > L[k]:
                if L[i]!=L[j]!=L[k]:
                    ans+=1
print(ans)




Measured memory_bytes: 9064
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> Pii;
int main(){
	int n;
	scanf("%d",&n);
	map < int , int > M;
	n = n * (n - 1) / 2;
	for(int i = 0; i < n; i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		M[a] += (c > d) ?  3 : (c == d) ? 1 : 0;
		M[b] += (d > c) ?  3 : (c == d) ? 1 : 0;
	}
	Pii p[128];
	map<int,int>::iterator it = M.begin();
	int len = 0;
	for(it = M.begin(); it != M.end(); it++){
		p[len].first = it->second;
		p[len].second = it->first;
		len++;
	}
	sort(p,p+len);
	reverse(p,p+len);
	
	int rank = 1;
	for(int i = 0; i < len ;){
		int x = p[i].first;
		int j;
		for(j = i ; p[j].first == x; j++){
			p[j].first = rank;
		}
		rank += (j-i);
		i += (j-i);
	}

	for(int i = 0; i < len; i++){
		swap(p[i].first,p[i].second);
	}
	sort(p,p+len);
	for(int i = 0; i < len; i++){
		printf("%d\n",p[i].second);
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
	int N = 0;
	std::cin >> N;

	int current = 0;
	std::vector<int> int_array;
	for (int i = 0; i < N; i++) {
		std::cin >> current;
		int_array.push_back(current);
	}

	int max_abs = INT_MIN;
	int abs1 = 0;
	int abs2 = 0;
	int tmp_max_abs = 0;
	for (int j = 0; j < N; j++) {
		for (int k = 0; k < N; k++) {
			abs1 = std::abs(int_array[k] - int_array[j]);
			abs2 = std::abs(int_array[j] - int_array[k]);
			tmp_max_abs = std::max(abs1, abs2);
			if (max_abs <= tmp_max_abs) {
				max_abs = tmp_max_abs;
			}
		}
	}

	std::cout << max_abs << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N+1];
        for(int i=1;i<=N;i++){
            A[i]=sc.nextInt();
        }
        int idx=2;
        int ans=0;
        while(idx<=N){
            if(A[idx]==A[idx-1]){
                ans++;
                idx++;
            }
            idx++;
        }
        System.out.println(ans);
    }
}


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

int main () {
    long N, K;
    cin >> N >> K;
    long d[100002] = {0};
    
    for (int i = 0; i < N; i++) {
        long a, b;
        cin >> a >> b;
        d[a] += b;
    }
    
    long s = 0;
    
    for (int i = 0; i < 100002; i++) {
        s += d[i];
        if (s >= K) {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 1024
using System;

namespace ABC165B
{
    class Program
    {
        static void Main(string[] args)
        {
            long X = long.Parse(Console.ReadLine());

            long num = 100;
            int count = 0;

            while (num < X)
            {
                num = (long)(num * 1.01);
                count++;
            }


            Console.WriteLine(count);

            Console.ReadKey();


        }
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> mou(n);
  for(int i=0; i<n; ++i) cin >> mou[i];
  int l=-1, r=min(mou[0],mou[n-1])+1;
  vector<int> ans(n);
  while(l<r-1){
    int mid = (l+r)/2;
    ans[0] = mid;
    bool ansis = false;
    for(int i=1; i<n; ++i){
      ans[i] = mou[i-1] - ans[i-1];
      if(ans[i] < 0){
        if(i%2) r = mid;
        else l = mid;
        break;
      }
      if(i==n-1){
        int x = mou[n-1] - ans[n-1] - ans[0];
        if(x==0) ansis = true;
        else if(x<0) r = mid;
        else l = mid;
      }
    }
    if(ansis) break;
  }
  for(int i=0; i<n; ++i){
    if(i==n-1) cout << ans[i]*2 << endl;
    else cout << ans[i]*2 << " ";
  }
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int k[n],a[31][31];
  for(int i=0;i<n;i++)
  {
    cin>>k[i];
    for(int j=0;j<k[i];j++) cin>>a[i][j];
  }

  int ans[31],cnt=0;
  for(int i=0;i<31;i++) ans[i]=0;

  for(int i=0;i<n;i++)
  for(int j=0;j<k[i];j++) ans[a[i][j]]++;

  for(int i=0;i<31;i++)
  {
    if(ans[i]==n) cnt++;
  }
  cout<<cnt<<endl;


}

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

using namespace std;

typedef long long LL;
#define N 120000

LL n,a[N],sum,m,p,num;

int main(){
	scanf("%lld",&n);
	for (LL i=1;i<=n;++i){
		scanf("%lld",a+i);
		sum+=a[i];
	}
	m=n*(n+1)/2;
	if (sum%m!=0){puts("NO"); return 0;}
	num=sum/m;
	a[0]=a[n];
	for (LL i=1;i<=n;++i){
		LL x=a[i]-a[i-1];
		if (num-x<0||(num-x)%n!=0){puts("NO"); return 0;}
		LL t=(num-x)/n;
		p+=t;
	}
	puts(p==num?"YES":"NO");
	
	return 0;
}
			

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll inf = 1e18;
struct Edge{
  	ll to, cost;
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

vll dijkstra(const Graph &g, int s){
  	vll d(g.size(), inf);
  	d[s] = 0;
  	priority_queue<P, vector<P>, greater<P>> que;
  	que.push(P(0, s));
  	while(!que.empty()){
    	ll dist = que.top().first;
    	int v = que.top().second;
    	que.pop();
    	if(d[v] < dist) continue;
    	for(const auto &e: g[v]){
      		if(d[e.to] <= d[v] + e.cost) continue;
      		d[e.to] = d[v] + e.cost;
      		que.push(P(d[e.to], e.to));
    	}
  	}
  	return d;
}

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

    ll n, m;
    cin >> n >> m;
    ll u, v;
    Graph g(3 * n);
    REP(i, m){
        cin >> u >> v;
        u--, v--;
        g[u].push_back(Edge{n + v, 1});
        g[n + u].push_back(Edge{2 * n + v, 1});
        g[2 * n + u].push_back(Edge{v, 1});
    }
    ll s, t;
    cin >> s >> t;
    s--, t--;
    vll d0 = dijkstra(g, s), d1 = dijkstra(g, n + s), d2 = dijkstra(g, 2 * n + s);
    ll res = min(d0[t], min(d1[n + t], d2[2 * n + t]));
    if(res == inf) cout << -1 << endl;
    else cout << res / 3 << endl;
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#include <string.h>
 using namespace std;
int main()
{
 long long n,m;
 cin>>n>>m;
 double a[n],sum=0;
 for(int i=0;i<n;i++){
   cin>>a[i];
   sum=sum+a[i];
 }
 long long count=0;
 double s=sum/(4*m*1.0);
 for(int i=0;i<n;i++){
   if(a[i]>=s)
   count++;
 }
 if(count>=m)
 cout<<"Yes"<<endl;
 else 
 cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, T;
    cin >> n >> T;
    int ans = INF;
    rep(i,n) {
        int c, t;
        cin >> c >> t;
        if (t > T) continue;
        ans = min(ans, c);
    }
    if (ans == INF) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
//#define int long long
signed main(){
    int  h, w;
    cin >> h >> w;
    char s[h][w];
    int a[h][w];
    pair<int,int> t;
    int al=0;
    queue<pair<int,int>> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s[i][j];
            a[i][j]=-1;
            if(s[i][j]=='.')al++;
       
        }
    }
    a[0][0]=1;
    que.push(make_pair(0,0));
    while(!que.empty()&&a[h-1][w-1]==-1){
        
        t = que.front();
        que.pop();
        cerr << t.first<<' '<<t.second<<endl;
       
        if(s[t.first][t.second]=='#')continue;
        if(t.first<h-1 && a[t.first +1][t.second]==-1){

            que.push(make_pair(t.first +1,t.second));
            a[t.first +1][t.second]=a[t.first ][t.second]+1;
        }
         if(t.second<w-1 && a[t.first ][t.second+1]==-1){

            que.push(make_pair(t.first ,t.second +1));
            a[t.first ][t.second+1]=a[t.first ][t.second]+1;
        }
        if(t.first>0 && a[t.first -1][t.second]==-1){

            que.push(make_pair(t.first -1,t.second));
            a[t.first -1][t.second]=a[t.first ][t.second]+1;
        }
         if(t.second>0 && a[t.first ][t.second-1]==-1){

            que.push(make_pair(t.first ,t.second -1));
            a[t.first ][t.second-1]=a[t.first ][t.second]+1;
        }
    }
    cerr << a[0][0]<<a[1][1]<<endl;
    if(a[h-1][w-1]==-1)cout << -1;
    else cout << al-a[h-1][w-1];

 
    return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, m;
    scan(n, m);
    auto ball = new long[](n);
    ball[] = 1;
    auto red = new long[](n);
    red[0] = 1;
    foreach (_; iota(m))
    {
        long x, y;
        scan(x, y);
        x--, y--;
        ball[x]--, ball[y]++;

        if (red[x])
            red[y] = 1;
        if (!ball[x])
            red[x] = 0;
    }
    red.sum().writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 5208
n = int(input())
p_lst = list(map(int,input().split()))
q_lst = list(map(int,input().split()))
p_used = []
q_used = []
a = 0
b = 0

def factorial(n):
    answer = 1
    for i in range(1,n+1):
        answer *= i
    return answer

for i in range(n-1):
    p = p_lst[i]
    k = 0
    for l in range(len(p_used)):
        tmp = [j for j in range(1,p)]
        if p_used[l] in tmp:
            k += 1
    a += (p-1-k)*factorial(n-1-i)
    p_used.append(p)

for i in range(n-1):
    q = q_lst[i]
    k = 0
    for l in range(len(q_used)):
        tmp = [j for j in range(1,q)]
        if q_used[l] in tmp:
            k += 1
    b += (q-1-k)*factorial(n-1-i)
    q_used.append(q)

print(abs(a-b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
template<class T> void show_with_brank(T a){ int cnt = 0; for(auto itr :a){ if(cnt++ != 0) cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n;
    while(cin >> n,n){
        int ans  = 0;
        vector<string>vs(n);
        rep(i,n){
            cin >> vs[i];
        }
        reverse(all(vs));
        int now = 0;
        rep(i,n/2){
            string a,b;
            a = vs.back();
            vs.pop_back();
            b = vs.back();
            vs.pop_back();
            if(a > b) swap(a, b);
            if(now == 0  && (a == "lu" && b == "ru")){ans++;now ++;}
            else if(now == 1  && (a == "ld" && b == "rd")){ans++;now--;};
        }
        cout << ans << endl;
    }
}






Measured memory_bytes: 3152
#include<iostream>
#include<complex>
#include<cstdio>
using namespace std;
bool crossfl(complex<double> v, complex<double> a, complex<double> b);
double outv(complex<double> a, complex<double> b);
int main(){
  complex<double> a,b,c,d;
  for(;;){
    if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&(a.real()),&(a.imag()),&(b.real()),&(b.imag()),&(c.real()),&(c.imag()),&(d.real()),&(d.imag())) == EOF) break;
    if((crossfl(c-a,b-a,d-a)) && crossfl(d-b,a-b,c-b)) cout <<"YES"<<endl;
    else cout <<"NO"<<endl;
  }
}
bool crossfl(complex<double> v, complex<double> a, complex<double> b){
  return ((outv(v,a)*outv(v,b))<0);
}
double outv(complex<double> a, complex<double> b){
  return a.real()*b.imag()-a.imag()*b.real();
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N, i;
  cin >> N;
  vi a(N);
  REP(0, N, i) {
    cin >> a[i];
  }
  vvi edges(N);
  REP(0, N-1, i) {
    i64 u, v;
    cin >> u >> v;
    u--;
    v--;
    edges[u].pb(v);
    edges[v].pb(u);
  }

  i64 INF = *max_element(all(a)) + 1;
  vi min_vals(N, INF); // the minimum final element of increasing subsequence of length (i+1)
  vi visited_from(N, -1);
  vi ans(N, -1);
  vector<pi> backup(N);
  stack<i64> st;
  st.push(0);
  i64 prev = -1;
  while(!st.empty()) {
    i64 cur = st.top();
    st.pop();

    //cout << "visit " << cur << endl;

    // restore if necessary
    while(prev != visited_from[cur]) {
      i64 idx = backup[prev].first;
      i64 val = backup[prev].second;
      min_vals[idx] = val;
      
      //cout << "restore node " << prev << " idx " << idx << " val " << val << endl;
      prev = visited_from[prev];
    }

    // update
    auto lb = lower_bound(all(min_vals), a[cur]);
    i64 idx = lb - min_vals.begin();
    backup[cur] = pi(idx, min_vals[idx]);
    min_vals[idx] = a[cur];

    ans[cur] = lower_bound(all(min_vals), INF) - min_vals.begin();

    for(auto e: edges[cur]) {
      if(e != visited_from[cur]) {
	st.push(e);
	visited_from[e] = cur;
      }
    }

    prev = cur;
  }

  REP(0, N, i) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 28452
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#define inf 2147483647
#define N 1000010
#define p(a) putchar(a)
#define For(i,a,b) for(long long i=a;i<=b;++i)

using namespace std;
long long n,pos;
long long a[N];
double t;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x){
    if(x<0){p('-');x=-x;}
    if(x>9)o(x/10);
    p(x%10+'0');
}

bool cmp(long long a,long long b){
	return a>b;
}

signed main(){
    in(n);
    For(i,1,n) in(a[i]);
    sort(a+1,a+n+1);
    o(a[n]);p(' ');
	pos=lower_bound(a+1,a+n,a[n]/2)-a;
	if(pos==n) pos--;
	t=(double)a[n]/2.0;
	if(fabs((double)a[pos]-t)>=fabs((double)a[pos-1]-t))
		o(a[pos-1]);
	else
		o(a[pos]);
    return 0;
}

Measured memory_bytes: 1024
def main():
    S = input()
    N = len(S)

    def checKPal(s):
        n = len(s)
        if n%2==0:
            if s[:int(n/2)] == s[:int(n/2)-1:-1]:
                return True
            else:
                return False
        else:
            if s[:int(n/2)] == s[:int(n/2):-1]:
                return True
            else:
                return False

    k1 = int((N-1)/2)
    k2 = int((N+3)/2)
    if checKPal(S) and checKPal(S[:k1]) and checKPal(S[k2-1:]):
        print("Yes")
    else:
        print("No")

main()


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


int main()
{
    long A, B, K;
    cin >> A >> B >> K;

    for(int k = 1; k <= K; k++) {
        if(k % 2 != 0) {
            if(A % 2 == 1) {
                A--;
            }
            B += A / 2;
            A -= A / 2;
        } else {
            if(B % 2 == 1) {
                B--;
            }
            A += B / 2;
            B -= B / 2;
        }
    }
    cout << A << " " << B;
    return 0;
}


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

using namespace std;
int main(void){
    // Your code here!
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    s1[0]+='A'-'a';
    s2[0]+='A'-'a';
    s3[0]+='A'-'a';
    
    
    
    cout<<s1[0]<<s2[0]<<s3[0]<<endl;

}

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

using namespace std;

const long long int INF=1e16;

int main() {
    long long int H, W;
    cin >> H >> W;

    long long int ans=INF, Sx, Sn;
    Sx = max(H/3, max((H-H/3)/2, (H-H/3)-(H-H/3)/2))*W;
    Sn = min(H/3, max((H-H/3)/2, (H-H/3)-(H-H/3)/2))*W;
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;
    
    Sx = max(W/3, max((W-W/3)/2, (W-W/3)-(W-W/3)/2))*H;
    Sn = min(W/3, max((W-W/3)/2, (W-W/3)-(W-W/3)/2))*H;
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;

    Sx = max(H/3*W, max(W/2, W-W/2)*(H-H/3));
    Sn = min(H/3*W, min(W/2, W-W/2)*(H-H/3));
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;
    
    Sx = max((H/3+1)*W, max(W/2, W-W/2)*(H-H/3-1));
    Sn = min((H/3+1)*W, min(W/2, W-W/2)*(H-H/3-1));
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;

    Sx = max(W/3*H, max(H/2, H-H/2)*(W-W/3));
    Sn = min(W/3*H, min(H/2, H-H/2)*(W-W/3));
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;

    Sx = max((W/3+1)*H, max(H/2, H-H/2)*(W-W/3-1));
    Sn = min((W/3+1)*H, min(H/2, H-H/2)*(W-W/3-1));
    ans = min(ans, Sx-Sn);
    // cout << Sx << ", " << Sn << endl;
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	num := scanIntNum()
	input := scanString()
	fmt.Println(rot(num, input))
}

func rot(n int, s string) string {
	var result []byte
	for i := 0; i < len(s); i++ {
		c := s[i]
		if int(c) > 90-n {
			c = c - byte(26)
		}
		c = c + byte(n)
		result = append(result, c)
	}
	return string(result)
}

func scanIntNum() (num int) {
	sc.Scan()

	num, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return num
}

func scanString() string {
	sc.Scan()

	return sc.Text()
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;

    if (n == 0)
        cout << 1;
    else
        cout << 0;

    return 0;
}

Measured memory_bytes: 3644
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        r: i32,
        g: i32,
        b: i32,
    }
    let x = r*100+g*10+b;
    let ans = if x%4 == 0 {
        "YES"
    } else {
        "NO"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
def preParse(u, p):
    if u == -1:
        return p
    p += [u]
    preParse(left[u], p)
    preParse(right[u], p)

def inParse(u, p):
    if u == -1:
        return p
    inParse(left[u], p)
    p += [u]
    inParse(right[u], p)

def postParse(u, p):
    if u == -1:
        return p
    postParse(left[u], p)
    postParse(right[u], p)
    p += [u]

n = int(input())
parent = [-1] * n
left   = [-1] * n
right  = [-1] * n
preo = []
ino  = []
post = []

for i in range(n):
    p, l, r = map(int, input().split())
    left[p] = l
    right[p] = r
    if l != -1:
        parent[l] = p
    if r != -1:
        parent[r] = p

root = parent.index(-1)

preParse(root, preo)
inParse(root, ino)
postParse(root, post)

for i, j in zip(['Preorder', 'Inorder', 'Postorder'], [preo, ino, post]):
    print(i)
    print(' '+' '.join(map(str, j)))


Measured memory_bytes: 5612
X, N = list(map(int, input().split()))
if(N == 0):
  print(X)
  exit()
p = list(map(int, input().split()))
a = [num for num in range(-1001, 1001)]
diff = list(set(a) - set(p))
diff.sort(reverse=True)
ans = 10**10
for i in diff:
  if(abs(ans - X) >= abs(i - X)):
    ans = i
print(ans)

Measured memory_bytes: 9296
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define inf 1e18
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main(){
	int n;
	cin >> n;
	vector<int> a(n,0);
	int div, j;
	rep(i, n) {
		div =i+1,j=2;
		while (div != 1) {
			while (div%j == 0) {
				a[j]++;
				div /= j;
			}
			j++;
		}
		
	}
	int cnt[80];
	rep(i, 80) {
		cnt[i] = 0;
		rep(j, n) {
			if (a[j] >= i) {
				cnt[i]++;
			}
		}
	}
	cout << cnt[74] + cnt[24] * (cnt[2] - 1) + cnt[14] * (cnt[4] - 1) + cnt[4] * (cnt[4] - 1)*(cnt[2] - 2)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int a,b;
	double i;
	scanf("%d %d",&a,&b);
	
	printf("%d\n",a/b);
	printf("%d\n", a%b);
	
	i = 1.0*a/b;
	printf("%lf\n",i);
	return 0;
}

Measured memory_bytes: 632
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()
l = [0]*n

for i in range(m):
    a,b = iim()
    l[a-1] += 1
    l[b-1] += 1
for j in l:
    print(j)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
const int N = 0;
int x, y;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> x >> y;
  cout << x + y / 2 << endl;
  return 0;
}

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

int main(){
  int a, b;
  string s;
  cin >> a >> b >> s;

  bool ans=s[a]=='-';
  for(int i=0; i<s.size(); i++){
    if(i!=a && !isdigit(s[i])) ans=false;
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#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 maxn = 1e6 + 5;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int t;
    cin >> t;
    while(t--) {
        ll D = 0, M = 0, DM = 0;
        int k;
        cin >> k;
        ll ans = 0;
        f(k) {
            if (s[i] == 'C') {
                ans += DM;
            }
            else if(s[i] == 'D') {
                D++;
            }
            else if(s[i] == 'M') {
                M++;
                DM += D;
            }
        }
        for (int i = k ; i < n ; i++) {
            if (s[i - k] == 'D') {
                DM -= M;
                D--;
            }
            else if(s[i-k] == 'M') {
                M--;
            }
            if (s[i] == 'C') {
                ans += DM;
            }
            else if(s[i] == 'D') {
                D++;
            }
            else if(s[i] == 'M') {
                M++;
                DM += D;
            }
        }
        cout << ans << '\n';
    }
}

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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long


signed main()
{
    int n;
    while(cin>>n, n) {
        int ans = 0;
        for(int i=1; i<=n/2; ++i) {
            int tmp = i;
            int j = i;
            while(true) {
                if(tmp>n) break;
                if(tmp==n) {
                    ans++;
                    break;
                }
                j++;
                tmp += j;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2996
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BStringsWithTheSameLength {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();
            char[] t = in.next().toCharArray();

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                sb.append(s[i]).append(t[i]);
            }
            out.println(sb);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21332
a=(1..4).map{(1..3).map{[0]*10}}
gets.to_i.times{
b,f,r,v=gets.split.map &:to_i
a[b-1][f-1][r-1]+=v
}
puts a.map{|x| x.map{|y| " "+y.join(" ")}.join("\n")}.join("\n"+"#"*20+"\n")


Measured memory_bytes: 6904
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__

MOD = 10**9 + 7


def main():
    s = input()
    t = s[::-1]

    n = len(s)

    rem = 0
    filler = []
    for i in range(n):
        if t[i] == '?':
            filler.append(pow(10, i, 13))
        else:
            rem += pow(10, i, 13) * int(t[i])

    rem %= 13

    if not filler:
        if rem == 5:
            print(1)
        else:
            print(0)
        return

    dp = [0] * 13
    for i in range(10):
        dp[i * filler[0] % 13] += 1

    for i in range(1, len(filler)):
        dp_row = [0] * 13
        for j in range(10):
            dp_row[filler[i] * j % 13] += 1

        dp_copy = [0] * 13
        for i in range(13):
            for j in range(13):
                dp_copy[(i + j) % 13] = (dp[i] * dp_row[j] + dp_copy[(i + j) % 13]) % MOD
        dp = dp_copy

    print(dp[(5 - rem) % 13])


# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 38764
#include <iostream>

using namespace std;

int main()
{
	int m;	// 自分の所持金
	int f;	// 友達の所持金
	int b;	// 本の値段

	cin >> m >> f >> b;

	if (b <= m) {
		// 買える
		cout << 0 << endl;
	} else if (b <= m + f) {
		//　友達に借りれば買える
		cout << b - m << endl;
	} else {
		// 買えない
		cout << "NA" << endl;
	}
	return 0;
}



Measured memory_bytes: 3128
#include <cstdio>
#include <algorithm>
using namespace std;

int L;
char S[500500];

bool chk(int m)
{
	int r = 0, s = m * 9;
	for (int i=L-1;i>=0;i--){
		while (r+s > 0 && (r+s) % 10 != S[i] - '0') s--;
		if ((r+s) % 10 != S[i] - '0') return false;
		r += s;
		r /= 10;
	}
	return true;
}

int main()
{
	scanf ("%s",S);
	while (S[L]) L++;

	int l = 0, r = L;
	while (l + 1 < r){
		int m = (l + r) / 2;
		if (chk(m)) r = m;
		else l = m;
	}
	printf ("%d\n",r);

	return 0;
}


Measured memory_bytes: 768