akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fr(i,a,n) for(i=a;i<n;i++)
#define frn(i,a,n) for(i=a;i<=n;i++)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vp vector<pll>
#define ub upper_bound
#define lb lower_bound
//#define map map<ll,ll>
#define mem(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(),v.end()
#define bs binary_search
#define qll queue<ll>
#define sll set<ll>
#define ma 500000
ll power(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return power(x*x,n/2);
    else                             //n is odd
        return x*power(x*x,(n-1)/2);
}
int highestPowerof2(int n)
{
   int p = (int)log2(n);
   return (int)pow(2, p);  
}
ll powermod(ll x, ll y, ll p)  
{  
    ll res = 1;
    x = x % p;
    if (x == 0) return 0;  
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}
 
int main()
{
    fastio;
    string s,t;
    cin>>s>>t;
    ll n =  s.length();
    ll m= t.length();
    string r;
    ll ans = INT_MAX,c=0;
    for(ll i=0;i<n-m+1;i++)
    {
         r=s.substr(i,m);
         for(ll j=0;j<m;j++)
         {
             if(r[j]!=t[j])
             c++;
         }
         ans=min(ans,c);
         c=0;
    }
    cout<<ans<<endl;
    
}

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


public class Test
{	
    public static void Main()
	{
	    int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        if(nums[0]-nums[1] > 0) Console.WriteLine(nums[0] - nums[1]);
        else Console.WriteLine("0");
        
	}
}

Measured memory_bytes: 11348
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<queue>
#include <cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<ctime>
//#include <bits/stdc++.h>
#define rep(i,n) for (long int i = 0; i < (n); ++i)
using namespace std;

int main(){
    long int N,ans=0;
    long long D;
    cin>>N>>D;
    rep(i,N){
        long long X,Y;
        cin>>X>>Y;
        long long a=X*X+Y*Y;
        if (a<=D*D) ans+=1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
def matDot(A,B,MOD):
    N,M,L = len(A),len(A[0]),len(B[0])
    
    res = [[0]*L for i in range(N)]

    for i in range(N):
        for j in range(L):
            s = 0
            for k in range(M):
                s = (s + A[i][k]*B[k][j]) % MOD
            res[i][j] = s
    
    return res

def matPow(A,x,MOD):
    N = len(A)
    res = [[0]*N for i in range(N)]
    
    for i in range(N):
        res[i][i] = 1
    
    for i in range(x.bit_length()):
        if (x>>i) & 1:
            res = matDot(res,A,MOD)
        A = matDot(A,A,MOD)
    
    return res

n,k = map(int,input().split())
mod = 10**9+7

a = [list(map(int,input().split())) for i in range(n)]
a = list(map(list, zip(*a)))

b = matPow(a,k,mod)

ans = 0
for i in range(n):
    for j in range(n):
        ans = (ans+b[i][j])%mod

print(ans)

Measured memory_bytes: 41324
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def main():
    s = S()
    N = int(s)
    if N % 2 == 1:
        print(0)
        return
    dig = len(s)
    cnt = 0
    for i in range(1, 36):
        if 5 ** i > N//2:
            break
        cnt += (N // 2) // (5**i)
    print(cnt)
main()



Measured memory_bytes: 5436
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
*/

#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bs 1000000007

#define bsize 256

#define ldouble long double

using namespace std;

long long INF = 1e9;
const int N = 400031;

long long n,X,Y,smallest_w[N],smallest_pref[N],smallest_suf[N];
long long c[N],w[N];

vector<pair<long long, long long> > entries[N];

int free_cells;
vector<long long> free_list;

bool is_movable_c(int id)
{
	if (smallest_pref[id-1]+entries[id][0].first<=Y)
		return true;
	if (smallest_suf[id+1]+entries[id][0].first<=Y)
		return true;
	return false;
}

bool is_movable(int id)
{
	if (smallest_pref[c[id]-1]+w[id]<=Y)
		return true;
	if (smallest_suf[c[id]+1]+w[id]<=Y)
		return true;
	if (is_movable_c(c[id])&&w[id]+entries[c[id]][0].first<=X)
		return true;
	return false;
}

long long fact[N],invf[N];

long long pw(long long a,long long b)
{
	if (b==0)
		return 1;
	if (b%2)
		return a*pw(a,b-1)%bs;
	return pw(a*a%bs,b/2);
}

long long inv(long long x)
{
	return pw(x,bs-2);
}

long long C(long long n,long long m)
{
	long long res=fact[n];
	res*=invf[m];
	res%=bs;
	res*=invf[n-m];
	return res%bs;
}

int main(){
	//freopen("cinema.in","r",stdin);
	//freopen("cinema.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);

	fact[0]=1;
	for (int i=1;i<N;i++)
	{
		fact[i]=fact[i-1]*i%bs;
	}

	for (int i=0;i<N;i++)
	{
		invf[i]=inv(fact[i]);
	}

	cin>>n>>X>>Y;
	for (int i=1;i<=n;i++)
	{
		smallest_w[i]=2e9;
	}

	for (int i=1;i<=n;i++)
	{
		cin>>c[i]>>w[i];
		smallest_w[c[i]]=min(smallest_w[c[i]],w[i]);
		entries[c[i]].push_back(make_pair(w[i],i));
	}

	for (int i=1;i<=n;i++)
	{
		sort(entries[i].begin(),entries[i].end());
	}

	smallest_pref[0]=smallest_suf[n+1]=2e9;

	for (int i=1;i<=n;i++)
	{
		smallest_pref[i]=min(smallest_pref[i-1],smallest_w[i]);
	}
	for (int i=n;i>=1;--i)
	{
		smallest_suf[i]=min(smallest_suf[i+1],smallest_w[i]);
	}

	/*for (int i=1;i<=n;i++)
	{
		cout<<smallest_pref[i]<<" "<<smallest_suf[i]<<endl;
	}*/

	for (int i=1;i<=n;i++)
	{
		if (is_movable(i))
			free_cells++,
			free_list.push_back(c[i]);
	}

	sort(free_list.begin(),free_list.end());

	/*cout<<free_cells<<endl;
	for (int i=0;i<free_list.size();i++)
	{
		cout<<free_list[i]<<" ";
	}
	cout<<endl;
*/
	long long ans=1;
	int cnt=0;
	for (int i=0;i<free_list.size();i++)
	{
		if (i>0&&free_list[i]!=free_list[i-1])
		{
			ans=ans*C(free_cells,cnt);
			ans=ans%bs;
			free_cells-=cnt;
			cnt=0;
		}
		++cnt;
	}
	cout<<ans<<endl;

	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 39416
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn min (a: &i64, b: &i64)-> i64{
    if *a <= 0i64 {*b}
    else if *b <= 0i64  {*a}
    else if *a < *b {*a}
    else {*b}
}

fn abs (a: &i64, b: &i64) -> i64{
    if *a - *b <= 0 {*b - *a} else {*a - *b}
}

fn main(){
    input!{
        n: i64,
        k: i64
    }
    print!("{}",if n%k==0 {0} else {min(&(n%k), &(k-(n%k)))})
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)


signed main(){
    cout << fixed << setprecision(10);
    intl l,r,d;
    cin >> l >> r >> d;
    intl cnt = 0;
    repi(i,l,r + 1){
        if(!(i % d))cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		//String word_before = sc.next();
		//int K = sc.nextInt();
		
		int N = sc.nextInt();
		int R = sc.nextInt();
		
		if (N>=10) {
			System.out.println(R);
		}else{
			System.out.println(R+(10-N)*100);
		}

      	sc.close();
    }
		
		
}

Measured memory_bytes: 21588
import math
K = int(input())
ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            tmp_gcd = math.gcd(i, j)
            tmp_gcd = math.gcd(tmp_gcd, k)
            if i == j == k:
                ans += tmp_gcd
            elif i == j or i == k or j == k:
                ans += tmp_gcd * 3
            else:
                ans += tmp_gcd * 6
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
#define ll long long
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define y1 wzpakking
#define fi first
#define se second
#define BG begin
#define ED end
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?(x)-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a))
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define sqr(x) (1ll*x*x)
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
#define INF (1ll<<60)
using namespace std;
int n;
ll x[100005],y[100005];
bool check(ll x,ll y){
	return y>=0&&((x&y)==y);
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%lld%lld",&x[i],&y[i]);
	ll ans=0,D=1ll<<60;
	Rep(i,60,0){
		ans+=1ll<<i;
		int bit=0;
		For(j,1,n) bit^=check(D-x[j]-y[j],ans-y[j]);
		if (!bit) ans-=1ll<<i;
	}
	printf("%lld\n",(1ll<<60)-ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;
vector<int> a;

int main() {

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());

	cout << a.size() << endl;

	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int ho;
    int count;
    for(int i=n-1;i>1;i--){
        count=0;
        if(i%2==1){
            continue;
        }
        if(i%2==0){
            ho=i/2;
            for(int j=0;j<ho;j++){
                if(s[j]==s[ho+j]){
                    count++;
                }
                
            }

        }
        if(count==ho){
                    cout<<i;
                    break; 
                    
                }
    }
}


Measured memory_bytes: 256
N,K = map(int,input().split())
ans = 0
for n in range(1,N+1):
    if n >= K:
        ans += 1
        continue
    k = 0
    m = n
    while m < K:
        m *= 2
        k += 1
    ans += 2**-k
print(ans/N)

Measured memory_bytes: 3188
#include <stdio.h>
  
int main(){
  
int i=0;
int a[10000];
  
scanf("%d\n",&a[i]);
while(a[i]!=0){
     printf("Case %d: %d\n",i+1,a[i]);
     i++;
     scanf("%d\n",&a[i]);
}
}

Measured memory_bytes: 2768
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vector<vector<int>> adj(n);
	for(int i = 1; i < n; ++ i){
		int u, v;
		cin >> u >> v, -- u, -- v;
		adj[u].push_back(v), adj[v].push_back(u);
	}
	vector<int> prev(n, -1);
	queue<pair<int, int>> q{{{0, 0}}};
	while(!q.empty()){
		int u, p;
		tie(u, p) = q.front(); q.pop();
		for(auto v: adj[u]){
			if(v != p){
				prev[v] = u;
				q.push({v, u});
			}
		}
	}
	vector<int> path, visited(n);
	for(auto u = n - 1; ~u; u = prev[u]){
		path.push_back(u);
		visited[u] = true;
	}
	reverse(path.begin(), path.end());
	int res = 0;
	for(auto i = 0, j = int(path.size()) - 1; i <= j; ++ i, -- j){
		function<void(int, int)> dfs = [&](int u, int delta){
			visited[u] = true;
			res += delta;
			for(auto v: adj[u]){
				if(!visited[v]){
					dfs(v, delta);
				}
			}
		};
		dfs(path[i], 1);
		if(i != j) dfs(path[j], -1);
	}
	res > 0 ? cout << "Fennec\n" : cout << "Snuke\n";
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 7164
package main

import (
	"fmt"
)

func main() {
	var a, b, c []byte
	fmt.Scan(&a, &b, &c)
	var S [3][]byte
	S[0] = a
	S[1] = b
	S[2] = c
	var next byte = 0
	for {
		if len(S[int(next)]) == 0 {
			fmt.Printf("%s\n", string(next+'A'))
			return
		}
		next, S[next] = S[next][0] - 'a', S[next][1:]
	}
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;

const ll INF = 100000000000000000;

int r[100005], c[100005];
ll a[100005];
vector<int> x[100005], y[100005];
bool used[100005];
ll dx[100005], dy[100005];

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    for(int i = 0; i < n; i++){
        cin >> r[i] >> c[i] >> a[i];
        r[i]--; c[i]--;
        x[r[i]].push_back(i);
        y[c[i]].push_back(i);
    }
    for(int i = 0; i < h; i++) dx[i] = INF;
    for(int i = 0; i < w; i++) dy[i] = INF;
    queue<int> que;
    for(int i = 0; i < n; i++){
        if(used[i]) continue;
        ll xmin = 0, ymin = 0;
        used[i] = true;
        dx[r[i]] = 0;
        dy[c[i]] = 0;
        que.push(i);
        while(que.size()){
            int p = que.front();
            que.pop();
            for(int j : y[c[p]]){
                if(used[j]) continue;
                used[j] = true;
                if(dx[r[j]] != INF){
                    if(a[j] - a[p] != dx[r[j]] - dx[r[p]]){
                        cout << "No" << endl;
                        return 0;
                    }
                }
                else{
                    dx[r[j]] = dx[r[p]] + (a[j] - a[p]);
                    xmin = min(xmin, dx[r[j]]);
                }
                que.push(j);
            }
            for(int j : x[r[p]]){
                if(used[j]) continue;
                used[j] = true;
                if(dy[c[j]] != INF){
                    if(a[j] - a[p] != dy[c[j]] - dy[c[p]]){
                        cout << "No" << endl;
                        return 0;
                    }
                }
                else{
                    dy[c[j]] = dy[c[p]] + (a[j] - a[p]);
                    ymin = min(ymin, dy[c[j]]);
                }
                que.push(j);
            }
        }
        if(a[i] + xmin + ymin < 0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 14464
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int i = 1;
    int ans = 0;
    
    while(i*i <= n) {
      ans = i*i;
      i++;
    }
        
    System.out.println(ans);
  }
}


Measured memory_bytes: 35372
#include <bits/stdc++.h>
using namespace std;
 
main(){
  int N;
  int m=0;
  cin >> N;
  vector<int> vec(200);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0; i<N; i++){
    if(vec.at(i) == vec.at(i+1)){
      m--;
    }
    else{
      continue;
    }
  }
  cout << N+m << endl;      
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;

int main() {

    int n;
    cin >> n;

    vector<int> W(n);
    for (int i = 0; i < n; i++) {
        cin >> W[i];
    }

    int a = 0, b = 0;
    int m = 1000000;

    for (int i = 0; i < n; i++) {
        a = 0;
        b = 0;
        for (int j = 0; j < n; j++) {
            if(j < i) a += W[j];
            else b += W[j];
            
        }
        if(abs(a - b) < m) {
            m = abs(a - b);
        }

    }

    cout << m << endl;

    return 0;
    

}

Measured memory_bytes: 256
import scala.annotation.tailrec
import scala.collection.{immutable, mutable}
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    val d = readInt()
    if (d == 0) return
    val n = readInt()
    val m = readInt()
    val shops = 0 +: Array.fill(n - 1) {
      readInt()
    }.sorted :+ d
    println(
      Array.fill(m) {
        readInt()
      }.map {
        case 0 ⇒ 0
        case dest ⇒
          val position = lowerBound(shops, dest)
          math.min(shops(position) - dest, dest - shops(position - 1))
      }.sum
    )
    loop()
  }
  @inline def lowerBound(array: Array[Int], value: Int): Int = {
    var left = 0
    var right = array.length
    while (left < right) {
      val mid = (left + right) / 2
      if (array(mid) < value) left = mid + 1
      else right = mid
    }
    right
  }
}


Measured memory_bytes: 65352
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll H, W, ans=0, tmp=0;
vector<ll> Ws, Hs, S;

signed main(){
    cin >> W >> H;
    for(int i=0;i<W;i++) {
        ll a;
        cin >> a;
        Ws.push_back(a);
        ans += a*(H+1);
    }
    for(int i=0;i<H;i++) {
        ll a;
        cin >> a;
        Hs.push_back(a);
        ans += a*(W+1);
    }
    //cout << ans << endl;
    sort(Ws.begin(), Ws.end());
    S = Ws;
    for(int i=1;i<W;i++) {
        S[W-1-i] += S[W-i];
    }
    for(int i=0;i<H;i++) {
        ll id = lower_bound(Ws.begin(), Ws.end(), Hs[i])-Ws.begin();
        //cout << Hs[i]*id << " " << S[i] << endl;
        ans -= Hs[i]*id;
        if(id<W) ans -= S[id];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5684
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    string s;
    cin>>n;
    set<string>st;
    while(n--)
    {
        cin>>s;
        st.insert(s);
    }
    cout<<st.size();
}




Measured memory_bytes: 19204
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int N, T, L, B;
	
	while(true){
		cin >> N >> T >> L >> B;
		if(N == 0 && T == 0){
			break;
		}
		double P[150][150] = {};
		bool l[150] = {};
		bool b[150] = {};
		P[0][0] = 1;
		
		for(int i = 0; i < L; i++){
			int num;
			cin >> num;
			l[num] = true;
		}
		for(int i = 0; i < B; i++){
			int num;
			cin >> num;
			b[num] = true;
		}
		
		for(int i = 0; i <= T; i++){
			for(int j = 0; j < N; j++){
				if(b[j]){
					for(int k = 1; k <= 6; k++){
						P[i + 1][min(k, N - (k - N))] += P[i][j] / 6;
					}
				}else if(l[j]){
					for(int k = 1; k <= 6; k++){
						P[i + 2][min(j + k, N - (j + k - N))] += P[i][j] / 6;
					}
				}else{
					for(int k = 1; k <= 6; k++){
						P[i + 1][min(j + k, N - (j + k - N))] += P[i][j] / 6;
					}
				}
			}
			P[i + 1][N] += P[i][N];
		}
		
		printf("%.10f\n", P[T][N]);
		
	}
	
	return 0;
}

Measured memory_bytes: 3252
"""
dp[i][j] : i番目において、(表-裏)+N=j
dp[i+1][j+1] : dp[i][j] * (表)
dp[i+1][j-1] : dp[i][j] * (裏)
"""
N = int(input())
ps = list(map(float, input().split()))

dp = [[0]*(2*N+1) for i in range(N+1)]
dp[0][N] = 1
for i,p in enumerate(ps):
    for j in range(2*N):
        dp[i+1][j-1] += dp[i][j] * (1-p)
        dp[i+1][j+1] += dp[i][j] * p
    # print(dp[i+1])
print(sum(dp[N][N:]))

Measured memory_bytes: 487432
#include <stdio.h>

//メイン関数
int main(void){
  int H, W;

  while(1){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0) break;
    for(int i=1; i<=H; i++){
      for(int j=1; j<=W; j++){
        if((i+j)%2 == 0){
          printf("#");
        }
        else if((i+j)%2 == 1){
          printf(".");
        }
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; 
//const long double PI = acos(-1.0);
//#define int long long
signed main(){
	int n;
	cin >> n;
	if (100 <= n && n <= 111) {
		cout << 111 << endl;
	}
	else if (112 <= n && n <= 222) {
		cout << 222 << endl;
	}
	else if (223 <= n && n <= 333) {
		cout << 333 << endl;
	}
	else if (334 <= n && n <= 444) {
		cout << 444 << endl;
	}
	else if (445 <= n && n <= 555) {
		cout << 555 << endl;
	}
	else if (556 <= n && n <= 666) {
		cout << 666 << endl;
	}
	else if (667 <= n && n <= 777) {
		cout << 777 << endl;
	}
	else if (778 <= n && n <= 888) {
		cout << 888 << endl;
	}
	else if (889 <= n && n <= 999) {
		cout << 999 << endl;
	}
	return 0;
}

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

const Int MAX = 333;
using BS = bitset<MAX*2>;
using mat = vector<BS>;
void gauss(mat &v){
  int n=v.size();
  for(Int i=0;i<n;i++){
    for(Int k=i;k<n;k++){
      if(v[k][i]){
	swap(v[i],v[k]);
	break;
      }
    }
    for(Int k=0;k<n;k++)
      if(i!=k&&v[k][i]) v[k]^=v[i];
  }
}

int mrank(mat v,int m){
  int n=v.size();
  int r=0,c=0;
  for(int i=0;i<n;i++){
    int s=-1;
    while(c<m){
      for(int j=i;j<n;j++){
	if(v[j][c]){
	  s=j;
	  break;
	}
      }
      if(~s) break;
      c++;
    }
    if(c>=m) break;
    
    swap(v[i],v[s]);
    for(int j=0;j<n;j++)
      if(i!=j&&v[j][c]) v[j]^=v[i];
    
    r++;c++;
  }
  return r;
}

mat mul(const mat &a,const mat &b){
  int n=a.size();
  vector<vector<int> > tmp(n,vector<int>(n,0));
  mat res(n,BS(0));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)
	tmp[i][j]+=(a[i][k]&b[k][j]);
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      res[i][j]=tmp[i][j]&1;
  
  return res;
}

mat mat_pow(mat v,int k){
  int n=v.size();
  mat res(n,BS(0));
  for(int i=0;i<n;i++)
    res[i][i]=1;
  while(k){
    if(k&1) res=mul(res,v);
    v=mul(v,v);
    k>>=1;
  }
  return res;
}

signed main(){
  int n;
  cin>>n;
  mat v(n,BS(0));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      int k;
      cin>>k;
      v[i][j]=k;
    }
  }
  BS w;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    w[i]=k;
  }
  int t;
  cin>>t;
  v=mat_pow(v,t);

  int a=mrank(v,n);
  for(int i=0;i<n;i++) v[i][n]=w[i];
  int b=mrank(v,n+1);

  //cout<<n<<":"<<a<<" "<<b<<endl;

  if(a!=b){
    cout<<"none"<<endl;
    return 0;
  }

  if(a!=n){
    cout<<"ambiguous"<<endl;
    return 0;
  }

  auto pv=v;
  
  gauss(v);
  for(int i=0;i<n;i++) cout<<v[i][n]<<" \n"[i==n-1];
  
  return 0;
}



Measured memory_bytes: 3492
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

//   String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
    String[] s=sc.nextLine().split("");
//     String[] e=sc.nextLine().split(" ");

//int n=Integer.parseInt(nyuA);

//int N=Integer.parseInt(s[0]);
//int K=Integer.parseInt(s[1]);


System.out.println(s[0]+(s.length-2)+s[s.length-1]);

//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);


	}
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007;
const ld PI = 4.0 * atanl(1.0), PREC = .000001;
const char nl = '\n';

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.end(), x.begin()
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)(x).size()
#define ins insert

int n, m, t, a[MXN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

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

int main() {
  fast();
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == '1') {
    for (int i = 1; i < s.length(); ++i) {
      if (i % 2 == 0 && s[i] == '0') ++ans;
      if (i % 2 != 0 && s[i] == '1') ++ans;
    }
  } else {
    for (int i = 1; i < s.length(); ++i) {
      if (i % 2 == 0 && s[i] == '1') ++ans;
      if (i % 2 != 0 && s[i] == '0') ++ans;
    }
  }
  cout << ans;

  return 0;
}



Measured memory_bytes: 3732
#include<iostream>
#include<set>
#include<string>
#include<cstdlib>
using namespace std;
int main() {
	int a, b;
	set<int> c;
	int d[101];
	string f;
	while (cin>>f&&f!="0,0") {
		f += ",";
		string h = "";
		int u = 0;
		for (int i = 0; i < f.length(); i++) {
			if (f[i] == ',') {
				if (u == 0) a = atoi(h.c_str());
				else b = atoi(h.c_str());
				u++;
				h = "";
			}
			else
				h += f[i];
		}
		c.insert(b);
		d[a] = b;
	}
	int k = c.size();
	while (cin >> a){
		b = d[a];
		set<int>::iterator it = c.end();
		it--;
		int sum = 0;
		for (int j = 0; j < k; j++) {
			sum++;
			if ((*it) == b) {
				cout << sum << endl;
				break;
			}
			it--;
		}
	}
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int cnt_div2(int a) {
  int cnt = 0;
  while (a%2 == 0) {
    a /= 2;
    cnt++;
  }
  return cnt;
}

int main () {
  int N; cin >> N;
  vi a(N); REP(i,N) cin >> a[i];

  int cnt_2 = 0;
  int cnt_4 = 0;
  REP(i,N) {
    if (cnt_div2(a[i]) == 1) {
      cnt_2++;
    }
    else if (cnt_div2(a[i]) >= 2) {
      cnt_4++;
    }
  }

  cout << (cnt_4 >= (N-max(0,cnt_2-1))/2 ? "Yes" : "No") << endl;
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int mod = A % B, mod2 = -1, n = 2;
  while (C != mod2) {
    mod2 = (A * n) % B;
    if (mod == mod2) {
      cout << "NO";
      return 0;
    }
    n++;
  }
  cout << "YES";
  return 0;
}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; ++i){
        cin >> d[i];
    }
    
    ll res = 0;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            res += d[i] * d[j];
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
#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[i];
    }
    cout << *min_element(a.begin(), a.end()) << " " << *max_element(a.begin(), a.end()) << " " << accumulate(a.begin(), a.end(), 0LL) << '\n';
    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 2e5 + 5;
int bit[N];

void update(int pos, int val)
{
    while(pos < N)
    {
        bit[pos] = max(bit[pos], val);
        pos += pos & (-pos);
    }
}

int query(int pos)
{
    int res = 0;
    while(pos > 0)
    {
        res = max(res, bit[pos]);
        pos -= pos & (-pos);
    }
    return res;
}

int32_t main()
{
    int n;
    cin >> n;
    int h[n], v[n];

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

    for(int i = 0; i < n; i++)
        cin >> v[i];
    
    int res = 0;

    for(int i = 0; i < n; i++)
    {
        int curr = query(h[i]) + v[i];
        res = max(res, curr);
        update(h[i], curr);
    }
    
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Linq;

namespace ABC155B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(a.Where(e => e % 2 == 0).Any(e => e % 3 != 0 && e % 5 != 0) ? "DENIED" : "APPROVED");

        }
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;




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

	vector<ll> sum(n,0);
	rep(i, 0, n) {
		cin >> sum[i];
	}
	rep(i, 1, n) {
		sum[i] += sum[i - 1];
	}

	ll ans=inf;
	rep(i, 0, n-1) {
		ll sn, ar;
		sn = sum[i];
		ar = sum[n - 1] - sum[i];
		ans = min(ans, abs(sn - ar));
	}

	cout << ans << endl;


	
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long LL;

const int MOD = 1e9+7;

void solve(){
    LL h;
    cin>>h;
    LL ans = 1;
    while(h){
        ans = ans<<1;
        h=h/2;
    }
    ans--;
    cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}



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

#define rep(i, a) for (int i = 0; i < (int)a; ++i)
#define REP(i, a, b) for (int i = (a); i < (int)b; ++i)

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

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

void Main() {
  int n;
	cin >> n;
  int a;
  vector<P> ord;
	for (int i = 0; i < n; i++) {
		cin >> a;
    ord.emplace_back(a, i);
	}

  vector<ll> dp(n+1, 0);
	sort(ord.begin(), ord.end());
  rep(i, n) {
    rep(l, n - i + 1) {
			int r = l + i;
			const auto &[a, pos] = ord[i];
			dp[l] = max(dp[l] + a * abs(pos - r), dp[l + 1] + a * abs(pos - l));
		}
	}

  cout << dp[0] << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3720
import sys
input = sys.stdin.readline


class Vector():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, vec):
        return Vector(self.x+vec.x, self.y+vec.y)

    def __sub__(self, vec):
        return Vector(self.x-vec.x, self.y-vec.y)

    def __mul__(self, sc):
        return Vector(self.x*sc, self.y*sc)

    def __truediv__(self, sc):
        return Vector(self.x/sc, self.y/sc)

    def __iadd__(self, vec):
        self.x += vec.x
        self.y += vec.y
        return self

    def __isub__(self, vec):
        self.x -= vec.x
        self.y -= vec.y
        return self

    def __imul__(self, sc):
        self.x *= sc
        self.y *= sc
        return self

    def __itruediv__(self, sc):
        self.x /= sc
        self.y /= sc
        return self

    def __str__(self):
        return f'{self.x} {self.y}'

    def __eq__(self, vec):
        return self.x == vec.x and self.y == vec.y

    def dot(self, vec):
        return self.x * vec.x + self.y * vec.y

    def abs(self):
        return (self.x*self.x + self.y*self.y)**0.5


x1, y1, x2, y2 = map(int, input().split())
v1 = Vector(x1, y1)
v2 = Vector(x2, y2)
n = v2-v1
n /= n.abs()

for _ in [0]*int(input()):
    x, y = map(int, input().split())
    v = Vector(x, y) - v1
    print(v1 + n * (n.dot(v)))



Measured memory_bytes: 5792
# coding: utf-8
# Your code here!

a = []
b = []
for i in range(0,10):
    n = int(input())
    a.append(n)
    a.sort()
    W = a[7:10]
for i in range(10,20):
    n = int(input())
    b.append(n)
    b.sort()
    K = b[7:10]
print(sum(W),sum(K))



Measured memory_bytes: 5600
while 1:
    n = input()
    if n == 0:
        break
    player1 = 0
    player2 = 0
    for i in range(n):
        line = map(int, raw_input().split())
        if line[0] > line[1]:
            player1 += sum(line)
        elif line[0] == line[1]:
            player1 += line[0]
            player2 += line[1]
        else:
            player2 += sum(line)
    print "%d %d" % (player1, player2)

Measured memory_bytes: 4476
#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;

vector<int> g[2000];

int dfs(int x, int p, int d) {
	if (d == 0) return 0;

	int res = 1;
	FOR(i, 0, SZ(g[x])){
		int to = g[x][i];
		if (to == p) continue;

		res += dfs(to, x, d - 1);
	}

	return res;
}

int main()
{
//	freopen("in.txt","r",stdin);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR(i, 0, n - 1) {
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;

		g[x].push_back(y);
		g[y].push_back(x);
	}

	int mm = 0;
	FOR(i, 0, n) {
		if (m % 2 == 0) {
			int c = 0;
			FOR(k, 0, SZ(g[i])) {
				c += dfs(g[i][k], i, m / 2);
			}

		//	cout << "*" << i << ' ' << c << endl;

			mm = max(mm, c + 1);
		}
		else {
			vector<pair<int, int> > a;
			FOR(k, 0, SZ(g[i])) {
				a.push_back(MP(dfs(g[i][k], i, m / 2), dfs(g[i][k], i, m / 2 + 1)));
			}

			int s = 0;
			FOR(k, 0, SZ(a)) {
				s += a[k].first;
			}

			FOR(k, 0, SZ(a)) {
				int c = s - a[k].first + a[k].second;

				mm = max(mm, c + 1);
			}
		}
	}

	cout << n - mm << endl;

}


Measured memory_bytes: 384
import java.util.*;
import java.util.regex.Pattern;

public class Main {

  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    int result = 0;
   
    
    for(int i = 1; i <= n; i++){
      
      int sum = 0;
      int num = i;
      while(num > 0){
        // 10 でわった余りを足す
        sum += num % 10;
        // 再帰的に足すため 10 で割った値を再代入
        num /= 10;
      }
      
      if(sum >= a && sum <= b){
        result += i;
      }
      
    }
    
    System.out.println(result);

  }

}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();

  map<int,int> m;
  REP(i, N) m[nextInt()]++;

  int ans = 0;
  for (auto it = m.begin(); it != m.end(); ++it) {
    int n = it->first;
    int cnt = it->second;
    if (n < cnt) ans += cnt - n;
    else if (n > cnt) ans += cnt;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

ll dp[110][10];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    dp[0][0] = 1;
    for (int i = 0; i < h; i++){
        for (int bit = 0; bit < (1<<(w - 1)); bit++){
            bool ng = false;
            for (int k = 0; k < w - 1; k++){
                if (bit >> (k - 1) & 1 && bit >> k & 1) ng = true;
            }
            if (ng) continue;

            for (int j = 0; j < w; j++){
                if (1 <= j && (bit >> (j - 1)) & 1) (dp[i + 1][j - 1] += dp[i][j]) %= MOD;
                else if (j < w - 1 && (bit >> (j)) & 1) (dp[i + 1][j + 1] += dp[i][j]) %= MOD;
                else (dp[i + 1][j] += dp[i][j]) %= MOD;
            }
        }
    }

    cout << dp[h][k - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<double,double> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main(){
  ll x,y,a,b,u=0LL,d=0LL;
  cin>>x>>y;
  a=max(x,y),b=min(x,y);
  while(true){
    if(a<0||b<0){
      cout<<0;return 0;
    }
    if(a==b*2){
      u+=b;break;
    }
    if(a==b){
      if(a%3==0){
        u+=a/3;d+=a/3;break;
      }
      else{
        cout<<0;return 0;
      }
    }
    if(a>b*2){
      a-=2;b--;
      u++;
    }else if(a<b*2){
      a--;b-=2;
      d++;
    }
  }
  x=1LL,y=1LL,a=1LL;
  reps(i,1,1+u){x*=i;x%=M;}
  reps(i,1,1+d){y*=i;y%=M;}
  reps(i,1,d+1+u){a*=i;a%=M;}
  cout<<a*modinv((x*y%M),M)%M;
}

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;
template <typename Head, typename... Tail> tuple<Head, Tail...> read() {
    Head head; cin >> head;
    if constexpr (sizeof...(Tail) == 0) return tuple<Head>(head);
    else return tuple_cat(tuple<Head>(head), read<Tail...>());
}

// Fenwick Tree
struct FenwickTree {
    int length;
    vector<ll> node;
    FenwickTree (int N) : length(N), node(length + 1, 0) {}
    void add(int idx, ll val) {
        ++idx;
        while (idx <= length) {
            node[idx] += val;
            idx += (idx & (-idx));
        }
    }
    ll getsum(int idx) {
        ll ans = 0;
        while (idx) {
            ans += node[idx];
            idx -= (idx & (-idx));
        }
        return ans;
    }
};

// Main
int main() {
    int n, q;
    cin >> n >> q;
    FenwickTree fw(n);
    rep(i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    rep(i, q) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0) fw.add(x, y);
        else cout << fw.getsum(y) - fw.getsum(x) << "\n";
    }
    return 0;
}


Measured memory_bytes: 8256