akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

ll dp[2010][2010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;
    VI s(n), t(m);
    dp[0][0] = 1;
    FOR(i, 0, n) {
        cin >> s[i];
        dp[i + 1][0] += dp[i][0];
    }
    FOR(i, 0, m) {
        cin >> t[i];
        dp[0][i + 1] += dp[0][i];
    }
    
    eFOR(i, 0, n)eFOR(j, 0, m) {
        if (s[i] == t[j])dp[i + 1][j + 1] += dp[i][j];
        dp[i + 1][j + 1] += dp[i][j + 1];
        dp[i + 1][j + 1] += dp[i + 1][j];
        dp[i + 1][j + 1] -= dp[i][j];
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + mod) % mod;
    }
    cout << dp[n][m] << endl;
}

Measured memory_bytes: 31744
#include<bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define mp make_pair
#define P pair<ll,ll>
#define F first
#define S second
#define vll vector<ll>
#define pb push_back
#define M 1000000007
#define for1(i,n) for(ll i=1;i<=n;i++)
#define for0(i,n) for(ll i=0;i<n;i++)
#define forab(i,a,b,c) for(ll i=a;i<=b;i+=c)
using namespace std;
int main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	char a;
	cin >> a;
	if (a >= 97)
	{
		cout <<'a';
	}
	else
	{
		cout<<'A';
	}
	return 0;
}

Measured memory_bytes: 3588
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] b = new int[n-1];
        for(int i=0; i<n-1; i++){
            b[i] = sc.nextInt();
        }

        int[] a  = new int[n];
        a[0] = b[0];
        for(int i=0; i<n-2; i++){
            a[i+1] = Math.min(b[i], b[i+1]);
        }
        a[n-1] = b[n-2];

        long ans = 0;
        for(int i=0; i<n; i++){
            ans += a[i];
        }

        System.out.println(ans);
    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


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

int main(){
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> ans(n,0);
    rep(i,q){
        int a;
        cin >> a;
        ans.at(a-1)++;
    }
    rep(i,n){
        if(ans.at(i)-(q-k)>=1) cout << "Yes" << endl;
        else cout << "No" <<endl;
    }
}

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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans = 0;

    if (A+B >= C*2){
        if (X < Y){
            ans += X * C * 2;
            if (B < C * 2){
                ans += B * (Y - X);
            } else {
                ans += 2 * C * (Y - X);
            }
        }
        if (X >= Y){
            ans += Y * C * 2;
            if (A < C * 2){
                ans += A * (X - Y);
            } else {
                ans += 2 * C * (X - Y);
            }
        }

    } else {
        if (X < Y){
            ans += X * A;
            if (B < C * 2){
                ans += B * Y;
            } else {
                ans += 2 * C * Y;
                ans -= A * X;
            }
        }
        if (X >= Y){
            ans += Y * B;
            if (A < C * 2){
                ans += A * X;
            } else {
                ans += 2 * C * X;
                ans -= B * Y;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<long long> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    if (n == 1) {
        cout << "Yes" << endl;
        return 0;
    }

    long long cnt = 0;
    for (int i = 0; i < n - 1; i++) {
        if (h[i] > h[i + 1]) {
            cnt++;
        }
        else if (h[i] < h[i + 1]) {
            cnt = 0;
        }

        if (h[i] - h[i + 1] >= 2) {
            cout << "No" << endl;
            return 0;
        }

        if (cnt >= 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

struct BIT{
    vector<ll> bit;
    int N;
    //1-indexed
    
    void init(int n_){
        N=n_;
        n_*=2;
        for(int i=30;i>=0;i--){
            if(n_&(1<<i)){
                n_=1<<i;
                n_++;
                break;
            }
        }
        bit.assign(n_,0LL);
    }
    
    ll sum(int i){
        ll s=0;
        while(i>0){
            s+=bit[i];
            i-=i&-i;
        }
        return s;
    }
    
    //sからtの和=sum(t)-sum(s-1)
    
    void add(int i,ll x){
        while(i<=N){
            bit[i]+=x;
            i+=i&-i;
        }
    }
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    BIT bi;
    bi.init(N);
    
    for(int i=0;i<N;i++){
        ll a;cin>>a;
        bi.add(i+1,a);
    }
    
    while(Q--){
        ll k,a,b;cin>>k>>a>>b;
        if(k){
            cout<<bi.sum(b)-bi.sum(a)<<"\n";
        }else{
            bi.add(a+1,b);
        }
    }
    
}


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

using namespace std;

// int ball_counter[100];
// int ball_selection[100];


long long ball_counter[200100];
long long ball_selection[200100];


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

    for(long long i=0; i<N; ++i){
        ball_counter[a[i]]++;
    }

    for(long long i=0; i<200100; ++i){
        if(ball_counter[i] > 1){
            // if(ball_counter[i] %2 == 0){
            //     ball_selection[i] = ball_counter[i]/2 ;
            //     ball_selection[i] *= (ball_counter[i] - 1);
            // }else{
            //     ball_selection[i] = (ball_counter[i] - 1)/2;
            //     ball_selection[i] *= ball_counter[i] ;
            // }
            // ball_selection[i] = ball_counter[i] * (ball_counter[i] - 1 )/2;

            ball_selection[i] = ball_counter[i] * (ball_counter[i] - 1 );
            ball_selection[i] /= 2;
        }
    }

    long long total = 0;
    for(long long i=0; i<200100; ++i){
        total += ball_selection[i];
    }


    for(int i=0; i<N; ++i){
        long long ans;

        // if( ball_counter[a[i]] - 1 < 2 ){
        //     ans = total;
        // }else{
        ans = total - (ball_counter[a[i]] - 1);
//         }

        cout << ans << endl;
    }
}

Measured memory_bytes: 7892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int mod = 1e9 + 7;
	int h, w, K;
	cin >> h >> w >> K;
	vector<vector<int>> dp(h + 1, vector<int>(w));
	dp[0][0] = 1;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < (1 << w - 1); j++) {
			bitset<7> bit = j;
			bool valid = true;
			for (int k = 0; k < 6; k++) {
				if (bit[k] && bit[k + 1]) valid = false;
			}
			if (!valid) continue;
			vector<int> perm(w);
			iota(perm.begin(), perm.end(), 0);
			for (int k = 0; k < w - 1; k++) {
				if (bit[k]) swap(perm[k], perm[k + 1]);
			}
			for (int k = 0; k < w; k++) {
				dp[i + 1][k] += dp[i][perm[k]];
				dp[i + 1][k] %= mod;
			}
		}
	}
	cout << dp[h][K - 1] << endl;
	return 0;
}

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

int x[110];
int y[110];
int diff[110];
double d[4];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", x+i);
	for(int i = 0; i < n; i++)
		scanf("%d", y+i);
	for(int i = 0; i < n; i++)
		diff[i] = abs(x[i] - y[i]);
	for(int i = 0; i < n; i++) {
		d[0] += diff[i];
		d[1] += pow(diff[i], 2);
		d[2] += pow(diff[i], 3);
		d[3] = max(d[3], (double)diff[i]);
	}
	d[1] = sqrt(d[1]);
	d[2] = cbrt(d[2]);
	for(int i = 0; i < 4; i++)
		printf("%.12lf\n", d[i]);
}



Measured memory_bytes: 3436
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  private static int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[] xs = sc.nextIntArray(n);
    List<Integer> abs = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      if (x == xs[i]) continue;
      abs.add(x > xs[i] ? x - xs[i] : xs[i] - x);
    }
    int d = abs.get(0);
    for (int i = 1; i < n; i++) {
      d = gcd(d, abs.get(i));
    }
    System.out.println(d);
  }
}

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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

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

using namespace std;

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

    ll x;
    cin >> x;

    ll ans = 0;
    ans += (x/500)*1000;
    x %= 500;
    ans += (x/5)*5;
    x %= 100;
    x %= 50;
    x %= 10;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N =2e5+10;
const int mod=1e9+7;
#define P pair<int, int>
const double pi=acos(-1.0);
ll a[N],b[N],sum_a,n,k;
int check(ll x)
{
    ll res=0;
    for(int i=1;i<=n;i++)
    {
        ll y=x/b[i];
        if(y<a[i])
            res+=(a[i]-y);
    }
    if(res>k)
        return 1;
    return 0;
}
int main()
{
   ll ans;
   cin>>n>>k;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       sum_a+=a[i];
   }
   sort(a+1,a+n+1);
   reverse(a+1,a+n+1);
   for(int i=1;i<=n;i++)
   {
       cin>>b[i];
   }
   sort(b+1,b+n+1);

    ll l=0,r=(ll)1e18,mid;
    while(l<r)
    {
        mid=(l+r)/2;
        if(check(mid))
        {
            l=mid+1;
        }
        else
        {
            r=mid;
        }
    }
    cout<<l<<"\n";
    return 0;
}


Measured memory_bytes: 3328
function Main(input) {
	input = input.split("\n");
	var p = input[0].split(" ").map(Number);
	var max = p[1]-0;
	var dp = new Array(p[0]+1);
	//.fill(new Array(max+1));
	//dp[0] = new Array(max+1).fill(0)
	for(var n=0;n<p[0]+1;n++){
	    dp[n] = new Array(max+1).fill(0);
	}
	//	console.log(dp)
    for(var i=1;i<input.length;i++){
    var mem = input[i].split(" ").map(Number);
    for(var j=0;j<=max;j++){
        //console.log(i,j)
      if(j>=mem[1]) dp[i][j] = Math.max(dp[i-1][j-mem[1]]+mem[0],dp[i-1][j])
      else dp[i][j] = dp[i-1][j];
    }
  }
  console.log(dp[p[0]][max])
 // console.log(dp)
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 29448
N, M = map(int, input().split())
H = list(map(int, input().split()))

X = [[] for i in range(N)] #辺リスト
for i in range(M):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

cnt = 0
for i in range(N):
    c = 0
    for k in X[i]:
        if H[i] <= H[k]:
            c += 1
    if c == 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 94540
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) break;
			for (int i = 0; i < n; i++) {
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				
				char ans = 0;
				if (ans == 0) {
					if (a >= 100 || b >= 100 || c >= 100) ans = 'A';
				}
				if (ans == 0) {
					if (a + b >= 180) ans = 'A';
				}
				if (ans == 0) {
					if (a + b + c >= 240) ans = 'A';
				}
				if (ans == 0) {
					if (a + b + c >= 210) ans = 'B';
				}
				if (ans == 0) {
					if (a + b + c >= 150 && (a >= 80 || b >= 80)) ans = 'B';
				}
				if (ans == 0) {
					ans = 'C';
				}
				System.out.println(ans);
			}
		}
	}
}

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

int h[100000][3];
int dp[100000][3];

int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i)
		cin >> h[i][0] >> h[i][1] >> h[i][2];
	dp[0][0] = h[0][0]; dp[0][1] = h[0][1]; dp[0][2] = h[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] = max(dp[i][j], dp[i-1][k] + h[i][j]);
			}
		}
	}
	vector<int> ans{dp[N-1][0], dp[N-1][1], dp[N-1][2]};
	sort(ans.begin(), ans.end());
	cout << ans[2] << '\n';
}


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

int main()
{
	char str[256];
	int i,sum, n;
	sum = 0;
//	printf("n : %d\n",n);


	scanf("%s",str);

	n = atoi(str);

	for(i=0 ; i<strlen(str);i++)
	{
		sum += str[i] - 0x30;
	}

	if( n % sum == 0 )printf("Yes\n");
		else printf("No\n");
	
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int r,d,x[13];
	scanf("%d%d%d",&r,&d,&x[0]);
	for (int i = 1; i <= 10; ++i)
	{
		x[i] = r * x[i - 1] - d;
		printf("%d\n", x[i]);
	}
	return 0;
}


Measured memory_bytes: 128
<?php
$n = intval(fgets(STDIN));
for($i = 0; $i < $n; $i++){
    list($city, $rate) = explode(" ", trim(fgets(STDIN)));
    $map[$city][$rate] = $i;
    $cityMap[$city] = true;
}
$cityArray = array_keys($cityMap);
sort($cityArray);
foreach($cityArray as $city){
    $ratings = $map[$city];
    krsort($ratings);
    foreach($ratings as $i){
        echo ($i+1)."\n";
    }
}


Measured memory_bytes: 4732
N,A,B=map(int,input().split())
H = [int(input()) for i in range(N)]
H.sort()
from math import ceil
def KnockOut(t):
    base = B*t
    for i in range(N):
        h = H[i]
        h -= base
        if h > 0:
            t -= ceil(h/(A-B))
            if t < 0:
                return False
    return True
l = 0
r = ceil(max(H)/B)
while l != r-1:
    t = int((l+r)/2)
    if KnockOut(t):
        r = t
    else:
        l = t
print(r)    

Measured memory_bytes: 7384
#include<bits/stdc++.h>
#define lld long long int
#define pb push_back
#define in insert
#define mod 1000000007
#define pi 3.14159265358979

using namespace std;

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

    string s;
    cin>>s;
    lld len=s.size();
    char t[len],u[len];

    for(lld i=0;i<len;i++)
    {
        if(i%2==0){t[i]='0';u[i]='1';}
        else {t[i]='1';u[i]='0';}
    }

    lld c=0,c1=0;
    for(lld i=0;i<len;i++)
    {
        if(s[i]!=t[i])c++;
        if(s[i]!=u[i])c1++;
    }

    cout<<min(c,c1)<<"\n";
}


Measured memory_bytes: 3912
n=int(input())
a=[list(map(int,input().split())) for i in range(2)]
ans=0
if n==1:
  print(sum(a[0])+sum(a[1]))
  exit()
for i in range(n):
  ans=max(ans,sum(a[0][0:i])+sum(a[1][i-1:n]))
print(ans)

Measured memory_bytes: 8908
#include<iostream>
#include<math.h>
#include<string>

using namespace std;

#define REP(i, n) for(int i=0; i<n; i++)
typedef unsigned long long ll;

ll n, k;
ll a[100010];
ll output[41];
int maxidx=41;

ll llpow2(ll a) {
    if (a==0) return 1;
    ll half = llpow2(a/2);
    if (a%2 == 0) {
        return half * half;
    } else {
        return half * half * 2;
    }
}

bool chooseone(ll idx, ll *a) {
    int output = 0;
    REP(i, n) {
        if(a[i] & (1ll<<idx)) output ++;
    }

    return !(n-output < output);
}

int bitsum(ll idx, ll *a, bool kbit) {
    int output = 0;
    REP(i, n) {
        if(bool(a[i] & (1ll<<idx)) != kbit) output ++;
    }

    return output;
}

int main(){
    cin >> n >> k;
    REP(i, n) {
        cin >> a[i];
    }

    bool small = false;
    for (int i=maxidx; i>=0; i--) {
        bool abit = chooseone(i, a);
        if ((bool)(k & (1ll<<i)) == abit || small) {
            output[i]= bitsum(i, a, abit);
        } else {
            if (!abit) small = true; // choose zero
            output[i] = bitsum(i, a, 0);
        }
    }

    ll numoutput = 0;
    for (int i=maxidx; i>=0; i--) {
        numoutput += output[i] * llpow2(i);
    }
    cout << numoutput << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    map<LL, int> m;
    rep(i, n) {
        LL a; cin >> a;
        ++m[a];
    }
    int ans = 0;
    for (auto e : m) {
        if (e.first == e.second) continue;
        else if (e.first < e.second) ans += e.second - e.first;
        else ans += e.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6272
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long es[] = new long[n];
        for (int i = 0; i < n; i++) {
            es[i] = sc.nextLong();
        }
        Arrays.sort(es);
        long ans;
        long l = 0, r = 1000000000L;
        while (r - l > 1) {
            ans = (r - l) / 2 + l;
            if (check(es, ans, a, b)) {
                r = ans;
            }
            else {
                l = ans;
            }
        }
        System.out.println(r);
    }
 
    static boolean check(long[] es, long t, long a, long b) {
        int idx = 0;
        long add = a - b;
        long base = b * t;
        while(idx < es.length && es[idx] <= base) idx++;
        long count = 0;
        for (; idx < es.length; idx++) {
            count += (es[idx] - base + add - 1) / add;
        }
        return count <= t;
    }
}

Measured memory_bytes: 50820
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

bool check(ll n, ll k, vector<ll> &a, vector<ll> &f) {
    int m = a.size();
    ll sum = 0;
    rep(i, m) {
        if(a[i] * f[i] > n)
            sum += a[i] - n / f[i];
    }
    return (sum <= k);
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> F[i];
    sort(All(A));
    sort(All(F));
    reverse(All(F));

    ll ok = 1e13, ng = -1;
    while(abs(ok - ng) > 1LL) {
        ll mid = (ng + ok) / 2;
        if(check(mid, K, A, F))
            ok = mid;
        else
            ng = mid;
    }

    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


string dp[51][51][51];

int X, Y, Z;
int N;

string S;

// qUUUU >= UUUUU
bool ok() {
    REP (x, X+1) REP (y, Y+1) REP (z, Z+1) dp[x][y][z].clear();
    REP (x, X+1) REP (y, Y+1) REP (z, Z+1) if (x+y+z == (int)dp[x][y][z].size()) {
	for (char c='c'; c>='a'; c--) {
	    string g = string(1, c) + dp[x][y][z];
	    string &t = (c=='c'? dp[x][y][z+1]:
		    (c=='b'? dp[x][y+1][z]: dp[x+1][y][z]));
	    if (t.empty() || t < g) if (g + S + S > S + S) {
		t = g;
	    }
	}
    }
    return !dp[X][Y][Z].empty();
}

void MAIN() {
    scanf("%d%d%d", &X, &Y, &Z);
    N = X + Y + Z;

    S = string(N, 'a');
    REP (i, N) {
	S[i] = 'c';
	if (!ok()) {
	    S[i] = 'b';
	    if (!ok()) S[i] = 'a';
	}
    }

    puts(S.c_str());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << endl;}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int solve() {
	var(int, n, X);
	vec(int, x, n);
	if (n == 1)
		return abs(x[0] - X);
	sort(all(x));
	int ans = __gcd(abs(x[0] - X), abs(x[1] - X));
	rep(i, 2, n) {
		ans = __gcd(ans, abs(x[i] - X));
	}
	return ans;
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 640
class Tree():
    def __init__(self, n, edge):
        self.n = n
        self.tree = [[] for _ in range(n)]
        for e in edge:
            self.tree[e[0] - 1].append(e[1] - 1)
            self.tree[e[1] - 1].append(e[0] - 1)

    def setroot(self, root):
        self.root = root
        self.parent = [None for _ in range(self.n)]
        self.parent[root] = -1
        self.depth = [None for _ in range(self.n)]
        self.depth[root] = 0
        self.order = []
        self.order.append(root)
        stack = [root]
        while stack:
            node = stack.pop()
            for adj in self.tree[node]:
                if self.parent[adj] is None:
                    self.parent[adj] = node
                    self.depth[adj] = self.depth[node] + 1
                    self.order.append(adj)
                    stack.append(adj)

    def rerooting(self, func, merge, ti, ei):
        dp = [ti for _ in range(self.n)]
        lt = [ei for _ in range(self.n)]
        rt = [ei for _ in range(self.n)]
        inv = [ei for _ in range(self.n)]
        self.setroot(0)
        for node in self.order[::-1]:
            tmp = ti
            for adj in self.tree[node]:
                if self.parent[adj] == node:
                    lt[adj] = tmp
                    tmp = func(tmp, dp[adj])
            tmp = ti
            for adj in self.tree[node][::-1]:
                if self.parent[adj] == node:
                    rt[adj] = tmp
                    tmp = func(tmp, dp[adj])
            dp[node] = tmp
        for node in self.order:
            if node == 0:
                continue
            merged = merge(lt[node], rt[node])
            par = self.parent[node]
            inv[node] = func(merged, inv[par])
            dp[node] = func(dp[node], inv[node])
        return dp

class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.factorial[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.factorial[i + 1] = self.factorial[i] * (i + 1) % mod
        self.inv[n] = pow(self.factorial[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.factorial[m]

    def invfact(self, m):
        return self.inv[m]

import sys
input = sys.stdin.readline

MOD = 1000000007

N = int(input())
E = [tuple(map(int, input().split())) for _ in range(N - 1)]

T = Tree(N, E)
F = Factorial(N + 1, MOD)

def func(node, adj):
    size = node[1] + adj[1]
    count = node[0] * adj[0] * F.invfact(adj[1]) * F.fact(size - 1) * F.invfact(node[1] - 1)
    count %= MOD
    return count, size

def merge(lt, rt):
    size = lt[1] + rt[1] - 1
    count = lt[0] * rt[0] * F.invfact(lt[1] - 1) * F.invfact(rt[1] - 1) * F.fact(size - 1)
    count %= MOD
    return count, size

ti = (1, 1)
ei = (1, 0)

D = T.rerooting(func, merge, ti, ei)

res = []

for i in range(N):
    res.append(D[i][0])

print('\n'.join(map(str, res)))

Measured memory_bytes: 229064
#b
import sys
N=input()
N=int(N)
a=int(N/3)
b=int(N/5)
c=int(N/15)
S=N*(N+1)/2 - 3*a*(a+1)/2 - 5*b*(b+1)/2 + 15*c*(c+1)/2
print(int(S))

Measured memory_bytes: 9184
#include<stdio.h>
int main(){
  int n,m,i,j,count,t=0;
  while(1){
    count=0;
  scanf("%d",&n);
  
  scanf("%d",&m);
  
  if(n+m==0) break;
  if(t>0)   printf("\n");
  t++;
   if(n+m>6000) printf("NA\n");
   else{
  for(i=n;i<=m;i++){
    if(i%4==0 && i%100!=0){
      printf("%d\n",i);
      count=1;
    }
    else if(i%400==0){
      printf("%d\n",i);
      count=1;
    }
  }

  if(count!=1) printf("NA\n");
  }
  }
  return 0;
}

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

int main(){
	int n,t,s;
	cin >> n >> t >> s;
	vector<int> a(n), b(n);
	for(int i=0; i<n; i++){
		cin >> a[i] >> b[i];
	}

	vector<vector<int>> dp_f(t+1, vector<int>(n+1, 0));
	auto dp_b = dp_f;
	for(int d=0; d<2; d++){
		for(int i=0; i<n; i++){
			for(int j=t; j>=0; j--){
				dp_f[j][i+1] = dp_f[j][i];
				if(j-b[i] >= 0){
					dp_f[j][i+1] = max(dp_f[j][i+1], dp_f[j-b[i]][i]+a[i]);
				}
			}
		}
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		swap(dp_f, dp_b);
	}

	int ans = 0;
	for(int i=0; i<=n; i++){
		int sub_f = *max_element(dp_f[s].begin(), dp_f[s].begin()+i+1);
		int sub_b = *max_element(dp_b[t-s].begin(), dp_b[t-s].begin()+n-i+1);
		ans = max(ans, sub_f + sub_b);
	}
	cout << ans << endl;
	return 0;
}



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

int main () {
  int N;
  cin >> N;
  
  if (N % 1110 < 10)
    cout << "Yes" << endl;
  else if ((N % 1000)% 111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
'use strict'

const main = (input) => {
    const s = input.split('\n')[0].split('').map(v => parseInt(v))
    const k = parseInt(input.split('\n')[1])

    for(let i = 0; i < k; i++){
        if(s[i] >= 2){
            console.log(s[i])
            return
        }
    }
    console.log(1)
}

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

Measured memory_bytes: 7372
from collections import Counter


n, p = map(int, input().split())
S = map(int, reversed(input()))

if p == 2 or p == 5:
    ans = 0
    mods = map(lambda x: x % p, S)
    for idx, mod in enumerate(mods):
        if mod == 0:
            ans += n - idx
    print(ans)
    exit()

mods = [0]
num = 0
digit = 1
for s in S:
    num += s * digit
    num %= p
    mods.append(num)
    digit = digit * 10 % p

counter = Counter(mods)
ans = 0
for count in counter.values():
    ans += count * (count-1) // 2
print(ans)


Measured memory_bytes: 11804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int H, W, m;
    cin >> H >> W >> m;
    vector<int> h(m), w(m);
    rep(i, m)cin >> h[i] >> w[i];

    vector<P> mx(H), my(W);
    rep(i, H)mx[i].second = i;
    rep(i, W)my[i].second = i;

    set<P> s;
    rep(i, m){
        h[i]--; w[i]--;
        mx[h[i]].first++;
        my[w[i]].first++;
        s.insert(make_pair(h[i], w[i]));
    }

    sort(mx.begin(), mx.end(), greater<P>());
    sort(my.begin(), my.end(), greater<P>());

    ll nx = 0;
    ll ny = 0;
    rep(i, H)if(mx[i].first == mx[0].first)nx++;
    rep(i, W)if(my[i].first == my[0].first)ny++;
    
    if(nx * ny > m)cout << mx[0].first + my[0].first << endl;
    else{
        vector<int> lx, ly;
        rep(i, H)if(mx[i].first == mx[0].first)lx.push_back(mx[i].second);
        rep(i, W)if(my[i].first == my[0].first)ly.push_back(my[i].second);
        bool v = false;
        for(int x : lx){
            for(int y : ly){
                if(s.find(make_pair(x, y)) == s.end())v = true;
            }
        }
        if(v)cout << mx[0].first + my[0].first << endl;
        else cout << mx[0].first + my[0].first - 1 << endl;
    }
    
}

Measured memory_bytes: 26452
readline = open(0).readline
N = int(readline())
*A, = map(int, readline().split())
Q = int(readline())
for _ in range(Q):
    b, e, t = map(int, readline().split())
    for k in range(e-b):
        A[b+k], A[t+k] = A[t+k], A[b+k]
print(*A)


Measured memory_bytes: 5840
while True:
    n,k=[int(s)for s in input().split(" ")]
    if n==k==0:break
    a=[int(input())for a in range(n)]
    s=0
    for i in range(k):s+=a[i]
    maxval=s
    for i in range(n-k):
        s+=a[i+k]-a[i]
        if s>maxval:maxval=s
    print(maxval)

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

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

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

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

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m,x;cin>>n>>m>>x;
  vector<int> c(n);
  vector<vector<int> > a(n,vector<int>(m));
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  
  ll ans = INFL;
  rep(bit,1<<n){
    auto bs = bitset<12>(bit);
    ll sum = 0;
    vector<int> b(m,0);
    rep(i,n){
      if(!bs[i])continue;
      sum += c[i];
      rep(j,m){
        b[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(i,m){
      if(b[i] < x){
        ok = false;
        break;
      }
    }
    if(ok)chmin(ans,sum);
  }
  if(ans != INFL)print(ans);
  else print(-1);
  return 0; 
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a*b%2!=0){cout<<"Yes"<<endl;}
    else {cout<<"No"<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define uld unsigned long long
#define int long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)



signed main(){
    FAST;
    int x, y;
    cin>>x>>y;
    for(int i=1; i<=x; i++){
        if( (i*2 + (x-i)*4)==y || (i*4 + (x-i)*2)==y ) {cout<<"Yes"<<endl; return 0;}
    }
    cout<<"No"<<endl;
}


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

int binarySearch( int n , int a[n] , int key);

int main( void ){
	
	int n , q;
	int *s , *t;
	int i;
	int c = 0;
	
	scanf( "%d" , &n );
	s = (int *)malloc(n * sizeof(int));  
	for( i = 0; i < n; i++ ){
		scanf( "%d" , &s[i] );
	}
	
	scanf( "%d" , &q );
	t = (int *)malloc(q * sizeof(int));  
	for( i = 0; i < q; i++ ){
		scanf( "%d" , &t[i] );
	}
	
	for( i = 0; i < q; i++ ){
		if( binarySearch( n , s , t[i]) != -1 ){
			c++;
		}
	}
	
	printf( "%d\n" , c );
	
}

int binarySearch( int n , int a[n] , int key){

	int right , left , mid;
	
	left = 0;
	right = n;
	
	while( left < right ){
		mid = ( left + right ) / 2;
		
		if( a[mid] == key ){
			return mid;
		}else if( key < a[mid] ){
			right = mid;
		}else{
			left = mid + 1;
		}
	}
	
	return -1;
	
}


Measured memory_bytes: 2268
#include <iostream>
#include <queue>
#include <map>

using namespace std;

int solve(string s)
{
    map<string, int> mem;
    queue<pair<string, int> > q;

    q.push(pair<string, int>(s, 0));
    mem[s] = 0;

    while (!q.empty()) {
        pair<string, int> tmp;
        bool flag = true;

        tmp = q.front();
        q.pop();

        // Check
        for (int i = 1; i < tmp.first.size(); i++)
            if (tmp.first[0] != tmp.first[i]) {
                flag = false;
                break;
            }
        if (flag) 
            return tmp.second;

        for (int i = 0; i < tmp.first.size() - 1; i++) {
            if (tmp.first[i] != tmp.first[i + 1]) {
                string str = tmp.first;
                int num = (int)(tmp.first[i] + tmp.first[i + 1]);

                if (num == 217) 
                    str[i] = str[i + 1] = 'b';
                else if (num == 212) 
                    str[i] = str[i + 1] = 'g';
                else if (num == 201) 
                    str[i] = str[i + 1] = 'r';

                if (mem.count(str) == 0) {
                    q.push(pair<string, int>(str, tmp.second + 1));
                    mem[str] = tmp.second + 1;
                }
            }
        }
    }
    return -1;
}

int main()
{
    string inp;

    while (cin >> inp, inp != "0") {
        int num = solve(inp);

        if (num >= 0)
            cout << num << endl;
        else 
            cout << "NA" << endl;
    }

    return 0;
}

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

int main(){
    int input;
    int counter=1;
    while(1){
        cin >> input;
        if(input==0){
            break;
        }else{
            cout << "Case " << counter << ": " << input << endl;
            counter++;
        }
    }
    return 0;
}

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

using namespace std;

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

    vector<bool> digits(10, true);

    for(int i = 0; i < K; ++i) {
        int x; cin >> x;
        digits[x] = false;
    }

    // From all the available digits, create another number >= N
    // If N does not contain a violating digit, we are done
    // else N + 1
    auto check = [&](int x) {
        while(x >= 10) {
            int d = x % 10;
            if(!digits[d]) return false;
            
            x -= d;
            x /= 10;
        }
        
        return (bool) digits[x];
    };

    while(true) {
        if(check(N)) {
            cout << N << endl;
            break;
        }
        ++N;
    }
}


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

int main(){
    int N, Q;
    cin >> N >> Q;
    int num[100000] = {0};
    num[1] = 1;
    int pos = 0;
    for(int i=0; i<Q; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        if(a == pos){
            pos = b;
        }else if(b == pos){
            pos = a;
        }
        swap(num[a], num[b]);
        for(int p : {pos-1, pos+1}) if(0 <= p && p < N) num[p]++;
    }
    int ans = 0;
    for(int i=0; i<N; i++) if(pos == i || num[i] > 0) ans++;
    cout << ans << endl;
    return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int gcd(int a,int b) {
    while (b) {
        a %= b;
        swap(a,b);
    }
    return a;
}

int main() {
    int n;
    cin >> n;
    int g = 0;
    for (int i = 0;i < n;++i) {
        int a;
        cin >> a;
        g = gcd(g,a);
    }
    cout << g << endl;
}

Measured memory_bytes: 256
MODE = "stdio"
#require 'matrix'
#include Math
line = Array.new

if(defined? MODE)
  line = STDIN.read.split("\n")
else
  tmp = '6
  5 2 4 6 1 3'.split("\n")
  tmp.each{|s|
    line << s.strip
  }
end


n = line[0].to_i

arr = line[1].split(" ").map(&:to_i)

flag = 1
i = 0
cnt = 0
while flag==1
  flag=0
  (n-1).downto(i+1) do |j|
    if arr[j]<arr[j-1]
      arr[j], arr[j-1] = arr[j-1], arr[j]
      flag=1
      cnt+=1
    end
  end
  i += 1
end
puts arr.join(" ")
puts cnt

Measured memory_bytes: 8732
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if(s.charAt(s.length()-1)=='s') {
			s=s+"es";
		}
		else {
			s+="s";
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 38528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int par[100100], l[100100], r[100100], d[100100]; //lは一番左の子、rはすぐ隣の兄弟、dは深さ

void print (int u) {
    cout << "node " << u << ": parent = " << par[u] << ", depth = " << d[u];
    if (par[u] == -1) {
        cout << ", root, [";
    } else if (l[u] == -1) {
        cout << ", leaf, [";
    } else {
        cout << ", internal node, [";
    }
    for (int i = 0, cur = l[u]; cur != -1; i++, cur = r[cur]) {
        if (i) cout << ", ";
        cout << cur;
    }
    cout << "]\n";
}

int setD (int u, int now) {
    d[u] = now;
    if (l[u] != -1) setD (l[u], now + 1);
    if (r[u] != -1) setD (r[u], now);
}

int main() {
    int n;
    cin >> n;
    rep (i, n) par[i] = l[i] = r[i] = -1;
    int cur, k;
    rep (i, n) {
        cin >> cur >> k;
        int prev;
        rep (j, k) {
            int next;
            cin >> next;
            par[next] = cur;
            if (j == 0) l[cur] = next;
            if (j > 0) r[prev] = next;
            prev = next;
        }
    }
    int root;
    rep (i, n) {
        if (par[i] == -1) root = i;
    }
    setD (root, 0);
    rep (i, n) print (i);
}



Measured memory_bytes: 4632
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        HashSet<Integer> ac = new HashSet<Integer>();
        HashMap<Integer,Integer> wa = new HashMap<Integer,Integer>();
        for(int i = 0; i < m; i++){
            int num = sc.nextInt();
            String s = sc.next();
            if(s.equals("AC")){
                ac.add(num);
            }else{
                if(ac.contains(num)){
                    continue;
                }else{
                    if(wa.containsKey(num)){
                        wa.put(num,wa.get(num)+1);
                    }else{
                        wa.put(num,1);
                    }
                }
            }
        }
        int was = 0;
        for(Map.Entry<Integer,Integer> entry : wa.entrySet()){
            if(ac.contains(entry.getKey())){
                was += entry.getValue();   
            }
		}
        System.out.print(ac.size() + " ");
        System.out.println(was);
    }
}

Measured memory_bytes: 68356
K,A,B = map(int, raw_input().split())
if B-A<=2:
  print K+1
else:
  c = A-1
  if c>K:
    print K+1
  else:
    if (K-c)%2!=0:
      c += 1
    print max(K+1, 1+c+(B-A)*(K-c)/2)


Measured memory_bytes: 2568
#include <stdio.h>

int main(void){

  long n,Lt;
  scanf("%ld %ld", &n, &Lt);
  long t[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &t[i]);
  }
  long x = Lt;
  for (long i = 1; i < n; i++) {
    if (t[i]-t[i-1] >= Lt) {
      x += Lt;
    } else {
      x += t[i]-t[i-1];
    }
  }
  printf("%ld\n", x);

  return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    double a[n];
    double sum = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum += a[i];
    }
    double d = sum/(4*m);
    int count=0;
    for(int i1=0;i1<n;i1++){
        if(a[i1]<d){
          continue;
        }
        count++;
    }
    //cout << sum << endl;
    //cout << d << endl;
    //cout << count << endl;
    if(count>=m){
      cout << "Yes";
    }
    else{
      cout << "No";
    }
}


Measured memory_bytes: 256