akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

vector<int> G[100000];
int par[100000];
int ord[100000], dst[100000], rev[200000], time;

void dfs(int v, int p)
{
	par[v] = p;
	ord[v] = time++;
	rev[time - 1] = v;
	
	for (int i = 0; i < G[v].size(); i++){
		if (G[v][i] != p){
			dfs(G[v][i], v);
		}
	}
	dst[v] = time++;
}

int seg[1 << 19], lazy[1 << 19];

void eval(int k)
{
	seg[k] = max(seg[k], lazy[k]);
	if (k < (1 << 18) - 1){
		lazy[k * 2 + 1] = max(lazy[k * 2 + 1], lazy[k]);
		lazy[k * 2 + 2] = max(lazy[k * 2 + 2], lazy[k]);
	}
	lazy[k] = 0;
}

void updateNode(int k)
{
	seg[k] = max(seg[k * 2 + 1], seg[k * 2 + 2]);
}

void changeMax(int a, int b, int x, int k = 0, int l = 0, int r = 1 << 18)
{
	eval(k);
	if (b <= l || r <= a) return;
	
	if (a <= l && r <= b){
		lazy[k] = max(lazy[k], x);
		eval(k);
		return;
	}
	
	changeMax(a, b, x, k * 2 + 1, l, l + r >> 1);
	changeMax(a, b, x, k * 2 + 2, l + r >> 1, r);
	updateNode(k);
}

int get(int a, int k = 0, int l = 0, int r = 1 << 18)
{	
	eval(k);
	if (a + 1 <= l || r <= a) return (-1);
	
	if (a <= l && r <= a + 1){
		return (seg[k]);
	}
	
	int lch = get(a, k * 2 + 1, l, l + r >> 1);
	int rch = get(a, k * 2 + 2, l + r >> 1, r);
	updateNode(k);
	return (max(lch, rch));
}

int main()
{
	int N, Q;
	
	while (scanf("%d %d", &N, &Q) && N){
		for (int i = 0; i < N; i++) G[i].clear();
		
		for (int i = 1; i < N; i++){
			int v;
			scanf("%d", &v);
			G[--v].push_back(i);
		}
		
		time = 0;
		dfs(0, -1);
		memset(seg, 0, sizeof(seg));
		memset(lazy, 0, sizeof(lazy));
		
		long long int ans = 0;
		for (int i = 0; i < Q; i++){
			char t[10];
			int v;
			scanf("%s %d", t, &v);
			--v;
			
			if (t[0] == 'Q'){
				ans += rev[get(ord[v])] + 1;
			}
			else {
				changeMax(ord[v], dst[v] + 1, ord[v]);
			}
		}
		
		printf("%lld\n", ans);
	}
	
	return (0);
}

Measured memory_bytes: 17828
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;
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;
}
int main() {
    COMinit();
    int n,m,k;
    long long x=0,y=0,z,d,nn,mm,kk;
    cin >> n >> m >> k;
    z=COM(n*m-2,k-2); nn=n; mm=m; kk=k;
    for(d=1;d<n;d++) x=(x+(((d*(nn-d)%MOD)*mm%MOD)*mm%MOD))%MOD;
    for(d=1;d<m;d++) y=(y+(((d*(mm-d)%MOD)*nn%MOD)*nn%MOD))%MOD;
    cout << ((x+y)%MOD)*z%MOD << endl;
}


Measured memory_bytes: 12160
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> D(N);
  rep(i, N) { cin >> D[i]; }

  ll Ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      if (i == j) continue;
      Ans += (D[i] * D[j]);
    }
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,m;
  cin>>n>>m;
  ll x[51],y[51];
  ll xx[51],yy[51];
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
    xx[i]=x[i];
    yy[i]=y[i];
  }
  sort(xx,xx+n);
  sort(yy,yy+n);
  ll ans=4*1e18;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=0;k<n;k++){
	for(int l=k+1;l<n;l++){
	  int cnt=0;
	  for(int a=0;a<n;a++){
	    if(x[a]<xx[i]||xx[j]<x[a])continue;
	    if(y[a]<yy[k]||yy[l]<y[a])continue;
	    cnt++;
	  }
	  if(cnt>=m)
	    ans=min(ans,(xx[j]-xx[i])*(yy[l]-yy[k]));
	}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int N=1e3+5;
int h,w;
int dp[N][N];
string s[N];

int find(int x,int y){
	if(x==0&&y==0) return(1);
	if(dp[x][y]!=-1) return(dp[x][y]);
	if(s[x][y]=='#') return(dp[x][y]=0);
	int ans=0;
	if(x-1>=0) ans=(ans+find(x-1,y))%M;
	if(y-1>=0) ans=(ans+find(x,y-1))%M;
	return(dp[x][y]=ans);
}

int32_t main(){
    IOS;
    memset(dp,-1,sizeof(dp));
    cin>>h>>w;
    for(int i=0;i<h;i++){
    	cin>>s[i];
    }
    cout<<find(h-1,w-1)<<endl;
}

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

using namespace std;

bool dfs(int n, int u, int v, vector<int> *graph) {
  bool is_visited[55];
  for (int i = 0; i < 55; i++) {
    is_visited[i] = false;
  }

  stack<int> st;
  st.push(0);
 
  while (!st.empty()) {
    int cur = st.top();
    st.pop();
    is_visited[cur] = true;
    
    for (int i = 0; i < graph[cur].size(); i++) {
      int next_v = graph[cur][i];

      // 辺を使わない処理
      if (cur == u && next_v == v) { continue; }
      if (cur == v && next_v == u) { continue; }

      if ( is_visited[next_v] == false ) {
        st.push(next_v);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if ( is_visited[i] == false ) {
      return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  int aa[55], bb[55];
  vector<int> graph[55];

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

  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    aa[i] = a; bb[i] = b;

    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    int u = aa[i]-1, v = bb[i]-1;
    if ( dfs(n, u, v, graph) == false ) {
      ans++;
    }
  }

  printf("%d\n", ans);

  return 0;
}

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

int main() {
 int A, B, C;
 cin >> A >> B >> C;
  int a = 0;
 for(int i = 0; i < 1000; i++) {
   a += A;
   if(a % B == C) { cout << "YES"; return 0; }
 }

 cout << "NO";
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int k;

    scanf("%d", &k);
    if(k % 2 == 0){
        printf("%d\n", (k / 2) * (k / 2));
    }else{
        printf("%d\n", (k / 2) * (k / 2 + 1));
    }
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <numeric>
#define ll long long
using namespace std;

ll B(ll x) {
    return (x*(x+1))/2;
}

ll Solve(const vector<pair<int,int>>& A) {
    int minval = 0;
    ll ans = 0;
    int N=A.size();
    for(int i=0;i<N;i++) {
        if (A[i].first==0) { // <
            int ct = A[i].second;
            //printf("<%d\n",ct);

            ans += B(ct-1);
            minval += ct;
        } else {
            int ct = A[i].second;
            //printf(">%d\n",ct);

            minval = max(minval, A[i].second);
            //printf("minval=%d %lld\n",minval,minval + B(ct-1));
            ans += minval + B(ct-1);
            minval = 0;
        }
    }
    ans += minval;
    return ans;
}


int main() {
    string S;
    cin>>S;
    
    vector<pair<int,int>> cts;
    for(int i=0;i<S.size();) {
        int j=i;
        while(j+1<S.size() && S[j+1]==S[i]) {
            j++;
        }
        cts.push_back({S[i]=='>',j-i+1});
        i=j+1;
    }
    
    

    cout << Solve(cts) << endl;


}


Measured memory_bytes: 3068
import java.util.*;

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


Measured memory_bytes: 27756
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  vector<P> v;
  rep(i,n) {
    REP(j,i+1,n) {
      string s="";
      rep(k,n) {
        if(k==i||k==j) s+='1';
        else s+='0';
      }
      pr("?",s);
      cout.flush();
      int x;
      R x;
      if(x) v.pb(P(i,j));
    }
  }
  cout << "!";
  rep(i,v.size()) {
    cout << " (" << v[i].F << "," << v[i].S << ")";
  }
  ln;
  cout.flush();
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e3+5;

ll n , ans;
vector<ll> v;

ll BS(ll val , ll idx)
{
    ll l=idx+1 , h=v.size()-1 , mid , ind = -1;
    while(l<=h)
    {
        mid = (l+h)/2;
        if (v[mid] < val)
        {
            ind = max(ind , mid);
            l = mid+1;
        }
        else h = mid-1;
    }
    if (ind==-1) return 0;
    return ind - idx;
}

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

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        ll x;
        cin >> x;
        v.push_back(x);
    }

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

    for(int i=0; i<v.size(); i++)
    {
        for(int j=i+1; j<v.size(); j++)
        {
            ll val = BS(v[i]+v[j] , j);
            ans += val;
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
L, R = map(int, input().split())

modL = L % 2019
modR = R % 2019
min2019 = 2019

if R - L >= 2018:
    print(0)
elif modL <=3 and modR >=673:
    print(0)
else:
    for j in range(modL, modR+1):
        for k in range(j+1, modR+1):
            min2019 = min(min2019, j * k % 2019)
    print(min2019)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cctype>
#include <math.h>
using namespace std;
using ll = long long;
using VI = vector<int>;


int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = n; i > 0; i--) {
        string a = to_string(i);
        if (a.size() % 2 != 0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        double x1 = scan.nextDouble(), y1 = scan.nextDouble(),
                x2 = scan.nextDouble(), y2 = scan.nextDouble();
        double dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1);
        double distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));

        System.out.printf("%9.8f", distance);
    }
}

Measured memory_bytes: 28152
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <deque>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);

	string s;
	cin >> s;
	deque <char> c;
	for (int i = 0; i < s.length(); ++i) {
		c.push_back(s[i]);
	}
	int n;
	cin >> n;
	bool rev = false;
	deque <char> ff, bb;
	while (n--) {
		int num;
		cin >> num;
		if (num == 1) {
			rev = !rev;
		}
		else {
			int f;
			cin >> f;
			char cc;
			cin >> cc;
			if (f == 1) {
				if (!rev) {
					ff.push_front(cc);
				}
				else {
					bb.push_back(cc);
				}
			}
			else {
				if (!rev) {
					bb.push_back(cc);
				}
				else {
					ff.push_front(cc);
				}
			}
		}
	}
	vector <char> ans;
	for (int i = 0; i < ff.size(); ++i) {
		ans.push_back(ff[i]);
	}
	for (int i = 0; i < c.size(); ++i) {
		ans.push_back(c[i]);
	}
	for (int i = 0; i < bb.size(); ++i) {
		ans.push_back(bb[i]);
	}
	if (rev) {
		reverse(ans.begin(), ans.end());
	}

	for (int i = 0; i < ans.size(); ++i) {
		cout << ans[i];
	}
}

Measured memory_bytes: 1364
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;

int H, W;
vector<string> c(22);
int bfs(int, int, int, int);

int main(void)
{
	cin >> H >> W;
	c[0] = "######################";
	c[H + 1] = "######################";
	rep(i, 1, H + 1) {
		string tmp; cin >> tmp;
		c[i] = "#";
		c[i] += tmp;
		c[i] += "#";
	}
	int ans = -1;
	rep(sy, 1, H + 1) {
		rep(sx, 1, W + 1) {
			rep(gy, 1, H + 1) {
				rep(gx, 1, W + 1) {
					if (c[sy][sx] == '.'&&c[gy][gx] == '.') {
						ans = max(bfs(sy, sx, gy, gx), ans);
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

int bfs(int sy, int sx, int gy, int gx)
{
	vector<vector<int>> dis(H + 2, vector<int>(W + 2, -1));
	queue<int> X, Y; X.push(sx); Y.push(sy); dis[sy][sx] = 0;
	vector<int> vx = { 1,0,-1,0 }, vy = { 0,1,0,-1 };
	while (!X.empty()) {
		int tmp_x = X.front(), tmp_y = Y.front(); X.pop(); Y.pop();
		rep(i, 0, 4) {
			if (dis[tmp_y + vy[i]][tmp_x + vx[i]] == -1 && c[tmp_y + vy[i]][tmp_x + vx[i]] == '.') {
				dis[tmp_y + vy[i]][tmp_x + vx[i]] = dis[tmp_y][tmp_x] + 1;
				X.push(tmp_x + vx[i]);
				Y.push(tmp_y + vy[i]);
			}
		}
	}

	return dis[gy][gx];
}

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


void print(int h, int w) {
  for (int a=0; a<h; a++) {
    for (int b=0; b<w; b++) {
      if (a%2==b%2) {
        cout << "#";
      } else {
        cout << ".";
      }
    }
    cout << endl;
  }
}

int main() {
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H==0 && W==0) {
      break;
    } else {
      print(H, W);
      cout << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  char a[H+2][W+2];
    
  for(int i=0; i<H+2;i++){
    for(int j=0;j<W+2;j++){
      a[i][j] ='#';
    }
  }
  
  for(int i=1; i<H+1; i++){
    for(int j=1; j<W+1; j++){
      cin >> a[i][j];
    }
  }
  
  for(int i=0;i<H+2;i++){
    for(int j=0;j<W+2;j++){
      cout << a[i][j];
    }
    cout << endl;
  }
  
  
  
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using static System.Math;

class P
{
  static void Main()
  {
    var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    Console.SetOut(sw);
    int N = int.Parse(Console.ReadLine());
    int j = 0;
    var so = new List<int>();
    var R = new List<int>();
    for (int i=3; i<55555; i+=2){
      bool f = false;
      foreach (int p in so){
        if(i%p==0) f=true;
      }
      if(f)continue;
      so.Add(i);
      if(i%5!=1)continue;
      R.Add(i);
      j++;
      if (j==N) break;
    }
    Console.WriteLine(string.Join(" ", R.ToArray()));
    Console.Out.Flush();
  }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a < b) { a=b; return 1; }return 0;}
template<class T> inline bool chmin(T& a, T b){ if(a > b) { a=b; return 1; }return 0;}
const long long INF = 1LL << 60;

// --------write my code!!!!!----------//

int main(){
    int y,m,d;
    char c1,c2;
    cin >> y >> c1 >> m >> c2 >> d;
    if(m<=4) cout << "Heisei" <<endl;
    else cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

const int MOD = 1e9 + 7, M = 13;

int main() {
    string S;
    cin >> S;

    int n = S.size();
    long dp[n+1][M] = {};
    dp[0][0] = 1;
    rep(i, n) {
        int c = S[i] - '0';
        if (S[i] == '?') c = -1;
        rep(j, 10) {
            if (c != -1 && c != j) continue;
            rep(k, M) {
                dp[i + 1][(k * 10 + j) % M] += dp[i][k];
                dp[i + 1][(k * 10 + j) % M] %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 10624
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as M
import Data.List
 
main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  as <- B.words <$> B.getLine
  print $ solve k $ count as
 
count :: [B.ByteString] -> M.Map B.ByteString Int
count = foldr (\x y -> M.insertWith (+) x 1 y) M.empty
 
solve :: Int -> M.Map B.ByteString Int -> Int
solve k = sum . drop k . sortOn negate . M.elems

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

using namespace std;

#define ll long long
#define mp make_pair
#define f first
#define s second
#define pb push_back

int main()
{
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);

    string a,b;
    cin>>a>>b;
    cout<<(a[0]==b[0])+(a[1]==b[1])+(a[2]==b[2]);
}


Measured memory_bytes: 256
N,W  = list(map(int,input().split()))
item = [list(map(int,input().split())) for i in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(N):
    for j in range(W+1):
        if j-item[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-item[i][0]]+item[i][1])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])

Measured memory_bytes: 120044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
typedef pair<int,int> pii;

const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

int main(){
    int N; cin >> N;
    vector<ll> C(N);
    rep(i, 0, N){
        ll t; cin >> t;
        C[i] = t;
    }
    sort(C.begin(), C.end(), greater<ll>());
    
    mint ans = 0;
    rep(i, 0, N){
        ans = ans + (mint)(i + 2) * (mint)C[i];
    }
    mint t = 2;

    ans = ans * (t^(2*N-2));

    cout << ans << endl; 

}


Measured memory_bytes: 1792
//
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (int i = 0; i < M; ++i)
    {
        int Atemp;
        cin >> Atemp;
        A[i] = Atemp;
    }
    int sum = 0;
    for (int i = 0; i < M; ++i)
    {
        sum += A[i];
    }
    int ans = (std::max)(-1, N - sum);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;

int calcScore(vector<int> c, vector<vector<int>> s, vector<int> t, vector<vector<int>> last, int day) {
	int score = 0;
	for (int i = 0; i < day; i++) {
		score += s[i][t[i] - 1];
		rep(j, 26) {
			score -= c[j] * (i + 1 - last[i][j]);
		}
	}
	return score;
}

int main() {
	int d;
	cin >> d;
	// Read in C (degree of losing satisfaction per contest)
	vector<int> c(26);
	rep(i, 26) {
		cin >> c[i];
	}
	// Read in S_ij (Increase in satisfaction per day per contest)
	vector<vector<int>> s(d, vector<int>(26));
	rep(i, d) {
		rep(j, 26) {
			cin >> s[i][j];
		}
	}
	
	vector<int> t (d);
	vector<int> last (26, 0);
	int score = 0;
	int max_score = 0;
	rep(i, d) {
		int temp_max = 0;
		int max_j = 0;
		rep(j, 26) {
			last[j] = i + 1;
			if (s[i][j] - c[j] * (d - last[j]) > temp_max) {
				temp_max = s[i][j] - c[j] * (d - last[j]);
				max_j = j;
			}
		}
		last[max_j] = max_j + 1;
		cout << max_j + 1 << endl;
		max_score = temp_max;
		score += max_score;
	}
	//score = max(score + 1000000, 0);
	//cout << score << endl;
	return 0;
}

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

int main(){
	string s;
  	cin >> s;
  
  	if(s.substr(2, 1) == s.substr(3, 1) && s.substr(4, 1) == s.substr(5, 1)){
    	cout << "Yes" << endl;
    } else cout << "No" << endl;
}

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

int n, A[2001];

bool solve(int i, int m) {
  if (m == 0 || A[i] == m) return true;
  if (i >= n || m < 0) return false;

  i++;
  return solve(i, m-A[i-1]) || solve(i, m);
}

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

  int m, q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> m;
    if (solve(0, m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define PI acos(-1.0)
#define eps 1e-67
#define pf printf
#define sf scanf
#define sd(n) scanf("%d",&n)
#define sd2(n1,n2) scanf("%d %d",&n1,&n2)
#define slf(n) scanf("%lf",&n)
#define slf2(n1,n2) scanf("%lf %lf",&n1,&n2)
#define sLf(n1) scanf("%Lf",&n1)
#define sLf2(n1,n2) scanf("%Lf %Lf",&n1,&n2)
#define sl(n) scanf("%lld",&n)
#define sl2(n1,n2) scanf("%lld %lld",&n1,&n2)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define repb(i,a,b) for(long long int i=a;i>=b;i--)
#define repa(i,a,b,c) for(long long int i=a;i<b;i=i+c)
#define reps(i,a,b,c) for(long long int i=a;i>b;i=i-c)
#define asort(a) sort(a.begin(),a.end())
#define asortb(a,comp) sort(a.begin(),a.end(),comp)
#define arev(a) reverse(a.begin(),a.end())
#define all(v) (v).begin(),(v).end()
#define allc(v,comp) (v).begin(),(v).end(),comp
#define allrc(v,a,b,comp) (v).begin()+a,(v).end()-b,comp
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define pbb pop_back
#define mp make_pair
#define mt make_tuple
#define bs(v,x) binary_search(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define tl(c) towlower(c)
#define root(x) sqrt(x)
#define power(a,n) pow(a,n)
#define tu(c) towupper(c)
#define sq(a) ((a)*(a))
#define cube(a) ((a)*(a)*(a))
#define mx 1000
#define MX 100000
#define mod 1000000007
using namespace std;
typedef string str;
typedef long long int ll;
typedef double lf;
typedef long double llf;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef char ch;
typedef map<ll,ll> mp;
void Solve()
{
   ll x,mm,mmm,ans,mk;
   llf ans1;
   cin>>x;
   mm=x-1;
   ans1=floor((mm*1.00)/11)*2;
   mk=mm%11;
   if(mk<=5)
   {
       ans1=ans1+1.00;
   }
   else
   {
       ans1=ans1+2.00;
   }
   ans=(ll)ans1;
   cout<<ans<<endl;

}
int main()
{
    Solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD 1000000007
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll n, k;
vector< vll > graph(100005);
ll dfs(int i, int p, ll depth)
{
    ll ans = 1;
    ll sub = 0;
    if(depth == 0)
        sub = 1;
    else
        sub = 2;
    int j, si = graph[i].size();
    ll cnt = 0;
    FOR0(j , si) 
    {
        int v = graph[i][j];
        if(v == p) continue;
        ans *= ((k - sub - cnt)%MOD*dfs(v, i, depth+1)%MOD)%MOD;
        cnt++;
        ans %= MOD;
    }
    return ans;
}
int main()
{
    she_told_me_dont_worry
    cin>>n>>k;
    int i;
    FOR0(i, n-1)
    {
        ll u, v;
        cin>>u>>v;
        u--;v--;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    ll ans = (k%MOD*dfs(0, -1, 0)%MOD)%MOD;
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 12800
from math import gcd

N,X=map(int,input().split())
x = list(map(int,input().split()))

if N == 1:
  print(abs(X-x[0]))
  exit()

diff = [abs(X-x[i]) for i in range(N)]

for i in range(1,N):
  if i == 1:
    total_gcd = gcd(diff[i],diff[i-1])
  else:
    total_gcd = gcd(diff[i],total_gcd)
    
print(total_gcd)

Measured memory_bytes: 20216
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long int
#define ld long double
#define FOR(i,a,b) for (auto i = (a); i != (b); i = (a)<(b)? i+1 : i-1)
#define pb push_back
#define mod 1000000007
long long binpow(long long a, long long b, long long m=mod) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll ans=0;
    for(int x=1;x<=n;x++)
    {
        if(x%15!=0 && x%3!=0 && x%5!=0)
        {
            ans+=x;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        if (n % 2 == 1) {
            int a = 1;
            int b = n;
            for (int i = 0; i < m; ++i) {
                System.out.println(a + " " + b);
                a++;
                b--;
            }
        } else {
            int aOdd = 1;
            int bOdd = n;
            int [] used = new int[n + 1];
            for (int i = 0; i < (m + 1) / 2; ++i) {
                System.out.println(aOdd + " " + bOdd);
                used[aOdd] = 1;
                used[bOdd] = 1;
                aOdd++;
                bOdd--;
            }
            int aEven = 2;
            int bEven = n;
            while (used[aEven] == 1 || used[bEven] == 1) {
                aEven++;
                bEven--;
            }
            for (int i = 0; i < m - (m + 1) / 2; ++i) {
                System.out.println(aEven + " " + bEven);
                aEven++;
                bEven--;
            }
        }
    }
}


Measured memory_bytes: 52824
#include<stdio.h>
#define N 500000
 
void merge(int *, int, int, int);
void mergeSort(int *, int, int);
 
int count=0;
 
int main()
{
  int i, n, A[N];
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
 
  mergeSort(A, 0, n);
 
  for(i = 0; i < n-1; i++){
    printf("%d ", A[i]);
  }
  printf("%d\n", A[n-1]);
  printf("%d\n", count);
 
  return 0;
}
 
void merge(int *A, int left, int mid, int right)
{
   
  int n1, n2, i, j, k;
  int L[N], R[N];
   
  n1 = mid-left;
  n2 = right-mid;
   for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];
 
  L[n1] = 1000000000;
  R[n2] = 1000000000;
  i = j = 0;
 
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{ 
      A[k] = R[j];
      j++;
    }
    count++;
  }
}
 
void mergeSort(int *A, int left, int right)
{
 
  int mid;
 
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}



Measured memory_bytes: 5760
#include<cstdio>
#include<algorithm>
using namespace std;
int T,k,n,a,b,c,d;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&a,&b,&c,&d);n=a+b;
        int l=0,r=n+1,mid,A,B;k=(max(a,b)-1)/(min(a,b)+1)+1;;
        while(l<r){
            mid=(l+r)>>1;
            A=a-mid/(k+1)*k-mid%(k+1);B=b-mid/(k+1);
            if(B<=1ll*A*k)l=mid+1;else r=mid;
        }
        A=a-l/(k+1)*k-l%(k+1);B=b-l/(k+1);r=l+B-A*k+1;
        for(int i=c;i<=min(d,l);i++)putchar(i%(k+1)?'A':'B');
        for(int i=max(c,l+1);i<=d;i++)putchar((i-r)%(k+1)?'B':'A');
        puts("");
    }
    return 0;
}

Measured memory_bytes: 256
NUM = (
        0b0111111,
        0b0000110,
        0b1011011,
        0b1001111,
        0b1100110,
        0b1101101,
        0b1111101,
        0b0100111,
        0b1111111,
        0b1101111,
        )

while 1:
    n = int(input())
    if n == -1:break

    current = 0
    for i in range(n):
        num = NUM[int(input())]
        print(format(current ^ num,'b').zfill(7))
        current = num

Measured memory_bytes: 6724
import numpy as np
from numba import njit

@njit('(i4[::1],)', cache=True)
def f(A):
  N = len(A)
  cnt = 0
  for i in range(N):
    for j in range(i + 1, N):
      for k in range(j + 1, N):
        cnt += (A[k] < A[i] + A[j])
  return cnt

N = int(input())
A = np.array(input().split(), np.int32)
A.sort()
print(f(A))


Measured memory_bytes: 106428
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <deque>
#include <map>

using namespace std;

const int CMax = 1002;
const int CInf = 2000000001;
const long long CMod = 1000000007;

int n, A[CMax];

int gcd(int a, int b)
{
    if (b != 0) return gcd(b, a % b);
    else return a;
}

string baseConverter(int base, int num) {
    string tNum = "";
    while (num > 0) {
        tNum = (char)('0' + num%base) + tNum;
        num /= base;
    }
}

bool isPalindrom(string tS) {
    int sn = (int)tS.length();
    for (int i = 0; i < sn / 2; i++) {
        if (tS[i] != tS[sn - i - 1]) return false;
    }
    return true;
}

int dist(int i, int j) {
    return  (j < i ? n + j : j) - i;
}

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

    int tmp, minDiff;

    for (int i = 0; i < n; i++) {
        scanf("%d", &tmp);

        if (i == 0) A[i] = tmp;
        else A[i] = A[i-1] + tmp;
    }

    minDiff = abs(A[0] - (A[n-1] - A[0]));

    for (int i = 1; i < n-1; i++) {
        minDiff = min(minDiff, abs(A[i] - (A[n-1] - A[i])));
    }

    printf("%d\n", minDiff);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
int n, ans=0;
void calc(int x, int a, int b, int c){
    if(x>n)return;
    if(a&&b&&c)ans++;
    calc(x*10+3, 1ll, b, c);
    calc(x*10+5, a, 1ll, c);
    calc(x*10+7, a, b, 1ll);
}
void solve(){
    cin>>n;
    calc(0ll, 0ll, 0ll, 0ll); 
    cout<<ans;  
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

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


int main(){
   
    int n;
    cin >> n;
    int count=0;
    for(int i=0;i<n;i++){
        int j;
        cin >> j;
        //cout << (int)pow(j,0.5)<<endl;;
        if((int)pow(j,0.5) < 2){
            count++;
        }
        for(int k=2;k<=pow(j,0.5);k++){
            if(j % k == 0){
                break;
            }
            else if(k == (int)pow(j,0.5)){
                count++;
            }
        }
    }
    cout << count << endl;
}


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

public class Main{
	public static void main(String []args)
	{
		int a,b,c,x,y;
		Scanner cin=new Scanner(System.in);
		while(cin.hasNext())
		{
			a=cin.nextInt();
			b=cin.nextInt();
			c=cin.nextInt();
			x=cin.nextInt();
			y=cin.nextInt();
			int ans=Math.min(x, y);
			double ave=1.0*(a+b)/2;
			long  mon=0;
			if(ave>c)
			{
				mon+=2*ans*c;
				int mm=x>y?(x-y)*a:(y-x)*b;
				int nn=x>y?(x-y)*2*c:(y-x)*2*c;
				mon+=Math.min(mm,nn);
				
			}
			else 
			{
				mon+=a*x+b*y;
			}
			System.out.println(mon);
			
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    char ch;
    char ans[1200];
    int n,i=0;;
    while(1){
        scanf("%c", &ch);
        if(ch=='\n'){
            n=i;
            break;
        }
        if('A'<=ch && ch<='Z') ch=ch+32;
        else if('a'<=ch && ch<='z') ch=ch-32;
        ans[i]=ch;
        ++i;
    }
    for(int j=0;j<n;j++) cout << ans[j];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3144
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static long[] array, waite;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		int l = sc.nextInt();
		if(l == 0)return false;
		
		array = new long[l];
		waite = new long[l];
		for(int i = 0; i < array.length; i++){
			array[i] = sc.nextInt();
		}
		return true;
	}
	
	static void solve(){
		Arrays.sort(array);
		long res = 0;
		for(int i = 1; i < waite.length; i++){
			waite[i] = waite[i-1] + array[i-1];
		}
		for(int i = 0; i < waite.length; i++){			
			res += waite[i];
		}
		System.out.println(res);
	}

}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string c1, c2;
    cin >> c1 >> c2;

    if(c1.at(0)==c2.at(2)&&c1.at(1)==c2.at(1)&&c1.at(2)==c2.at(0)) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
let sum_digits i =
  let rec go acc j =
    if j = 0 then acc
    else go (acc + j mod 10) (j / 10)
  in go 0 i

let solve n a b =
  let rec go i acc =
    let s = sum_digits i
    in let newacc = if a <= s && s <= b then acc + i else acc
       in if i = n then newacc
          else go (i + 1) newacc
  in go 0 0

let () = Scanf.scanf "%d %d %d" solve |> print_int

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n,greater<ll>());
  ll ans = a[0];
  n -= 2;
  int pos = 1;
  while(n > 0) {
    if(n == 1) {
      ans += a[pos];
      n = 0;
      pos++;
    } else {
      ans += 2*a[pos];
      n -= 2;
      pos++;
    }
  } 
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b;
  cin >> a >> b;
  cout << max(a+a-1, max(a+b, b+b-1)) << newl;
  return 0;
}

Measured memory_bytes: 3656
N = int(input())
a = list(map(int, input().split()))

d = {}
for i in a:
    d[i] = d[i] + 1 if d.get(i) else 1

remove_count = 0
for k, v in d.items():
    if k != v:
        remove_count += v if k > v else v - k
        
print(remove_count)


Measured memory_bytes: 17780
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    long long int N;
    cin >> N;
    long long int T[N+1],X[N+1],Y[N+1];
    vector<tuple<int,int,int>> A(N+1);
    A[0] = make_tuple(0,0,0);
    for(int i = 1;i < N+1;i++){
      cin >> T[i] >> X[i] >> Y[i];
      A[i] = make_tuple(T[i],X[i],Y[i]);
    }
    sort(A.begin(),A.end());
    bool frag = 1;
    int a = 0;
    for(int i = 0;i < N;i++){
      long long int t = get<0>(A[i+1])-get<0>(A[i]);
      long long int x = get<1>(A[i]),y = get<2>(A[i]);
      long long int x1 = get<1>(A[i+1]),y1 = get<2>(A[i+1]);
      long long int dis = abs(x1-x) + abs(y1-y);
      if(t >= dis && ((t%2 == 0 && dis%2 == 0) || (t%2 == 1 && dis%2 == 1))){
        a++;
      }else{
        frag = 0;
      }
    }
    if(frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3712
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(ll X) {
	if (!X) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
int A[100001];
int MA[100001], MI[100001];
int saidai, k = 1, k2 = 1;
ll kotae[100001];

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


	int N = getint();
	rep(i, N) {
		int a = getint();
		if (a > saidai) {
			MA[k] = a;
			MI[k++] = i;
			saidai = a;
		}
		else A[k2++] = a;
	}
	k2--;
	pakuri_sort(k2, A + 1);

	ll cnt = 0;
	for (int i = k - 1; i >= 1; i--) {
		ll tmp = (MA[i] - MA[i - 1]) * ++cnt;
		while (MA[i - 1] < A[k2]) {
			tmp += A[k2] - MA[i - 1];
			cnt++;
			k2--;
		}
		kotae[MI[i]] = tmp;
	}

	rep(i, N) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;


int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a <= 5) {
		cout << 0 << endl;
	}
	else {
		cout << b/2 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false
	

int main() {
	int N;
	cin >> N;
	vint T(N + 1, 0);
	for (int i = 1; i <= N; i++) cin >> T[i];
	int sum = accumulate(all(T), 0);
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		int P, X;
		cin >> P >> X;
		cout << sum + X - T[P] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << range(begin(i), end(i));
	}

sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<PLL > VPL;
typedef vector<double> VD;
typedef long double ld;

const double PI = acos(-1.);

void solve(int ks) {
	int n;
	cin >> n;
	cout << 180 + (n - 3) * 180 << endl;
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 25);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std; using P=pair<int,int>; using ll=long long;

int main() {
  ll x; cin>>x;
  ll an=1e9;
  while(x>=100) {
    an=min(an,abs(753-x%1000));
    x/=10;
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256