akhauriyash/Code-Regression huggingface dataset:
// jai shri ram
 //**********************************
 //**********************************
 //**********************************
 /**      BU_Excalibur      **/
/**  ABES college   **/

#include <bits/stdc++.h>
using namespace std;
#define pr(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define Toggle(n,i) (n^(1<<i))
#define Check(n,i) (n&(1<<i))
#define Set(n,i) (n|(1<<i))
#define Reset(n,i) (n&(~(1<<i)))
#define fo(a,x,y) for(int i=(x);i<=(y);++i){cout<<a[i]<<" ";}cout<<endl;
#define me(arr,val) memset(arr,val,sizeof arr)
#define inf 10e8
#define infl LLONG_MAX
#define mod 1000000007
#define f first
#define  g(t,a)  (get<a>(t))
#define pra(a) for(auto i:a){cout<<i<<endl;}
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 int main()
 {   IOS
     ll t,i,j;
  
     long long int n,e=INT_MAX,x=0,d=0,k,p,q,r,c,sum=1,l,ii;
       cin>>n;
        for(i=n;i<=100000000;i++)
        {  c=0;
            for(j=2;j<=sqrt(n);j++)
           { if(i%j==0)
               c++;

           }
           if(c==0)
            { cout<<i<<endl;
               break;
            }
           }
        }



Measured memory_bytes: 3652
#include<stdio.h>
int main(void){
    int N,M,T,i,ans=0;
    int syo[100000];
    scanf("%d %d %d",&N,&M,&T);
    syo[0]=-M;
    syo[N+1]=T+M;
    for(i=1;i<=N;i++){
        scanf("%d",&syo[i]);
    }
    for(i=0;i<N+1;i++){
        if(syo[i+1]-syo[i]-2*M>0){ans+=syo[i+1]-syo[i]-2*M;}
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 604
H, W, A, B = map(int, input().split())
ans = [[0 for j in range(W)] for i in range(H)]
for i in range(A):
	for j in range(B):
		ans[j][i] = 1
i = A
while i < W:
	j = B
	while j < H:
		ans[j][i] = 1
		j += 1
	i += 1
for i in ans:
	for j in i:
		print(j, end='')
	print()

Measured memory_bytes: 121820
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void){
  int i,j,n;
  char w[101][11];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%s",w[i]);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      if(!strcmp(w[i],w[j])){
        printf("No\n");
        return 0;
      }
  for(i=0;i<n-1;i++){
    for(j=0;w[i][j]!='\0';j++);
    if(w[i][j-1]!=w[i+1][0]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

void solve(int K, vi& a) {
    ll lo = 2, hi = 2;
    for (int i=K-1; i>=0; --i) {
        ll mod = a[i];
        // [lo, hi]
        if (hi < mod) goto impossible;
        ll nlo = lo - (lo % mod);
        if (nlo < lo) nlo += mod;
        if (nlo > hi) goto impossible;

        ll nhi = hi - (hi % mod);
        if (nhi < lo) goto impossible;

        lo = nlo; hi = nhi + (mod-1);
    }
    cout << lo << " " << hi << endl;
    return;
impossible:
    cout << -1 << endl;
}

int main() {
    vi a;
    int K = loadvec(a);
    solve(K,a);
    return 0;
}


Measured memory_bytes: 1664
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;

            var ans = new int[N];

            for (int i = 0; i < N-1; i++)
            {
                ans[cin.ReadInt - 1]++; 
            }
            for (int i = 0; i < N; i++)
            {
                WriteLine(ans[i]);
            }
        }

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 46140
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, a, b, c, d, e;
  ll x;
  cin >> n >> a >> b >> c >> d >> e;
  
  x = min(a, min(b, min(c, min(d, e))));
  
  if(n % x == 0){
    cout << (n / x) + 4 << endl;
  }else{
    cout << (n / x) + 5 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string s;
  cin >>s;
  
  cout << s.substr(0,4) << " " << s.substr(4,8) << endl;
  
  
}


Measured memory_bytes: 256
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a+b >= c ? "Yes" : "No") << "\n";
    
    return 0;
}

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


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

	int N;
	cin >> N;
	vector<pair<double,double>>v(N);
	vector<int>idx(N);
	sort(all(v));
	for (int i = 0; i < N; i++) {
		double x, y;
		cin >> x >> y;
		v[i] = { x,y };
		idx[i] = i;
	}

	double sum = 0;
	double cnt = 0;
	do {
		vector < pair < double, double >>temp(N);
		for (int i = 0; i < N; i++)temp[i] = v[idx[i]];
		for (int i = 1; i < N; i++) {
			double x = temp[i].first;
			double xpre = temp[i - 1].first;
			double y = temp[i].second;
			double ypre = temp[i - 1].second;
			sum += sqrt((x - xpre)*(x - xpre) + (y - ypre)*(y - ypre));
		}
		cnt++;
	} while (next_permutation(all(idx)));
	cout << setprecision(20) << (sum / cnt) << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " " << max(0, (a + b) - n) << endl;
}


Measured memory_bytes: 256
"""
C - Same Integers
"""

numbers = list(map(int, input().split()))

odd_cnt = 0
parities = []
for n in numbers:
    p = n % 2
    parities.append(p)
    odd_cnt += p

process_cnt = 0

# 修正が必要
if odd_cnt == 1:
    process_cnt += 1
    # evenに対して操作1
    for i in range(3):
        if parities[i] == 0:
            numbers[i] += 1
elif odd_cnt == 2:
    process_cnt += 1
    # oddに対して操作1
    for i in range(3):
        if parities[i] != 0:
            numbers[i] += 1

# あとは数を合わせるだけ 操作2
numbers_max = max(numbers)
for n in numbers:
    process_cnt += (numbers_max - n) // 2

print(process_cnt)


Measured memory_bytes: 3064
s = list(input())
n = int(input())

pre = ''
count = 0
for i in s:
    if pre == i:
        count+=1
        pre = ''
    else:
        pre = i

if n == 1:
    print(count)
    exit()

count2 = 0
for i in s:
    if pre == i:
        count2+=1
        pre = ''
    else:
        pre = i

if n == 2:
    print(count + (n-1) * count2)
    exit()

count3 = 0
for i in s:
    if pre == i:
        count3+=1
        pre = ''
    else:
        pre = i

if count2 == count3:
    print(count + (n-1) * count2)
else:
    print(count + ((n-1)//2 + (n-1)%2) * count2 + ((n-1)//2)*count3)

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

int main() {

    int r, c, sum;
    int a[101][101]={0};
    cin >> r >> c;

    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            cin >> a[i][j];
        }
    }

    for (int i=0; i<r; i++){
        for (int j=0; j<c; j++){
            cout << a[i][j] << " ";
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
        }
        cout << a[i][c] << endl;
    }

    for (int j=0; j<c; j++){
        cout << a[r][j] << " ";
        sum += a[r][j];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <set>

int main() {
    int N, K;
    std::cin >> N >> K;

    std::set<int> s;
    for (int i = 0; i < K; ++i) {
        int d;
        std::cin >> d;

        for (int j = 0; j < d; ++j) {
            int a;
            std::cin >> a;

            s.emplace(a);
        }
    }

    const int ret = N - static_cast<int>(s.size());
    std::cout << ret << std::endl;            
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int n,i,j,min,max,energy,ans = 1000000000;
    cin>>n;
    vector<int> dist(n);
    rep(i,n){
        cin>>dist.at(i);
    }
    min = dist.at(0);
    max = dist.at(0);
    rep(i,n){
        min = (std::min)(dist.at(i),min);
        max = (std::max)(dist.at(i),max);
    }

    for(i=min;i<=max;i++){
        energy = 0;
        rep(j,n){
            energy += (dist.at(j) - i)*(dist.at(j) - i) ;
        }
        ans = (std::min)(ans,energy);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    int n,m;
    cin >> n >> m;
    vi hune[202020];
    vi tyukan;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        hune[a].pb(b);
        hune[b].pb(a);
        if(a == 1 || b == 1) tyukan.pb(a+b-1);
    }
    rep(i, tyukan.size()){
        rep(j, hune[tyukan[i]].size()){
            if(hune[tyukan[i]][j] == n){
                puts("POSSIBLE");
                return 0;
            }
        }
    }
    puts("IMPOSSIBLE");
}


Measured memory_bytes: 12392
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;
int c[2][MAX];

int main(){
	int n;
	cin>>n;
	rep(i,n){
		int v;
		cin>>v;
		c[i%2][v]++;
	}
	//c[0][j]でmaxとなるindexを出す
	int ind0=-1;
	int c0mx=0;
	rep1(j,1e5){
		if(c[0][j]>c0mx){
			ind0=j;
			c0mx=c[0][j];
		}
	}
	//c[1][j]でmaxとなるindexを出す
	int ind1=-1;
	int c1mx=0;
	rep1(j,1e5){
		if(c[1][j]>c1mx){
			ind1=j;
			c1mx=c[1][j];
		}
	}
//  	cout<<ind0<<" "<<c0mx<<endl;
//  	cout<<ind1<<" "<<c1mx<<endl;
	//ind0!=ind1ならかんたん
	if(ind0!=ind1){
		cout<<n-c[0][ind0]-c[1][ind1];
	}
	//ind0=ind1なら困る。
	//ind0以外でのmaxをc[0],c[1]両方でとる。
	else{
		int ind=ind0;
		int c0my=0;
		rep1(j,1e5){
			if(j==ind)continue;
			if(c[0][j]>c0my){
				c0my=c[0][j];
			}
		}
		int c1my=0;
		rep1(j,1e5){
			if(j==ind)continue;
			if(c[1][j]>c1my){
				c1my=c[1][j];
			}
		}
		int mx=max(c[0][ind]+c1my,c0my+c[1][ind]);
		cout<<n-mx;
	}
}

Measured memory_bytes: 1024
from itertools import product

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0

for row_bit in product(range(2), repeat=h):
    for col_bit in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int result = 0;
    for (int i = 1; i <= N; i++){
        int fifth = i / 10000;
        int forth = (i - fifth * 10000) / 1000;
        int third = (i - fifth * 10000 - forth * 1000) / 100;
        int second = (i - fifth * 10000 - forth * 1000 - third * 100) / 10;
        int first = i - fifth * 10000 - forth * 1000 - third * 100 - second * 10;
        int sum = fifth + forth + third + second + first;
        if(A <= sum && sum <= B){
            result = result + i;
        }
    }
    cout << result << endl;
    return 0;
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long H, long long W, std::vector<std::string> a) {
    vvi dp(H + 1, vi(W + 1, 0));
    rep(y, H) rep(x, W) {
        if (x == 0 and y == 0) {
            dp[1][1] = 1;
            continue;
        }
        if (a[y][x] == '#') continue;
        dp[y + 1][x + 1] = dp[y][x + 1] + dp[y + 1][x];
        dp[y + 1][x + 1] %= mod;
        // cout << a[y][x] << " " << x << " " << y << " : " << dp[y][x] << " " << dp[y + 1][x] << " " << dp[y][x + 1] << " " << dp[y + 1][x + 1] << endl;
    }
    cout << dp[H][W] << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long H;
    cin >> H;
    long long W;
    cin >> W;
    std::vector<std::string> a(H);
    for (int i = 0; i < H; i++) {
        cin >> a[i];
    }
    solve(H, W, std::move(a));
    return 0;
}


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

using namespace std;

int n;
vector<int> vec, vec2;
int dp[1000005], dp2[1000005];

int main(void)
{
  for(long long i = 1; i*(i+1)*(i+2)/6 <= 1000000; i++){
    long long x = i*(i+1)*(i+2)/6;
    if(x % 2) vec2.push_back(x);
    vec.push_back(x);
  }
  //for(int i = 0 ;i < vec.size(); i++) cout << vec[i] << " "; cout << endl;

  for(int i = 0; i <= 1000000; i++) dp[i] = dp2[i] = 1e9;
  dp[0] = dp2[0] = 0;
  for(int i = 0; i < 1000000; i++){
    for(int j = 0; j < vec.size(); j++){
      if(i+vec[j] <= 1000000) dp[i+vec[j]] = min(dp[i+vec[j]], dp[i]+1);
    }
    for(int j = 0; j < vec2.size(); j++){
      if(i+vec2[j] <= 1000000) dp2[i+vec2[j]] = min(dp2[i+vec2[j]], dp2[i]+1);
    }
  }

  while(1){
    cin >> n;
    if(n == 0) break;
    cout << dp[n] << " " << dp2[n] << endl;
  }
  return 0;
}



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

int main(){
	int a, b, n;
	while(cin >> a >> b >> n){
		a *= 10;
		int ans = 0;
		for(int i=0; i < n; i++){
			ans += a / b % 10;
			a %= b;
			a *= 10;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>

#define M 100
#define INF 110000
#define whi 0
#define gra 1
#define bla 2

int n;
int T[M][M],d[M],color[M];

void dijkstra(void){
  int i,j;
  int min,u;

  for(i=0; i<n; i++){
    color[i] = whi;
    d[i] = INF;
  }

  d[0] = 0;

  while(1){
    min = INF;
    for(i=0; i<n; i++){
      if(color[i] != bla && d[i] < min){
	min = d[i];
	u = i;
      }
    }

    if(min == INF) break;

    color[u] = bla;

    for(i=0; i<n; i++){
      if(color[i] != bla && T[u][i] != INF){
	if(d[i] > (d[u] + T[u][i])){
	  d[i] = (d[u] + T[u][i]);
	  color[i] = gra;
	}
      }
    }
  }
}

int main(){
  int i,j;
  int u,k,v,c;
  
  scanf("%d",&n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      T[i][j] = INF;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&u,&k);
    for(j=0; j<k; j++){
      scanf("%d %d",&v,&c);
      T[u][v] = c;
    }
  }

  dijkstra();

  for(i=0; i<n; i++){
    if(d[i] == INF)d[i] = -1;
    printf("%d %d\n",i,d[i]);
  }
  
  return 0;
}



Measured memory_bytes: 2056
import java.io.*
import java.util.*
import java.lang.Math.*


fun main() {
    val N = rd.readInt()

    var ans = 0
    for (i in 1..10) {
        if (1000*i >= N) {
            ans = 1000*i - N
            break
        }
    }

    println(ans)
}


//val rd = debug.Reader("abc", "172", "a", "sample-1")
val rd = Reader()
fun main(args: Array<String>) {
    Thread(null, MainThread(), "mainThread", 128 * 1024 * 1024).start()
}


const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
class MainThread : Runnable {
    override fun run() { main() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 34540
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N; cin >> N;
	string S; cin >> S;
	int ans = 0;
	for (int i = 0; i < N - 2; i++) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
	}
	cout << ans << endl;

	return 0;
}

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

int main () {
  int N;	cin >> N;
  int t[110000], x[110000], y[110000];
  t[0] = x[0] = y[0] = 0;
  for (int i=0; i<N; i++)
    cin >>t[i+1] >> x[i+1] >> y[i+1];	//1-index
  
  bool can=true;
  for (int i=0; i<N; i++) {
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] -y[i]);
    if (dt < dist) can = false;
    if (dist %2 != dt %2) can = false;	//dist, dt の偶奇は一致する
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<string> W(N);
    set<string> S;
    rep(i, 0, N) cin >> W.at(i);
    char start;
    rep(i, 0, N){
        if (S.count(W.at(i))){
            cout << "No" << endl;
            return 0;
        }
        if (i > 0 && W.at(i).at(0) != start){
            cout << "No" << endl;
            return 0;
        }
        start = W.at(i).at(W.at(i).size() - 1);
        S.insert(W.at(i));
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

int main(void) {
    int n;
    cin >> n;
    VI v(n + 1, 0);
    VI result(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }

    int light = 1;
    int times = 0;
    result[1] = 1;
    times++;

    while (1) {
        light = v[light];
        if (light == 2) {
            break; 
        }
        if (result[light] == 1) {
            cout << "-1" << endl; 
            return 0;
        } else {
            result[light] = 1;
            times++;
        }
    }
    cout << times << endl;
    return 0;
}



Measured memory_bytes: 1024
module modulo_util
  implicit none
  integer(8), parameter :: md = 1000000007
  integer(8), allocatable :: f(:), invf(:)
contains
  subroutine init(n)
    integer, intent(in) :: n
    integer :: i
    if (allocated(f)) deallocate(f)
    if (allocated(invf)) deallocate(invf)
    allocate(f(0:n),invf(0:n))
    f = 0_8
    invf = 0_8
    f(0) = 1_8
    do i = 1, n
      f(i) = mod(f(i-1)*int(i,8),md)
    end do
    invf(n) = inv(f(n))
    do i = n, 1, -1
      invf(i-1) = mod(invf(i)*int(i,8),md)
    end do
  end
  integer(8) function perm(n,k)
    integer, intent(in) :: n, k
    perm = 0_8
    if (k > n .or. n < 0 .or. k < 0) return
    perm = mod(f(n)*invf(n-k),md)
  end
  integer(8) function comb(n,k)
    integer, intent(in) :: n, k
    comb = mod(perm(n,k)*invf(k),md)
  end
  integer(8) function homo(n,k)
    integer, intent(in) :: n, k
    homo = 1_8
    if (n == 0 .and. k == 0) return
    homo = comb(n+k-1,k)
  end
  function inv(n) result(y)
    integer(8), intent(in) :: n
    integer(8) :: a, b, x, y, t, q
    a = modulo(n,md)
    b = md
    x = 0_8
    y = 1_8
    do while (b /= 0_8)
      q = a/b
      t = b
      b = mod(a,b)
      a = t
      t = y
      y = x
      x = t-q*x
    end do
    y = modulo(y,md)
  end
  function pow(a,b) result(r)
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer :: k
    integer(8) :: r, p
    r = 1_8
    p = a
    k = b
    do while (k > 0)
      if (btest(k,0)) r = mod(r*p,md)
      p = mod(p*p,md)
      k = rshift(k,1)
    end do
  end
end module modulo_util
program max_min_sums
  use modulo_util
  implicit none
  integer :: n, k, i
  integer(8) :: a(100000) = 0, ans = 0
  read(*,*) n, k
  read(*,*) a(1:n)
  a(1:n) = a(1:n)-minval(a(1:n))
  call quick_sort(a(1:n))
  call init(n)
  do i = 1, n
    ans = mod(ans+modulo((comb(i-1,k-1)-comb(n-i,k-1))*a(i),md),md)
  end do
  write(*,'(i0)') ans
contains
  recursive subroutine quick_sort(a)
    integer(8), intent(inout) :: a(:)
    integer :: n, l, r, m
    integer(8) :: p
    n = size(a,1)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program max_min_sums

Measured memory_bytes: 3200
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    AK = list(set(A))
    AK.sort()
    AN = dict()
    for a in A:
        if a in AN: AN[a] += 1
        else: AN[a] = 1
    low = 0; high = len(AK) - 1
    while low < high:
        if AN[AK[low]] <= 1 and AN[AK[high]] <= 1:
            low += 1
            high -= 1
        elif AN[AK[low]] <= 1: low += 1
        elif AN[AK[high]] <= 1: high -= 1
        else:
            AN[AK[low]] -= 1
            AN[AK[high]] -= 1
    total = 0
    for key in AN: total += AN[key]
    while AN[AK[low]] > 2:
        total -= 2
        AN[AK[low]] -= 2
    if AN[AK[low]] > 1:
        total -= 2
    print(total)
    
    return 0

if __name__ == "__main__":
    solve()

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

int main(){
  vector<int> x(5);
  rep(i,5){
    cin >> x[i];
  }
  rep(i,5){
    if(x[i]==0){
      cout << i+1<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
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; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n;
  cin>>n;
  vector<ll> a(60,0LL);
  rep(i,n){
    ll d;cin>>d;
    rep(j,60){
      a[j]+=d%2;d/=2;
    }
  }
  ll c=0LL,d=1LL;
  rep(i,60){
    (c+=a[i]*(n-a[i])%M*d%M)%=M;
    (d*=2)%=M;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m, a, b;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> m){
        ll n = -1;
        REP(i, 10000) {
            if (i * (i - 1) / 2 == m) {
                n = i; break;
            }
        }
        if (n == -1) {
            cout << "No" << endl;
            continue;
        }
        cout << "Yes" << endl;
        vector<vi> ans(n);
        int k = 0;
        REP(i, n) {
            REP(j, i) {
                ++ k;
                ans[i].push_back(k);
                ans[j].push_back(k);
            }
        }
        cout << n << endl;
        REP(i, n) {
            cout << ans[i].size();
            for(int x : ans[i]) cout << " " << x;
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll L[4000];
 
void input() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> L[i];
}
 
void solve() {
    input();
    vector<ll> v(N);
    for(int i = 0; i < N; i++) v[i] = L[i+1];
    sort(v.begin(), v.end());
    ll ans = 0;
    for(ll mid = N - 1; mid >= 0; mid--) {
        for(ll low = mid - 1; low >= 0; low--) {
            auto itr = lower_bound(v.begin(), v.end(), v[mid] + v[low]);
            ll ng = distance(itr, v.end());
            ans += (N - 1 - mid) - ng;
            //cerr << v[mid] + v[low] << " " << ng << " " << (N-1-mid)-ng << endl;
        }
    }
    cout << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == B && A != C) || (B == C && B != A) || (C == A && C != B)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ar array
//#define int long long 
#define F(i,a,b) for(i=a;i<b;++i)
#define RF(i,b,a) for(i=b;i>=a;--i) 
#define NL cout<<"\n";

typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
bool comp(ll a,ll b)
{
	return a<b;
}
ll powm(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a);
		a=(a*a);
		b>>=1;
	}
	return res;
}

ll minm(ll a,ll b){
	if(a<b) return a;
	return b;
}

ll maxm(ll a,ll b){
	if(a>b){ return a;}
	else return b;
}

string s,t;
int dp[3001][3001];
int n,m;

signed main()     
{

	fast;

   #ifndef ONLINE_JUDGE
	  freopen("input.txt","r",stdin);
	  freopen("output.txt","w",stdout);
    #endif

	int test_cases=1;
	memset(dp,0,sizeof dp);
	//cin>>test_cases;
	for(int _=1;_<=test_cases;_++){
	       	cin>>s>>t;
	       	n=s.length();
	       	m=t.length();
          
           for(int i=1;i<=n;++i){
           	for(int j=1;j<=m;++j){
               
               if(s[i-1]==t[j-1]){
               	dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
               }
               else
               dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));

           	}
           }


		//cout<<"Case #"<<_<<": ";
	    
	}
	//cout<<dp[n][m]<<"\n";
	string ans="";

	int i=n-1;
	int j=m-1;

	while(i>=0&&j>=0){
		if(s[i]==t[j]){
			ans+=s[i];
			--i;
			--j;
		}
		else{
			if(dp[i+1][j]>dp[i][j+1]){
				--j;
			}
			else{
				--i;
			}
		}
	}
	reverse(all(ans));
	cout<<ans<<"\n";

}



Measured memory_bytes: 38852
#include <bits/stdc++.h>
#define ll long long
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define next fuck
#define se second
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s.size() == 2)
    {
        cout<<s<<endl;
    }
    else
    {
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * @author khokharnikunj8
 */

public class Main {
    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                new Main().solve();
            }
        }, "1", 1 << 26).start();
    }

    void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenCoins solver = new BGoldenCoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenCoins {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            long n = in.scanInt();
            long ans = (n / 500) * 1000;
            n %= 500;
            out.println(ans + (n / 5l) * 5l);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 23508
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; 
  while(cin >> n, n) {
    vector<string> vs(n);
    FOR(i,0,n) cin >> vs[i];
    string a = "aiueo";
    bool ok = true;
    FOR(k,1,60) {
      set<string> SET;
      ok = true;
      FOR(i,0,n) {
        string s = "";
        s = s + vs[i][0];
        FOR(j,0,vs[i].length()-1) {
          if(s.length() == k) break;
          FOR(m,0,5) {
            if(vs[i][j] == a[m]) {
              s += vs[i][j+1];
              break;
            }
          }
        }
        if(SET.count(s)) {
          ok = false;
          break;
        }
        SET.insert(s);
      }
      if(ok) {
        cout << k << endl;
        break;
      }
    }
    if(!ok) cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3192
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <iostream>

int main(){
	int n;
//	long inf=1000000001;
	scanf("%d", &n);
	int a[100001];
	for(int i=0;i<100001;i++){
			a[i]=0;
	}
	int ans=0;
	for(int i=0;i<n;i++){
		long ai;
		scanf("%ld", &ai);
		if(ai>n){
			ans++;
		}else if(a[ai]<ai){
			a[ai]++;
		}else{
			ans++;
		}
	}
	for(int i=0;i<100001;i++){
		if(a[i]<i){
			ans=ans+a[i];
		}
	}
	printf("%d\n", ans);
}




/*int main(){
	int n;
	long inf=1000000001;
	scanf("%d", &n);
	long a[n];
	for(int i=0;i<n;i++){
		long ai;
		scanf("%ld", &ai);
		a[i]=ai;
	}
	int ans=0;
	sort(a,a+n)
	for(int i=0;i<n;i++){
		long ai;
		scanf("%ld", &ai);
		if(a[ai]<ai){
			a[ai]++;
		}else{
			ans++;
		}
	}
	printf("%d\n", ans);
}*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
#define f first
#define s second
//#define mp make_pair
#define gg return 0;
#define pii pair < int, int>
 
using namespace std;
 
const int maxn = (int)2e5 + 7;
const int INF = (int)1e9;
 
ll a,b[maxn],c,d,cnt,e[(int)2e3 + 1][(int)2e3 + 1],cost[maxn],tout[maxn],mn = INF,mx = -INF,l,r;
 
string s,s1;
 
ll pos;
 
bool u[maxn];
 
vector <int> v;
 
void forn( int s, int f, int inter){
	for(int i = s; i <= f; i += inter){
		b[i] = i;
	}
}
 
ll pref;
 
map <char , int> mp;
 
//vector <int> g[maxn],d[maxn];
 
ll lvlc,lvl[maxn];
/*
void dfs(int v){
	lvlc++;
	lvl[v] = lvlc;
	d[lvl[v]].pb(v);
	u[v] = 1;
	for(int i = 0; i < g[v].size(); ++i){
		int to = g[v][i];
		if(!u[to]){
			dfs(to);
		}
	}
	lvlc--;
}*/
 
vector < char > ans;

int main()
{
	cin >> s;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'B'){
			if(ans.size() != 0){
				ans.pop_back();
			}
		}
		else{
			ans.pb(s[i]);
		}
	}
	for(char i : ans){
		cout << i;
	}
	gg;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  vector<long long> a(3*n);
  for(int i=0;i<3*n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  long long ans=0;
  for(int i=1;i<2*n;i+=2){
    ans+=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
N = int(input())
for i in range(N):
    tmp =  [int(x) for x in input().split()]
    B = 0
    C = 0
    flg = 0
    for i in tmp:
        if B >= C:
            if B < i :
                B = i
                continue
            else:
                if C < i :
                    C = i
                    continue
                else:
                    flg = 1
                    break

        else:
            if C < i :
                C = i
                continue
            else:
                if B < i :
                    C = i
                    continue
                else:
                    flg = 1
                    break
    if flg != 1:
        print("YES")
    else:
        print("NO")



    


Measured memory_bytes: 5600
import java.util.Scanner;

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

	int N = scan.nextInt();
	int D = scan.nextInt();
	int X = scan.nextInt();
	int[] A_ = new int[N];
	
	for(int i = 0; i < N; i++){
	    A_[i] = scan.nextInt();
	}

	int sum = 0;
	for(int i = 0; i < N; i++){
	    int count = 0;
	    for(int j = 1; count <= D; j++){
		sum += 1;
		count = (1 + A_[i]*j);
	    }
	}

	System.out.println(sum+X);
    }
}


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

int main()
{
    int x, n;
    cin >> x >> n;
    bool b[105]{0};
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        b[p] = true;
    }
    int ans = -1;
    for(int i = 0; i <= 102; i++){
        if(!b[i]){
            if(abs(x - ans) > abs(x - i)) ans = i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
T lcm(T a, T b) {
    return (a / gcd(a, b)) * b;
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        }
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int main(void) {
    int n;
    cin >> n;
    VLL a(n);
    REP(i, n) cin >> a[i];
    VLL b(n);
    LL sum = 0;
    REP(i, n) {
        sum += a[i];
        b[i] = sum;
    }
    LL ans = LLONG_MAX;
    REP(i, n-1) {
        ans = min(ans, abs(sum - 2 * b[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328