akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N,Q;
int a[200010];
int front[200010];
int cover[200010];
int covered;
 
void add(int x){
	int n = front[x]-1;
	if(n>0){
		if(cover[n]==0) covered++;
		cover[n]++;
	}
	front[x]--;
}
void erase(int x){
	int n = front[x];
	if(n>0){
		cover[n]--;
		if(cover[n]==0) covered--;
	}
	front[x]++;
}
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	cin>>N>>Q;
	rep1(i,N) front[i] = i+1;
	rep(i,N){
		cin>>a[i];
		add(a[i]);
	}
	rep(t,Q){
		int x,v;
		cin>>x>>v;
		x--;
		int pv = a[x];
		erase(pv);
		add(v);
		a[x] = v;
		cout<<N-covered<<endl;
	}
}

Measured memory_bytes: 3840
p = [1 for i in range(300000)]
p[0] = 0
p[1] = 0
for i in range(2, 300000): 
  j = i
  i += j
  while(i < 300000):
    p[i] = 0
    i += j

while True:
  n = int(input())
  if n == 0:
     break
  cnt = 0
  for i in range(n + 1, 2 * n + 1):
    if p[i] == 1:
      cnt += 1
  print(cnt)


Measured memory_bytes: 7964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll);
ll mod_fact(ll, ll);
ll mod_inv(ll, ll);
//
int main(){
    int n, m;
    cin >> n >> m;
    if(m % 2){
        for(int l = 1, r = m; l < r; l++, r--){
            cout << l << " " << r << "\n";
        }for(int l = m + 1, r = 2 * m + 1; l < r; l++, r--){
            cout << l << " " << r << "\n";
        }
    }else{
        for(int l = 1, r = m + 1; l < r; l++, r--){
            cout << l << " " << r << "\n";
        }for(int l = m + 2, r = 2 * m + 1; l < r; l++, r--){
            cout << l << " " << r << "\n";
        }
    }
}

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

int main(){
	/*input*/
	int A[5];
	int k;
	for(int i = 0; i < 5; i++){
		cin >> A[i];
	}
	cin >> k; 
	/*calculation*/
	bool flag = false;	//true:通信可能 false:通信不可
	((A[4] - A[0]) <= k)?flag = true:flag = false;
	
	
	/*output*/
	if(flag){
		cout << "Yay!" << endl;
	}else{
		cout << ":(" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[][] hapiness = new int[N][3];
        int[][] dp = new int[N][3];
        for(int i = 0; i < N ; i++) {
            hapiness[i][0] = scanner.nextInt();
            hapiness[i][1] = scanner.nextInt();
            hapiness[i][2] = scanner.nextInt();
        }

        dp[0][0] = hapiness[0][0];
        dp[0][1] = hapiness[0][1];
        dp[0][2] = hapiness[0][2];
        for(int i = 1; i < N; i++) {
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < 3; k++) {
                    if (j == k) continue;
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + hapiness[i][j]);
                }
            }
        }
        int ret = 0;
        ret = Math.max(dp[N-1][0], dp[N-1][1]);
        ret = Math.max(ret, dp[N-1][2]);
        System.out.println(ret);
    }
}

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

int main() {
  int a,b; cin>>a>>b;
  cout<<((b-1)+(a-2))/(a-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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 rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
 
typedef long long ll;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int h,w;
    std::cin >> h>>w;
    vvector(a,char,h,w,'0');
    reprep(i,j,h,w)std::cin >> a[i][j];
    std::vector<int> c(26,0);
    reprep(i,j,h,w)c[a[i][j]-'a']++;
    int a1=0,a2=0;
    if(h%2==1&&w%2==1)a1=1;
    if(h%2==1)a2=w/2;
    if(w%2==1)a2+=h/2;
    int m=26;
    rep(i,m)c[i]%=4;
    //bool h=1;
    int c1=0,c2=0;
    rep(i,m){
        c1+=c[i]%2;
        c2+=c[i]/2;
    }
  //  std::cout << c[0] << std::endl;
    if(a1>=c1&&a2>=c2)std::cout << Yes << std::endl;
    else std::cout << No << std::endl;
}

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

char replace(char c, int n) {
  c -= 'A';
  c += n;
  c %= 26;
  c += 'A';
  return c;
}

int main(void) {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.size(); i++) {
    cout << replace(s[i], n);
  }
  cout << endl;
}

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

int main()
{
    const int kOneTypeCardNum = 13;
    const int kTypeNum = 4;
    const char kCardChar[kTypeNum] = {'S','H','C','D'};

    bool isHad[kTypeNum][kOneTypeCardNum] = {false};
    int num=0, no=0;
    char type;

    cin >> num;
    for (int i=0; i<num; ++i)
    {
        cin >> type >> no;
        for (int j=0; j<kTypeNum; ++j)
        {
            if (type == kCardChar[j])
            {
                isHad[j][no-1] = true;
                break;
            }
        }
    }
    
    for (int i=0; i<kTypeNum; ++i)
    {
        for (int j=0; j<kOneTypeCardNum; ++j)
        {
            if (!isHad[i][j])   cout << kCardChar[i] << ' ' << j+1 << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for _ in range(n)]
def LIR(n):
    return [LI() for _ in range(n)]
def SR(n):
    return [S() for _ in range(n)]
def LSR(n):
    return [LS() for _ in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]

    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

    n,m = LI()
    par = list(range(n))
    rank = [0]*n
    s = n-1
    for _ in range(m):
        a,b = LI()
        a -= 1
        b -= 1
        if root(a) != root(b):
            s -= 1
            unite(a,b)
    print(s)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 80632
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <boost/math/common_factor_rt.hpp>
#define EPS (1e-7)
using namespace std;
#define ll long long


int main() {

	int N;
	cin >> N;
	vector<int> a(3,0);//4の倍数、4の倍数ではないが偶数、奇数に分類する
	string ans = "Yes";
	int temp;
	for (auto i = 0; i < N; i++)
	{
		cin >> temp;

		if (temp % 4 == 0)a[0] += 1;
		else if (temp % 2 == 0)a[1] += 1;
		else a[2] += 1;

	}

	if (a[0] < a[2] -1)
	{
		ans = "No";
		cout << ans << endl;
		return 0;
	}
	else {
		a[0] -= a[2] - 1;
		a[2] = 1;
	}

	if (a[1] == 0) {
		cout << ans << endl;
		return 0;
	}
	else {
		if (a[0] == 0) {
			ans = "No";
			cout << ans << endl;
			return 0;
		}
		else {
			cout << ans << endl;
			return 0;
		}
	}




	return 0;
}


Measured memory_bytes: 256
from sys import stdin

t = int(input())
nums = list(map(int, stdin.readline().split()))
nums.sort()


n = nums[-1]

is_prime = [1]*(n+1)
small = nums[0]

d = dict()
for elem in nums:
    if elem not in d:
        d[elem] = 0
    else:
        is_prime[elem] = 0


# 3 8 11 16 24
for num in nums:
    # if num*num>n:
    #     break

    # if is_prime[num] == 0:
    #     continue

    for mult in range(2*num, n+1, num):
        is_prime[mult] = 0


print(sum([is_prime[i] for i in nums]))
# primes = [i for i in range(n+1) if is_prime[i]]
# print(*primes)

Measured memory_bytes: 121144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int total = 0;
		if (A > B) {
			total += A;
			A--;
		} else {
			total += B;
			B--;
		}

		if (A > B) {
			total += A;

		} else {
			total += B;
		}
		System.out.println(total);
	}

}


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

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

    two_sat data(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            if (abs(x[i] - x[j]) < d) data.add_clause(i, false, j, false);
            if (abs(x[i] - y[j]) < d) data.add_clause(i, false, j, true);
            if (abs(y[i] - x[j]) < d) data.add_clause(i, true, j, false);
            if (abs(y[i] - y[j]) < d) data.add_clause(i, true, j, true);
        }
    }

    if (!data.satisfiable()) {
        cout << "No" << "\n";
        return 0;
    }
    cout << "Yes" << "\n";
    auto ans = data.answer();
    for (int i = 0; i < n; i++) cout << (ans[i] ? x[i] : y[i]) << "\n";
    return 0;
}

Measured memory_bytes: 3776
q=int(input())
n=10**5+10
d=[0]+[1 for _ in range(n)]

d[1]=0
f=2
while f*f<n+1:
  i=2
  while f*i<=n:
    d[f*i]=0
    i+=1
  f+=1
  while d[f]==0 and f*f<n+1:
    f+=1

e=[0 for _ in range(n+1)]
for i in range(1,n+1,2):
  if d[i]==1 and d[(i+1)//2]==1:
    e[i]=1

e[1]=0

import itertools
an=list(itertools.accumulate(e))

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

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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val << " ";
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;

const int mod = 1e9 + 7;
const int INF = 1e18;

signed main() {
  int n;
  cin >> n;

  if (n == 3) {
    cout << "2 5 63" << endl;
    return 0;
  }
  if (n == 4) {
    cout << "2 5 20 63" << endl;
    return 0;
  }

  vector<int> m2;
  vector<int> m3;

  for (int i = 1; i * 2 <= 30000; i++) {
    m2.push_back(i * 2);
  }
  for (int i = 0; i * 6 + 3 <= 30000; i++) {
    m3.push_back(i * 6 + 3);
  }

  int s = 0;
  rep(i, m2.size()) {
    s += m2[i];
    if (s % 3 == 0) {
      if (m3.size() >= n - i - 1 && (n - i - 1) % 2 == 0 && (n - i - 1) >= 1) {
        rep(j, i + 1) { cout << m2[j] << " "; }
        rep(j, n - i - 1) { cout << m3[j] << " "; }
        return 0;
      }
    }
  }
}

/*
  2 4 8 16

  a = odd & gcd(a + 2, 3) != 1

*/

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch TaxIncrease | diff TaxIncrease.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address TaxIncrease.cpp && ./a.out

/*
 
 3/8/2020
 
 20:38-
 
 */

int A,B;

void solve() {
  FORE(x,1,1000) {
    if(x*8/100==A&&x/10==B) {
      cout<<x<<endl;
      return;
    }
  }
  cout<<-1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>A>>B;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

int N;

int main() {
   
    int A, B;
    
    cin >> A >> B;
    
    
    if (B%A == 0){
        cout << A+B << endl;
        return 0;
    }else{
        
        cout << B-A << endl;
        return 0;
        
    }
    
    return 0;
}










Measured memory_bytes: 256
x = int(input())
if x <= 599 and x >= 400:
    print(8)
elif x <= 799 and x >= 600:
    print(7)
elif x <= 999 and x >= 700:
    print(6)
elif x <= 1199 and x >= 1000:
    print(5)
elif x <= 1399 and x >= 1200:
    print(4)
elif x <= 1599 and x >= 1400:
    print(3)
elif x <= 1799 and x >= 1600:
    print(2)
elif x <= 1999 and x >= 1800:
    print(1)

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    string s2;
    s2 = s;
    reverse(all(s2));
    int ans = 0;
    rep(i, s.length()) {
        if (s[i] != s2[i]) {
            ans++;
        }
    }
    cout << (ans / 2) << endl;
    return 0;
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    cin>>str;
    rep(i,str.length()){
        if(str[i]=='R') sum++;
    }
    b=sum;
    rep(i,b){
        if(str[i]=='R') sum--;
    }
cout<<sum<<endl;    
    return 0;
}


Measured memory_bytes: 3760
import java.util.Scanner
object Main extends App{
  val sc = new Scanner(System.in)
    
  val n = sc.nextInt()
  val a = sc.nextInt()

  val square = Math.pow(_:Int, 2).asInstanceOf[Int]
  val diff = (_:Int) - (_:Int)

  println(diff(square(n), a))
}


Measured memory_bytes: 25552
#include <iostream>

using namespace std;

int main(void)
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while(true){
        // 高橋君の攻撃 
        C -= B;
        if(C <= 0){
            cout << "Yes" << endl;
            break;
        }

        // 青木君の攻撃 
        A -= D;
        if(A <= 0){
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3592
H, W = map(int, input().split())
S = ['#'*(W+2)]+[
  '#' + input() + '#' for _ in range(H)
]+['#'*(W+2)]

ST = list(map(''.join, zip(*S)))

ansX = [[None] * (W+2) for _ in range(H+2)]
ansY = [[None] * (H+2) for _ in range(W+2)]

final = 0
for y in range(1, H+1):
  Sy = S[y]
  ansXy = ansX[y]
  #ansYy = ansY[y]
  for x in range(1, W+1):
    if Sy[x] == '#':
      continue
    if ansX[y][x] is None:
      t = Sy.find('#', x)
      ansXy[x:t] = [t-x] * (t-x)
    if ansY[x][y] is None:
      t = ST[x].find('#', y)
      ansY[x][y:t] = [t-y] * (t-y)
    a = ansXy[x] + ansY[x][y] - 1
    final = a if a > final else final
print(final)

Measured memory_bytes: 241440
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long ll;
#define MAX_N 1000001
#define INF 1000000000

int tetrahedron(int num){
	return num*(num+1)*(num+2)/6;
}


int main()
{
	vector<int> dp(MAX_N,INF),oddDp(MAX_N,INF);
	dp[0] = oddDp[0] = 0;
	int num = 0;
	for(int i = 1; num < MAX_N; i++){
		num = tetrahedron(i);
		for(int j = num; j < MAX_N; j++){
			dp[j] = min(dp[j],dp[j-num]+1);
			if(num % 2 == 1){
				oddDp[j] = min(oddDp[j],oddDp[j-num]+1);
			}
		}
	}
	int n;
	cin>>n;
	while( n != 0){
		cout<<dp[n]<<" "<<oddDp[n]<<endl;
		cin>>n;
	}
	return 0;
}




Measured memory_bytes: 10480
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S,K;
	int i,l,e;
	cin >> S;
	l = S.size();	
	K = "keyence";
	i = 0;
	while(S.at(i) == K.at(i)) {
		i++;
		if(i == 7) break;
	}
	while(i < 7) {
		if(S.at(l - 7 + i) == K.at(i)) {
			i++;
		}
		else {
			break;
		}
	}
	if(i == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (s); i < (e); ++i)
#define per(i,s,e) for(int i = (s)-1; i >= e; --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<typename T, size_t N, typename U>
void Fill(T (&a)[N], const U&v){
    std::fill((U*)a,(U*)(a+N),v);
}

int main(){
  int n; cin >> n;
  vector<int> b(n);
  for(int&e:b)cin >> e;
  ll sum = 0;
  rep(i,0,n){
    rep(j,i+1,n){
      sum += b[i] * b[j];		      
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <climits>
#include <bitset>
#include <cassert>
#include <random>
#include <complex>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end())
#define MP make_pair
#define MT make_tuple

using namespace std;

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

int potion[13];
int dmg[256];
int dp[1010][1 << 12];

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

	int dx[256] = {};
	int dy[256] = {};

	rep(i, 4){
		dx["UDRL"[i]] = vector<int>({ 0, 0, 1, -1 })[i];
		dy["UDRL"[i]] = vector<int>({ -1, 1, 0, 0 })[i];
	}	

	int mhp, hp;
	while (cin >> hp >> mhp, hp){
		int r, c;
		cin >> r >> c;
		vector<string> dangeon(r);
		rep(i, r) cin >> dangeon[i];

		int t;
		cin >> t;
		rep(i, t){
			char c;
			int d;
			cin >> c >> d;
			dmg[c] = d;
		}

		int x, y;
		x = y = 0;
		string mv;
		mv += dangeon[y][x];

		int s;
		cin >> s;
		while (s--){
			char c;
			int k;
			cin >> c >> k;
			while (k--){
				x += dx[c];
				y += dy[c];
				mv += dangeon[y][x];
			}
		}

		int p;
		cin >> p;
		rep(i, p){
			int x;
			cin >> x;
			potion[i] = x;
		}

		MEMSET(dp, 0);
		dp[0][0] = hp;

		int sz = mv.size();
		rep(i, sz){
			if(i) rep(j, 1 << p){
				dp[i][j] = dp[i-1][j] - dmg[mv[i]];
			}
			rep(j, 1 << p){
				rep(k, p){
					int x = 1 << k;
					if (~j&x) continue;
					if (dp[i][j&~x] <= 0) continue;
					dp[i][j] = max(dp[i][j], min(mhp, dp[i][j&~x] + potion[k]));
				}
			}

			//rep(j, 1 << p){
			//	bitset<2> b(j);
			//	cout << b.to_string() << ' ' << dp[i][j] << endl;
			//}
		}
		bool b = *max_element(dp[sz - 1], dp[sz - 1] + (1 << p)) >= 1;
		cout << (b ? "YES" : "NO") << endl;
	}
	
	return 0;
}

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

ans = 10**7

for A in range(1, N):
    B = N - A
    a = [int(a) for a in str(A)]
    b = [int(b) for b in str(B)]
    s = sum(a) + sum(b)
    
    if s < ans:
        ans = s
        
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
struct Card {
	char pattern;
	int number;
	int unc;
};
int partition(struct Card cards[],int n, int p, int r){
	int i,j;
	Card t;
	i=p-1;
	for(j=p;j<r;j++){
		if(cards[j].number<=cards[r].number){
			i++;
			t=cards[i];
			cards[i]=cards[j];
			cards[j]=t;
		}	
	}
	t=cards[i+1];
	cards[i+1]=cards[r];
	cards[r]=t;
	return i+1;
}

void QuickSort(struct Card cards[],int n, int p, int r){
	int q;
	if(p<r){
		q=partition(cards,n,p,r);
		QuickSort(cards,n,p,q-1);
		QuickSort(cards,n,q+1,r);
	}
}

int main(){
	int antei=0;
	int n;
	scanf("%d",&n);
	Card cards[n];
	for(int i=0;i<n;i++){
		scanf("%s %d",&cards[i].pattern,&cards[i].number);
		cards[i].unc=i;
	}	
	QuickSort(cards,n,0,n-1);
	for(int i=0;i<n;i++){
		if(cards[i].number==cards[i+1].number){
			if(cards[i].unc>cards[i+1].unc){
				antei=1;
			}
		}
	}
	if(antei==0){printf("Stable\n");}
	else{printf("Not stable\n");}
	for(int k=0;k<n;k++){
		printf("%s %d\n",&cards[k].pattern,cards[k].number);
	}
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    for (;n >= 2;n--){
        int tmp = n;
        for (int i = 2;i*i <= tmp;i++){
            while(tmp%i == 0){
                tmp/= i;
                m[i]++;
            }
        }
        if (tmp != 1) m[tmp]++;
    }
    ll ans = 1LL;
    for (auto q:m){
        ans*=(q.second+1);
        ans%=mod;
    }
    cout << ans << endl;

     

    return 0;

}


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

int main() {
	int n;
	cin >> n;
	bool canDecrease = true;
	int left;
	cin >> left;
	for (int i = 0, h; i < n - 1; i++) {
		cin >> h;
		if (h > left) {
			canDecrease = true;
		} else if (h == left - 1) {
			if (canDecrease)
				canDecrease = false;
			else {
				cout << "No" << endl;
				return 0;
			}

		} else if (h < left - 1) {
			cout << "No" << endl;
			return 0;
		}
		left = h;

	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 256
def main():
    s=set()
    for digit in range(16):
        for i in range(1,1000):
            c=i*10**digit+int('9'*digit or 0)
            if c<10**15:
                s.add(c)
    c=sorted(s)
    for i,n in enumerate(c):
        sn=n/sum(map(int,str(n)))
        for m in c[i+1:i+100]:
            sm=m/sum(map(int,str(m)))
            if sm<sn:
                s.remove(n)
                break
    print(*sorted(s)[:int(input())],sep='\n')
main()

Measured memory_bytes: 4208
using System;using System.Linq;class P{static void Main(){var a=Console.ReadLine().Split().Select(int.Parse).ToList();double r=a[2]*Math.PI/180,s=Math.Sin(r);Console.WriteLine($"{a[0]*a[1]*s/2}\n{Math.Sqrt(a[0]*a[0]+a[1]*a[1]-2*a[0]*a[1]*Math.Cos(r))+a[0]+a[1]}\n{s*a[1]}");}}


Measured memory_bytes: 18380
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (LL)1e15
#define mod 1e9+7
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
///#define safeMod(a, m) ((((a)%(m))+(m))%(m))/*handling negative sign of remainder*/
///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))
///#define dis_without_sqrt(x,y,x1,y1) (x-x1)*(x-x1)+(y-y1)*(y-y1)
///int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
/*bool structCompare(struct_name first,struct_name second)
{
    return first.variable_name<second.variable_name //sorts element in increasing order
}*/

using namespace std;

//int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
//int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///int setb(int n,int pos){return n=n | (1 << pos);}
///int resb(int n,int pos){return n=n & ~(1 << pos);}
///int togb(int n,int pos){return n=n ^ (1 << pos);}
///bool checkb(int n,int pos){return (bool)(n & (1 << pos)); }
///lsb T = (S & (-S)),log2(T);
///inline bool isEq(double a, double b){return abs(a - b) < eps;}
///inline bool isEq(double a, double b, double eps){return abs(a - b) < eps;}
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}

const int S=12345;
int main()
{
    //FI;
    //FO;
    //ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b;
    while(cin>>a>>b)
    {
        bool flag=false;
        for(int i=1;i<=3;i++)
        {
            if((a*b*i)%2==1)
            {
                flag=true;
                break;
            }
        }
        if(flag)puts("Yes");
        else puts("No");
    }
    return 0;
}









Measured memory_bytes: 256
N,X = map(int,input().split())
L = [int(x) for x in input().split()]
D = [0] * (N+1)
buf = 1

for i in range(1,N+1) :
    D[i] = D[i-1] + L[i-1]
    if D[i] <= X :
        buf += 1
    else :
        break
print(buf)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
//思路，两个小长方体组成一个大长方体，这两个长方体绝对是只能有一个数字不同，即ABC中只有一个不同
//而且每次都是取最小的对半分 
 
int main(void)
{
	long long int a[3];
	for(int i=0;i<3;i++)
		cin>>a[i];
	sort(a,a+3);		//升序
	long long int cut1=a[2]/2;
	long long int cut2=a[2]-cut1;
	cout<<a[0]*a[1]*(cut2-cut1)<<endl;
	return 0;
} 

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.trim().split(" ");
  const N = Number(input[0]);
  const X = Number(input[1]);
  const T = Number(input[2]);
  let ans = 0;

  let i;
  for (i = 0; ans < N; i++) {
    ans += X;
  }

  console.log(T * i);
}

function numberSort(array) {
  array.sort(f);
  return array;
}

var f = function (a, b) {
  return a - b;
};

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


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

int main(){

  int h, w, n, a;
  int f[110][110];
  vector<int> v;
  cin >> h >> w >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    for(int j = 0; j < a; j++) v.push_back(i + 1);
  }
  int idx = 0;
  for(int i = 0; i < h; i++){
    if(i % 2 == 0){
      for(int j = 0; j < w; j++) f[i][j] = v[idx++];
    }else{
      for(int j = w-1; j >= 0; j--) f[i][j] = v[idx++];
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << f[i][j] << " ";
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int d[31][31];
int mp[501][501];
map<int,int> cnt[3];

int main() {
  int n, c;
  cin >> n >> c;
  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= c; j++) {
      cin >> d[i][j];
    }
  }

  for (int i = 1 ; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      cin >> mp[i][j];
      cnt[(i + j) % 3][mp[i][j]]++;
    }
  }

  int ans = 1e9;
  for (int i = 1; i <= c; i++) {
    for (int j = 1; j <= c; j++) {
      for (int k = 1; k <= c; k++) {
        if (i == j || j == k || i == k) continue;
        int tmp = 0;
        int color[3] = {i, j, k};
        for (int p = 0; p < 3; p++) {
          for (auto q: cnt[p]) {
            tmp += q.second * d[q.first][color[p]];
          }
        }
        ans = min(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1280
import sys

for s in sys.stdin:
  p,q=map(int,s[:-1].split())
  F={}
  X=[]
  c=0
  p%=q
  while not(p in F or p==0):
    F[p]=c
    a,p=divmod(p*10,q)
    X.append(a)
    c+=1
  print "".join(map(str,X))
  if p!=0: print " "*F[p]+"^"*(c-F[p])

Measured memory_bytes: 4220
import sys
import collections
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = sorted([int(i) for i in input().split()])
    cnt_list = collections.Counter(a)
    search_list = [0] * (a[-1]+1)
    ans = 0
    for num, cnt in cnt_list.items():
        search_list[num] = cnt
    for i in a:
        if search_list[i] == 1:
            ans += 1
        for j in range(i, a[-1]+1, i):
            search_list[j] = 0
    print(ans)
    
if __name__ == '__main__':
    main()

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

int main() {
    string s;
    cin >> s;
    int w;
    cin >> w;
    int a=0;
    while(1){
        cout << s[a];
        a+=w;
        if(a>=s.size()) break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <set>
#include <queue>

#define INTFY 10000000

using namespace std;

int N, P;
long long cnt;


long long fct[51];


int main() {
	cin >> N >> P;
	int g = 0, k = 0;

	fct[0] = 1;
	for (int i = 1; i < 51; ++i) {
		fct[i] = fct[i - 1] * 2;
		//printf("fct[%d]:", i);
		//cout << fct[i] << endl;
	}
	fct[0] = 0;

	for (int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		if (t % 2 == 0)
			g++;
		else
			k++;
	}

	if (k == 0) {
		if (P == 0)
			cout << fct[N] << endl;
		else
			printf("0\n");
	}
	else
		cout << fct[k+g-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline char gc() {
	static char now[1<<16], *S, *T;
	if(S == T) {T = (S = now) + fread(now, 1, 1<<16, stdin); if(S == T) return EOF;}
	return *S++;
}
inline int read() {
	int x = 0, f = 1; char c = gc();
	while(c < '0' || c > '9') {(c ^ '-') ? 0 : (f = 0); c = gc();}
	while(c >= '0' && c <= '9') {x = (x << 3) + (x << 1) + (c ^ 48); c = gc();}
	return f ? x : ((~x) + 1);
}
#define N 100010
struct item {
	int a, b, c;
} p[N];
inline bool operator < (const item &A, const item &B) {
	return A.a - A.b > B.a - B.b;
}
int X, Y, Z, n;
priority_queue<int, vector<int>, greater<int> > q;
ll sum[2][N];
int main() {
	X = read(); Y = read(); Z = read();
	n = X + Y + Z;
	for (int i = 1; i <= n; ++ i) {
		p[i].a = read(); p[i].b = read(); p[i].c = read();
	}
	sort(p + 1, p + n + 1);
	ll tot;
	tot = 0;
	while (!q.empty()) q.pop();
	for (int i = 1; i <= X - 1; ++ i) {
		q.push(p[i].a - p[i].c);
		tot += p[i].a - p[i].c;
	}
	for (int i = X; i <= n - Y; ++ i) {
		q.push(p[i].a - p[i].c);
		tot += p[i].a - p[i].c;
		while ((int)q.size() > X) {
			tot -= q.top();
			q.pop();
		}
		sum[0][i] = tot;
	}
	tot = 0;
	while (!q.empty()) q.pop();
	for (int i = n; i >= n - Y + 2; -- i) {
		q.push(p[i].b - p[i].c);
		tot += p[i].b - p[i].c;
	}
	for (int i = n - Y + 1; i >= X + 1; -- i) {
		q.push(p[i].b - p[i].c);
		tot += p[i].b - p[i].c;
		while ((int)q.size() > Y) {
			tot -= q.top();
			q.pop();
		}
		sum[1][i] = tot;
	}
	tot = 0;
	ll ans = 0;
	for (int i = 1; i <= n; ++ i) tot += p[i].c;
	for (int i = X; i <= n - Y; ++ i) {
		ans = max(ans, tot + sum[0][i] + sum[1][i + 1]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2688
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
vector<ll> v[MAX];
int main()
{
        ll n,k;
		cin>>n>>k;
		ll h[n+5];
		for(int i=1;i<=n;i++)
		{
			cin>>h[i];
		}
		
		for(int i=1;i<=k;i++)
		{
			ll x,y;
			cin>>x>>y;
			v[x].push_back(y);
			v[y].push_back(x);
		}
		int cnt=0;
		ll count=0;
		for(int i=1;i<=n;i++)
		{
			bool flag=true;
			for(int j=0;j<v[i].size();j++)
			{
				if(h[i]<=h[v[i][j]])
				{flag=false;break;}
			}
			cnt++;
			if(flag==true)
			count++;
		}
		cout<<count;
		
}

Measured memory_bytes: 10208
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    bool maki=true;
    for(int i=0;i<n;i++){
    	cin>>a[i];
    	if(a[i]>i)maki=false;
    	if(i&&a[i]-a[i-1]>=2)maki=false;
    }
    if(!maki){
    	cout << -1<<endl;
    	return 0;
    }
    ll ans=0;
    for(int i=1;i<n;i++){
    	if(a[i]-a[i-1]==1)ans++;
    	else ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
def examC():
    ABC = LI(); ABC.sort()
    judge = ABC[2]*2-ABC[1]-ABC[0]
    ans = judge//2 + (judge%2)*2
    print(ans)
    return

def examD():
    def judge(A,B):
        if A==B:
            return (A-1)*2
        cur = int((A*B)**0.5)
        if cur**2==A*B:
            return (cur-1)*2 -1
        if cur*(cur+1)>=A*B:
            return cur*2 -2
        else:
            return cur*2-1
    Q = I()
    ans = []
    for _ in range(Q):
        a,b = LI()
        ans.append(judge(a,b))
    for v in ans:
        print(v)
    return

def examE():
    N = I()
    ans = 0; minc = inf
    for i in range(N):
        a, b = LI()
        ans +=a
        if a>b:
            minc = min(minc,b)
    ans =max(ans-minc,0)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examE()


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

int main() {
  int n, a[100000];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];

  sort(a, a + n);
  
  if (n == 1) {
    if (a[0] == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << 1 << endl;
      return 0;
    }
  }

  int prev = a[0], cnt = 1, ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] == prev) cnt++;
    if (a[i] != prev) {
      if (cnt < prev) {
        ans += cnt;
      } else if (cnt > prev) {
        ans += cnt - prev;
      }
      cnt = 1;
      prev = a[i];
    }
    if (i == n - 1) {
      if (cnt < prev) {
        ans += cnt;
      } else if (cnt > prev) {
        ans += cnt - prev;
      }
      cnt = 1;
      prev = a[i];
    }
  }   

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <numeric>
#include <map>
#include <cstring>
using namespace std;

void AddScore(map<long long, vector<long long>>& C, long long* S, long long i, int* visited)
{
    const auto r = C[i];
    if (r.size() == 0) {
        return;
    }
    const auto s = S[i - 1];
    visited[i - 1] = true;
    for (auto j : r) {
        if (visited[j - 1] != 0) {
            continue;
        }
        S[j - 1] += s;
        AddScore(C, S, j, visited);
    }
}

int main()
{
    long long N, Q;
    cin >> N;
    cin >> Q;

    map<long long, vector<long long>> C;
    for (long long i = 0; i < N - 1; i++) {
        long long a, b;
        cin >> a >> b;
        C[a].push_back(b);
        C[b].push_back(a);
    }

    vector<long long> S;
    S.resize(N);
    memset(S.data(), 0, sizeof(S[0]) * N);
    for (long long i = 0; i < Q; i++) {
        long long p, x;
        cin >> p >> x;
        S[p - 1] += x;
    }

    vector<int> visited;
    visited.resize(N);
    memset(visited.data(), 0, sizeof(visited[0])*N);

    AddScore(C, S.data(), 1, visited.data());

    for (long long i = 0; i < N; ++i) {
        cout << S[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 54784
def calc_a(i, s):
    if i == 1:
        return s
    else:
        return f(calc_a(i-1, s))


def f(n):
    if n % 2 ==0:
        return int(n /2)
    else:
        return int(3 * n + 1)


if __name__ == '__main__':
    S = int(input())

    an_list = []

    for m in range(1, 1000001):
        am = calc_a(m, S)
        if am in an_list:
            break
        else:
            an_list.append(am)

    answer = m
    print(answer)


Measured memory_bytes: 3060
#include<iostream>
#include <iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

struct edge{
    ll to,cost;
};
ll n;
vector<edge>  G[100010];
ll d[100010];

void  dijkstra(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d,d+n,LLINF);
    d[s]=0;
    que.push(pii(0,s));

    while(!que.empty()){
        pii p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    } 
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q,k;
    cin>>n;
    rep(i,n-1){
        ll  a,b,c;
        cin >>a>>b>>c;
        a--;b--;
        G[a].pb({b,c});
        G[b].pb({a,c});
    }
    cin>>q>>k;
    k--;
    dijkstra(k);
    rep(i,q){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        cout<<d[x]+d[y]<<endl;
    }
    return 0;
}

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

using namespace std;

 
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >>a.at(i);
    }
    int count =0;
    int M;
    if(N % 2 == 0){
        M == N/2;
    }
    else if(!(N%2==0)){
        M == N/2 +1;
    }
    if(N%2==0){
        for(int i=0;i<N/2;i++){
            if(!(a.at(2*i)%2 ==0)){
                count++;
            }
        }
    }
    else if(!(N%2==0)){
        for(int i =0;i<=(N-1)/2;i++){
            if(!(a.at(i*2)%2==0)){
                count ++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n,m;
  cin >> n >> m;
  ll ans = 0;
  ll can = min(n,m/2);
  ans += can; n -= can; m -= can*2;
  ans += m/4;
  cout << ans << endl;  
}


Measured memory_bytes: 256
use std::io::BufRead;
use std::cmp::PartialOrd;

fn main() {
  let stdin = std::io::stdin();
  let mut lines = stdin.lock().lines();

  let n = lines.next().unwrap().unwrap()
    .parse::<usize>().unwrap();

  let vec_x = lines.next().unwrap().unwrap()
    .split_whitespace()
    .map(|x| x.parse::<f64>().unwrap())
    .collect::<Vec<_>>();

  let vec_y = lines.next().unwrap().unwrap()
    .split_whitespace()
    .map(|x| x.parse::<f64>().unwrap())
    .collect::<Vec<_>>();

  for p in 1..3+1 {
    let sum = vec_x.iter().zip(vec_y.iter())
      .map(|(x, y)| (x - y).abs().powi(p))
      .sum::<f64>();
    println!("{}", sum.powf(1. / (p as f64)));
  }

  let max = vec_x.iter().zip(vec_y.iter())
    .map(|(x, y)| (x - y).abs())
    .fold(0.0f64, |acc, x| acc.max(x));

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


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

int main(){
  ll i,now=0,N,K;
  cin>>N>>K;
  vector<ll> g(N),loop;
  rep(i,N){
    cin>>g[i];
    --g[i];
  }
  set<ll> se;
  while(se.insert(now).second&&K--){
    now=g[now];
  }
  if(K<=0){
    cout<<now+1<<endl;
    return 0;
  }
  se.clear();
  while(se.insert(now).second){
    loop.emplace_back(now);
    now=g[now];
  }
  cout<<loop[K%loop.size()]+1<<endl;
}


Measured memory_bytes: 12252
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

void solve() {
	int a, b, n, x;
	int f[105]={};
	cin>>x>>n;
	for(int i=1;i<=n;++i) {
		cin>>a;
		f[a]=1;
	}

	int d1=0, d2=0;
	a=0, b=0;
	for(int i=x;;--i) {
		if(!f[i]) {
			d1=x-i;
			a=i;
			break;
		}
	}
	for(int i=x+1;;++i) {
		if(!f[i]) {
			d2=i-x;
			b=i;
			break;
		}
	}

	int res;
	if(d1<=d2) {
		res=a;
	} else res=b;
	cout<<res<<endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
    	solve();
    }
    return 0;
}

// ll, reset, 1, bottom

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define N 31
#define INF (1e9)
using namespace std;
typedef pair<double,int> P;
typedef  pair<P,int> PP;
struct dat{
  double cost;
  int pos,pre,v;
  bool operator > (dat x)const{return cost>x.cost;}
};
int n,m;
vector<dat> G[N];

double dijkstra(int s,int g){
  double D[N][N][N];
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=0;k<N;k++)D[i][j][k]=INF;
  priority_queue<dat,vector<dat>,greater<dat> >Q;
  Q.push((dat){0,s,-1,0});
  D[s][s][1]=0;
  while(!Q.empty()){
    dat t=Q.top();Q.pop();
    double cost=t.cost;
    int pos=t.pos;
    int pre=t.pre;  
    int v=t.v;
    if(D[pos][pre][v]<cost)continue;
    if(pos==g&&v==1) return cost;
    
    for(int i=max(1,v-1);i<=v+1;i++){
      for(int j=0;j<G[pos].size();j++){
	double ncost=cost+G[pos][j].cost/i;
	int mxv=G[pos][j].v;
	int nx=G[pos][j].pos;
	if(nx==pre||mxv<i||D[nx][pos][i]<=ncost)continue;
	Q.push((dat){ncost,nx,pos,i});
	D[nx][pos][i]=ncost;
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>n>>m;
    if(!n&&!m)break;
    int s,g;
    cin>>s>>g;s--,g--;
    for(int i=0;i<n;i++)G[i].clear();
    for(int i=0,a,b,d,c;i<m;i++){
      cin>>a>>b>>d>>c;a--,b--;
      G[a].push_back((dat){d,b,-1,c});
      G[b].push_back((dat){d,a,-1,c});
    }
    double ans=dijkstra(s,g);
    if(ans==-1) cout<<"unreachable"<<endl;
    else printf("%.12f\n",ans);
  }
  return 0;
}

Measured memory_bytes: 3792