akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int n, k, q, tmp;
    cin >> n >> k >> q;
    vector<int> a(n);
    int ini = k - q;
    rep(i, n) a[i] = ini;
    rep(i, q) {
        cin >> tmp;
        a[tmp - 1]++;
    }
    rep(i, n) {
        if (a[i] <= 0)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3700
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let n: i64 = read_as_vec()[0];
    let mut capacities: Vec<i64> = Vec::new();
    for _ in 0..5{
        capacities.push(read_as_vec()[0]);
    }

    let min_cap = capacities.iter().min().unwrap();


    println!("{}", (n-1)/min_cap+5);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int start = 1;
		for (int i=0;i<N;i++) {
			if (start<K) {
				start*=2;
			} else {
				start+=K;
			}
		}
		System.out.println(start);
	}
}

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

int main(){
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (a >= k) {
    cout << k << endl;
  } else if (a + b >= k){
    cout << a << endl;
  } else {
    cout << 2 * a + b - k << endl; 
  }
}

Measured memory_bytes: 3636
import numpy as np

N = int(input())
X = np.sort([int(x) for x in input().split()])

ave = 0
for i in range(N):
  ave += X[i]/N
ave = int(np.round(ave))
sum = 0
for i in range(N):
  sum += (X[i]-ave)**2
print(sum)

Measured memory_bytes: 13416
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll x;
    cin>>x;
    if (x>=30)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}


Measured memory_bytes: 3648
s=input()
n=len(s)
k=int(input())
if s[0]==s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  if d==0:
    print(ans*k)
  else:
    ans2=0
    for i in range(n):
      if s[i-1]==s[i] and d==1:
        ans2+=1
        d=0
      elif s[i-1]==s[i] and d==0:
        d=1
      elif s[i-1]!=s[i]:
        d=1
    if d==1:
      print(ans+ans2*(k-1))
    else:
      if k%2==0:
        print((ans+ans2)*k//2)
      else:
        print((ans+ans2)*(k//2)+ans)
elif s[0]!=s[n-1]:
  d=1
  ans=0
  for i in range(1,n):
    if s[i-1]==s[i] and d==1:
      ans+=1
      d=0
    elif s[i-1]==s[i] and d==0:
      d=1
    elif s[i-1]!=s[i]:
      d=1
  print(ans*k)

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

int main(){
  int N;
  cin >> N;
  ll ans=1;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i=0;i<N;i++){
    if(ans>(double)1e18/(double)A[i]){
      cout << -1 << endl;
      return 0;      
    }
    if(ans*A[i]>(ll)1e18){
      cout << -1 << endl;
      return 0;          
    }
    ans*=A[i];
  }
  cout << ans << endl;
}

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

array<array<bool, 1000>, 4> dp;
array<array<bool, 1000>, 4> dp_n;

void solve(long long N, string S)
{
    dp[0][0] = true;

    for (auto&& s : S) {
        for (int len = 0; len <= 3; ++len) {
            for (int current_key = 0; current_key < 1000; current_key++) {
                if (dp[len][current_key]) {
                    if (len < 3) {
                        dp_n[len + 1][current_key * 10 + s - '0'] = true;
                    }
                    dp_n[len][current_key] = true;
                }
            }
        }
        dp = dp_n;
        dp_n.fill({});
    }

    ll ans = count(begin(dp[3]), end(dp[3]), true);
    cout << ans << "\n";
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    long long N;
    scanf("%lld",&N);
    string S;
    cin >> S;
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(N, move(S));
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

int main() 
{
    int K, N;
    cin >> K >> N;
    int max_diff = 0;
    int sum = 0;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
        if(0 != i) {
            sum += vec.at(i) - vec.at(i - 1);
            if (max_diff < vec.at(i) - vec.at(i-1)) {
                max_diff = vec.at(i) - vec.at(i - 1);
            }
        }
    }

    sum += vec.at(0) + (K - vec.at(N - 1));
    if (max_diff < vec.at(0) + (K - vec.at(N-1))) {
        max_diff = vec.at(0) + (K - vec.at(N - 1));
    }

    sum -= max_diff;
    cout << sum << endl;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = Array(1000000) { 0L }
    val input = readLine()!!.split(" ").map { it.toLong() }
    input.forEach { numbers[it.toInt()]++ }
    var sum = input.sum()
    val q = readLine()!!.toInt()
    repeat(q) {
        val (b,c) = readLine()!!.split(" ").map { it.toLong() }
        val numberB = numbers[b.toInt()]
        sum += (c-b) * numberB
        println(sum)
        numbers[c.toInt()] += numberB
        numbers[b.toInt()] = 0L
    }
}


Measured memory_bytes: 71160
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

char ABC(char abc, int n) {
	int a = abc - 'A';
	a += n;
	a %= 26;
	char ans = 'A' + a;
	return ans;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
	char x;
	ff(i, 0, s.size()) {
		x = ABC(s[i],n);
		cout << x;
	}
	cout << endl;
	return 0;
}

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

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

typedef long long ll;

int hand(char c){
	string right = "yuiophjklnm";
	int n = right.length();
	REP(i,n){
		if (c == right[i])
			return 1;
	}
	return 0;
}

int main(void){
	string s;
	while (cin >> s && s[0] != '#'){
		int ans = 0;
		int ho = hand(s[0]) , h;
		FOR(i,1,s.length()-1){
			h = hand(s[i]);
			if (h!=ho)
				ans++;
			ho = h;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n;
  cin >> n;
  for (int a = 1; a <= 9; ++a) {
    for (int b = 1; b <= 9; ++b) {
      if (a*b == n) {
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 256
N,C=gets.split.map &:to_i
D=C.times.map{gets.split.map &:to_i}
M=N.times.map{gets.split.map &:to_i}
T=3.times.map{[0]*C}
N.times{|y|N.times{|x|T[(y+x)%3][M[y][x]-1]+=1}}
p [*0...C].permutation(3).map{|e|
	r=0
	3.times{|i|C.times{|c|
		r+=T[i][c]*D[c][e[i]]
	}}
	r
}.min

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

int main() {
  ll a,b;
  cin>>a>>b;
  bool imp=true;
  
  if(a<b){
  	for(int i=0;i<b;i++){
    	if(a+i==b-i){
        	cout<<i+a<<endl;
           imp=false;
          break;
       
        }
    }
  }
  
   else if(a>b){
  	for(int i=0;i<a;i++){
    	if(a-i==b+i){
        	cout<<i+b<<endl;
          imp=false;
          break;
       
        }
    }
  }
  if(imp)cout<<"IMPOSSIBLE"<<endl;
  //これ大-小/2+小で良くないか

}

Measured memory_bytes: 256
//Bismillah hirrahmanir Rahim
#include<bits/stdc++.h>
#define corret 1
#define ll long long
#define pb push_back
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);

const int m = 10e6;
using namespace std;


int main(){

  ll a,b,c,k;

 cin>>a>>b>>c>>k;
 ll sum = 0;

    if(k > 0){
        sum += min(a,k);
        int x =  min(a,k);
     k-=x;
     }

    if(k > 0){
      k  -= b;
    }

    if(k > 0){

        sum -= min(c,k);
        int x =  min(c,k);
    }

    cout<<sum<<endl;


    return 0;

}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=(1<<21);
int main(){

  int n;
  
  while( cin >> n, n ) {
    int town[11][11];
    int a, b, c;
    int min_total = INF;
    int min_town = 0;
    int s[11] = {0};
    for(int i=0; i<11; i++) {
      for(int j=0; j<11; j++) {
	town[i][j] = (i == j) ? 0 : INF;
      }
    }
 
    int v = 0;
    for(int i=0; i<n; i++) {
    cin >> a >> b >> c;
    town[a][b] = c;
    town[b][a] = c;
    v = max(max(v, a), b);
  }

    for(int i=0; i<=v; i++) {
      for(int j=0; j<=v; j++) {
	for(int k=0; k<=v; k++) {
	  town[j][k] = min(town[j][k], town[j][i]+town[i][k]);
	}
      }
    }

    for(int i=0; i<=v; i++) {
      int total = 0;
      for(int j=0; j<=v; j++) {
	total += town[i][j];
      }
      s[i] = total;
      min_total = min(min_total, total);
    }
    for(int i=0; i<=v; i++) {
      if( s[i] == min_total ) {
	cout << i << ' ';
	cout << min_total << endl;
	break;

      }
    }
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> h(n);rep(i,n)cin>>h[i];
  h[0]--;
  rep(i,n){
    if(!i)continue;
    if(h[i-1] != h[i]){
      --h[i];
    }
    if(i+1 < n && h[i] > h[i+1]){
      print("No");
      return 0;
    }
  }
  print("Yes");
  return 0;
}


Measured memory_bytes: 640
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,1000000)}
  n,k,q := input.NextInts()
  a := append(input.NextIntArray(),-1)
  m := 1000000001
  for i:=0;i<n;i++ {
    var s []int
    for x,y:=-1,0;y<n+1;y++ {
      if a[y] < a[i] {
        if y-x-1 >= k {
          var b []int
          for j:=x+1;j<y;j++ { b = append(b,a[j]) }
          sort.Ints(b)
          for j:=0;j<y-x-k;j++ { s = append(s,b[j]) }
        }
        x = y
      }
    }
    sort.Ints(s)
    if len(s) >= q && m > s[q-1]-a[i] { m = s[q-1]-a[i] }
  }
  fmt.Println(m)
}

type Input struct {
  reader *bufio.Reader
}
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  z,_ := strconv.Atoi(s[2])
  return x,y,z
}
func(i *Input) NextIntArray() []int {
  s := strings.Split(i.NextLine()," ")
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

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

int main() {
	int i,j,equal;
	char s[101],p[101],scircle[201];
	int s_length,p_length;
	
	scanf("%s",s);
	scanf("%s",p);
	
	s_length = strlen(s);
	p_length = strlen(p);
	sprintf(scircle,"%s%s",s,s);
	
	for(i = 0; i < s_length; i++) {
		equal = 1;
		for(j = 0; j < p_length; j++) {
			if(scircle[i+j] != p[j]) {
				equal = 0;
				break;
			}
		}
		if(equal == 1) {
			break;
		}
	}
	if(equal == 1) {
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 552
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<numeric>

using namespace std;

int main()
{
    int N, K, d, a;
    cin >> N >> K;
    vector<int> Nusuke(N, 1);

    for(int i=0;i<K;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a;
            Nusuke[a-1] = 0;
        }
    }

    cout << accumulate( Nusuke.begin(), Nusuke.end(), 0) << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2==1){
        cout<<1<<endl;
        return 0;
    }else{
        cout << 0<<endl;
    }
    return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
 long long key, i, h;
 key = getKey(str);
 for (i = 0;; i++){
   h = (h1(key) + i * h2(key)) % M;
   if(strcmp(H[h], str) == 0) return 1;
   else if(strlen(H[h]) == 0) return 0;
 }
   return 0;
 }

int insert(char str[]){
   long long key, i, h;
  key = getKey(str);
  for(i = 0;; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0){
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	    scanf("%s %s", com, str);

	    if ( com[0] == 'i' ){
	      insert(str);
	    } else {
	      if (find(str)){
		      printf("yes\n");
	      } else {
		      printf("no\n");
	      }
	    }
    }

    return 0;
}



Measured memory_bytes: 16044
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

struct triple
{
	int x, y, num;
	bool operator < (const triple &a) {return x < a.x;}
};

int parent[200005], sz[200005], answer[200005];
triple point[200005];
set <pair <int, int> > opa;

int find_parent(int v)
{
 	if (v == parent[v]) return v;
 	return parent[v] = find_parent(parent[v]);
}

void unions(int a, int b)
{
 	a = find_parent(a), b = find_parent(b);
 	if (a != b)
 	{
 	 	if (sz[a] < sz[b]) swap(a, b);
 	 	sz[a] += sz[b], parent[b] = a;
 	}
 	return;
}

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int n;
 	cin >> n;
 	for (int i = 1; i <= n; i++)
 	{
 		cin >> point[i].x >> point[i].y;
 		point[i].num = i;
 	}
 	sort(point + 1, point + n + 1);
 	for (int i = 1; i <= n; i++) sz[i] = 1, parent[i] = i;

 	for (int i = 1; i <= n; i++)
 	{
 		pair <int, int> mins;
 		if (!opa.empty() && (*opa.begin()).x < point[i].y) mins = *opa.begin();
 		else mins = mp(point[i].y, i);
 		while (!opa.empty() && (*opa.begin()).x < point[i].y)
 		{
 		 	pair <int, int> A = *opa.begin();
 		 	opa.erase(opa.begin());
 		 	unions(A.y, i);
 	 	}
 	 	opa.insert(mins);
 	}
 	for (int i = 1; i <= n; i++) answer[point[i].num] = sz[find_parent(i)];
 	for (int i = 1; i <= n; i++) cout << answer[i] << '\n';
 	return 0;
}

Measured memory_bytes: 12476
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <deque>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<int> route(r);
    for( int i = 0; i < r; i++ ) cin >> route[i];
    ll edge[201][201] = {};
    for( int i = 1; i <= n; i++ ) for( int j = 1; j <= n; j++ ) edge[i][j] = ( i == j ) ? 0 : 1e9;
    for( int i = 0; i < m; i++ ) {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a][b] = edge[b][a] = c;
    }
    for( int k = 1; k <= n; k++ ) {
        for( int i = 1; i <= n; i++ ) {
            for( int j = 1; j <= n; j++ ) {
                edge[i][j] = min( edge[i][j], edge[i][k] + edge[k][j] );
            }
        }
    }
    ll res = 1e18;
    sort( route.begin(), route.end() );
    do {
        ll sum = 0;
        for( int i = 0; i < r-1; i++ ) sum += edge[route[i]][route[i+1]];
        res = min( res, sum );
    } while( next_permutation( route.begin(), route.end() ) );
    dump( res );
    return 0;  
}

Measured memory_bytes: 640
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    sc.nextLine()
    // 席は空席、男性が座っている、女性が座っているのどちらか
    // ただし、同性同士が隣り合う席に座っていることはありません
    // Nが3以上の奇数の場合、空席は少なくとも1つは存在することが示せる
    // Nのみが与えられ、各席の状態は与えられない。
    // どれか1つの空席の番号を当てることです。
    // そのために、あなたは次のクエリを繰り返し送ることができます。
    // 整数iを選ぶ、席iが空席なら正答となる。そうでなければ席iに座っている人の性別が知らされる
    // クエリを高々20回まで送ることで、どれか１つの空席の番号を当ててください

    // とりあえず1回クエリした時
    // 男が返ってくる => 隣は女である必要がある
    // 女が返ってくる => 隣は男である必要がある
    // ある男の席を起点とすると、その並びは
    // 男,女,男,女,...,男,女,空席,女 のパターン
    // 男,女,男,女,...,女,男,空席,男 のパターン
    // がある.
    // 椅子の席が奇数であることから、一度クエリした時に反対側の2つをクエリすることで
    // ズレの傾向を読むことができるかも？
    // 一度適当な箇所をクエリした時に
    // iをクエリする => 男が返ってくる =>
    // i + (N / 2) をクエリする =>
    // i から (N / 2) をクエリする、ということは、偶数番移動なので、
    // そこに歪み(空席)がなければ、男,女,の順なので、男が返ってくるはず
    // 男が返ってくれば, i ~ i + (N / 2) の間には空席はないものとみなす
    // そして, (i + (N / 2)) + 1 ~ (i - 1) の新しい領域について考える必要がある
    // しかしこのケース, 空席が2つ以上中に含まれている場合には回答できない?
    // 空席が存在する場合に必ず歪みが存在すると仮定しているので
    // 二分探索の場合、最大100000席探索するのに13回あれば十分なので、
    // 残り7回の探索について考える必要がある？
    // (right - left / 2)は常に偶数
    // leftが常に偶数の時、oppositeは常に偶数、opposite - 1は常に奇数
    // r - l が偶数の場合 r, lが異性なら空席が含まれる
    // r - l が奇数の場合, r, lが同性なら空席が含まれる
    def solve(): Unit = {
      def query(n: Int): String = {
        println(n) // query start
        val result = sc.nextLine() // Vacant, Male, Female
        result match {
          case "Vacant" => sys.exit()
          case sex => sex
        }
      }
      val leftSex = query(0)
      @scala.annotation.tailrec
      def recursive(left: Int, right: Int): Unit =
        if (right - left > 1) {
          val center = (right + left) / 2
          val centerSex = query(center)
          if ((center % 2 == 0 && centerSex == leftSex) || (center % 2 == 1 && centerSex != leftSex)) {
            recursive(center, right)
          } else {
            recursive(left, center)
          }
        } else query(left)
      recursive(0, N)
    }
    solve()
  }

}


Measured memory_bytes: 55528
import math
ans = 0
n = int(input())
K = [0 for _ in range(n + 1)]
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    K[math.gcd(i,i2)] += 1
for i in range(1,n + 1):
  for i2 in range(1,n + 1):
    ans += K[i] * math.gcd(i,i2)
print(ans)


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

int main() {
  int n,k,s;
  cin >> n >> k;
  s = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < k; i++) {
    s += a.at(i);
  }

  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}
 
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> num(n, 1);
    vector<bool> red(n, 0);
    red[0] = 1;
    vector<vector<int>> d(m, vector<int> (2));
    rep(i, m) {
        cin >> d[i][0] >> d[i][1];
        d[i][0]--;
        d[i][1]--;
    }
    rep(i, m) {
        if(red[d[i][0]]) red[d[i][1]] = 1;
        num[d[i][0]]--;
        num[d[i][1]]++;
        if(num[d[i][0]] == 0) red[d[i][0]] = 0;
    }
    int count = 0;
    rep(i, n) if(red[i]) count++;
    cout << count << "\n";
}

Measured memory_bytes: 9064
//by rko27
//One more....
//---------------------------------------------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int  long long 
#define ll  long long 
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define god ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//----------------------------------------------------------------------------------------------------------------------------------------------------


int mod=1000000000+7;
int modu=998244353;

//----------------------------------------------------------------------------------------------------------------------------------------------------

ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}
void fun()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	//786
}
bool isPrime(int n){for(int i=2;i*i<=n;i++)if(n%i==0) return false;return true;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}

//-------------------------------------------------------------------------------------------------------------------------------------------------------

std::vector<pair<int,int > > v;

//--------------------------------------------------------------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() 
{
	god;
	//rko;
	fun();
	int tt=1; //cin>>tt;
	while(tt--)
	{
		int n; cin>>n;
		int a[n][3],dp[3],dp1[3];
		memset(dp,0,sizeof(dp));
		memset(dp1,0,sizeof(dp1));
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<3;j++)
			{
				cin>>a[i][j];
			}
		}
		dp[0]=a[0][0], dp[1]=a[0][1], dp[2]=a[0][2];
		for(int j=0;j<3;j++) dp1[j]=dp[j];
		//cout<<dp[0]<<' '<<dp[1]<<' '<<dp[2]<<nl;
		for(int i=1;i<n;i++)
		{
			dp1[0]=max(dp[1] + a[i][0], dp[2] + a[i][0]);
			dp1[1]=max(dp[0] + a[i][1], dp[2] + a[i][1]);
			dp1[2]=max(dp[1] + a[i][2], dp[0] + a[i][2]);
			for(int j=0;j<3;j++) dp[j]=dp1[j];
			//cout<<dp[0]<<' '<<dp[1]<<' '<<dp[2]<<nl;
		}
		int ans=0;
		cout<<max({dp1[2], dp1[1], dp1[0]});
	}
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>

int main(){
	int A[10000],B[10000],i,n,score_A = 0,score_B = 0;
	while(1){
		scanf("%d",&n);
		if(n == 0) return 0;
		for(i = 0;i < n;i++){
			scanf("%d %d",&A[i],&B[i]);
			if(A[i] < B[i]) {
				score_B = score_B + A[i] + B[i];
			}else if(A[i] > B[i]){
				score_A = score_A + A[i] + B[i];
			}else{
				score_A+=A[i];
				score_B+=B[i];
			}
		}
		printf("%d %d\n",score_A,score_B);
		score_A = 0;
		score_B = 0;
	}
	return 0;
}

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

#define MAX_DIG 10   /* <= 10^9 */

long long powInt (long long base, long long power) {
    int result = 1;
    while (power != 0) {
        result *= base;
        power--;
    }
    return result;
}

void radixSort (long long *A, int length)
{
    long long TmpA[length];
    long long radix; /* A[] <= 10^9 */
    int dig, i, j, k;
    for (dig = 0, radix = 1; dig < MAX_DIG; dig++, radix *= 10) {
        for (i = k = 0; i < 10; i++) {
            for (j = 0; j < length; j++) {
                if ((A[j] / radix) % 10 == i) TmpA[k++] = A[j];
            }
        }
        for (j = 0; j < length; j++) {
            A[j] = TmpA[j];
        }
    }
}

int main (void)
{
    int N;
    long long A[200000];
    long long tmpA, midA;
    long long minA = 1000000000;
    long long result;
    scanf("%d", &N);
    int i;
    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        A[i] -= (long long)i + 1;
        if (minA > A[i]) minA = A[i];
    }
    for (i = 0; i < N; i++) {
        A[i] -= minA;
//printf("%ld, ", A[i]);
    }
//printf("\n");

    radixSort(A, N);
/*for (i = 0; i < N; i++) {
    printf("%lld, ", A[i]);
} return 0;*/

    midA = A[N >> 1];
//printf("mid:%lld\n", midA);
    result = 0;
    for (i = 0; i < N; i++) {
        result += labs(A[i] - midA);
//printf("%lld", A[i]);
    }
//printf("\n");

    printf("%lld", result);

    return 0;
}

Measured memory_bytes: 3328
use proconio::input;

fn main() {
    input! {
        n: usize,
        d: i64,
        xy: [(i64, i64); n]
    }

    solve(n, d, &xy);
}

fn solve(n: usize, d: i64, xy: &[(i64, i64)]) {
    let mut cnt = 0;
    for i in 0..n {
        if xy[i].0.pow(2) + xy[i].1.pow(2) <= d.pow(2) {
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 7776
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int main()
{
	int n;
	while (cin >> n) {
		if (n == 0)return 0;
		P a[105000];

		string s1, s2;
		for (int i = 0; i < n; i++) {
			cin >> s1 >> s2;
			int hour1 = (int)(s1[0] - '0') * 10 + (int)(s1[1] - '0');
			int min1= (int)(s1[3] - '0') * 10 + (int)(s1[4] - '0');
			int sec1 = (int)(s1[6] - '0') * 10 + (int)(s1[7] - '0');
			int hour2 = (int)(s2[0] - '0') * 10 + (int)(s2[1] - '0');
			int min2 = (int)(s2[3] - '0') * 10 + (int)(s2[4] - '0');
			int sec2 = (int)(s2[6] - '0') * 10 + (int)(s2[7] - '0');
			a[i].first = 3600 * hour1 + 60 * min1 + sec1;
			a[i].second = 3600 * hour2 + 60 * min2 + sec2;
		}
		sort(a, a + n);
		/*
		for (int i = 0; i < n; i++) {
			cout << a[i].first <<" "<< a[i].second << endl;
		}
		*/

		priority_queue<int,vector<int>,greater<int> >que;
		que.push(a[0].second);
		int cnt = 1;
		for (int i = 1; i < n; i++) {
			
			if (que.empty()) {
				cnt++;
				que.push(a[i].second);
			}
			else {
				int k = que.top();
				if (a[i].first >= k) {
					que.pop();
					que.push(a[i].second);
					continue;
				}
				else {
					cnt++;
					que.push(a[i].second);
				}
			}
		}
		cout << cnt << endl;

	}

	return 0;
}

Measured memory_bytes: 3996
#include<stdio.h>
#include<math.h>
int main(void)
{
  double a,b;
  double S,L,h;
  int c;
  scanf("%lf %lf %d",&a,&b,&c);
  S=a*b*sin(c/180.0*M_PI)/2;
  L=a+b+sqrt(a*a+b*b-2*a*b*cos(c/180.0*M_PI));
  h=2*S/a;
  printf("%lf %lf %lf",S,L,h);
  return 0;
}

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

typedef pair <int, int> ii;

const int Maxn = 505;
const int Maxm = Maxn * Maxn;

int n;
int wr[Maxm];
vector <ii> seq;
int nd[Maxn];
int lft[Maxn];
int res[Maxm];

int main()
{
    scanf("%d", &n);
    priority_queue <ii> Q;
    for (int i = 1; i <= n; i++) {
        int x; scanf("%d", &x);
        if (wr[x]) { printf("No\n"); return 0; }
        wr[x] = i;
        Q.push(ii(i - x, i));
        nd[i] = i - 1;
    }
    int pnt = 0;
    for (int i = 1; i <= n * n; i++) {
        if (wr[i]) {
            res[i] = wr[i];
            if (nd[wr[i]] > 0) { printf("No\n"); return 0; }
            lft[wr[i]] = n - wr[i];
        } else {
            while (!Q.empty() && nd[Q.top().second] == 0) Q.pop();
            if (!Q.empty()) {
                ii p = Q.top(); Q.pop();
                res[i] = p.second;
                nd[p.second]--;
                p.first--;
                Q.push(p);
            } else {
                int oth = 1;
                while (oth <= n && lft[oth] == 0) oth++;
                if (oth > n) { printf("No\n"); return 0; }
                res[i] = oth;
                lft[oth]--;
            }
        }
    }
    printf("Yes\n");
    for (int i = 1; i <= n * n; i++)
        printf("%d%c", res[i], i + 1 <= n * n? ' ': '\n');
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;

const int N=2e5+5;
long long n,a[N],ANS,G[3*N];
vector < long long > v;

void Upd(long long x) {
	while (x<=N) {
		G[x]++;
		x+=(x & -x);
	}
}

long long Get(long long x) {
	long long res=0;
	while (x>0) {
		res+=G[x];
		x-=(x & -x);
	}
	return res;
}

bool check(long long x) {
	long long b[N+5];
	vector < long long > s;
	for (int i=0; i<=N; i++) G[i]=0,b[i]=0;
	
	for (int i=1; i<=n; i++) {
		if (x<=a[i]) b[i]=1;
				else b[i]=-1;
		b[i]+=b[i-1];
		s.push_back(b[i]);
	}

	sort(s.begin(),s.end());
	
	map < int , int > F;
	
	long long tot=0;

	for (int i=0; i<s.size(); i++) 
		if (!F[s[i]]) F[s[i]]=++tot;
	
	long long res=0;
	
	for (int i=1; i<=n; i++) {
		if (b[i]>=0) res++; 
		res+=Get(F[b[i]]);
		Upd(F[b[i]]);
	}

	if (((1LL*n*(n+1))/2+1)/2<=res) return 1;
	return 0;
}

main () {
	ios::sync_with_stdio(false);
	cin>>n;
	
	for (int i=1; i<=n; i++) {
		cin>>a[i];
		v.push_back(a[i]);
	}
	
	sort(v.begin(),v.end());
	
	long long l=0,r=v.size()-1,mid;
	
	while (l<=r) {
		mid=(l+r)/2;
		if (check(v[mid])) { ANS=mid; l=mid+1; }
							  else r=mid-1;
	}
	
	cout<<v[ANS]<<endl;
}

Measured memory_bytes: 11744
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    for (int i = 0; i < 5; i++) {
      int x = sc.nextInt();
      if (x == 0) {
        System.out.println(i + 1);
        return;
      }
    }
  }
}


Measured memory_bytes: 35764
use std::io;

fn read_input() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s);
    s
}

fn wa() {
    println!("WA");
    std::process::exit(0);
}

fn solve(s: String) {
    let mut c = 0;
    for (i, j) in s.chars().enumerate() {
        match (i, j) {
            (0, 'A') => continue,
            (0, _) => wa(),
            (1, 'A'...'Z') => wa(),
            (i, 'A') => wa(),
            (i, 'B') => wa(),
            (i, 'D'...'Z') => wa(),
            (i, 'C') if i == 1 || i >= s.len() - 2 || c == 1 => wa(),
            (i, 'C') => c += 1,
            (_, _) => continue,
        }
    }
    if c == 0 {
        wa();
    }
    println!("AC");
}

fn main() {
    solve(read_input());
}


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

namespace ABC136B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                string n = i.ToString();
                if (n.Length % 2 != 0)
                {
                    ans += 1;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


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

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

		if (a > b) {
			swap(a, b);
		}if (b > c) {
			swap(b, c);
		}if (a>b){
                        swap(a,b);
	        }
		
	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main(){
  int N;
  cin>>N;
  int cost1=(N*100)/108;
  int cost2=cost1+1;
  int Ans1 = cost1*1.08;
  int Ans2 = cost2*1.08;
  if(Ans1 == N){
    cout<<cost1<<endl;
  }else if(Ans2 == N){
    cout<<cost2<<endl;
  }else{
    cout<<":("<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,Y=map(int,input().split())
t,T,M=1000,10**6,range(N+1)
A=[(T*T*i+T*j+(N-i-j)) for i in M for j in M if (9*i+4*j+N==Y//t)*(i+j<=N)>0]
if A:
    a,b=A[0]%T,A[0]//T
    b,c=b%T,b//T
else:
    a,b,c=-1,-1,-1
print(c,b,a)

Measured memory_bytes: 9128
import java.util.*;

class Main{
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    boolean APPROVED = true;
    for(int i=0;i<N;i++){
      int A = sc.nextInt();
      if (A%2==0){
        if (A%3 != 0 && A%5 != 0){
          APPROVED = false;
        }
      }
    }
    if (APPROVED){
     System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
}

Measured memory_bytes: 25300
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  set<int> h;

  for (int i = 0; i < 1000; i++)
  {
    h.insert(i*i);
  }
  

  vector<vector<int>> x(n,vector<int> (d));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < d; j++)
    {
      cin >> x[i][j]; 
    }    
  }

  int ans=0;
  for (int i = 0; i < n; i++)
  {
    for (int j = i+1; j < n; j++)
    {
      int dis = 0;
      for (int k = 0; k < d; k++)
      {
        dis+=(abs(x[i][k]-x[j][k])) * (abs(x[i][k]-x[j][k]));
      }
      if(h.find(dis)!=h.end()) ans++;
    }
    
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long[] power = new long[1001];
        power[0] = 0;
        for (int i = 1; i <= 1000; ++i) {
            power[i] = ((long)i) * i * i * i * i;
        }
        for (int a = -1000; a <= 1000; ++a) {
            for (int b = -1000; b <= 1000; ++b) {
                long powerA = power[Math.abs(a)];
                if (a < 0) {
                    powerA *= -1L;
                }
                long powerB = power[Math.abs(b)];
                if (b < 0) {
                    powerB *= -1L;
                }
                if (powerA - powerB == x) {
                    System.out.println(a + " " + b);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 38988
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

int main() {
    while (true){
        int n;
        cin >> n;
        if (n == 0) break;
        ll ans = 0;
        vector<ll>a(n);
        for(int i=0; i<n;i++){
            cin>>a.at(i);
        }
        for(int i=0;i<n;i++){
            ans+=a.at(i);
        }
        ll cnt=0;
        for(int i=0;i<n;i++){
            if (a.at(i)*n<=ans){
                cnt++;
            }
        }
        cout << cnt << '\n';
    }
    return 0;
}


Measured memory_bytes: 3192
from math import sqrt

n,m = map(int,input().split())
graph=dict()
heights = list(map(int,input().split()))

for i in range(m):
    u,v = map(int,input().split())
    if(graph.get(u-1,0) == 0):
        graph[u-1]=[v-1]
    else:
        graph[u-1].append(v-1)
    if (graph.get(v - 1, 0) == 0):
        graph[v - 1] = [u - 1]
    else:
        graph[v - 1].append(u - 1)
ans=0
for key in graph:
    flag=True
    for obs in graph[key]:
        if(heights[key]<=heights[obs]):
            flag=False
            break
    if(flag):
        ans+=1
ans += (n-len(graph.keys()))
print(ans)





















Measured memory_bytes: 34708
#include <iostream>
#define MAX 100

using namespace std;

int main(void)
{

    
    int n;
    int a[MAX];
    int min;
    int max;
    int dis;
    
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        
        cin >> a[i];
        
        if (i == 0) {
            
            min = a[i];
            max = a[i];
            
        }
        
        if (min > a[i]) {
            
            min = a[i];
            
        }
        
        if (max < a[i]) {
            
            max = a[i];
            
        }
        
    }
    
    dis = max - min;
    
    cout << dis << endl;
    
    
    return 0;
    
}




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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    vec A(26, 0);
    REP(i,0,SZ(S)) A[S[i]-'a'] = i + 1;
    if(SZ(S) < 26) {
        ll k = 0;
        while(A[k] > 0) ++k;
        PR(S+(char)(k+'a'));
    }
    else {
        ll k = 25;
        while(k > 0 && S[k-1] > S[k]) --k;
        if(k > 0) {
            char c = 'z';
            REP(i,k,26) {
                if(S[i] > S[k-1]) c = MIN(c,S[i]);
            }
            PR(S.substr(0,k-1)+c);
        }
        else PR(-1);
    }

    return 0;
}

/*

*/ 

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

using namespace std;
#define sint(a) scanf("%d",&a)
#define sint2(a,b) scanf("%d %d",&a,&b)
#define sll(a) scanf("%lld",&a)
#define sll2(a,b) scanf("%lld %lld",&a,&b)
#define mem(a,i) memset(a,i,sizeof(a))
#define pb push_back
#define ll long long
#define lson node<<1
#define rson (node<<1)+1

const int maxn=1e6+10;
const ll mod=1e9+7;
const double pi=acos(-1);


int main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++)
        {
         int a;
         cin>>a;
         if(i&1&&a&1)
            ans++;
        }
        cout<<ans;
    return 0;
}



Measured memory_bytes: 3564
from sys import stdin, stdout
from collections import defaultdict
n = int(stdin.readline().strip())
word_map = defaultdict(lambda: 0)
maxi = 0
for i in range(n):
  word = stdin.readline().strip()
  x = word_map[word]
  word_map[word] = x + 1
  maxi = max(maxi, x+1)
  
word_list = []
for key, value in word_map.items():
  if value == maxi:
    word_list.append(key)
word_list.sort()
for word in word_list:
  stdout.write(word+'\n')

Measured memory_bytes: 32452
n = int(input())

buildings = [[[0 for x in range(10)] for y in range(3)] for z in range(4)]

for x in range(n):
    b, f, r, v = map(int, input().split())
    buildings[b - 1][f - 1][r - 1] += v

for x in range(4):
    for floor in buildings[x]:
        print("", *floor)
    if x != 3:
        print("####################")



Measured memory_bytes: 5624
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
int n,a[100005];
bool o=true;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        a[x]++;
    }
    if(n%2==0){
        for(int i=1;i<n;i+=2)if(a[i]!=2)o=false;
    }else{
        for(int i=0;i<n;i+=2)if((i==0&&a[i]!=1)||(i!=0&&a[i]!=2))o=false;
    }
    ll ans=1;
    for(int i=0;i<n/2;i++)ans=ans*2%M;
    if(o)cout<<ans<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 640
<?php
$a = [];
fscanf(STDIN, "%d", $s);
$ans = 0;
while(true) {
    $ans++;
    if (isset($a[$s])) {
        break;    
    } else {
        $a[$s] = 1;
        if ($s % 2 === 0) {
            $s /= 2;
        } else {
            $s = $s * 3 + 1;
        }
    }
}
echo $ans;


Measured memory_bytes: 4604
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int[] H = new int[N];
        for (int i = 0; i < N; i++) {
            H[i] = scanner.nextInt();
        }

        Set<Integer>[] near = new HashSet[N];
        for (int i = 0; i < N; i++) {
            near[i] = new HashSet<>();
        }

        for (int i = 0; i < M; i++) {
            int p1 = scanner.nextInt();
            int p2 = scanner.nextInt();

            near[p1 - 1].add(p2);
            near[p2 - 1].add(p1);
        }

        int goods = 0;
        for (int i = 0; i < N; i++) {
            final int idx = i;
            long count = near[i].stream().map(integer -> H[integer - 1])
                    // お作法的に良くないやつ
                    .filter(integer -> integer >= H[idx])
                    .count();

            if (count == 0) {
                goods++;
            }
        }

        System.out.println(goods);
    }
}


Measured memory_bytes: 81348
def gcd(x, y):
    if x < y:
        x, y = y, x
    while y != 0:
        org_x = x
        x = y
        y = org_x % y
    return x

k = int(input())

sum = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        gcd_ab = gcd(a, b)
        for c in range(1, k+1):
            sum += gcd(gcd_ab, c)

print(sum)

Measured memory_bytes: 9204
// abc146_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;

    if (S == "SAT"){
        print(1);
    } else if (S == "FRI"){
        print(2);
    }else if (S == "THU"){
        print(3);
    }else if (S == "WED"){
        print(4);
    }else if (S == "TUE"){
        print(5);
    }else if (S == "MON"){
        print(6);
    }else if (S == "SUN"){
        print(7);
    }


    return 0;
}


Measured memory_bytes: 256