akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
int func(int h) {
	if (h == 1)
		return 1;
	else
		return 2 * func(h / 2) + 1;
}
signed main() {
	int H;
	cin >> H;
	cout << func(H);
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = read().rstrip().decode()
cnt = 0
ans = [0] * len(s)
for i, ss in enumerate(s):
    if ss == 'L':
        ans[i] += cnt // 2
        ans[i - 1] += cnt // 2
        if cnt % 2 == 1:
            ans[i - 1] += 1
        cnt = 0
    else:
        cnt += 1
ans = ans[::-1]
for i, ss in enumerate(s[::-1]):
    if ss == 'R':
        ans[i] += cnt // 2
        ans[i - 1] += cnt // 2
        if cnt % 2 == 1:
            ans[i - 1] += 1
        cnt = 0
    else:
        cnt += 1
print(*ans[::-1])


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

namespace AthleteProgramming
{
    class Program
    {
        static void Main()
        {
            int[] array = new int[10];
            for(int i = 0; i < 10; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
            }
            Sort(ref array);
            for(int i =0;i<3;i++)
            {
                Console.WriteLine(array[9-i]);
            }
        }

        static void Sort(ref int[] array)
        {
            for(int i = 1; i < array.Length; i++)
            {
                int j = i-1;
                int tmp = array[j+1];
                while (j >= 0 && tmp < array[j])
                {
                    array[j+1] = array[j];
                    j--;
                }
                array[j + 1] = tmp;

            }
        }

    }
}

Measured memory_bytes: 9240
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int N=2010,P=1e9+7;

int n,m,cnt,G[N],a[N],b[N],w[N],id[N],fa[N];
struct edge{
  int t,nx,w;
}E[N];

int dis[N][N];

ll x;

inline bool cmp(const int &a,const int &b){
  return w[a]<w[b];
}

int getfa(int x){
  return x==fa[x]?x:fa[x]=getfa(fa[x]);
}

int fat[N];

int getfat(int x){
  return fat[x]==x?x:fat[x]=getfat(fat[x]);
}

ll mst;

inline int calc(ll x){
  int cnt=m;
  for(int i=1;i<=m;i++)
    if(mst+w[i]-dis[a[i]][b[i]]<x) cnt--;
  int ans=1; cnt=cnt==m?cnt:cnt+1;
  for(int i=1;i<=cnt;i++) ans=2LL*ans%P;
  return ans;
}

inline void addedge(int x,int y,int w){
  E[++cnt].t=y; E[cnt].nx=G[x]; E[cnt].w=w; G[x]=cnt;
  E[++cnt].t=x; E[cnt].nx=G[y]; E[cnt].w=w; G[y]=cnt;
}

void dfs(int x,int f,int d,int s){
  dis[x][s]=d;
  for(int i=G[x];i;i=E[i].nx)
    if(E[i].t!=f) dfs(E[i].t,x,max(d,E[i].w),s);
}

int main(){
  scanf("%d%d",&n,&m);
  scanf("%lld",&x);
  for(int i=1;i<=m;i++)
    scanf("%d%d%d",&a[i],&b[i],&w[i]);
  for(int i=1;i<=m;i++) id[i]=i;
  sort(id+1,id+1+m,cmp);
  for(int i=1;i<=m;i++) fa[i]=fat[i]=i;
  for(int i=1;i<=m;i++){
    int x=getfa(a[id[i]]),y=getfa(b[id[i]]);
    if(x==y) continue;
    mst+=w[id[i]]; fa[x]=y;
    addedge(a[id[i]],b[id[i]],w[id[i]]);
  }
  for(int i=1;i<=n;i++) dfs(i,0,0,i);
  printf("%d\n",(calc(x)+P-calc(x+1))%P);
  return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <cstdio>

using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

typedef long long ll;

int f(ll n){
    if(n<=3) return 1;
    return 1+f((n+2)/3);
}

int main(){
    ll n;
    cin >> n;
    cout << f(n) << endl;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  cout<<max({a+b,a-b,a*b})<<"\n";
  return 0;
}

Measured memory_bytes: 3616
use std::io::stdin;

fn main() {
    let mut is = String::new();
    stdin().read_line(&mut is).ok();
    let mut itr = is.split_whitespace().map(|e| e.parse().unwrap());
    let x: usize = itr.next().unwrap();
    let y: usize = itr.next().unwrap();
    println!(
        "{}",
        if y % 2 == 0 && 2 * x <= y && y <= 4 * x {
            "Yes"
        } else {
            "No"
        }
    );
}


Measured memory_bytes: 2108
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n;
  cin>>n;
  LL a[n], b[n];
  LL dif[n];
  LL suma=0, sumb=0;
  REP(i, n){
    cin>>a[i];
    suma+=a[i];
  }
  REP(i, n){
    cin>>b[i];
    sumb+=b[i];
    dif[i]=a[i]-b[i];
  }
  sort(dif, dif+n);

  if(suma<sumb){
    cout<<-1<<endl;
    return 0;
  }
  if(dif[0]>=0){
    cout<<0<<endl;
    return 0;
  }

  LL demand=0;
  int ans;
  REP(i, n){
    if(dif[i]>=0){
      ans=i;
      break;
    }
    demand+=abs(dif[i]);
  }
  LL work=0;
  for(int i=n-1; i>-1; --i){
    work+=dif[i];
    ++ans;
    if(demand<=work) break;
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
R=range(8)
A=[4,1,4,1,2,1,2,1]
A+=A
B="41412121"
B=map(int,[B[i:]+B[:i] for i in R])

import sys
for s in sys.stdin:
  x=map(int,s[:-1].split())
  m=sum(x)
  for i in R:
    s=sum([max(0,x[j]-A[i+j]) for j in R])
    if s<m: m,p=s,i
    elif m==s and B[i]<B[p]: p=i
  for i in R: print A[p+i],
  print

Measured memory_bytes: 4232
n, m, k = map(int, input().split())

if k == 0 or k == n * m:
    print("Yes")
    exit()

for i in range(n + 1):
    for j in range(m + 1):
        if i * j + (n - i) * (m - j) == k:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int a=0,b=0;
for(int i=0;i<3;i++)
{
    if(s[i]=='A')
    a++;
    else
    b++;
}
if(a==0||b==0)
cout<<"No\n";
else
    cout<<"Yes\n";
}


Measured memory_bytes: 256
import sys
# from collections import defaultdict, deque
# import math
# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 1000000007
def solve():
    n = getN()
    dp = [-INF]
    for i in range(n):
        num = getN()
        num = -num
        if num >= dp[-1]:
            dp.append(num)
        else:
            idx = bisect_right(dp, num)
            dp[idx] = num


    print(len(dp) - 1)
    return

def main():
    n = getN()
    for _ in range(n):
        solve()
if __name__ == "__main__":
    # main()
    solve()


Measured memory_bytes: 78580
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

ll p(ll x, ll n) {
    ll res=1;
    while(n) {
        if(n&1) res=(res*x);
        x=(x*x);
        n/=2;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll h,height;
    cin >> h;
    height=log2(h);
    cout << p(2,height+1)-1 << "\n";
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define pbb pop_back
#define make_pair mp
#define all(x) x.begin(), x.end()
#define mem(array, value) memset(array, value, sizeof(array))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a,b))*b
#define line cout << "==========" << endl
#define mod 1000000007
#define SIZE 1000001
bool check(int x)
{
    int limit = sqrt(x);
    for (int i = 2; i<=limit; i++){
        int temp = x;
        while (temp && temp % i == 0){
            temp/=i;
        }
        if (temp == 1)
            return true;
    }
    return false;
}
int main ()
{
    int x;
    cin >> x;
    if (x == 1 || x == 2 || x == 3){
        cout << 1 << endl;
        return 0;
    }
    for (int i = x; i>=1; i--){
        if (check(i)){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
S = input()

result = [0]
count = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        count += 1
    else:
        result.append(count)
        count = 0
result.append(count)
print(max(result))

Measured memory_bytes: 3060
import java.util.*;
import java.math.*;
public class Main{

	static int INF = 2 << 27;
	static int m;
	static int n;
	static int k;
	static int d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			Data[] data = new Data[n];
			for(int i = 0; i < n; i++) {
				data[i] = new Data(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
			}
			for(int i = 0; i < n; i++) {
				for(int j = i + 1; j < n; j++) {
					boolean check = check(data,i,j);
					if(check) data[j].up |= (1 << i);
				}
			}
			boolean[] dp = new boolean[1 << n];
			dp[0] = true;
			for(int i = 0; i < dp.length; i++) {
				if(!dp[i]) continue;
				ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
				for(int j = 0; j < 5; j++) {
					list.add(new ArrayList<Integer>());
				}
				for(int j = 0; j < n; j++) {
					if((i & (1 << j)) != 0 || (i & data[j].up) != data[j].up) continue;
					list.get(data[j].c).add(j);
				}
				for(int j = 1; j < 5; j++) {
					ArrayList<Integer> lX = list.get(j);
					int TMP = lX.size()-1;
					int TMPA = lX.size();
					for(int k = 0; k < TMP; k++) {
						for(int l = k + 1; l < TMPA; l++) {
							int next = i | (1 << lX.get(k) | (1 << lX.get(l)));
							dp[next] = true;
						}
					}
				}
			}
			int max = 0;
			for(int i = 0; i < dp.length; i++) {
				if(dp[i]) max = Math.max(max, Integer.bitCount(i));
			}
			System.out.println(max);
			
		}
	}
	static boolean check(Data[] data, int a, int b) {
		int dis = (int)(Math.pow(data[a].x - data[b].x, 2) + Math.pow(data[a].y - data[b].y, 2));
		return dis < Math.pow(data[a].r + data[b].r,2);
	}
	static class Data {
		int up = 0;
		int x;
		int y;
		int r;
		int c;
		Data(int a, int b, int c, int d) {
			this.x = a;
			this.y = b;
			this.r = c;
			this.c = d;
		}
	}
}

Measured memory_bytes: 242356
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = sc.next();
        String t = sc.next();

        int HOGE = 100000;
        int min = HOGE;
        for (int i = 0; i <= s.length() - t.length(); i++) {
            int count = 0;
            for (int j = 0; j < t.length(); j++) {
                if (s.charAt(i + j) != t.charAt(j)) {
                    count++;
                }
            }
            min = Math.min(min, count);
        }
        System.out.println(min == HOGE ? 0 : min);
        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 36248
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main() {
    int n = 0, x = 0;
    scanf("%d %d\n", &n, &x);
    int min = 1001;
    int sum_m = 0;
    int count = n;
    for (int i=0; i<n; i++) {
        int buf = 0;
        scanf("%d", &buf);
        sum_m += buf;
        if (buf < min) min = buf;
    }
    x -= sum_m;
    count += x / min;
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		if(n==m || n%m==0) {
			System.out.println(-1);
		}else {
			System.out.println(n);
		}
	}
}



Measured memory_bytes: 21972
import math
mod = 10 ** 9 + 7
n = int(input())

def nprf(n):
    E = [0] * (n + 1)
    for i in range(2, n + 1):
        for j in range(2, i + 1):
            while i % j == 0:
                E[j] += 1
                i //= j
    return E

ans = 1
for i in nprf(n):
    ans *= i + 1
    
print(ans % mod)

Measured memory_bytes: 3064
x_1, y_1, x_2, y_2 = map(int, input().split())

x_3 = x_2 + y_1 - y_2
y_3 = y_2 + x_2 - x_1
x_4 = x_3 + y_2 - y_3
y_4 = y_3 + x_3 - x_2

print(x_3,y_3,x_4,y_4)

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
  int tB,tA,aB,aA,i;

  scanf("%d%d%d%d",&tB,&tA,&aB,&aA);

  while(1)
  {
    aB -= tA;
    if(aB <= 0)
      break;
    tB -= aA;
    if(tB <= 0)
      break;
  }

  if(aB <= 0)
    printf("Yes");
  else
    printf("No");

  return 0;
}


Measured memory_bytes: 1736
N = int(input())
A = list(map(int, input().split()))
B = [0]
for i in range(1, N):
    if A[i - 1] - A[i] > 0:
        B.append(A[i - 1] - A[i])
        A[i] += A[i - 1] - A[i]
print(sum(B))

Measured memory_bytes: 32176
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define tisic 47
#define soclose 1e-8
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
using uint = unsigned int;
using cat = long long;
using dbl = long double;
constexpr dbl pi = 3.14159265358979323846;
using namespace std;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	cout << (H2*60+M2)-(H1*60+M1)-K << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 3668
#include<stdio.h>
#include<vector>
#include<algorithm>
using lint = long long;
using std::pair;
using std::vector;
using pll = pair<lint, lint>;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<pll> vec;
	for (int i = 0; i < n; i++) {
		lint a, b;
		scanf("%lld%lld", &a, &b);
		vec.push_back({ a,b });
		
	}
	lint ans = 0;
	for (pll p : vec) {
		if ((p.first|k) == k) {
			ans += p.second;
		}
	}
	for (int i = 0; i <= 30; i++) {
		if (k&(1 << i)) {
			int q = (1 << i) - 1;
			int tmp = (k | q) ^ (1<<i);
			lint sum = 0;
			for (pll p : vec) {
				if ((p.first|tmp) == tmp) {
					sum += p.second;
				}
			}
			ans = std::max(ans, sum);
		}
	}
	printf("%lld", ans);

}

Measured memory_bytes: 2420
import sys

input = sys.stdin.readline
print = sys.stdout.write

def checkmine(matrix,r,c):
    if matrix[r][c] == "#":
        return "#"

    dr = [-1,-1,-1, 0,0, 1,1,1]
    dc = [-1, 0, 1,-1,1,-1,0,1]
    
    numberOfBombs = 0
    for i in range(8):
        #if r + dr[i] > -1 and r + dr[i] < len(matrix) and c + dc[i] > -1 and c + dc[i] < len(matrix[0]):
        try:
            if matrix[r+dr[i]][c+dc[i]] == "#" and r+dr[i] > -1 and c+dc[i] > -1:
                numberOfBombs += 1
        except:
            pass
        
    return numberOfBombs

N,M = map(int,input().split())
l = []
for i in range(N):
    l.append(input())
    
for i in range(N):
    for j in range(M):
        print(str(checkmine(l,i,j)))
    print("\n")

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


int main() {
  string kind = "Three";
  int N;
  string S;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S;
    if (S == "Y") {
      kind = "Four";
      break;
    }
  }
  cout << kind << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;
ll ara[N];
int main()
{
    IOS;
    int n;cin>>n;
    for(int i=0;i<n;i++)cin>>ara[i];
    sort(ara,ara+n);
    int ans=n,last=-1;
    ll sum=0;
//    prinT(ara,n);
    for(int i=0;i<n-1;i++)
    {
        sum+=ara[i];
        if(sum*2<ara[i+1])last=i;
    }
    cout<<ans-last-1<<endl;
}










Measured memory_bytes: 4348
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
const int INF=1001001001;

int main() {
  int N,X,Y;
  cin>>N>>X>>Y; 
  X--;
  Y--;
  vector<int>ans(N);
  rep(i,N){
    vector<int>dist(N,INF);
    queue<int>q;
    auto push=[&](int v,int d){
      if(dist[v]!=INF){
        return;
      }
      dist[v]=d;
      q.push(v);
    };
    push(i,0);
    while(!q.empty()){
      int v=q.front();
      q.pop();
      int d=dist[v];
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < N) push(v+1, d+1);
      if (v == X) push(Y, d+1);
      if (v == Y) push(X, d+1);
    }
    rep(i,N) ans[dist[i]]++;
  }

  
  rep(i,N) ans[i] /= 2;
  for (int i = 1; i <= N-1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main() {
    map<string, vector<int>> list;
    string word;
    int page;
    while (cin >> word >> page) {
        if (list.count(word)) {
            list[word].push_back(page);
        } else {
            list[word] = vector<int>(1, page);
        }
    }
    for (auto li : list) {
        cout << li.first << endl;
        sort(li.second.begin(), li.second.end());
        for (int i=0; i<(int)li.second.size(); ++i) {
            cout << (i == 0 ? "" : " ") << li.second[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1244
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int n;
    while(1){
        cin>>n;
        if(n==0)break;
        int i,ans=0;
        vector<int> v(n,0);
        double sum=0;
        rep(i,n){
            cin>>v[i];
            sum+=v[i];
        }
        sum/=n;
        rep(i,n)if(v[i]<=sum)ans++;
        
        cout<<ans<<endl;
    }
//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 3184
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    N, M = LI()
    A = [LI() for _ in range(N)]
    not_flag = [False]*M
    ans = N
    for i in range(M):
        d = defaultdict(int)
        for k in range(N):
            for j in range(M):
                cur = A[k][j]-1
                if not_flag[cur]:
                    continue
                d[cur] +=1
                break
        d = sorted(d.items(),key=lambda x:x[1],reverse=True)
#        print(d)
        not_flag[d[0][0]] = True
        ans = min(ans,d[0][1])
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 4832
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int> > a(H, vector<int>(W));
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++) cin >> a[i][j];
    }
    vector<int> x(H*W), y(H*W), xx(H*W), yy(H*W);
    int k = 0;
    for (int i=0; i<H; i++){
        for (int j=0; j<W-1; j++){
            if (a[i][j]%2 == 1){
                a[i][j] -= 1;
                a[i][j+1] += 1;
                x[k] = j+1;
                xx[k] = j+2;
                y[k] = i+1;
                yy[k] = i+1;
                k += 1;
            }
        }
    }
    for (int i=0; i<H-1; i++){
        if (a[i][W-1]%2 == 1){
            a[i][W-1] -= 1;
            a[i+1][W-1] += 1;
            x[k] = W;
            xx[k] = W;
            y[k] = i+1;
            yy[k] = i+2;
            k += 1;
        }
    }
    cout << k << endl;
    for (int i=0; i<k; i++){
        if (x[i] == 0) return 0;
        cout << y[i] << " " << x[i] << " ";
        cout << yy[i] << " " << xx[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 7040
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
void YES(bool ok){
    cout << (ok ? "Yes" : "No") << endl;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;cin >> s;
    ll n = s.size();
    ll t = 0;
    rep(i,0,n){
        if(t == 0 && s[i] == 'C')t++;
        if(t == 1 && s[i] == 'F')t++;
    }

    YES(t == 2);
}

Measured memory_bytes: 3560
#include<cstdio>

int main(){
    int n;
    scanf("%d", &n);
    int t[n];
    for(int i=0;i<n;i++) scanf("%d", &t[i]);
    long int ans = 0;
    for(int i=1;i<n;i++){
        if(t[i-1] > t[i]){
            int gap = t[i-1] - t[i];
            ans += gap;
            t[i] += gap;
        }
    }
    printf("%ld", ans);
    return 0;
}

Measured memory_bytes: 2504
#include<iostream>
using namespace std;
int main(){
	bool num[1000000] = {0};
	for(int i=2; i<1000; i++){
		if(!num[i]){
			for(int j=i*i; j<1000000; j+=i){num[j] = true;}
		}
	}
	int n;
	while(cin >>n){
		int f = 0;
		for(int i=2; i<=n; i++){
			if(!num[i]){f++;}
		}
		cout <<f<<endl;
	}
}

Measured memory_bytes: 0
use std::io;
use std::i32;

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();

    // N
    stdin.read_line(&mut buf).unwrap();
    let n: usize = buf.trim().parse().unwrap();

    let mut r: Vec<i32> = vec![0; n];
    for i in 0..n {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        r[i] = buf.trim().parse().unwrap();
    }

    let mut minv = r[0];
    let mut maxdf = i32::MIN;
    for i in 1..n {
        if maxdf < r[i] - minv {
            maxdf = r[i] - minv;
        }
        if r[i] < minv { 
            minv = r[i];
        }
    }

    println!("{}", maxdf);
}



Measured memory_bytes: 5052
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	long long n,a[100005],dis[100005];
	long long sum=0;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=a[i];
	}
	if(sum%(n*(n+1)/2))
	printf("NO\n");
	else
	{
		long long k=sum/((n*(n+1))/2);
		dis[1]=a[1]-a[n];
	    for(int i=2;i<=n;i++)
	    dis[i]=a[i]-a[i-1];
	    int flag=1;
	    long long cnt=0;
	    for(int i=1;i<=n;i++)
	    {
	    	if(k-dis[i]<0||(k-dis[i])%n)
	    	flag=0;
	    	else
	    	cnt+=(k-dis[i])/n;
		}
		if(cnt!=k)
		flag=0;
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        a--;
    }
    return ans;
}
int main(){
    int n;
    cin >> n;
    vl v(n);
    rep(i,n)cin >> v[i];
    ll a=v[0];
    rep(i,n)a=__gcd(a,v[i]);
    cout << a << endl;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
  int q;
  cin >> q;
  rep(k, q) {
    string x, y;
    cin >> x >> y;
    int m = x.size();
    int n = y.size();
    vector<vector<int> > dp(m + 1, vector<int>(n + 1, 0));
    rep(i, m) {
      rep(j, n) {
        if (x[i] == y[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
        } else {
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
        }
      }
    }
    cout << dp[m][n] << endl;
  }
  return 0;
}



Measured memory_bytes: 6908
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	ll A, B, C, K;
	cin >> A >> B >> C >> K;
	if (K % 2 == 0)puts(A - B);
	else puts(B - A);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>
#include <stack>
#include <set>
#include <map>
using namespace std;

const int MAX=1e5+5;
int n,x[MAX],a,b;
long long ans;

int main(){
	int i;
	
	scanf("%d%d%d",&n,&a,&b);
	for(i=0;i<n;i++)
		scanf("%d",&x[i]);
	for(i=1;i<n;i++){
		if((long long)a*(x[i]-x[i-1])<b) ans+=(long long)a*(x[i]-x[i-1]);
		else ans+=b;
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

av = sum(A) / N

min_dist = 9999
min_idx = 0

for i in range(N):
  if min_dist > abs(A[i] - av):
    min_dist = abs(A[i] - av)
    min_idx = i
    
print(min_idx)

Measured memory_bytes: 3060
#include <stdio.h>

int check(int n){
    int i;
    for (i=2;i<n;i++){
        if ((n%i)==0){
            return 0;
        }
    }
    return n;
}

int main(void){
    int x, prime=0;
    scanf("%d", &x);
    while (prime==0){
        prime = check(x);
        x += 1;
    }
    printf("%d", prime);
    return 0;
}

Measured memory_bytes: 128
import sys
import subprocess
import re
import datetime
import os


A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for i in range(A+1):
    for j in range(B+1):
         for k in range(C+1):
            if (500*i+100*j+50*k)==X:
                count = count + 1

print(count)

Measured memory_bytes: 4436
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,K=MAP()
S=input()

if N==1:
    print(1)
    exit()

L=[]
cnt0=0
if S[0]=='0':
    L.append(0)
    cur=0
else:
    cur=1
cnt=0
for i in range(N):
    if cur==0:
        if S[i]=='0':
            cnt+=1
        else:
            L.append(cnt)
            cnt=1
            cur=1
            cnt0+=1
    else:
        if S[i]=='1':
            cnt+=1
        else:
            L.append(cnt)
            cnt=1
            cur=0
else:
    if cnt!=0:
        if cur==0:
            L.append(cnt)
            cnt0+=1
        else:
            L.append(cnt)
if S[-1]=='0':
    L.append(0)

acc=[0]+list(accumulate(L))
mx=0
if cnt0<K:
    K=cnt0
for i in range(0, len(acc), 2):
    if i+(K*2+1)<len(acc):
        mx=max(mx, acc[i+(K*2+1)]-acc[i])
print(mx)


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

using namespace std;


int main() {
    vector<int> v(3);
    for (int i = 0; i < 3; i++)cin >> v[i];
    sort(v.begin(), v.end());
    int k;
    cin >> k;
    for (int i = 0; i < k; i++)v[2] *= 2;
    cout << v[0] + v[1] + v[2] << endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int64_t n;
  cin>>n;

  int ans = 0;

  auto ok = [](int64_t n)->bool{
    bool a=false,b=false,c=false;
    while(n){
      if(n%10==3)a=true;
      if(n%10==5)b=true;
      if(n%10==7)c=true;
      n/=10;
    }
    return a&&b&&c;
  };

  auto dfs = [&](auto&& dfs,int64_t now)->void{
    if(now>n)return;
    if(ok(now))ans++;
    dfs(dfs,now*10+3);
    dfs(dfs,now*10+5);
    dfs(dfs,now*10+7);
  };
  dfs(dfs,0);
  cout<<(ans)<<endl;

}

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


int main() {
    int N;
    std::cin >> N;
    std::vector<std::pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        int val;
        std::cin >> val;
        A[i] = std::make_pair(i, val);
    }
    std::sort(A.begin(), A.end(), [](auto lhs, auto rhs) {return lhs.second > rhs.second;});

    auto max = A[0];
    for (int i = 0; i < N; i++) {
        if (max.first == i) {
            std::cout << A[1].second << std::endl;
        } else {
            std::cout << max.second << std::endl;
        }
    }
}


Measured memory_bytes: 4772
#include<stdio.h>
#include<stdlib.h>

int main(void) {
    int *a = new int;
    int *b = new int;

    scanf("%d %d", a, b);
    
    if(*a * *b %2 == 0){
    printf("Even");
    }else{
    printf("Odd");
	}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int T, n, m, to[10101];
vector<int> v[404];
vector<P> G[404];
vector<vector<int>> dist(404, vector<int>(404, INF));
vector<int> route[404][404];

void floyd(){
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			for(int k = 1; k <= n; k++){
				if(dist[j][k] > dist[j][i] + dist[i][k]){
					//route[j][k] = route[j][i]+route[i][k];
					route[j][k] = route[j][i];
					route[j][k].insert(route[j][k].end(),route[i][k].begin(),route[i][k].end());
					dist[j][k] = dist[j][i] + dist[i][k];
				}
			}
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i = 0; i <= n; i++){
		dist[i][i] = 0;
	}
	for(int i = 0; i < m; i++){
		int a,b,c;
		cin >> a >> b >> c;
		G[a].push_back(P(b,c));
		G[b].push_back(P(a,c));
		dist[a][b] = c;
		dist[b][a] = c;
		route[a][b].push_back(b);
		route[b][a].push_back(a);
	}
	cin >> T;
	for(int i = 0; i < T; i++){
		int a,b,c;
		cin >> a;
		if(a){
			cin >> b >> c;
			v[c].push_back(i);
			to[i] = c;
		}
	}
	
	floyd();
	
	int now = 1, next = 0;
	int have[404] = {0};
	for(int t = 0; t < T; t++){
		if(now == 1) have[to[t]]++;
		if(next > t) continue;
		int k, ma = -1;
		for(int i = 2; i <= n; i++){
			if(!have[i]) continue;
			if(dist[1][i] >= T-t) continue;
			int cnt = 0;
			for(int j = 0; j < route[1][i].size(); j++){
				cnt += have[route[1][i][j]];
			}
			if(ma < cnt * 1000 / dist[1][i]){
				ma = cnt;
				k = i;
			}
		}
		
		if(ma >= 100){
			next = t + dist[1][k]*2;
			int cnt = t;
			for(int j = 0; j < route[1][k].size(); j++){
				int npos = route[1][k][j];
				have[npos] = 0;
				for(int i = 0; i < dist[now][npos]; i++){
					if(cnt >= T) break;
					cnt++;
					cout << npos << endl;
				}
				now = npos;
			}
			for(int i = route[1][k].size()-2; i >= -1; i--){
				int npos;
				if(i == -1) npos = 1;
				else npos = route[1][k][i];
				for(int j = 0; j < dist[now][npos]; j++){
					if(cnt >= T) break;
					cnt++;
					cout << npos << endl;
				}
				now = npos;
			}
		}
		else{
			cout << -1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 27136
using System;
using System.Collections.Generic;

namespace b
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var X = Console.ReadLine().Split(' ');
            int A = int.Parse(X[0]);
            int B = int.Parse(X[1]);
            int C = int.Parse(X[2]);
            int D = int.Parse(X[3]);
            while (true)
            {
                C = C - B;
                if(C <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }
                A = A - D;
                if(A <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 17848
//1_3_D                                                                         
#include<stdio.h>

int main(void)
{
        int a, b, c, i, div = 0;
        scanf("%d %d %d", &a, &b, &c);

        for(i = a; i <= b; i++){
                if(c%i == 0){
                        div += 1;
                }
        }

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

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

int N, A, B, C;
string s[110000];
stack<char> res;

bool dfs(int depth, int a, int b, int c) {
    if(a < 0 || b < 0 || c < 0) return false;

    if(depth == N) {
        return true;
    }

    if(s[depth] == "AB") {
        if(dfs(depth + 1, a + 1, b - 1, c)) {
            res.push('A'); return true;
        }
        if(dfs(depth + 1, a - 1, b + 1, c)) {
            res.push('B'); return true;
        }
        return false;
    } else if(s[depth] == "BC") {
        if(dfs(depth + 1, a, b + 1, c - 1)) {
            res.push('B'); return true;
        }
        if(dfs(depth + 1, a, b - 1, c + 1)) {
            res.push('C'); return true;
        }
        return false;
    } else {
        if(dfs(depth + 1, a - 1, b, c + 1)) {
            res.push('C'); return true;
        }
        if(dfs(depth + 1, a + 1, b, c - 1)) {
            res.push('A'); return true;
        }
        return false;
    }
}

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

    dfs(0, A, B, C);
    if(res.size() < N) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
        while(!res.empty()) {
            cout << res.top() << '\n';
            res.pop();
        }
    }
}

Measured memory_bytes: 13416
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int w,h,n; cin>>w>>h>>n;
	int vec[120][120];
	n++;
	while(--n){
		int x,y; cin>>x>>y;
		//--x; --y;
		int type; cin>>type;
		if(type==1){
			rep(i,0,x){
				rep(j,0,h){
					vec[i][j]=1;
				}
			}
		}
		else if(type==2){
			rep(i,x,w){
				rep(j,0,h){
					vec[i][j]=1;
				}
			}
		}
		else if(type==3){
			rep(i,0,w){
				rep(j,0,y){
					vec[i][j]=1;
				}
			}
		}
		else{
			rep(i,0,w){
				rep(j,y,h){
					vec[i][j]=1;
				}
			}
		}
	}
	ll ans=0;
	rep(i,0,w){
		rep(j,0,h){
			if(!vec[i][j]) ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<cstring>
#define ll long long
using namespace std;
const int maxn=5*1e5+5;

int n;
string s;

struct po
{
	int le;
	int ri;
	int ans;
}head[maxn<<2];

void update(int num)
{
	head[num].ans=head[num*2].ans|head[num*2+1].ans;
}

void maketree(int num,int l,int r)
{
	head[num].le=l;
	head[num].ri=r;
	if(l==r) 
	{
		head[num].ans=1<<(s[l-1]-97);
	}
	else 
	{
		int mid=(l+r)/2;
		maketree(num*2,l,mid);
		maketree(num*2+1,mid+1,r);
		update(num);
	}
}

void change(int num,int n,int wei)
{
	if(head[num].le==head[num].ri)
	{
		head[num].ans=1<<wei;
	}
	else 
	{
		int mid=(head[num].le+head[num].ri)/2;
		if(mid>=n) 
		{
			change(num*2,n,wei);
			update(num);
		}
		else 
		{
			change(num*2+1,n,wei);
			update(num);
		}
	}
}

int find(int num,int l,int r)
{
	if(l==head[num].le&&r==head[num].ri) return head[num].ans;
	int mid=(head[num].le+head[num].ri)/2;
	if(mid>=r) return find(num*2,l,r);
	else if(mid<l) return find(num*2+1,l,r);
	else return find(num*2,l,mid)|find(num*2+1,mid+1,r);
}


int main()
{
	cin>>n>>s;
	maketree(1,1,n);
	int q;
	cin>>q;
	for(int j=0;j<q;j++)
	{
		int nn,l,r;
		scanf("%d",&nn);
		if(nn==1)
		{
			int lo;
			char c;
			cin>>lo>>c;
			change(1,lo,c-97);
		}
		else 
		{
			int l,r;
			scanf("%d%d",&l,&r);
			int tot=0;
			int anss=find(1,l,r);
			for(int i=0;i<=26;i++)
			{
				int kk=1<<i;
				if(kk&anss) tot++;
			}
			cout<<tot<<endl;
		}
	}
    return 0;
}

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

using namespace std;

int p, n;
int arr[20100];
int ord[20100];
int rrd[20100];
int YES(int a) {return a*2;}
int NO(int a) {return a*2+1;}
int key = 32768;
struct twosat {
    vector<int> lis[140100];
    int lab[140100];
    int tim[140100];
    int lnk[140100];
    stack<int> st;
    int tt, ct;
    int NOT(int a) {return a^1;}
    void init() {
        int i;
        tt = ct = 0;
        for (i=0;i<4*key;i++) lnk[i] = lab[i] = tim[i] = -1;
        for (i=0;i<4*key;i++) lis[i].clear();
    }
    void add(int a, int b) {
        lis[NOT(a)].push_back(b);
        lis[NOT(b)].push_back(a);
    }
    void dfs(int here) {
        lnk[here] = tim[here] = tt++;
        st.push(here);
        int i;
        for (i=0;i<lis[here].size();i++) {
            int there = lis[here][i];
            if (tim[there]==-1) {
                dfs(there);
                lnk[here] = min(lnk[here],lnk[there]);
            }
            else if (lab[there]==-1) lnk[here] = min(lnk[here],tim[there]);
        }
        if (lnk[here]==tim[here]) {
            while(!st.empty()) {
                int t = st.top();
                lab[t] = ct;
                st.pop();
                if (t==here) break;
            }
            ct++;
        }
    }
    void scc() {
        for (int i=0;i<4*key;i++) if (tim[i]==-1) dfs(i);
    }
    bool ok() {
        scc();
        for (int i=0;i<2*key;i++) if (lab[YES(i)]==lab[NO(i)]) return false;
        return true;
    }
} ts;

void init() {
    int i;
    for (i=key-1;i>0;i--) {
        ts.add(NO(2*i),YES(i));
        ts.add(NO(2*i+1),YES(i));
    }
}

void upd(int s, int e, int idx) {
    s+=key;e+=key;idx+=key;
    while(s<=e) {
        if (s&1) ts.add(NO(idx),NO(s++));
        if (~e&1) ts.add(NO(idx),NO(e--));
        s>>=1;e>>=1;
    }
}

bool ok(int t) {
    int i, j;
    ts.init();
    for (i=0;i<n;i++) {
        ts.add(YES(rrd[i*2]+key),YES(rrd[i*2+1]+key));
        ts.add(NO(rrd[i*2]+key),NO(rrd[i*2+1]+key));
    }
    init();
    j = 1;
    for (i=0;i<2*n;i++) {
        for (j=max(j,i+1);j<2*n&&arr[ord[i]]+t>arr[ord[j]];j++);
        upd(i+1,j-1,i);
    }
    return ts.ok();
}

bool cmp(int a, int b) {return arr[a]<arr[b];}
int main() {
    int i;

    scanf("%d",&n);
    for (i=0;i<n;i++) scanf("%d%d",&arr[i*2],&arr[i*2+1]);
    for (i=0;i<2*n;i++) ord[i] = i;
    sort(ord,ord+2*n,cmp);
    for (i=0;i<2*n;i++) rrd[ord[i]] = i;
    int s = 0, e = 1e9+1;

    while(s<=e) {
        int d = (s+e)>>1;
        if (ok(d)) s = d+1;
        else e = d-1;
    }

    printf("%d\n",e);

    return 0;
}


Measured memory_bytes: 17568
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    ll c = 26, digit = 1;
    while (N - c > 0)
    {
        N -= c;
        c *= 26;
        digit++;
    }

    // 0-indexed
    N--;

    vector<ll> ans(digit, 0);
    rep(0, i, digit)
    {
        ans.at(i) = N % 26;
        N /= 26;
    }
    reverse(all(ans));

    rep(0, i, digit)
    {
        cout << (char)('a' + ans.at(i));
    }
    cout << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 10000000000

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int S[1000000000], L[1000000],R[1000000];
long long int cnv=0;

int main(){
  int i,n;

  scanf("%d",&n);


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

  mergeSort(S,0,n);

  printf("%lld\n",cnv);
  return 0;
}

void merge(int *A,int left,int mid,int right){

  int i,j,k,n,m;

  n=mid-left;
  m=right-mid;

  for(i=0;i<n;i++){  L[i]=A[left+i];  }
  for(i=0;i<m;i++){  R[i]=A[mid+i];  }
  i=j=0;
  L[n]=N;
  R[m]=N;

 

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j+=1;
      cnv+=n-i;
    }
  }
}

void mergeSort(int *A,int left, int right){

  int mid;

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



Measured memory_bytes: 3412
L,R = map(int,input().split())

if R-L > 672:
    print(0)
else:
    minMod = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            tmp = (i*j)%2019
            if tmp == 0:
                minMod = 0
                break
            minMod = min(tmp,minMod)
    print(minMod)
    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
#define ull unsigned long long
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const int ESP = 1e-12;

int main(){
    fast;
    string s;
    cin >> s;
    ll sum = 0;
    for(auto i : s){
        sum += i - '0';
    }
    if(sum % 3 == 0) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << st.size() << "\n";
}


Measured memory_bytes: 3572