akhauriyash/Code-Regression huggingface dataset:
n, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        dist = 0
        for d in range(D):
            dist += (x[i][d] - x[j][d])**2
        tmp = int(dist**0.5)
        if dist**0.5 - tmp == 0:
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, m, ans = 0;
	cin>> n>>m;
	int lmax = 0, rmin =n;
	for(int i=0;i<m;i++){
		int l, r;
		cin>>l>>r;
		if(lmax < l) lmax = l;
		if(r < rmin) rmin = r;
	}
	if(rmin<lmax){
		ans = 0;
	}else{
		ans = rmin - lmax + 1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3640
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int mod = 1000000007;
	static long inf = (long) 1e14;
	static int n, q;
	static ArrayList<Integer>[] ad;
	static long[][] memo;
	static boolean f;
	static boolean vis[];
	static int[] size, pa;
	static double[] x, y;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		System.out.println(sc.nextInt()^1);
		out.close();
	}

	static int[] si;
	static ArrayList<Integer> primes;

	static void seive(int N) {
		si = new int[N];
		primes = new ArrayList<>();
		si[1] = 1;
		for (int i = 2; i < N; i++) {
			if (si[i] == 0) {
				si[i] = i;
				primes.add(i);
			}
			for (int j = 0; j < primes.size() && primes.get(j) <= si[i] && (i * primes.get(j)) < N; j++)
				si[primes.get(j) * i] = primes.get(j);
		}
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 25344
#include<bits/stdc++.h>
using namespace std;
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N;
int a[100001];
vector<int>v[100001];

int dfs(int x){
    if(v[x].size()==0)return 0;
    vector<int>vv;
    int ans=0;
    REP(i,v[x].size()){
        int b=dfs(v[x][i]);
        vv.push_back(b);
    }
    sort(vv.begin(),vv.end(),greater<int>());
    REP(i,vv.size()){
        ans=max(ans,i+1+vv[i]);
    }
    //cout<<x<<" "<<ans<<endl;
    return ans;
}

int main(){
	cin>>N;
	REP(i,N-1){
	   cin>>a[i];
	   a[i]--;
	   v[a[i]].push_back(i+1);
	}
        cout<<dfs(0)<<endl;
	return(0);
}

Measured memory_bytes: 13952
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int m=in.nextInt();
			if(m==0)
				return;
			int tx[]=new int[m];//target star
			int ty[]=new int[m];
			for(int i=0;i<m;i++)
			{
				tx[i]=in.nextInt();
				ty[i]=in.nextInt();
			}
			int n=in.nextInt();
			int sorax[]=new int[n];//sky^^
			int soray[]=new int[n];
			boolean judge[]=new boolean[m];
			boolean cmp=false;
			judge[0]=true;
			for(int i=0;i<n;i++)
			{
				sorax[i]=in.nextInt();
				soray[i]=in.nextInt();
			}

			for(int i=0;i<n;i++)
			{
				int toX=sorax[i]-tx[0];
				int toY=soray[i]-ty[0];
				Arrays.fill(judge, false);
				cmp=true;
				judge[0]=true;
				for(int j=1;j<m;j++)
				{
					int nx=tx[j]+toX;
					int ny=ty[j]+toY;
					for(int k=0;k<n;k++)
					{
						if(nx==sorax[k]&&ny==soray[k])
						{
							judge[j]=true;
							break;
						}
					}	
				}
				for(int j=0;j<m;j++)
				{
					if(!judge[j])
					{
						cmp=false;
						break;
					}
				}
				if(cmp)
				{
					System.out.println(toX+" "+toY);
					break;
				}
			}
		}
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 29964
/*
 * Author:  heyuhhh
 * Created Time:  2019/11/16 20:26:13
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e6 + 15, MOD = 1e9 + 7;

int fac[N];

ll qpow(ll a, ll b) {
    ll ans = 1;
    while(b) {
        if(b & 1) ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;   
    }
    return ans;   
}

int C(int n, int m) {
    return 1ll * fac[n] * qpow(fac[n - m], MOD - 2) % MOD * qpow(fac[m], MOD - 2) % MOD;
}

void run(){
    fac[0] = 1;
    for(int i = 1; i < N; i++) fac[i] = 1ll * fac[i - 1] * i % MOD;
    int x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0) {
        cout << 0;
        return;
    }
    int t = (x + y) / 3;
    if(y - t >= 0 && y - t <= t) {
        cout << C(t, y - t);
    } else cout << 0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
	return 0;
}

Measured memory_bytes: 4224
from heapq import heapify, heappop, heappush
from collections import defaultdict
inpl = lambda: list(map(int,input().split()))
H, W = inpl()
s = []
for h in range(H):
    s.append(input())

def dijkstra(start, goal):
    q = [(0, start)]
    done = set()
    minimum = defaultdict(lambda: None)

    while q:
        D, x = heappop(q)
        if x in done:
            continue
        elif x == goal:
            return D
        done.add(x)
        for y in {(x[0]+1,x[1]), (x[0],x[1]+1)}:
            if y[0] >= H or y[1] >= W:
                continue
            if not y in done:
                m = minimum[y]
                p = D + int(s[x[0]][x[1]] != s[y[0]][y[1]])
                if m is None or m > p:
                    heappush(q, (p, y))
                    minimum[y] = p

N = dijkstra((0,0), (H-1,W-1)) + 1
if s[0][0] == '.':
    print(N//2)
else:
    print((N+1)//2)

Measured memory_bytes: 60892
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto a = RDA;

	long ans;
	foreach (i; 0..N)
	{
		if (i % 2 == 0 && a[i] % 2)
			++ans;
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2756
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

using namespace std;

int main() {
    int n;
    vector<int> s(3);

    while ( cin >> s[0] >> s[1] >> s[2] >> n, s[0] || s[1] || s[2] ) {
        sort(s.begin(), s.end());

        // REP(i, 3) cout << s[i] << " ";
        // cout << endl;

        double size = sqrt(s[0] * s[0] + s[1] * s[1]);

        // cout << size << " " << (s[0] * s[0]) << " " << (s[1] * s[1]) << endl;

        REP(i, n) {
            double r;
            cin >> r;
            // cout << "r:" << r*2 << " size:" << size << " r<size:" << (r*2<size) << endl;
            if ( r * 2 <= size )
                cout << "NA";
            else
                cout << "OK";
            cout << endl;

        }

    }

    return 0;
}

Measured memory_bytes: 1240
#include <iostream>

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

constexpr auto NMAX = (int)2e5 + 20;
constexpr auto INF = 2000000000;
using namespace std;

typedef unsigned long long ull;

int sub[NMAX];
int n;

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		int aux;
		cin >> aux;
		sub[aux]++;
	}

	for (int i = 1; i <= n; i++)
	{
		cout << sub[i] << '\n';
	}
	return 0;
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();


int n;
double X[100],Y[100];

double distance(double p){
    double sum = 0;
    REP(i,n){
        double w = abs(X[i]-Y[i]);
        sum += pow(w,p);
    }
    return pow(sum,1.0/p);
}
int main()
{
    cout << fixed << setprecision(12);
    scanf("%d",&n);
    
    REP(i,n)scanf("%lf",&X[i]);
    REP(i,n)scanf("%lf",&Y[i]);
    
    cout << distance(1) << endl;
    cout << distance(2) << endl;
    cout << distance(3) << endl;
    double mx = 0;
    REP(i,n) mx= max(mx,abs(X[i]-Y[i]));
    cout << mx << endl;

    // REP(i,n){
    //     Manhattan += abs(X[i]-Y[i]);
    //     Euclidean += (X[i]-Y[i])*(X[i]-Y[i]);
    //     distance3 += abs(X[i]-Y[i])*(X[i]-Y[i])*(X[i]-Y[i]);
    //     Chebyshev = max(Chebyshev,abs(X[i]-Y[i]));
    // }
    // Euclidean = sqrt(Euclidean);
    // distance3 = pow(distance3,1.0/3.0);
    // cout << Manhattan <<endl;
    // cout << Euclidean <<endl;
    // cout << distance3 <<endl;
    // cout << Chebyshev <<endl;

    // // printf("%.8lf\n",Manhattan);
    // // printf("%.8lf\n",Euclidean);
    // // printf("%.8f\n",distance3);
    // // printf("%.8lf\n",Chebyshev);
}


Measured memory_bytes: 3504
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int p[100005];
ll x[100005];
multiset<int> st;
ll ans;

int main(void) {
  int N;
  cin >> N;

  rep(i, 0, N) cin >> p[i];
  rep(i, 0, N) x[p[i]] = (ll)i;
  rep(i, 0, 2) st.insert(-1), st.insert(N);

  for (int i=N; i>=1; i--) {
      multiset<int>::iterator itr1, itr2;
      ll LL, LR, RL, RR;

      ll t = x[i];
      itr1 = itr2 = st.lower_bound(t);
      RL = *itr1, RR = *(++itr1);
      LR = *(--itr2), LL = *(--itr2);
      ans += (RR-RL)*(t-LR)*i;
      ans += (LR-LL)*(RL-t)*i;
      st.insert(t);
  }
  
  
  
  cout << ans << endl;
    return 0;
}





Measured memory_bytes: 9468
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX + 1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short) * n + 1);
  B = malloc(sizeof(short) * n + 1);

  for ( i = 0; i <= VMAX; i++ ) C[i] = 0;

  for ( i = 0; i < n; i++ ) {
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for ( i = 1; i <= VMAX; i++) C[i] = C[i] + C[i - 1];

  for ( j = 1; j <= n; j++ ) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for ( i = 1; i <= n; i++ ) {
    if ( i > 1) printf(" ");
    printf("%d", B[i]);
  }
  printf("\n");

  return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N;
    cin >> N;
    string S;
    cin >> S;

    Vl nr, ng, nb;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R')
            nr.emplace_back(i);
        else if (S[i] == 'G')
            ng.emplace_back(i);
        else
            nb.emplace_back(i);
    }

    ll num_r = (ll)nr.size();
    ll num_g = (ll)ng.size();
    ll num_b = (ll)nb.size();

    ll ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            int p = 2 * j - i;
            // 青
            if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
                ll t = upper_bound(nb.begin(), nb.end(), j) - nb.begin();
                ans += num_b - t;
                if (p < N && j < p) {
                    if (S[p] == 'B') --ans;
                }
            }

            // 赤
            if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
                ll t = upper_bound(nr.begin(), nr.end(), j) - nr.begin();
                ans += num_r - t;
                if (p < N && j < p) {
                    if (S[p] == 'R') --ans;
                }
            }

            // 緑
            if ((S[i] == 'B' && S[j] == 'R') || (S[i] == 'R' && S[j] == 'B')) {
                ll t = upper_bound(ng.begin(), ng.end(), j) - ng.begin();
                ans += num_g - t;
                if (p < N && j < p) {
                    if (S[p] == 'G') --ans;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3684
n = int(input())
w = list(map(int, input().split()))
ans = 10 ** 5
w_sum = sum(w)
for i in range(n):
    s1 = sum(w[:i+1])
    s2 = w_sum - s1
    min_i = abs(s1-s2)
    if ans > min_i:
        ans = min_i
    else:
        print(ans)
        exit()
print(ans)


Measured memory_bytes: 3060
import Data.List

main = do
    [n, k] <- map read . words <$> getLine
    hs <- map read <$> (sequence $ replicate n getLine)
    let hs' = sort hs
    let mms = zip hs' (drop (k - 1) hs')
    let diffs = map (\(x, y) -> y - x) mms
    print $ minimum diffs

Measured memory_bytes: 64252
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
const int INF = (int)1e9 + 7;
const int M = (int)1e9 + 7;
 


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

 
 int n;
 cin>>n;
 string s; cin>>s;

 for(int i=0;i<s.length();i++)
 {
   s[i]=(s[i]+n);
   int k=s[i]-'A';
   s[i]=k%26 +'A';
 }
 cout<<s;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
ll A[MAX_N];

int main(){
  cin >> N;
  REP(i, N) cin >> A[i];
  sort(A, A + N);

  ll crt = 0;
  int ans = N;
  REP(i, N){
    crt += A[i];
    if(i != N - 1) {
      if(A[i + 1] > 2 * crt) ans = N - i - 1;
    }
  }

  cout << ans << endl;


  return 0;
}



Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };

int main() {
	int L, R;
	scanf("%d%d", &L, &R);

	if (L / 2019 < R / 2019)
		printf("0");
	else {
		int Lm = L % 2019;
		int Rm = R % 2019;

		int ans = 2019;

		for (int i = Lm; i <= Rm; i++)
			for (int j = 1; i + j <= Rm; j++) {
				//printf("%d,%d\n",i,i+j);
				if ((i*(i + j)) % 2019 < ans)
					ans = (i*(i + j)) % 2019;

			}
		printf("%d", ans);
	}
}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
def dfs(l,x,y):
    
    if x+1 is w and y+1 is h:
        return l
    
    #right
    if w > x+1:
        if "#" is l[y][x+1]:

            l2 = list(l)
            l2[y][x+1] = "."

            return dfs(l2,x+1,y)

    #down
    if h > y+1:
        if "#" is l[y+1][x]:
            l3 = list(l)
            l3[y+1][x]= "."
            return  dfs(l3,x,y+1)



h,w = map(int,raw_input().split())


l = []
for i in range(h):
    l.append(list(raw_input()))

# print l
l[0][0] = "."
l2 = dfs(l,0,0)
# print l2
if l2:
    if "#" in [x for sublist in l2 for x in sublist]:
        print "Impossible"
    else:
        print "Possible"
else:
    print "Impossible"

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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  for(int i= 0;i<N;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  a.push_back(1000000000+1);
  
  vector<pair<ll,ll>> p;
  int c = 0;
  for(int i= 0;i<N;i++){
    c++;
    if(a[i] != a[i+1]){
      p.push_back(make_pair(a[i],c));
      c = 0;
       }
     }

  ll ans = 0;
  for(int i= 0;i<p.size();i++){
    if(p[i].second > p[i].first) ans += p[i].second - p[i].first;
    else if(p[i].second < p[i].first) ans += p[i].second;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4108
#include <stdio.h>    
#include <string.h>    
#include <set>  
#include <map>  
#include <algorithm>  
#include <iostream>  
#include <vector>  
#include <string>  
#include <queue>
#include <cmath>  
template <class T>
inline bool rd(T &ret) {
	char c; int sgn;
	if (c = getchar(), c == EOF) return 0;
	while (c != '-' && (c<'0' || c>'9')) c = getchar();
	sgn = (c == '-') ? -1 : 1;
	ret = (c == '-') ? 0 : (c - '0');
	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');
	ret *= sgn;
	return 1;
}
template <class T>
inline void pt(T x) {
	if (x <0) {
		putchar('-');
		x = -x;
	}
	if (x>9) pt(x / 10);
	putchar(x % 10 + '0');
}
using namespace std;
const int inf = 1e8;
const int N = 105;
const int M = 100010;
struct Edge{
	int from, to, dis, nex;
}edge[1005];
int head[N], edgenum;
void add(int u, int v, int dis){
	Edge E = { u, v, dis, head[u] };
	edge[edgenum] = E;
	head[u] = edgenum++;
}
void init(){ memset(head, -1, sizeof head); edgenum = 0; }
int n, m, c;
int dp[N][M], vis[N];
void bfs(){
	queue<int>q;
	q.push(n);
	dp[n][0] = 0;
	while (!q.empty()){
		int u = q.front(); q.pop(); vis[u] = 0;
		for (int i = head[u]; ~i; i = edge[i].nex){
			int v = edge[i].to;
			bool ok = false;
			for (int j = 0; j <= c; j++)
			{
				if (dp[u][j] == inf)continue;
				if (dp[v][j] > dp[u][j] + 1)
				{
					dp[v][j] = dp[u][j] + 1; ok = true;
				}
				if (j + edge[i].dis <= c && dp[v][j + edge[i].dis] > dp[u][j])
				{
					dp[v][j + edge[i].dis] = dp[u][j]; ok = true;
				}
			}
			if (ok && vis[v] == 0)vis[v] = 1, q.push(v);
		}
	}
}
int main(){
	int u, v, d;
	while (cin>>n>>m>>c, n+m+c){
		init();
		memset(vis, 0, sizeof vis);
		for (int i = 1; i <= n; i++)for (int j = 0; j <= c; j++)dp[i][j] = inf;
		while (m--)
		{
			rd(u); rd(v); rd(d);
			add(v, u, d);
		}
		bfs();
		int ans = inf;
		for (int i = 0; i <= c; i++)ans = min(ans, dp[1][i]);
		pt(ans); puts("");
	}
	return 0;
}
/*
3 3 3
1 2 10
1 2 5
2 3 3

4 5 3
1 2 10
1 2 5
2 3 3
3 4 1
4 2 6

4 5 1
1 2 10
1 2 5
2 3 3
3 4 1
4 2 6


4 5 8
1 2 10
1 2 5
2 3 3
3 4 1
4 2 6

4 5 0
1 2 10
1 2 5
2 3 3
3 4 1
4 2 6


*/  

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, m;
  vector<vector<int>> g;
  vector<int> memo;
  Solver2(LL n, LL m) : n(n), m(m), g(n + 1), memo(n + 1, -1){};

  void solve() {
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      g[--a].push_back(--b);
    }
    for (int i = 0; i < n; ++i) {
      g[n].push_back(i);
    }
    cout << dfs(n) - 1 << endl;
  }
  int dfs(int v) {
    if (memo[v] >= 0) return memo[v];
    int ret = 0;
    for (auto w : g[v]) {
      ret = max(ret, dfs(w) + 1);
    }
    return memo[v] = ret;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 8056
import numpy as np

# 入力
N, W = map(int, input().split())
wv = np.array([[int(i) for i in input().split()] for j in range(N)])

# DPテーブル
dp = np.zeros((N+1)*(W+1), dtype=int).reshape((N+1), (W+1))

# DPループ
for i in range(N):    # i番目の荷物について検討する
    dp[i+1][:wv[i-1][0]] = dp[i][:wv[i-1][0]]
    dp[i+1][wv[i-1][0]:] = np.maximum(dp[i][wv[i-1][0]:], dp[i][:(W+1)-wv[i-1][0]] + wv[i-1][1])
        
# 二次元リストの一番右下が最適解
print(dp[N][W])

Measured memory_bytes: 92120
package main

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

func main() {
	N := nextInt()
	X := make(points, N)

	for i := 0; i < N; i++ {
		X[i] = nextInt()
	}
	sort.Sort(X)

	dmin := math.MaxInt32

	for i := 0; i <= 100; i++ {
		d := 0
		for j := 0; j < N; j++ {
			xp := (X[j] - i)
			d += xp * xp
		}
		if dmin > d {
			dmin = d
		}
	}

	fmt.Println(dmin)
}

type points []int

func (a points) Len() int           { return len(a) }
func (a points) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a points) Less(i, j int) bool { return a[i] < a[j] }

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N, M, X, Y;
  cin >> N >> M >> X >> Y;
  ll xmax{-MOD}, ymin{MOD};
  rep(i, 0, N){
    ll x;
    cin >> x;
    xmax = max(xmax, x);
  }
  rep(i, 0, M){
    ll y;
    cin >> y;
    ymin = min(ymin, y);
  }
  if(xmax>=ymin){
    cout << "War" << rt;
    return 0;
  }
  rep(Z, xmax+1, ymin+1){
    if(X < Z && Z <= Y){
      cout << "No War" << rt;
      return 0;
    }
  }
  cout << "War" << rt;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.D_Challenge
{
    class ABC_097
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int[] ps = ReadInts();
            var xy = new int[nm[1]][];
            for(int i = 0; i < nm[1]; i++)
            {
                xy[i] = ReadInts();
                Array.Sort(xy[i]);
            }
            Array.Sort(xy, (a, b) => a[1] - b[1]);
            Array.Sort(xy, (a, b) => a[0] - b[0]);
            var unionFind = new int[nm[0]];
            for(int i = 0; i < nm[0]; i++)
            {
                unionFind[i] = i;
            }
            for (int i = 0; i < nm[1]; i++)
            {
                //親取得
                int indexL = xy[i][0] - 1;
                while (unionFind[indexL] != indexL)
                {
                    indexL = unionFind[indexL];
                }
                int indexR = xy[i][1] - 1;
                while (unionFind[indexR] != indexR)
                {
                    indexR = unionFind[indexR];
                }
                if(indexL< indexR)
                {
                    unionFind[indexR] = indexL;
                }
                else
                {
                    unionFind[indexL] = indexR;
                }
            }

            for (int i = 0; i < nm[0]; i++)
            {
                int index = i;
                while (unionFind[index] != index)
                {
                    index = unionFind[index];
                }
                unionFind[i] = index;
            }

            var groupDict = new Dictionary<int, Dictionary<int,bool>>();
            for(int i = 0; i < nm[0]; i++)
            {
                if (!groupDict.ContainsKey(unionFind[i]))
                {
                    groupDict.Add(unionFind[i],
                        new Dictionary<int, bool>());
                }
                groupDict[unionFind[i]].Add(ps[i]-1, true);
            }
            int cnt = 0;
            for(int i = 0; i < nm[0]; i++)
            {
                if (groupDict[unionFind[i]].ContainsKey(i))
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 49344
s = input()
res = 10**9
# sをすべてalpにしたい
for alp in set(list(s)):
    t = s
    cnt = 0
    while t!=t[0]*len(t):
        new_t = ''
        for i in range(len(t)-1):
            if alp in (t[i], t[i+1]):
                new_t += alp
            else:
                new_t += '!'
        t = new_t
        cnt += 1
    res = min(res, cnt)
print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main(){
  COMinit();
  int N,M; cin>>N>>M;
  int ans=1;
  for(int i=2;i*i<=M;i++){
    int count=0;
    while(M%i==0){
      M/=i;
      count++;
    }
    ans*=COM(N+count-1,count);
    ans%=MOD;
  }
  if(M>1){
    ans*=N;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }


Measured memory_bytes: 12160
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	string s, t;
	cin >> s;

	for (int i = 0; i < (int) s.size() / 2; i++) {
		t += "hi";
	}

	if (s == t) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;
const ll mod = 1e9 + 7;



//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}






int main()
{
    MohamedMotaz;
    ll n, m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
    
}








Measured memory_bytes: 256
// AOJ 2335: 10-Year-Old Dynamic Programming
// 2017.11.27 bal4u@uu

#include <stdio.h>

#define M 1000000007

long long fact[2020001];

int extended_gcd(int a, int b, int *x, int *y)
{
	int d;

	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a % b, y, x);
	*y -= a / b * (*x);
	return d;
}

long long inverse(int a)
{
    int x, y;
    if (extended_gcd(a, M, &x, &y) == 1) return (x + M) % M;
    return 0;
}

long long comb(int n, int k)
{
    if (n < 0 || k < 0 || n < k) return 0;
    return fact[n] * inverse((fact[k]*fact[n-k]) % M) % M;
}

int main()
{
	int n, m, k, i, j, ii, jj, kk;
	long long ans, r, c;

	for (fact[0] = 1, i = 1; i < 2020001; i++) fact[i] = (fact[i-1]*i) % M;

	scanf("%d%d%d", &n, &m, &k);

    ans = 0; kk = n + m + (k << 1);
    for (i = 0; i <= k; i++){
        j = k-i, ii = n + (i << 1), jj = m + (j << 1);
        r = (comb(ii, i) - comb(ii, i-1) + M) % M;
        c = (comb(jj, j) - comb(jj, j-1) + M) % M;
        ans = (ans + (r*c) % M * comb(kk, ii)) % M;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 17628
#include<bits/stdc++.h>
using namespace std;
long long a[100010],dp[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",a+i);
	dp[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++)
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	printf("%d",dp[n]);
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum = sum ^ a[i];
  }

  for (int i = 0; i < n; i++) {
    cout << (sum ^ a[i]) << endl;
  }
}

Measured memory_bytes: 4052
#include<stdio.h>

void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/* pushdouwn操作 */
void pushdown (int array[], int first, int last) {
  int parent = first;   // 親
  int child = 2*parent;   // 左の子
  while (child <= last) {
    if ((child < last) && (array[child] < array[child+1])) {
       child++;   // 右の子の方が大きいとき、右の子を比較対象に設定
    }
    if (array[child] <= array[parent]) { break; }   // ヒープ済み
    swap(&array[child], &array[parent]);
    parent = child;
    child = 2* parent;
  }
}

/* ヒープソート */
void heap_sort (int array[], int array_size) {
  int i;

  for (i = array_size/2; i >= 1; i--) {
    pushdown(array, i, array_size);   // 全体をヒープ化
  }
  for (i = array_size; i >= 2; i--) {
    swap(&array[1], &array[i]);   // 最大のものを最後に
    pushdown(array, 1, i-1);   // ヒープ再構築
  }
}


int tri(int i, int k, int m){
  if((i<k+m) && (k<m+i) && (m<k+i)){
    return 1;
  }else{
    return 0;
  }
}

int main(void){
  int N,i,m,k;
  scanf("%d", &N);
  int num[N+1];
  for(i=1; i<=N; i++){
    scanf("%d", &num[i]);
  }
 
  heap_sort(num,N);
  
  int count=0;
  for(i=N; i>0;i--){
    for(m=i-1; m>0; m--){
      for(k=m-1; k>0; k--){
        
        if(tri(num[i], num[m], num[k])==1){
      count += 1;
        }else{
          break;
        }
        
      }
    }
  }
  
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll a[n];
  ll ans = mod, cnt;
  REP(i, n){
    cin >> a[i];
    cnt = 0;
    while(a[i] % 2 == 0){
      a[i] /= 2;
      cnt++;
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
    int N, M, K, buf, ans = 0;
    cin >> N >> M;
    unordered_map<int,int> mp;
    for(int i = 1; i <= N; ++i){
        cin >> K;
        for(int j = 1; j <= K; ++j){
            cin >> buf;
            ++mp[buf];
        }
    }
    for(int i = 1; i <= M; ++i){
        if(mp[i] == N) ++ans;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  N %= 10;
  if(N == 3){
    cout << "bon";
  }
  else if(N == 0 || N == 1 || N == 6 || N == 8){
    cout << "pon";
  }
  else{
    cout << "hon";
  }
}


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

int num[10];
//map<int,int> mp;

int main(void)
{
    int m,n,l,r,i;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        if(i==0)
        {
            num[0]=l;
            num[1]=r;
            continue;
        }
        num[0]=max(num[0],l);
        num[1]=min(num[1],r);
    }
    //cout<<num[0]<<"<->"<<num[1]<<endl;
    if(num[0]>num[1]) cout<<0;
    else cout<<num[1]-num[0]+1;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int N;
long long C;

int main() {
  cin >> N >> C;

  // clock wise
  vector<long long> x_r(N, 0);
  vector<long long> v_r(N, 0);
  vector<long long> f_r(N, 0);
  vector<long long> g_r(N, 0);
  // anti clock-wise
  vector<long long> x_l(N, 0);
  vector<long long> v_l(N, 0);
  vector<long long> f_l(N, 0);
  vector<long long> g_l(N, 0);

  for (int i = 0; i < N; ++i) {
    cin >> x_r[i] >> v_r[i];

    x_l[N - 1 - i] = C - x_r[i];
    v_l[N - 1 - i] = v_r[i];
  }

  auto calc_fg = [](const vector<long long>& x, const vector<long long>& v,
                    vector<long long>& f, vector<long long>& g) {
    long long sum = v[0];
    f[0] = v[0] - x[0];
    g[0] = f[0];
    for (int i = 1; i < N; ++i) {
      sum += v[i];
      f[i] = sum - x[i];
      g[i] = max(g[i - 1], f[i]);
    }
  };

  calc_fg(x_r, v_r, f_r, g_r);
  calc_fg(x_l, v_l, f_l, g_l);

  auto solve = [](const vector<long long>& x, const vector<long long>& f,
                  const vector<long long>& g) {
    long long ans = g[N - 1];
    for (int i = 0; i < N - 1; ++i) {
      const auto w2 = f[i] - x[i];
      const auto k = N - 1 - i;
      ans = max(ans, g[k - 1] + w2);
    }
    return ans;
  };

  // Bを動かす, Aを動かす
  const auto ans = max({0LL, solve(x_l, f_l, g_r), solve(x_r, f_r, g_l)});
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6528
n = gets.to_i

s = n.times.map {gets.chomp.chars}

memo = Array.new(n)
t = -501
n.times do |i|
    if memo[i]
        s.map!(&:rotate!)
        next
    end
    
    catch do |tag|
        n.times do |x|
            x.upto(n-1) do |y|
                s[x][y] != s[y][x] and throw(tag, false)
            end
        end
        true
    end and (
        i.step(n-1, i-t) {|k| memo[k] = 1};
        t = i
    )

    s.map!(&:rotate!)
end

p memo.count(1) * n

Measured memory_bytes: 6012
# -*- coding: utf-8 -*-
from collections import defaultdict

N = int(input())
S = input()
A, B = S[:N], S[N:]
D = defaultdict(int)
ans = 0

def paint(X, i):
    r = ""
    b = ""
    for j, k in enumerate(format(i, "b").zfill(N)):
        if k == "1":
            r += X[j]
        else:
            b += X[j]
    return r, b

for i in range(2**N):
    r, b = paint(A, i)
    D[(r, b)] += 1

for i in range(2**N):
    r, b = paint(B, i)
    ans += D[(b[::-1], r[::-1])]

print(ans)

Measured memory_bytes: 125904
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::max($x, max!( $($y),+)));
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::min($x, min!( $($y),+)));
}

// solution 
use std::cmp;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        H: usize,
        W: usize,
    }

    let h = H / 3;
    let s1 = h * W;
    let w = W / 2;
    let s2 = (H-h) * w;
    let s3 = (H-h) * (W-w);
    let min = cp(std::usize::MAX, s1, s2, s3);

    let h1 = (H-h)/2;
    let s2 = h1 * W;
    let s3 = (H-h-h1)*W;
    let min = cp(min, s1, s2, s3);

    let h = H / 3 + 1;
    let s1 = h * W;
    let w = W / 2;
    let s2 = (H-h) * w;
    let s3 = (H-h) * (W-w);
    let min = cp(min, s1, s2, s3);

    let h1 = (H-h)/2;
    let s2 = h1 * W;
    let s3 = (H-h-h1)*W;
    let min = cp(min, s1, s2, s3);

    let w = W / 3;
    let s1 = w * H;
    let h = H / 2;
    let s2 = (W-w) * h;
    let s3 = (W-w) * (H-h);
    let min = cp(min, s1, s2, s3);

    let w1 = (W-w) / 2;
    let s1 = w * H;
    let s2 = w1 * H;
    let s3 = (W-w-w1)*H;
    let min = cp(min, s1, s2, s3);
    
    let w = W / 3 + 1;
    let s1 = w * H;
    let h = H / 2;
    let s2 = (W-w) * h;
    let s3 = (W-w) * (H-h);
    let min = cp(min, s1, s2, s3);

    let w1 = (W-w) / 2;
    let s1 = w * H;
    let s2 = w1 * H;
    let s3 = (W-w-w1)*H;
    let min = cp(min, s1, s2, s3);

    println!("{}", min);

}

fn cp(min: usize, s1: usize, s2: usize, s3: usize) -> usize {
    cmp::min(min,
             max!(s1, s2, s3) - min!(s1, s2, s3))
}


Measured memory_bytes: 4352
n = int(input())
c = list(input())

pos_r = []
pos_w = []
for i in range(n):
    if c[i] == 'R':
        pos_r.append(i)
    else:
        pos_w.append(i)
pos_r.reverse()

ans = 0
m = min(len(pos_r), len(pos_w))
for i in range(m):
    if pos_w[i] < pos_r[i]:
        ans += 1
print(ans)


Measured memory_bytes: 18704
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		no1();
	}
 
	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			Integer a = sc.nextInt();
			Integer b = sc.nextInt();
			Integer c = sc.nextInt();
			Integer d = sc.nextInt();
 
			if (a + b > c + d) {
				System.out.println("Left");
				return;
			}
			if (a + b < c + d) {
				System.out.println("Right");
				return;
			}
			System.out.println("Balanced");
		}
	}
}

Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void){
	int n;
	cin>>n;
	int count=0;
	for(int i = 1;i<=n;++i){
		if(i%2!=0)count+=1; 
	}
	double ans = (double)count/(double)n;
	printf("%lf\n",ans);
	return 0;
}

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

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

	if (N % 10 == 3) {
		cout << "bon";
	}
	else if(N % 10 == 0 ||N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
		cout << "pon";
	}
	else{
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3592
from collections import Counter
R = lambda: map(int, input().split())
n, k = R()
a = list(R())
r = k * sum(a[i] < a[j] for i in range(n) for j in range(i))
r += k*(k-1)//2 * (n*(n-1)//2 - sum(x*(x-1)//2 for x in Counter(a).values()))
print(r % (10**9 + 7))


Measured memory_bytes: 3564