akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m >> x){
        if(n < m * 2){
            ans = x / 1000 * n;
            if(x % 1000){
                if(x % 1000 <= 500 && n >= m){
                    ans += m;
                }else{
                    ans += n;
                }
            }
            print(ans);
        }else{
            print((x + 499) / 500 * m);
        }
    }
}



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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=200010;
struct Edge{int to,capa,next;} e[N];
int h[N],sum=0,n,m;
bool vis[N];
int cmt,cnt,col[N],c[3];
bool falun;

inline int color(const int &x)
{
    if(x>=3) return x-3;
    if(x<0) return x+3;
    return x;
}

void add_edge(int u,int v,int w)
{
    e[++sum].to=v;
    e[sum].capa=w;
    e[sum].next=h[u];
    h[u]=sum;
}

void dfs(int u){
    c[col[u]]++;vis[u]=1;cnt++;
    for(int tmp=h[u];tmp;tmp=e[tmp].next){
        cmt+=(e[tmp].capa==1);
        int v=e[tmp].to;
        if(!vis[v]) col[v]=color(col[u]+e[tmp].capa),dfs(v);
        else if(col[v]!=color(col[u]+e[tmp].capa)) falun=0;
    }
}

int main(){
    int u,v;
    n=read();m=read();
    for(int i=1;i<=m;i++){
        u=read();v=read();
        add_edge(u,v,1);
        add_edge(v,u,-1);
    }
    long long ans=0;
    for(int i=1;i<=n;i++){
        if(vis[i]) continue;
        memset(c,0,sizeof(c));
        cmt=cnt=0;falun=1;
        dfs(i);
        if(!falun) ans+=1ll*cnt*cnt;
        else if(c[0]&&c[1]&&c[2]) ans+=1ll*c[0]*c[1]+1ll*c[1]*c[2]+1ll*c[2]*c[0];
        else ans+=cmt;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7680
//phoenix




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=0; i--)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a) sort(a,a+n);


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;




ll solveDp(ll i,ll a[],ll n,ll k,vector <ll> &dp) {
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)
        return dp[i];
    else {
        ll mn=inf;
        fr(j,1,min(k+1,n-i))
            mn=min(mn,abs(a[i+j]-a[i])+solveDp(i+j,a,n,k,dp));
        return dp[i]=mn;
    }
}




void cazz() {
    ll t,n,i,j,k,ans=0,f=0,b;
    cin>>n>>k;
    ll a[n];
    fr(i,0,n) cin>>a[i];
    vector <ll> dp(n,-1);
    cout<<solveDp(0,a,n,k,dp)<<"\n";
}




int main() {
    spdio;
	cazz();
	return 0;
}





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

s=1
ans=0
v={}
for j in range(len(a)):
	if(ans==k):
		print(s)
		exit()
	if(s-1 in v):
		break
	else:
		v.update({s-1:ans})
		s=a[s-1]
		ans+=1
lens=ans-v[s-1]
k=(k-ans)%lens
for j in range(k):
	s=a[s-1]
print(s)


Measured memory_bytes: 32956
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n = Integer.parseInt(tmp[0]);
		int m = Integer.parseInt(tmp[1]);
		int sum = 0;

		String[] tp  = scanner.nextLine().split(" ");
		List<Integer> list  = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {

			int now = Integer.parseInt(tp[i]);

			list.add(now);

			sum += now;
		}

		double cl = sum / (4.0 * m);

		int ans = (int) list.stream()
					.filter(s -> s >= cl)
					.count();

		if(ans >= m)System.out.println("Yes");
		else System.out.println("No");

	}
}

Measured memory_bytes: 35868
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func findPrimes(n int) []int {
	notPrimes := make([]bool, n+1)
	notPrimes[0], notPrimes[1] = true, true
	for i := 2; i <= n; i++ {
		if notPrimes[i] {
			continue
		}
		for j := i * 2; j <= n; j += i {
			notPrimes[j] = true
		}
	}
	primes := make([]int, 0, n)
	for i := range notPrimes {
		if !notPrimes[i] {
			primes = append(primes, i)
		}
	}
	return primes
}

func main() {
	n := readInt()
	if n == 1 {
		fmt.Println(0)
		return
	}

	m := int(math.Sqrt(float64(n)))
	p := findPrimes(m)

	pFactors := make(map[int]int)
	for _, prime := range p {
		if prime > n {
			break
		}
		for {
			if n%prime != 0 {
				break
			}
			n /= prime
			pFactors[prime]++
		}
	}
	if n > 1 {
		pFactors[n]++
	}

	ans := 0
	for _, v := range pFactors {
		cnt := 1
		for {
			if v < cnt {
				break
			}
			v -= cnt
			cnt++
			ans++
		}
	}

	fmt.Println(ans)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 3696
/*
As you do not know the path of the wind,
or how the body is formed in a mother's womb,
so you cannot understand the work of God,
the Maker of all things.
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const int N = (int)2e5+5;
int n, t;
vector<ll> a;

int main() {
	scanf("%d%d", &n, &t);
	for (int i = 1, x; i <= n; ++i) scanf("%d", &x), a.push_back(x);
	reverse(a.begin(), a.end());
	ll res = 0, start = 0;
	while (SZ(a)) {
		if (SZ(a) == 1) res += (a.back() + (ll)t - start), a.pop_back();
		else {
			if (!(a.back() + (ll)t > a[SZ(a) - 2]))
				res += (a.back() + (ll)t - start), start = a[SZ(a) - 2];
			a.pop_back();
		}
	}
	printf("%lld", res);
	return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n, a) for(int i = a; i < n; ++i)
#define num 50000010

int main(void) {
  int n, i, j, ans = 0, a;
  bool *f;
  f = (bool*)malloc(sizeof(bool) * num);
  rep(i, num) f[i] = true;
  repi(i, 8002, 1) if(f[i]) for(j = 3 * i + 1; j <= num; j += 2 * i + 1) f[j] = false;
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d", &a);
    if(a == 2) ++ans; 
    if(a % 2 && f[(a - 1) / 2]) ++ans;
  }
  printf("%d\n", ans);
  free(f);
  return 0;
}


Measured memory_bytes: 51024
function main(input) {
    var input = input.split('\n')
    var num500 = input[0]
    var num100 = input[1]
    var num50 = input[2]
    var x = input[3]
    var counter = 0

    for(i=0; i<=num500;i++){
        for(j=0; j<=num100; j++){
            for(k=0; k<=num50;k++){
                var sum = (i*500+j*100+k*50)
                if(sum == x){
                   counter +=1
                }
            }
        }
    }
    console.log(counter)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
  int n,a,b,temp;
  cin>>n>>a>>b;
  int count=0;

  for(int i=1;i<=n;i++){
    temp=i%10+i/10%10+i/100%10+i/1000%10;
    if(temp>=a && temp<=b) count+=i;
  }
  if(n==10000) count+=10000;
  cout<<count<<endl;

  
  
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,n,r;

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

  r = a%b;
  while( r > 0 ){
    a = b;
    b = r;
    r = a%b;
  }

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

Measured memory_bytes: 0
#include <stdio.h>

int main(void) {
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2040
n = int(input())
s = list(input())
rgb = s.count('R')*s.count('G')*s.count('B')
for r in (range(n-2)):
    for g in range(r+1,n-1):
        b = g-r+g
        if(b>=n):
            break
        if(s[r] != s[g] and s[r] != s[b] and s[g] != s[b]):
            rgb -= 1
print(rgb)

Measured memory_bytes: 79752
#include<bits/stdc++.h>
using namespace std;
long long a,v,b,w,t;
int main()
{
	cin>>a>>v>>b>>w>>t;
	if (v<w) printf("NO\n");
	else 
	{
		if (abs(a-b)<=(v-w)*t) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int main(){
  int n,total=0;
  cin>>n;
  int a[n+2]={};
  for(int i=1;i<=n;i++){
    cin>>a[i];
    total+=abs(a[i]-a[i-1]); 
  }
  total+=abs(a[n]);
  for(int i=1;i<=n;i++)
  cout<<total+abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])<<endl;
  return 0;
}

Measured memory_bytes: 1664
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define int long long
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio 
    int k ;
    cin >> k ;
    int ans = 0 ;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int c = 1; c <= k; c++){
                ans += __gcd(__gcd(i, j) , c) ;
            }
        }
    }
    cout << ans << endl;
    return 0 ; 
}

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

int main() {
	int n;
	while (cin >> n, n) {
		bool a[200];
		for (int i = 0;i < 200;i++)a[i] = false;
		for (int i = 0;i < n;i++) {
			int b;
			cin >> b;
			a[b - 1] = true;
		}
		vector<int>h;
		vector<int>t;
		for (int i = 0;i < 2 * n;i++) {
			if (a[i])t.push_back(i + 1);
			else h.push_back(i + 1);
		}

		int c = 0;
		int j = 0;
		while (!h.empty() && !t.empty()) {
			if (j % 2 == 0) {
				int flg = 0;
				for (int i = 0;i < t.size();i++) {
					if (c < t[i]) {
						c = t[i];
						t.erase(t.begin() + i);
						flg = 1;
						break;
					}
				}
				if (flg == 0) {	c = 0;}
				j++;
			}
			else {
				int flg = 0;
				for (int i = 0;i < h.size();i++) {
					if (c < h[i]) {
						c = h[i];
						h.erase(h.begin() + i);
						flg = 1;
						break;
					}
				}
				if (flg == 0)c = 0;
				j++;
			}
		}
		cout << h.size() << endl << t.size() << endl;
	}
	return 0;
}

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

int main() {
  int a, b, n;
  cin >> a >> b;
  if (a + b > (a + b) / 2 * 2 ) cout << (a + b) / 2 + 1 << endl;
  else cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
function main(input){
  var str = input.split('\n');
  var int = str[1].split(' ');
  var times = parseInt(str[0]);
  var cards = [];
  for(let i=0;i<int.length;i++){
    cards.push(parseInt(int[i]));
  }
  cards.sort(function(x,y){return x-y;})
  var alice = 0;
  var bob = 0;
  for(let j=1;j<=times;j++){
    if(j%2 === 1){
      alice += cards[times-j];
    }else{
      bob += cards[times-j];
    }
  }
  console.log(alice-bob);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
	
	int a, b;
	
	cin >> a >> b;
	
	if (a%2 == 0 || b%2 == 0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n;
    cin >> n;
    unordered_map<int, vector<int>> um;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        um[a].push_back(b);
        um[b].push_back(a);
    }
    vector<int> last(n + 1, -1);
    vector<int> v(1, 1);
    last[1] = 1;
    while (v.size() > 0) {
        int index = v.back();
        v.pop_back();
        if (index == n) break;
        for (auto next : um[index]) {
            if (last[next] == -1 ) {
                last[next] = index;
                v.push_back(next);
            }
        }
    }
    vector<int> colored(1, n);
    int node = n;
    while (node != 1) {
        node = last[node];
        colored.push_back(node);
    }
    int s = colored.size();
    vector<int> res(n + 1, 0);
    v.clear();
    for (int i = 0; i < s / 2; i++) {
        res[colored[i]] = -1;
    }
    for (int i = s / 2; i < s; i++) {
        res[colored[i]] = 1;
        v.push_back(colored[i]);
    }
    while (v.size() > 0) {
        int index = v.back();
        v.pop_back();
        for (auto next : um[index]) {
            if (res[next] == 0) {
                res[next] = 1;
                v.push_back(next);
            }
        }
    }
    int c = 0;
    for (int i = 1; i <= n; i++) {
        if (res[i] == 1) c++;
    }
    if (c * 2 > n) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
}


Measured memory_bytes: 13644
#include<stdio.h>

int main (void){

    int N_num;
    int K_num;
    int dp[258][3][2]={{{0}}};

    int i,j,k,l;
    int date,kind;
    int ans=0;

    scanf("%d%d",&N_num,&K_num);

    for(i=0;i<N_num;i++){
        for(j=0;j<3;j++){
            for(k=0;k<2;k++){
                dp[i][j][k]=0;
            }
        }
    }
    for(i=0;i<3;i++)dp[0][i][0]=1;

    for(i=0;i<K_num;i++){
        scanf("%d%d",&date,&kind);
        for(j=0;j<3;j++){
            if(j!=kind-1){
                for(k=0;k<2;k++){
                    dp[date-1][j][k]=-1;
                }
            }
        }
    }
    for(i=0;i<N_num;i++){
        for(j=0;j<3;j++){
            if(dp[i][j][0]!=-1){
                for(k=0;k<2;k++){
                    switch(k){
                    case 0:
                        for(l=0;l<3;l++){
                            if(j==l){
                                if(dp[i+1][l][1]!=-1){
                                    dp[i+1][l][1]+=dp[i][j][0];
                                    dp[i+1][l][1]%=10000;
                                }
                            }else{
                                if(dp[i+1][l][0]!=-1){
                                    dp[i+1][l][0]+=dp[i][j][0];
                                    dp[i+1][l][0]%=10000;
                                }
                            }
                        }
                        break;
                    case 1:
                        for(l=0;l<3;l++){
                            if(j==l){
                            }else{
                                if(dp[i+1][l][0]!=-1){
                                    dp[i+1][l][0]+=dp[i][j][1];
                                    dp[i+1][l][0]%=10000;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
    }


    /*for(j=0;j<3;j++){
        printf("###");
        for(i=0;i<N_num;i++){
            for(k=0;k<2;k++){
                printf("%3d",dp[i][j][k]);
            }
            printf(" ");
        }
        puts("");
    }*/


    for(i=0;i<3;i++){
        for(j=0;j<2;j++){
            if(dp[N_num-1][i][j]!=-1){
                ans+=dp[N_num-1][i][j];
                ans%=10000;
            }
        }
    }
    printf("%d\n",ans);

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> itv(N);
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    pair<int, int> p(a+b, a-b);
    itv[i] = p;
//    cout << p.first << p.second << endl;
  }
  
  sort(itv.begin(), itv.end());
//  cout << itv[0].first << endl;
  int start = -15000000000;
  int count = 0;
  for (int i = 0; i < N; i++) {
//    cout << start << itv[i].second << endl;
    if (start <= itv[i].second) {
      count++;
      start = itv[i].first;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"
//import "sort"

func main(){
  var a,b,c,sum int
  fmt.Scan(&a, &b)
  for i:=0 ; i<b; i++{
    fmt.Scan(&c)
    sum += c
  }

  if sum >= a {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 5504
import java.util.*;

public class Main {

    private int N;
    private char[] S;

    public void inputData() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        S = new char[N];
        for (int i = 0; i < N; i++) {
            S[i] = sc.next().charAt(0);
        }
    }

    public void printAnswer() {
        for (int i = 0; i < N; i++) {
            if (S[i] == 'Y') {
                System.out.println("Four");
                return;
            }
        }
        System.out.println("Three");
    }

    public void run() {
        inputData();
        printAnswer();
    }

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

}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#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,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<vector<int>>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    SORT(a);
    int j = -1;
    ll cmsm = 0;
    for(int i = 0; i < n-1; i++){
        cmsm += a[i];
        if (cmsm*2 < a[i+1]) j = i;
    }
    cout << n-1-j;
}


int main(){
    int T;
    //cin >> T;
    T = 1;
    while(T--){
        solve();
        cout << endl;
    }
}











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

# define C continue;
# define R return;

# define D double
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()

# define pii pair < int , int >
# define vpii vector < pii >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.12f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(-1,1);
const D tpie = 2*pie;

void solve( int test_case )
{
    D n,k;
    cin>>n>>k;

    D dice = 1/n;
    D ans = 0;
    D show;
    for ( show = 1 ; show<min(k,n+1) ; show++ )
    {
        int P = ceil(log2(k/show));
        D update = 1;

        for ( int i=0 ; i<P ; i++ )
            update*=0.5;

        ans+=update;

    }
    ans*=dice;

    if ( show<=n )
        ans +=(n-show+1)*dice;

    pp(ans); line
}

int main()
{
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;

#define  mp  make_pair
typedef long long int ll;
const int N=1e6+6;
vector<pair<int,int> >vec[N];
ll vis[N],dead[N];
int main()
{
    ll n,m;cin>>n>>m;
    memset(vis,-1,sizeof vis);
    for(int i=1;i<=m;i++)
    {
        int l,r,d;cin>>l>>r>>d;
        vec[l].push_back(mp(r,d));
        dead[r]++;
    }
    queue<ll>q1;
    for(int i=1;i<=n;i++)
    {
        if(!dead[i])vis[i]=0,q1.push(i);
    }
    while(!q1.empty())
    {
        int u=q1.front();
        q1.pop();
        for(int i=0;i<vec[u].size();i++)
        {
            int v=vec[u][i].first;
            int w=vec[u][i].second;
            if(vis[v]==-1)
            {
                vis[v]=vis[u]+w;
                q1.push(v);
            }
            else
            {
                if(vis[v]!=vis[u]+w)
                {
                    cout<< "No\n";
                    return 0;
                }
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==-1)
        {
            cout<< "No\n";
            return 0;
        }
    }
    cout<< "Yes\n";


    return 0;
}


Measured memory_bytes: 37504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll a[100005],b[100005],ans;
int main(void){
	int n; cin>>n;
	for(int i=0;i<n+1;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	if(a[0]<b[0]){
		ans+=a[0];
		b[0]=b[0]-a[0];
		a[0]=0;
	}else{
		ans+=b[0];
		a[0]-=b[0];
		b[0]=0;
	}
	//cout<<a[0]<<" "<<b[0]<<" "<<ans<<endl;
	for(int i=1;i<n;i++){
		if(b[i-1]>0){
			if(a[i]<b[i-1]){
				ans+=a[i];
				a[i]=0;
			}else{
				ans+=b[i-1];
				a[i]=a[i]-b[i-1];
			}
		}
		if(a[i]<b[i]){
			ans+=a[i];
			b[i]-=a[i];
			a[i]=0;
		}else{
			ans+=b[i];
			a[i]-=b[i];
			b[i]=0;
		}
	}
	if(b[n-1]>0){
		ans+=min(a[n],b[n-1]);
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

int ans = 0;
int maxV = 0,N;
map<int,int> mp;
vi A;

void solve(){
    rep(i, maxV+1){
        ans = max(ans, mp[i-1]+mp[i]+mp[i+1]);
    }

    cout << ans << endl;
}

int main(){
    cin >> N;
    A.resize(N);
    rep(i, N) {
        cin >> A[i];
        mp[A[i]]++;
        maxV = max(maxV, A[i]);
    }

    solve();
}


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

int main(){
  ll A,B,N;
  cin >> N >> A >> B;
  ll c=A+B;
  ll ans = N/c;
  ll rem = N%c;
  cout << ans * A + min(rem,A) << endl;;
}


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

void solve(std::vector<long long> A) {
  int sum = accumulate(A.begin(), A.end(), 0);
  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  std::vector<long long> A(3);
  for (int i = 0; i < 3; i++) {
    scanf("%lld", &A[i]);
  }
  solve(std::move(A));
  return 0;
}


Measured memory_bytes: 3704
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x%y);
}

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

	int A, B, K;
	cin >> A >> B >> K;
	int res = gcd(A, B);
	K--;
	while (K) {
		res--;
		if (A % res == 0 && B % res == 0) K--;
	}
	cout << res << "\n";
	
	return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i = 0;i < 1000;i++){
    int a[3] = {i / 100, (i / 10) % 10, i % 10};
    int cnt = 0;
    for(int j = 0;j < N;j++){
      if(S[j] == ('0' + a[cnt])){
        cnt++;
      }
      if(cnt == 3){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[100005];
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(a[a[i]]==i){
      ans++;
    }
  }
  cout<<ans/2<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int s, w;
        cin >> s >> w;
        if(w >= s){
            cout << "unsafe\n";
        }else{
            cout << "safe\n";
        }
    }
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    string s, t; cin >> s >> t;
    vector<int> al1(26, 0), al2(26, 0);
    REP(i, 0, s.size()){
        al1[s[i]-'a']++;
    }
    REP(i, 0, t.size()){
        al2[t[i]-'a']++;
    }
    REP(i, 0, 26){
        if(al2[i] > 0 && al1[i] == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = -1, count = 0;
    vector<vector<ll> > slis(26);
    REP(i, 0, s.size()){
        int k = s[i] - 'a';
        slis[k].pb(i);
    }
    REP(i, 0, 26){
        sort(ALL(slis[i]));
    }
    REP(i, 0, t.size()){
        ll now = ans;
        ll key = t[i] - 'a';
        auto it = upper_bound(ALL(slis[key]), now);
        if((it - slis[key].begin()) >=  slis[key].size()){
            count++;
            ans = slis[key][0];
        }else{
            ans = *it;
        }
    }
    cout << count * s.size() + ans + 1 << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

const int inf = 1e9 + 7;
const ll inf_ll = 1e18L + 7;

template <typename T>
void mini(T& a, T b) {
  a = min(a, b);
}

template <typename T>
void maxi(T& a, T b) {
  a = max(a, b);
}

int main() {
  string a, b;
  cin >> a >> b;
  int n = a.size();
  int m = b.size();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      if (a[i - 1] == b[j - 1]) {
        maxi(dp[i][j], dp[i - 1][j - 1] + 1);
      } else {
        dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]);
      }
    }

  int x = n;
  int y = m;
  string ans;
  while (dp[x][y] != 0) {
    if (a[x-1] == b[y-1]) {
      ans += a[x - 1];
      --x;
      --y;
    } else if (dp[x - 1][y] > dp[x][y - 1]) {
      --x;
    } else {
      --y;
    }
  }
  reverse(begin(ans), end(ans));
  cout << ans;
  return 0;
}


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

int main() {
  cout << setprecision(15);
  ll n; 
  cin >> n;
  vector<int> a[2];
  for (int i = 0; i < 2*n; ++i) {
    int val;
    cin >> val;
    a[i/n].push_back(val);
  }
  int max_sum = 0;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      if (j <= i) sum += a[0][j]; 
      if (i <= j) sum += a[1][j]; 
    }
    max_sum = max(max_sum, sum);
  }
  cout << max_sum << endl;
  return 0;
}


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

#define int long long

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

	int n;
	cin >> n;
	vector<pair<int, int> > v;
	for (int i = 1; i <= n; i++) {
		int p, q;
		cin >> p >> q;
		v.push_back({p, q});
	}

	bool flag = 0;

	for (int i = 1 ; i < v.size() - 1; i++) {
		pair<int, int> p = v[i];
		pair<int, int> prev;
		pair<int, int> next;
		if (i + 1 < v.size()) {
			prev = v[i - 1];
			next = v[i + 1];
		}

		if (p.first == p.second and prev.first == prev.second and next.first == next.second) {
			flag = true;
		}
	}
	if (flag == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();
    int K; { ll k; cin >> k; K = min(1LL * n, k); }

    char res = '1';
    rep(i, min(n, K)){
        char c = in[i];
        if(c != '1'){
            res = c;
            break;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, m := scanInt(), scanInt()
	a := make([][]int, n+1)
	p := make([]int, m)
	y := make([]int, m)

	for i := 0; i < m; i++ {
		p[i], y[i] = scanInt(), scanInt()
		a[p[i]] = append(a[p[i]], y[i])
	}
	for i := 0; i <= n; i++ {
		sort.Ints(a[i])
	}
	for i := 0; i < m; i++ {
		fmt.Fprintf(wr, "%012d\n", p[i]*1e6+sort.Search(len(a[p[i]]), func(x int) bool {
			return y[i] < a[p[i]][x]
		}))
	}
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    VVI f(3);
    VVI a(3);
    REP(i,3){
        a[i].resize(3);
        f[i].resize(3);
        REP(j,3){
            cin>>a[i][j];
        }
    }
    int n;cin>>n;

    REP(k,n){
        int b;cin>>b;
        REP(i,3){
            REP(j,3){
                if(a[i][j] == b){
                    f[i][j] = 1;
                }
            }

        }
    }

    REP(i,3){
        if(f[i][0] + f[i][1] + f[i][2] == 3){
            cout << "Yes" << endl;
            return;
        }
    }
    
    REP(i,3){
        if(f[0][i] + f[1][i] + f[2][i] == 3){
            cout << "Yes" << endl;
            return;
        }
    }

    if(f[0][0] + f[1][1] + f[2][2] == 3){
        cout << "Yes" << endl;
        return;
    }

    if(f[0][2] + f[1][1] + f[2][0] == 3){
        cout << "Yes" << endl;
        return;
    }


    
    cout << "No" << endl;

	return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;
using namespace std;


bool pairCompare1st(const pair<int, int> &firstElof, const pair<int, int> &secondElof)
{
    if (firstElof.second != secondElof.second){
        return firstElof.second < secondElof.second;
    }else{
        return firstElof.first < secondElof.first;
    }
}


int main() {
   
   int x,n;
   vector<int> A;
   cin >> x >> n;
   if(n==0){
      cout << x << endl;
      return 0;
   }
   int p;
   for(int i=0;i<n;i++){
      cin >> p;
      A.push_back(p);
   }
   sort(A.begin(), A.end());
   int mina = A[0]-1;
   int maxa = A[A.size()-1]+1;
   
   vector<pair<int,int>> xyz;
   for(int i=mina;i<maxa+1;i++){
      if(find(A.begin(), A.end(), i) == A.end()){
         for(int j=0;j<A.size();j++){
            xyz.push_back(make_pair(i,abs(i-x)));
         }
      }
   }
   sort(xyz.begin(), xyz.end(), pairCompare1st);
   cout << xyz[0].first << endl;
   // for(int i=0;i<xyz.size();i++){
   //    cout << xyz[i].first << " " << xyz[i].second << endl;

   // }

}

Measured memory_bytes: 3656
#include<iostream>

using namespace std;

int main(void) {
	int num, a, b;
	int resa, resb;
	int i;

	while(true) {
		cin >> num;
		if(num == 0) { break; }
		resa = resb = 0;
		for(i = 0; i < num; i++) {
			cin >> a >> b;
			if(a > b) { resa += a + b; }
			else if(a < b) { resb += a + b; }
			else { resa += a; resb += b; }
		}
		cout << resa << " " << resb << endl;
	}

	return 0;
}

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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

vector< vector<int> > b;
int xs, ys, xg, yg;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

bool dfs(int y, int x, int color){
    if(y == yg && x == xg){
        return true;
    }
    b[y][x] = -2;
    bool res = false;
    rep(i, 4){
        int ny = y + dy[i], nx = x + dx[i];
        if(b[ny][nx] == color){
            res = res || dfs(ny, nx, color);
        }
    }
    return res;
}

int main(){
    while(true){
        int w, h;
        cin >> w >> h;
        if(w == 0 && h == 0){
            break;
        }
        b.resize(h+2);
        rep(i, h+2){
            b[i].resize(w+2);
        }
        rep(i, h+2){
            rep(j, w+2){
                b[i][j] = -2;
            }
        }
        cin >> xs >> ys >> xg >> yg;
        int n;
        cin >> n;
        rep(k, n){
            int c, d, x, y;
            cin >> c >> d >> x >> y;
            if(d == 0){
                REP(i, y, y+2){
                    REP(j, x, x+4){
                        b[i][j] = c;
                    }
                }
            }else{
                REP(i, y, y+4){
                    REP(j, x, x+2){
                        b[i][j] = c;
                    }
                }
            }
        }
        b[ys][xs] = max(b[ys][xs], -1);
        if(dfs(ys, xs, b[ys][xs])){
            cout << "OK" << endl;
        }else{
            cout << "NG" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3200
def solve():
    h, w = map(int, input().split())
    S = list(input() + '#' for _ in range(h)) + ['#' * (w + 1)]
    H = [[0] * w for _ in range(h + 1)]
    W = [[0] * w for _ in range(h + 1)]
    for r in range(h):
        c = 0
        while c < w:
            if S[r][c] == '.':
                t = S[r][c:].find('#')
                for j in range(c, c + t):
                    W[r][j] = t
                c += t
            c += 1
    for c in range(w):
        r = 0
        while r < h:
            if S[r][c] == '.':
                t = r + 1
                cnt = 1
                while S[t][c] == '.':
                    t += 1
                    cnt += 1
                for i in range(r, t):
                    H[i][c] = cnt
                r = t
            r += 1
    ans = 0
    for r in range(h):
        for c in range(w):
            ans = max(ans, H[r][c] + W[r][c] - 1)
    print(ans)
solve()

Measured memory_bytes: 125656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll nm=(n+1)/2;
	ll d = n;
	ll g = __gcd(nm,d);
	nm/=g;
	d/=g;
	long double ans = (nm*1.0)/d;
	cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
  int n, x, sum=0;
  cin >> n >> x;
  
  int arr[n];
  for (int i=0; i<n; i++) {
    cin >> arr[i];
    sum+=arr[i];
  }
 
  sort(arr, arr+n);
 
  cout << n+((x-sum)/arr[0]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
bool check(string s)
{
    string res = s;
    reverse(all(res));

    return (res==s);
}
signed main()
{
    fastio();
    cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int l;
    cin>>l;
    ld ans = l/(double)3;
    ans = sq(ans)*ans;
    cout<<ans;
    printclock;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;


int main(){  
  string s,t;
  cin >> s >> t;
  int n=s.size();
  int m=t.size();
  set<char> st;
  rep(i,n) st.insert(s[i]);
  rep(i,m){
    if(st.find(t[i])==st.end()){ cout << -1 << endl; return 0; }
  }

  ll ans = 0;
  ll lst = 0;
  ll cnt = 0;
  while(cnt<m){
    ans++;
    auto pos = s.find(t[cnt]);
    while(pos != std::string::npos){
      lst = pos;
      cnt++;
      pos = s.find(t[cnt],pos+1);
    }
  }
  cout << (ans-1)*n + lst + 1 << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{
      public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	int H;
    	int W;
    	
    	for(;;){
    		H = scan.nextInt();
        	W = scan.nextInt();
        	if(H == 0 && W == 0){
        		break;
        	}
        	
        	for(int y = 0; y < H; y++){
        		for(int x = 0; x < W; x++){
        			if(y != 0 && y != H-1 && x != 0 && x != W-1){
        				System.out.print(".");
        			}else{
        				System.out.print("#");
        			}
        		}
        		System.out.println("");
        	}
        	System.out.println("");
    	}
    	
     }
}

Measured memory_bytes: 33260
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace CsProgramSpace
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] inp = Console.ReadLine().Split(',').Select(_ => _).ToArray();
            string res = "";
            for(int i = 1;i<inp.Length;i++)
            {
                inp[i] = inp[i].Remove(0, 1);
            }
            for (int i = 0; i < inp.Length; i++)
            {
                char[] temp = inp[i].ToCharArray();
                res += ", ";
                for (int j = 0; j<temp.Length;j++)
                {
                    if (!Regex.IsMatch(temp[j].ToString(), "[A-Z||a-z]"))
                    {
                        res += temp[j];
                        continue;
                    }
                    if(char.IsUpper(temp[j]))
                    {
                        temp[j] = Char.ToLower(temp[j]);
                    }
                    else if(char.IsLower(temp[j]))
                    {
                        temp[j] = Char.ToUpper(temp[j]);
                    }
                    res += temp[j];
                }
            }
            res = res.Remove(0, 2);
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 21596