akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#define x first
#define y second
using namespace std;
int n, m, i, j, ii, sol, p, u, vf;
int a[405][405], t[405][405], ff[405], ok[405], c[405];
pair<int, int> v[100005];
int main(){
    cin>> n >> m;
    for(i = 1; i <= m; i++){
        cin>> v[i].x >> v[i].y;
        if(a[ v[i].x ][ v[i].y ] == 0){
            a[ v[i].x ][ v[i].y ] = i;
            a[ v[i].y ][ v[i].x ] = i;
        }
    }
    for(i = 1; i <= n; i++){
        ok[i] = 1;
        for(j = 1; j <= n; j++){
            ff[j] = 0;
        }
        t[i][i] = m + 1;
        p = u = 1;
        c[1] = i;
        while(p <= u){
            for(j = 1; j <= n; j++){
                if(a[ c[p] ][j] != 0 && a[ c[p] ][j] < t[i][ c[p] ] && t[i][j] == 0){
                    t[i][j] = a[ c[p] ][j];
                    c[++u] = j;
                }
            }
            p++;
        }
        for(j = 1; j <= m; j++){
            if(t[i][ v[j].x ] > j && t[i][ v[j].y ] > j){
                ok[i] = 0;
                break;
            }
            if(t[i][ v[j].x ] == j){
                ff[ v[j].x ] = 1;
                continue;
            }
            if(t[i][ v[j].y ] == j){
                ff[ v[j].y ] = 1;
                continue;
            }
            if(t[i][ v[j].x ] > j){
                if(ff[ v[j].y ] == 1){
                    ok[i] = 0;
                }
                else{
                    ff[ v[j].y ] = 1;
                }
                continue;
            }
            if(t[i][ v[j].y ] > j){
                if(ff[ v[j].x ] == 1){
                    ok[i] = 0;
                }
                else{
                    ff[ v[j].x ] = 1;
                }
                continue;
            }
            if(ff[ v[j].x ] == 1){
                ff[ v[j].y ] = 1;
                continue;
            }
            if(ff[ v[j].y ] == 1){
                ff[ v[j].x ] = 1;
                continue;
            }
        }
    }
    for(i = 1; i < n; i++){
        for(j = i + 1; j <= n; j++){
            if(ok[i] == 1 && ok[j] == 1){
                vf = 1;
                for(ii = 1; ii <= n; ii++){
                    if(t[i][ii] != 0 && t[j][ii] != 0 && t[i][ii] != t[j][ii]){
                        vf = 0;
                        break;
                    }
                }
                sol += vf;
            }
        }
    }
    cout<< sol;
}


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

int main(){
    int n; 
    cin >> n;
    string s;
    cin >> s;
    int c = 0;
    for(int i = 0; i <=n-3; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') c++;

    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
using namespace std;

int t;
ll A,B,C,D;
unordered_map<ll,ll> mp;
ll solve(ll n){
    if(n==0) return 0;
    if(n==1) return D;
    if(mp[n]>0) return  mp[n];
    ll l1=(n/2)*2LL;
    ll r1=((n+1)/2)*2LL;
    ll l2=(n/3)*3LL;
    ll r2=((n+2)/3)*3LL;
    ll l3=(n/5)*5LL;
    ll r3=((n+4)/5)*5LL;

    ll ans=(ll)1e18;
    if(n<(ans/D)) ans=n*D;

    ans=min(ans,llabs(n-l1)*D+A+solve(l1/2LL));
    ans=min(ans,llabs(n-r1)*D+A+solve(r1/2LL));
    
    ans=min(ans,llabs(n-l2)*D+B+solve(l2/3LL));
    ans=min(ans,llabs(n-r2)*D+B+solve(r2/3LL));

    ans=min(ans,llabs(n-l3)*D+C+solve(l3/5LL));
    ans=min(ans,llabs(n-r3)*D+C+solve(r3/5LL));
    
    mp[n]=ans;
    return mp[n];  
    
}

int main(){
   cin>>t;
   while(t--){
     ll n;
     cin>>n>>A>>B>>C>>D;
     cout<<solve(n)<<"\n";
     mp.clear();
   }
} 


Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int s[10];
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    s[a]++,s[b]++,s[c]++;
    if(s[5]==2&&s[7]==1) printf("YES\n");
    else printf("NO\n");
}


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

typedef pair<int, int> pii;
typedef long long ll;

int main(void) {
    int n, m;
    cin >> n >> m;
    vector<int> p(n), q(m);
    vector<pii> a;
    for (int i = 0; i < n; ++ i) {
        cin >> p[i];
        a.emplace_back(pii(p[i], 1));
    }
    for (int i = 0; i < m; ++ i) {
        cin >> q[i];
        a.emplace_back(pii(q[i], 0));
    }

    sort(begin(a), end(a));

    ll ans = 0;
    int rows = n + 1, cols = m + 1;
    for (int i = 0; i < n + m; ++ i) {
        if (a[i].second == 1) {
            if (rows == 1) continue;
            ans += cols * (ll)a[i].first;
            -- rows;
        } else {
            if (cols == 1) continue;
            ans += rows * (ll)a[i].first;
            -- cols;
        }
        if (rows == 1 && cols == 1) break;
    //    cout << rows << ' ' << cols << ' ' << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3820
n,t=map(int,input().split())
a=list(map(int,input().split()))
list1=[0]*n
list1[0]=a[0]
list2=[0]*n
list2[n-1]=a[n-1]
for i in range(1,n):
    list1[i]=min(list1[i-1],a[i])
for i in range(n-2,-1,-1):
    list2[i]=max(list2[i+1],a[i])
lst=[]
for i in range(n):
    lst.append([list2[i]-list1[i],list1[i]])
count=1
lst.sort(reverse=True)
for i in range(1,n):
    if lst[i][0]==lst[i-1][0]:
        if lst[i][1]!=lst[i-1][1]:
            count+=1
    else:
        break
print(count)

Measured memory_bytes: 74220
"""
被りなし
cmb(n-2,k)
被りあり2子使うなら
  x,x,x, A, y,y,y,y, A, z,z,z
cmb(n-2,k-2)
被りあり、１つだけ使うなら。。。
  cmb(n-2,k-1) * 2 # y使うかもしれないけーす
  cmb(count(x) + count(z), k-1) # y使わないケース（２倍カウントしてる）
"""
N = int(input())
A = list(map(int, input().split()))
dup = sum(A) - N*(N+1)//2
idx = []
for i in range(len(A)):
  if A[i] == dup:
    idx.append(i)
    
countXZ = N - idx[1] + idx[0]
### nCr mod
# https://qiita.com/derodero24/items/91b6468e66923a87f39f
mod = 10**9+7 #出力の制限
NMAX = 10**5+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NMAX + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def cmb(n, r, m=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % m

# solve
print(N) # k=1
for k in range(2,N+1):
  wk = cmb(N-1,k)
  wk += cmb(N-1,k-2)
  wk += cmb(N-1,k-1) * 2
  wk -= cmb(countXZ, k-1)
  #print(cmb(N-1,k), cmb(N-1,k-2), cmb(N-1,k-1) * 2, cmb(countXZ, k-1))
  print(wk % mod)
print(1) # k=N+1

Measured memory_bytes: 120528
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int M,N;

map<ll, ll> factorize(int m) {
    map<ll, ll> factors;
    for (int i=2; i*i<=m; i++) {
        while (m % i == 0) {
            m /= i;
            factors[i]++;
        }
    }
    if (m != 1) {
        factors[m] = 1;
    }
    return factors;
}

ll inv(int n, int k = MOD - 2) {
    if (k == 0) {
        return 1;
    }
    ll prev = inv(n, k / 2);
    if (k % 2 == 0) {
        return (prev * prev) % MOD;
    } else {
        return (((prev * prev) % MOD) * n) % MOD;
    }
}

// C(n,k) = n! / ( (n-k)! * k! )
ll comb(int n, int k) {
    ll answer = 1;
    for (int i=1; i<=k; i++) {
        answer *= (n - i + 1);
        answer %= MOD;
        answer *= inv(i);
        answer %= MOD;
    }
    return answer;
}

int main() {
    cin >> N >> M;
    auto&& factors = factorize(M);
    ll answer = 1;
    for (auto&& f : factors) {
        answer *= comb(f.second + N - 1, f.second);
        answer %= MOD;
    }
    cout << answer << endl;
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    map<ll, ll> A;
    ll maxi = 0;
    ll N;
    cin >> N;
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        A[temp]++;
    }
    for(ll i = (*A.begin()).first;i <= (*--A.end()).first;i++) {
        ll count = 0;
        if(A.find(i) != A.end()) count += A[i];
        if(A.find(i - 1) != A.end()) count += A[i - 1];
        if(A.find(i + 1) != A.end()) count += A[i + 1];
        maxi = max(maxi, count);
    }
    cout << maxi << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
int main(void){


    int a,b,c,i,z,count=0;
    
    scanf("%d %d %d",&a,&b,&c);
        for(i=a;i<=b;i++){
        z=c%i;
            if(z==0){
                count++;
            }
        }       
        printf("%d\n",count);
                
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define M 1e7
using namespace std;
int main(){
	int n,i,j,b[6];
	while(cin>>n,n){
		int a[86400]={0},ans=0,c=0;
		while(n--){
			scanf("%d:%d:%d %d:%d:%d",&b[0],&b[1],&b[2],&b[3],&b[4],&b[5]);
			a[b[0]*3600+b[1]*60+b[2]]++;
			a[b[3]*3600+b[4]*60+b[5]]--;
		}
		for(i=0;i<86400;i++){
			c+=a[i];
			ans=max(ans,c);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    vll l;
    for (auto x : mp) {
        while (x.se >= 2) {
            l.push_back(x.fi);
            x.se -= 2;
        }
    }
    sort(rall(l));
    ll ans = 0;
    if (l.size() >= 2) ans = l[0] * l[1];

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

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N, M;
    std::cin >> N >> M;

    vector<vector<int>> work(M);
    REP(i, N) {
        int a, b;
        std::cin >> a >> b;
        if(M < a) continue;
        work[a - 1].push_back(b);
    }

    ll  ans = 0;
    int i   = 0;
    int day = 0;
    priority_queue<int> pq;
    while(true) {
        if(0 < work[i].size()) {
            for(const auto& v : work[i]) {
                pq.emplace(v);
            }
        }

        if(0 < pq.size()) {
            auto top = pq.top();
            pq.pop();
            ans += top;
        }

        day++;
        if(day == M) break;
        i = min(i + 1, M - 1);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 5632
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n; cin >> n;
  int t = 0;
  int x = 0;
  int y = 0;
  for (int i = 0; i < n; i++) {
    int tt, xx, yy; cin >> tt >> xx >> yy;
    int d = abs(xx - x) + abs(yy - y);
    if (tt - t < d || (tt - t) % 2 != d % 2) {
      cout << "No";
      return 0;
    } 
  }
  cout << "Yes";
}

Measured memory_bytes: 764
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, readline().split()))
    s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
    bc = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                bc += 1

    ql = [[0, 0, 0]]
    ql = collections.deque(ql)
    fq = collections.defaultdict(list)
    fq[0, 0]
    mt = 10 ** 10
    while True:
        if len(ql) != 0:
            cost, xv, yv = ql.popleft()
            if xv == h - 1 and yv == w - 1:
                mt = min(mt, cost)
            for xv, yv in [[xv + 1, yv], [xv - 1, yv], [xv, yv + 1], [xv, yv - 1]]:
                if 0 <= xv < h and 0 <= yv < w:
                    if (xv, yv) not in fq and s[xv][yv] != "#":
                        ql.append([cost + 1, xv, yv])
                        fq[xv, yv]
        else:
            break
    print((h * w - mt - 1) - bc if mt != 10 ** 10 else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 41328
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans: usize = 0;
    for i in 0..n {
        if (i + 1) % 2 == 1 && a[i] % 2 == 1 {
            ans += 1;
        }
    }
    ans.to_string()
}


Measured memory_bytes: 2128
// Problem : E - Rotation Matching
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	int fst = 1, last = n;
	set<int> used;
	REP(_, k) {
		int diff = last - fst;
		while (used.count(last - fst) || used.count(n - (last - fst)) || 
			   ((last - fst) == (n / 2) && n % 2 == 0)) {
			last--;
		}
		used.insert(last - fst);
		used.insert(n - (last - fst));
		cout << fst << " " << last << "\n";
		last--;
		fst++;
	}
	return 0;
}
 


Measured memory_bytes: 12052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int N,K;
    scanf("%d%d",&N,&K);
    int sum=0;
    while(N)
    {
        N=N/K;
        sum++;
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 128
var n,h,num,max:int64;
    i:longint;
    a,b:array[0..200000]of int64;
procedure qs(l,r:longint);
var i,j,m,t:int64;
begin
  i:=l;
  j:=r;
  m:=b[(l+r)>>1];
  repeat
    while b[i]>m do inc(i);
    while b[j]<m do dec(j);
    if i<=j then
    begin
      t:=b[i];b[i]:=b[j];b[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;

begin
  read(n,h);
  for i:=1 to n do
  read(a[i],b[i]);
  qs(1,n); 
  for i:=1 to n do
  if a[i]>max then max:=a[i];
  for i:=1 to n do
  begin
    if (b[i]>max) then
    begin
      dec(h,b[i]);
      inc(num);
    end;
    if h<=0 then break;
  end;
  if h>0 then
  begin
    inc(num,h div max);
    if h mod max<>0 then inc(num);
  end;
  writeln(num);
end.


Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ACB170_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] xn = Console.ReadLine().Split(' ');
            int X = int.Parse(xn[0]);
            int N = int.Parse(xn[1]);
            List<int> p_list = new List<int>();
            int ans = X;

            if (N == 0)
            {
                Console.WriteLine(X);
                Console.ReadLine();
                return;
            }

            p_list = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            for (int i = 0; ; i++)
            {
                if (!p_list.Contains(X - i))
                {
                    Console.WriteLine(X - i);
                    return;
                }
                else if (!p_list.Contains(X + i))
                {
                    Console.WriteLine(X + i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 28280
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;



int main(){
	int N;
	cin>>N;
	vector<int> a(N);
	int cnt = 0;
	for(int i=0;i<N;i++){
		cin>>a[i];
		cnt+=a[i];
		a[i]*=N;
	}

	int min_a=99999;
	int ans;
	for(int i=0;i<N;i++){
		if(abs(cnt-a[i])<min_a){
			min_a=abs(cnt-a[i]);
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	long hm1, hm2;
	hm1 = h1 * 60 + m1; 
	hm2 = h2 * 60 + m2;

	long hmd = hm2 - hm1;
	long result = hmd - k ;
	
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  puts((abs(a-c)>d)*((abs(a-b)>d)||(abs(b-c)>d))?"No":"Yes");
  return 0;
}

Measured memory_bytes: 128
abc=list(map(int,input().split()))
abc.sort()

ans=abc[2]-abc[1]
abc[0]+=abc[2]-abc[1]
abc[1]=abc[2]


while True:
    if (abc[2]-abc[0])%2==0:
        break
    ans+=1
    abc[2]+=1

ans+=(abc[2]-abc[0])//2
print(ans)


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

string devide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for (int i=0; i<4; ++i) reverse(devide[i].begin(), devide[i].end());

    bool can = true;
    for (int i=0; i<S.size();) {
        bool can2 = false;
        for (int j=0; j<4; ++j) {
            string d = devide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

class Program
{
  public static void Main(string[] args)
  {
    int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = s[0];
    int m = s[1];
    int[][] a = new int[n][];
    int[] k = new int[m];
    for (int i = 0; i < m; i ++) k[i] = 0;
    for (int i = 0; i < n; i ++)
    {
      a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
      for (int j = 1; j < a[i].Count(); j ++)
      {
        k[a[i][j]-1] ++;
      }
    }
    var result = k.Where(value => value == n).Count();
    Console.WriteLine(result);
  }
}


Measured memory_bytes: 13524
#include<stdio.h>
#define   MAX 100
#define   INFTY 5000000
#define   WHITE 0
#define   GRAY 1
#define   BLACK 2

int n, M[MAX][MAX];

int prim()
{
   int u, minv;
   int d[MAX], p[MAX], color[MAX];
   int i, v, sum = 0;

   for (i=0; i<n; i++){
      d[i] = INFTY;
      p[i] = -1;
      color[i] = WHITE;
   }

   d[0] = 0;

   while (1){
      minv = INFTY;
      u = -1;
      for (i=0; i<n; i++){
         if (minv>d[i] && color[i]!=BLACK){
            u = i;
            minv = d[i];
         }
      }
      if (u==-1)
         break;
      color[u] = BLACK;
      for (v=0; v<n; v++){
         if (color[v]!=BLACK && M[u][v]!=INFTY){
            if (d[v]>M[u][v]){
               d[v] = M[u][v];
               p[v] = u;
               color[v] = GRAY;
            }
         }
      }
   }

   for (i=0; i<n; i++){
      if (p[i]!=-1)
         sum += M[i][p[i]];
   }

   return sum;
}

int main()
{
   int i, j, e;

   scanf("%d", &n);

   for (i=0; i<n; i++){
      for (j=0; j<n; j++){
         scanf("%d", &e);
         M[i][j] = (e==-1) ? INFTY : e;
      }
   }

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

   return 0;
}

Measured memory_bytes: 1748
#include <iostream>

using namespace std;

long long a, b;
long res;

int main()
{
	cin >> a >> b;

	res = 1;

	while (a <= b)
	{
		a *= 2;

		if (a <= b)
			++res;
	}

	cout << res << endl;

	return 0;
}

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

#define repfrom(i, from, n) for (ll i = (from); i < (n); i++)
#define rep(i, n) repfrom(i, 0, n)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
using uc = unsigned char;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
constexpr ll MAX_N = 1e5;

ll P[MAX_N + 1];
bool used[MAX_N + 1];
vector<ll> G[MAX_N + 1];

void dfs(ll node, vector<ll>& nodes, set<ll>& nums) {
    if (used[node]) {
        return;
    }
    
    used[node] = true;
    nodes.push_back(node);
    nums.insert(P[node]);
    
    for (auto g : G[node]) {
        dfs(g, nodes, nums);
    }
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, M;
    cin >> N >> M;
    
    reps(i, N) {
        cin >> P[i];
    }
    
    rep(i, M) {
        ll x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);

    }
    
    ll ans = 0;
    reps(i, N) {
        if (!used[i]) {
            vector<ll> nodes;
            set<ll> nums;
            dfs(i, nodes, nums);
            
            for (auto node : nodes) {
                ans += nums.count(node);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 16120
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  bool can = false;
  int N;
  int n;
  int h = 0;

  cin >> N;

  n = N;
  
  while(n != 0) {
    // cout << n << endl;
    h += n % 10;
    n /= 10;
  }

  if (N % h == 0) {
    can = true;
  }
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    b = list(map(int, input().split()))

    ans = 0
    for i in range(n-2):
        a = min(b[i], b[i + 1])
        ans += a
    print(ans + b[0] + b[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
while True:
	a,op,b=input().split(" ")
	a,b=[int(i) for i in (a,b)]
	if op=="+":
		print(a+b)
	elif op=="-":
		print(a-b)
	elif op=="*":
		print(a*b)
	elif op=="/":
		print(int(a/b))
	else:
		break

Measured memory_bytes: 6732
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int> > Matrix;


int main(){
  int n, m;
  cin >> n >> m;
  int maxl = 0, minr = 1000003;
  rep(i, m){
    int l, r;
    cin >> l >> r;
    maxl = max(maxl, l);
    minr = min(minr, r);
  }
  int ans = min(minr - maxl + 1, n);
  if (ans < 0) ans = 0;
  cout << ans << endl;
}

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

int main(void)
{
	char str[1000];
	int i;
	
	scanf("%s", str);
	
	for (i = 0; i < strlen(str); i++){
		switch(str[i]){
			case 'A':
				printf("X");
				break;
			case 'B':
				printf("Y");
				break;
			case 'C':
				printf("Z");
				break;
			default:
				printf("%c", str[i] - 3);
				break;
		}
	}
	printf("\n");
	
	return (0);
}

Measured memory_bytes: 524
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = INT()
S, T = input().split()

new_word = ""
for s, t in zip(S, T):
	new_word = new_word + s + t
print(new_word)

Measured memory_bytes: 60140
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main(void){
    map<char, char> p;
    p['A'] = 'T';
    p['T'] = 'A';
    p['C'] = 'G';
    p['G'] = 'C';
    string b;
    cin >> b;
    for(int i = 0; i < b.length(); i++) cout << p[b[i]];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))

s = 0

if n >= m:
    s = 0
else:
    x.sort()
    d = []
    for j in range(m-1):
        d.append(x[j+1]-x[j])
    d.sort()
    s = sum(d[:m-n])

print(s)

Measured memory_bytes: 90952
// ConsoleApplication69.cpp : アプリケーションのエントリ ポイントを定義します。

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;
typedef long long int ll;
ll  i, j, k, l, m, sum, flag, N, x, y, M, K, H, W,A,B;
ll h[100001];
bool check(ll x) {
	ll c = 0;
	REP(i, 0, N) {
		H = h[i] - x * B;
		if (H < 0)continue;
		if (H % A != 0)
			c += H / A + 1;
		else
			c += H / A;
	}
	return c <= x;
	
}

int main()
{

	sum = 0;
	flag = 0;
	cin >>N>> A >> B;
	A -= B;
	REP(i, 0, N) {
		cin >> h[i];
	}
	ll ng = 0;
	ll ok = 1000000000;

	while (ng + 1 != ok) {
		x = (ng + ok) / 2;
		if (check(x)) {
			ok = x;
		}
		else
			ng = x;
	}
	output(ok);
	return 0;
}













Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main(){
	string str;
	cin >> str;

	char temp = str[0];
	for(int i = 1; i < 4; i++) {
		if(temp == str[i]){
			cout << "Bad" << endl;
			return 0;
		}
		temp = str[i];
	}

	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

what_to_do = []
for i in range(N):
    input2 = input().split()
    tmp1,tmp2,tmp3 = list(map(int,input2))
    what_to_do.append([tmp1,tmp2,tmp3])

dp = []
for _ in range(N+1):
    dp.append([0,0,0])

for i in range(N):
    for k in range(3):
        for j in range(3):
            if k != j:
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + what_to_do[i][k])
                
            
print(max(dp[-1]))


Measured memory_bytes: 42900
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int n,x,y;
    cin>>n;
    int h[n],minC[n];
    for(int i=0;i<n;i++) cin>>h[i];
    minC[0]=0;
    minC[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++)
    {
        x=abs(h[i]-h[i-1])+minC[i-1];
        y=abs(h[i]-h[i-2])+minC[i-2];
        minC[i]=min(x,y);
    }
    cout<<minC[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
q = int(input())
n = 10**5
ansli = [0]*(n+1)

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime

li = primes(n+1)
for i in range(3,n + 1):
    if li[i] and li[(i+1)//2]:
        ansli[i] = ansli[i - 1] + 1
    else:
        ansli[i] = ansli[i - 1]

for i in range(q):
    l, r = map(int, input().split())
    print(ansli[r] - ansli[l-1])

Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

int main(){
    int n, q;
    scanf("%d%d", &n, &q);
    ppi p[n];
    rep(i, n){
        int s, t, x;
        scanf("%d%d%d", &s, &t, &x);
        p[i] = make_pair(make_pair(max(0, s-x), max(0, t-x)), x);
    }
    sort(p, p+n);
    int cur = 0;
    priority_queue<pii, vector<pii>, greater<pii>> que;
    rep(i, q){
        int d;
        scanf("%d", &d);
        while(cur < n && p[cur].fi.fi <= d){
            que.push(make_pair(p[cur].se, p[cur].fi.se));
            cur++;
        }
        while(true){
            if(que.empty()){
                printf("%d\n", -1);
                break;
            }
            pii v = que.top();
            if(v.se <= d){
                que.pop();
                continue;
            }
            printf("%d\n", v.fi);
            break;
        }
    }
}

Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i <= (n); i++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
using ll = long long;
template <class T>
using Grid = vector<vector<T>>;
vector<pair<int, int>> prime_fact(int n) {
    vector<pair<int, int>> v;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0)
            continue;
        int cnt = 0;
        while (n % i == 0) {
            cnt++;
            n /= i;
        }
        v.emplace_back(i, cnt);
    }
    if (n != 1)
        v.emplace_back(n, 1);
    return v;
}
const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x = 0)
        : x((x % mod + mod) % mod) {}
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        return mint(*this) += a;
    }
    mint operator-(const mint a) const {
        return mint(*this) -= a;
    }
    mint operator*(const mint a) const {
        return mint(*this) *= a;
    }
    mint pow(ll t) const {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint &operator/=(const mint a) {
        return *this *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream &operator>>(istream &is, const mint &a) {
    return is >> a.x;
}
ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint P(int n, int k){
        return fact[n] * ifact[n-k];
    }
};
int main() {
    int N, M;
    cin >> N >> M;
    const auto &v = prime_fact(M);
    mint ans = 1;
    combination c(N + 100);
    for (auto x : v) {
        ans *= c(x.second + N - 1, x.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4784
MyString=Union{String,SubString{String},Char}
MyStringArray=Union{Array{String,1},Array{SubString{String},1},Array{Char,1}}
parseInt(x::MyString) = parse(Int, x)
parseInt(x::Real) = trunc(Int, x)
parseBigInt(x::MyString) = parse(BigInt, x)
parseBigInt(x::Real) = trunc(BigInt, x)
parseFloat(x::MyString) = parse(Float64, x)
parseFloat(x::Real) = trunc(Float64, x)
parseBigFloat(x::MyString) = parse(BigFloat, x)
parseBigFloat(x::Real) = trunc(BigFloat, x)
parseMap(x::MyStringArray) = map(parseInt, x)
parseMapBig(x::MyStringArray) = map(parseBigInt, x)

ans=0
function dfs(s,n,arr::Vector{String},cnt)
    if cnt==n+1
        global ans+=sum(parseMap(arr))
        return
    end
    num=string(s[cnt])
    if cnt==1
        push!(arr,num)
        dfs(s,n,arr,cnt+1)
    else
        arr1,arr2=copy(arr),copy(arr)
        push!(arr1,num)
        dfs(s,n,arr1,cnt+1)
        arr2[end]=join([arr2[end],num])
        dfs(s,n,arr2,cnt+1)
    end
end
function main()
    s=chomp(readline())
    n=length(s)
    dfs(s,n,Vector{String}(),1)
    println(ans)
end
main()

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

using namespace std;
typedef long long LL;

int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	int Q;
	cin >> Q;
	set<int> s[26];
	char base='a';
	rep(i,N){
		int num=S[i]-base;
		s[num].insert(i);
	}
	while(Q--){
		int t;
		cin >> t;
		if(t==1){
			int i;
			char c;
			cin >> i >> c;
			i--;
			int del, add=c-base;
			rep(j,26){
				auto itr=s[j].find(i);
				if(itr==s[j].end()) continue;
				del=j;
				break;
			}
			s[del].erase(i);
			s[add].insert(i);
		}
		if(t==2){
			int l, r;
			cin >> l >> r;
			l--; r--;
			int ans=0;
			rep(i,26){
				auto itr=s[i].lower_bound(l);
				if(itr!=s[i].end() && *itr<=r) ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}

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

int main() {
	int n, x; cin >> n >> x;
	vector<int>a(n); for (auto&& xx : a)cin >> xx;
	long long ans = 0;
	if (a[0] > x) { long long dif = a[0] - x; a[0] -= dif; ans += dif; }
	for (int i = 0; i < n - 1; i++) {
		if ((a[i] + a[i + 1]) > x) { long long dif = (a[i] + a[i + 1]) - x; a[i + 1] -= dif; ans += dif; }
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

vector<int> factor;
int main(){
  IOS();
  int n,m;
  cin>>n>>m;
  REP1(i,sqrt(m)){
    if( m%i==0 ){
      factor.eb(i);
      if( i!=m/i ) factor.eb(m/i);
    }
  }
  sort(ALL(factor));
  int ans = 0;
  REP(i,SZ(factor))if( m/factor[i]>=n ) ans = factor[i];
  cout<<ans<<endl;
}


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

using namespace std;

int main() {

  int N;
  cin >> N;

  if (N == 0) {
    cout << '0' << endl;
  } else {

    forward_list<bool> l;
    int remain = N;
    for (int e = 0; remain != 0; ++e) {
      int target;
      if (e%2 == 0) {
        target = (1 << e);
      } else {
        target = -1 * (1 << e);
      }

      if (abs(remain) % (2 << e) != 0) {
        remain -= target;
        l.push_front(true);
      } else {
        l.push_front(false);
      }
    }

    for (auto itr = l.begin(); itr != l.end(); ++itr) {
      if (*itr) cout << '1';
      else cout << '0';
    }
    cout << endl;

  }

}


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

using namespace std;

const int Nmax = 2e5 + 5;
int n, M, a[Nmax];

bool check(int p)
{
    for(int x = 2*n; p<x; --x, ++p)
        if(a[p] + a[x] < M) return 0;
    return 1;
}

int main()
{
 //   freopen("input", "r", stdin);
    cin.sync_with_stdio(false);
    cin.tie(0);

    int i, j;

    cin >> n >> M;
    for(i=1; i<=2*n; ++i) cin >> a[i];
    sort(a+1, a+2*n+1);

    int st, dr, mid;

    st = 0; dr = n;
    while(st <= dr)
    {
        mid = (st + dr) / 2;
        if(check(2*mid+1)) dr = mid - 1;
            else st = mid + 1;
    }

    int split = 2 * st;
    int ans = 0;

    for(i=1, j=split; i<=split/2; ++i, --j)
    {
        assert(a[i] + a[j] < M);
        ans = max(ans, a[i] + a[j]);
    }

    for(i=split+1, j=2*n; j > n + split/2; ++i, --j)
    {
        assert(a[i] + a[j] >= M);
        ans = max(ans, a[i] + a[j] - M);
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        if(b>=a){
            System.out.println(a);
        }else{
            System.out.println(a-1);
        }
    }
}


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

const ll MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int a,b;cin>>a>>b;
	if(a>b){
		rep(i,a)cout<<b;
		cout<<endl;
	}
	else{
		rep(i,b)cout<<a;
		cout<<endl;
	}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Income Inequality
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int sum = 0;
			int[] arr = new int[n];
			arr[0] = 0;

			StringTokenizer st = new StringTokenizer(br.readLine());

			for (int i = 0; i < n; i++) {
				sum += arr[i] = parseInt(st.nextToken());
			}

			int avg = sum / n;
			int ans = 0;

			Arrays.sort(arr);

			for (int i = 0; i < n; i++) {
				if (arr[i] <= avg) ans++;
			}

			System.out.println(ans);
		}
	}
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, q;
    cin >> a >> b >> q;
    vector<LL> s(a+1), t(b+1), x(q);
    s[0] = -INFL, t[0] = -INFL;
    REP(i, a) cin >> s[i+1];
    REP(i, b) cin >> t[i+1];
    REP(i, q) cin >> x[i];
    s.push_back(INFL);
    t.push_back(INFL);

    REP(i, q)
    {
        LL sl = *(lower_bound(all(s), x[i]) - 1);
        LL sr = *upper_bound(all(s), x[i]);
        LL tl = *(lower_bound(all(t), x[i]) - 1);
        LL tr = *upper_bound(all(t), x[i]);
        //cout << sl << " " << sr << " " << tl << " " << tr << endl;
        LL ans = min({max(tr, sr) - x[i], x[i] - min(tl, sl), min(x[i] - tl, sr - x[i]) + sr - tl, min(x[i] - sl, tr - x[i]) + tr - sl});
        cout << ans << endl;
    }

}

Measured memory_bytes: 3680
n=int(input())
a=list(map(int,input().split()))
k=max(a)
b=[0]*(n)
def Count(A, B, k):
	C=[0]*(k+1)
	for j in range(n):
		C[A[j]]+=1
	for i in range(1,k+1):
		C[i]+=C[i-1]
	for i in range(n-1,-1,-1):
		B[C[A[i]]-1]=A[i]
		C[A[i]]-=1
Count(a,b,k)
print(*b)


Measured memory_bytes: 224384
import java.util.*;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        double n = (double)sc.nextInt();
        double c = Math.ceil(n/1000)*1000;
        int x = (int)c - (int)n;
        System.out.println(x);

    }
}


Measured memory_bytes: 35656
#include <iostream>
#define N 2000000

using namespace std;

int main(){
  int i, j, n, k=0;
  int A[N], B[N], C[N];

  cin >> n;
  for(i=0;i<n;++i){
    cin >> A[i];
    if(A[i] > k) k = A[i];
  }
  
  for(i=0;i<=k;++i)C[i] = 0;
  for(i=0;i<n;++i)C[A[i]]++;
  for(i=0;i<=k;++i)C[i] += C[i-1];
  for(j=n-1;j>=0;--j){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
  }
  
  for(i=0;i<n;++i){
    cout << B[i];
    if(i != n-1)cout << " ";
  }
  cout << "\n";
  return 0;
}



Measured memory_bytes: 18736
/* ex4_3
  bonbonc */

#include<stdio.h>
int solve(int diff,int west_height);//プロトタイプ宣言

int main(void){
	int west_height,east_height,diff,total_height;
	scanf("%d%d",&west_height,&east_height);
	diff = east_height-west_height;//西の塔と東の塔の高さの差

	printf("%d",solve(diff,west_height));

	return 0;
}

int solve(int diff,int west_height){
	int real_west_height;
	real_west_height = diff*(diff-1)/2;//西の塔はdiff-1番目の塔なのでこの式で地面からの高さが求まる。

	return real_west_height-west_height;//地面からの高さと雪の上に出ている部分の高さの差を返す。
}

Measured memory_bytes: 128
#include <iostream>
 using namespace std;
 
int main() {
  int h,m,s;
  
  cin >> s;

  h = s/3600;
  m = (s%3600)/60;
  s = s%3600%60; 

  cout << h << ":" << m << ":" << s << endl;

  return 0;
}



Measured memory_bytes: 3088
package main

import (
	"fmt"
	"sort"
)

func main(){

	var num, length int
	fmt.Scan(&num, &length)
	list := make([]string, num)
	for i , _:= range list {
		fmt.Scan(&list[i])
	}
	sort.Strings(list)

	var sb string
	for i, _ := range list {
		sb += list[i]
	}
	fmt.Println(sb)
}

Measured memory_bytes: 1280
import java.util.Scanner;
  
class Main {
    public static void main(String[] args) {
        Scanner kb = new Scanner( System.in);   
          
        while( true ) {
            int H = kb.nextInt();
            int W = kb.nextInt();
              
            if( 0==W && 0==H ) { break; }
           
           StringBuilder output = new StringBuilder( 300+1 );	
            boolean cPattern=true;
            for( int i=0; i<H; i++ ) {
                cPattern= (0==(i&1))? true: false;
                for( int j=0; j<W; j++ ) {
                    if( cPattern ) {
                    	output.append( "#"  );
                        cPattern=!cPattern;
                    } else {
                        output.append( "."  );
                        cPattern=!cPattern;
                    }
                }
                output.append( "\n"  );
            }
            System.out.println( output );
        }
    }
}

Measured memory_bytes: 21180
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  vector<pair<ll,ll>> ba(n);
  rep(i,n) {
    ll a,b;
    cin>>a>>b;
    ba[i]=make_pair(b,-a);
  }
  sort(ba.begin(),ba.end());
  ll t=0;
  rep(i,n) {
    ll a,b;
    tie(b,a)=ba[i];
    a=-a;
    t+=a;
    if(t>b) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3456
N,K=gets.split.map(&:to_i)
A=gets.split.map(&:to_i)
g=0
N.times do |i|
	g=g.gcd(A[i])
end

if K>A.max
	puts 'IMPOSSIBLE'
elsif K%g==0
	puts 'POSSIBLE'
else
	puts 'IMPOSSIBLE'
end

Measured memory_bytes: 8452
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;

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

    ll n, k;
    cin >> n >> k;
    if (k <= n / 2 + n % 2) cout << "YES";
    else cout << "NO";
    return 0;
}


Measured memory_bytes: 256
<?php

class Operator
{
    private $operations;
    private $operations_count;

    public function doOperations()
    {
        fscanf(STDIN, '%d', $this->operations_count);
        $this->operations = new \SplDoublyLinkedList();
        while ($this->operations_count > 0) {
            $word = trim(fgets(STDIN));
            if ($word[0] === 'i') {
                $this->operations->unshift(substr($word, 7));
            } elseif ($word[6] === 'F') {
                $this->operations->shift();
            } elseif ($word[6] === 'L') {
                $this->operations->pop();
            } else {
                foreach ($this->operations as $key => $element) {
                    if ($element === substr($word, 7)) {
                        $this->operations->offsetUnset($key);
                        break;
                    }
                }
            }
            $this->operations_count -= 1;
        }
    }

    public function getAnswer()
    {
        while (1) {
            if (count($this->operations) > 0) {
                $keys_operated[] = $this->operations->shift();
            } else {
                break;
            }
        }
        echo implode(' ', $keys_operated), PHP_EOL;
    }
}

$operator = new Operator();
$operator->doOperations();
$operator->getAnswer();



Measured memory_bytes: 136148