akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

void* cmalloc(int size, char* em){
	//malloc with checking.
	//in em, you can input some error message for identifying the error position.
	//if you don't input any in em, we won't output any extra message.
	void* ob = malloc(size);
	if(ob == NULL){
		printf("We can't ensure plenty memory in this program. %s \n", em);
		exit(0);
	}
    return ob;
}

void* crealloc(void* ob, int size, char* em){
	//realloc with checking.
	//in em, you can input some error message for identifying the error position.
	//if you don't input any in em, we won't output any extra message.
	//realloc cost linear time depeding size at worst.
	
	void* ret = realloc(ob, size);
	if(ret == NULL){
		printf("We can't re-ensure plenty memory in this program. %s \n", em);
		exit(0);
	}
	return ret;
}

typedef struct {
	int* arp;
	int size;
	int stack_size;
}vector_i;

int* vector_i_at(const vector_i* ob, int idx){
	//ob[idx]
	if(ob->size <= idx){
		printf("at-access in vector overes the range.\n");
		exit(0);
	}
	return (ob->arp + idx);
}

void vector_i_private_increase(vector_i* ob, int size){
	while(ob->stack_size < size)ob->stack_size *= 2;
}

void vector_i_constructor(vector_i* ob, int size){
	//fill the vector by 0.
	ob->size = size;
	ob->stack_size = 1;
	vector_i_private_increase(ob, size);
	ob->arp = cmalloc(sizeof(int) * ob->stack_size, "vector initialize failed.");
	
	for(int i = 0; i < ob->size; i++){
		ob->arp[i] = 0;
	}
}
void vector_i_destructor(vector_i* ob){
	ob->size = 0;
	ob->stack_size = 0;
	free(ob->arp);
}

void vector_i_resize(vector_i* ob, int size){
	if(ob->size < size){
		ob->arp = crealloc(ob->arp, size, "We cannot remalloc memory for vector resizing.");
		
		for(int i = ob->size; i < size; i++){
			*(ob->arp + i) = 0;
		}
	}else {
		for(int i = size; i < ob->size; i++){
			*(ob->arp + i) = 0;
		}
	}
	ob->size = size;
}

int* vector_i_begin(vector_i* ob){
	return ob->arp;
}

int* vector_i_end(vector_i* ob){
	return (ob->arp + ob->size);
}

void vector_i_push_back(vector_i* ob, int val){
	if(ob->size == ob->stack_size){
		vector_i_private_increase(ob, ob->size + 1);
		ob->arp = crealloc(ob->arp, sizeof(int) * ob->stack_size, "We can't resize in pushing back.");
	}
	*(ob->arp + ob->size) = val;
	ob->size++;
}

int vector_i_pop_back(vector_i * ob){
	if(ob->size == 0){
		printf("We cannot erase empty vector");
		exit(1);
	}
	ob->size--;
	int ret = ob->arp[ob->size];
	ob->arp[ob->size] = 0;
	return ret;
}

//compare
int comp(const int* a, const int* b){
	return *a - *b;
}

int main(){
	vector_i vi;
	vector_i_constructor(&vi, 0);
	
	for(int i = 0; i < 10; i++){
		int tmp;
		scanf("%d", &tmp);
		vector_i_push_back(&vi, tmp);
	}
	
	qsort(vector_i_begin(&vi), vi.size, sizeof(int), comp);
	
	for(int i = 9; i >= 7; i--)printf("%d\n", *vector_i_at(&vi, i));
	
	vector_i_destructor(&vi);
	return 0;
}


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

#define int long long

using namespace std;
             
map <int, int> used;
                
 main () {
 	int n;
 	cin >> n;
 	used[0] = 1;
 	int cur = 0;
	int ans = 0;
 	for (int i = 1;i <= n;i ++) {
		int x;
		cin >> x;
		cur += x;
		ans += used[cur]; 
		used[cur] ++;
 	}
 	cout << ans;
	return 0;
}


Measured memory_bytes: 12800
n,k = map(int,input().split())
s = input()
cou = 0
p = 1
nagasa = []
for i in range(n):
    if int(s[i]) == p:
        cou += 1
    elif int(s[i]) != p:
        if p == 1:
            p = 0
        elif p == 0:
            p = 1
        nagasa.append(cou)
        cou = 1
nagasa.append(cou)
if len(nagasa) % 2 == 0:
    nagasa.append(0)
h = len(nagasa)

if h // 2 <= k:
    print(n)
    exit()
lef = 0
rig = 2*k+1
now = sum(nagasa[lef:rig])
ans = now
while True:
    if rig == h:
        break
    now = now - nagasa[lef] - nagasa[lef+1] + nagasa[rig] + nagasa[rig+1]
    ans = max(ans,now)
    lef += 2
    rig += 2
print(ans)


Measured memory_bytes: 44764
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int jank(int a){
  char s[4]="spr";
  FOR(3)if(a==s[i])return i;
}

int main(void){
  ll n;
  scanf("%lld",&n);
  int cnt=0;
  while(n){
    n/=2;
    cnt++;
  }
  ll ans=1;
  FOR(cnt)ans*=2;
  PRL(ans-1);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define MAX_N 100000
#define INF (MAX_N * 10000)
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> H(N+1);
  rep(i, N) { cin >> H[i]; }
  H[N] = INF;

  vector<ll> dp(MAX_N + 1, INF);
  dp[0] = 0;
  rep(i, N-1) {
    for (int j = 1; j <= 2; j++) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(H[i] - H[i + j]));
    }
  }
  cout << dp[N - 1] << endl;
  return 0;
}

Measured memory_bytes: 1408
N,Q = map(int,input().split())
S = input()
t = [0] * (N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2] == 'AC' else 0)
for i in range(Q):
  l,r = map(int,input().split())
  print(t[r-1]-t[l-1])

Measured memory_bytes: 7748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;

signed main() {
	int K,X;
	cin >> K >> X;
	int r = 0;
	for(int i = X - (K - 1);i <= X + K - 1;i++) {
		cout << i << " ";
	}
  	cout << endl;
}

Measured memory_bytes: 256
houses = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())

for i in range(n):
    b, f, r, v = map(int, input().split())
    houses[b - 1][f - 1][r - 1] += v

for b in range(4):
    for f in houses[b]:
        print('', *f)
    if b != 3:
        print('#' * 20)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, k, x;
  cin >> n >> k;
  int ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> x;
    ans += 2 * min(x, abs(k - x));
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3592
W, H, D = 100.0, 50.0, 30.0

class Tank
  def initialize(board, tap)
    @tap = tap
    @block = make_block(board)
  end

  def make_block(board)
    board.each_cons(2).map{|b1, b2| Block.new(b1.x, b2.x, b1.height, b2.height)}
  end

  def block(x)
    @block.find{|b| b.in?(x)}
  end

  def height(x)
    block(x).water_height
  end

  def pour(time)
    @tap.each do |t|
      pour_run(block(t.x), t.stream * time)
    end
  end

  def pour_run(block, volume)
    overflow = block.pour(volume)
    return unless overflow
    return if @block.size == 1
    if block.left_height < block.right_height
      left = @block[@block.index(block) - 1]
      left = merge(left, block) if left.water_height == left.right_height
      pour_run(left, overflow)
    else
      right = @block[@block.index(block) + 1]
      right = merge(block, right) if right.water_height == right.left_height
      pour_run(right, overflow)
    end
  end

  def merge(left, right)
    block = Block.new(left.left_x, right.right_x, left.left_height, right.right_height)
    block.pour(left.water + right.water)
    @block.delete(right)
    @block[@block.index(left)] = block
  end
end

class Block
  attr_reader :left_x, :right_x, :left_height, :right_height
  attr_reader :water

  def initialize(left_x, right_x, left_height, right_height)
    @left_x, @right_x, @left_height, @right_height = [left_x, right_x, left_height, right_height].map(&:to_f)
    @volume = (@right_x - @left_x) * [@left_height, @right_height].min * D
    @water = 0.0
  end

  def in?(x)
    (@left_x ... @right_x).include?(x)
  end

  def water_height
    @water / (@right_x - @left_x) / D
  end

  def pour(volume)
    if @water + volume > @volume
      overflow = volume - (@volume - @water)
      @water = @volume
      return overflow
    end
    @water += volume
    nil
  end
end

class Tap
  attr_reader :x, :stream
  def initialize(x, stream)
    @x, @stream = [x, stream].map(&:to_f)
  end
end

class Board
  attr_reader :x, :height
  def initialize(x, height)
    @x, @height = [x, height].map(&:to_f)
  end
end

gets.to_i.times do
  board = Array.new
  board << Board.new(0, H)
  board.push( *gets.to_i.times.map{Board.new(*gets.split)} )
  board << Board.new(W, H)

  tap = gets.to_i.times.map{Tap.new(*gets.split)}

  gets.to_i.times do
    p, t = gets.split.map(&:to_f)
    tank = Tank.new(board, tap)
    tank.pour(t)
    p tank.height(p)
  end
end

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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const int MAXN = 1005;

bitset<MAXN> ss;

bool e[MAXN][MAXN];

int N, M, col[MAXN], sum, cnt = 0, all = 0;
bool vaild = 1;

void DFS(int node){
	if (!vaild) return;
	bool ok[2] = {1, 1};
	up (i, 1, N) if (e[node][i]) {
		if (col[i] != -1) ok[col[i]] = 0;
	}
	if (!ok[0] && !ok[1]) vaild = 0;
	up (i, 0, 1) if (ok[i]) {
		col[node] = i;
		all++;
		cnt += i == 0;
		break;
	}
	up (i, 1, N) if (e[node][i] && col[i] == -1) DFS(i);
}

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	scanf("%d%d", &N, &M);
	up (i, 1, N) up (j, 1, N) if (i != j) e[i][j] = 1;
	up (i, 1, M) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x][y] = e[y][x] = 0;
	}
	up (i, 1, N) col[i] = -1;
	ss.set(0);
	up (i, 1, N) if (col[i] == -1) {
		cnt = all = 0;
		DFS(i);
		ss = (ss << cnt) | (ss << (all - cnt));
		if (!vaild) return 0 * puts("-1");
	}
	int sum = N + 1;
	up (i, 0, N) if ((int)ss.test(i)) {
		cmin(sum, dmax(i, N - i));
	}
	int ans = sum * (N - sum);
	up (i, 1, N) up (j, i + 1, N) ans -= e[i][j];
	printf("%d\n", M - ans);
	return 0;
}



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

using namespace std;
constexpr int MOD = 1000000007;

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

    int n, m, tmp;
    cin >> n >> m;
    set<int> a;
    for (int i = 1; i < m + 1; i++) {
        cin >> tmp;
        a.insert(tmp);
    }

    int dp[n + 1];
    dp[0] = 1;

    auto it = a.find(1);
    if (it != a.end()) {
        dp[1] = 0;
    } else {
        dp[1] = 1;
    }

    for (int i = 2; i < n + 1; i++) {
        it = a.find(i);
        if (it == a.end()) {
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        } else {
            dp[i] = 0;
        }
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

const double pi = acos(-1);

int main() {
  int n;

  while(cin >> n, n != -1) {
    double x = 1, y = 1, ang =pi*135/180, len = sqrt(2);
    for(int i = 0; i < n-2; i++) {
      x += cos(ang);
      y += sin(ang);

      ang += atan(1/len);
      len = sqrt(len*len+1*1);
    }
    printf("%lf\n%lf\n", x, y);
  }
}

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

using namespace std;
int main()
{
	int n, v[20], c[50], a[50], ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	for (int i = 0; i < n; i++) {
		a[i] = v[i] - c[i];
	}
	for (int i = 0; i < n; i++) {
		if (a[i] > 0) {
			ans += a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define prinp(p) cout<<p.first<<" "<<p.second<<endl
#define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7,MAX = 1e6+5;
const ll INF = 1e18+5;

int main()
{
	ll n,k;
	cin>>n>>k;
	vl P(n+1);
	take(P,1,n);
	vl C(n+1);
	take(C,1,n);
	ll ans = -INF;
	for(int st=1;st<=n;st++)
	{
		ll curr = P[st];
		ll temp = 0;
		ll upto = C[curr];
		ll mov = 1;
		temp = upto;
		map<ll,ll> M;
		M[0] = 0;
		M[1] = temp;

		while(curr!=st)
		{
			if(mov==k) break;
			upto += C[P[curr]];
			temp = max(temp,upto);
			curr = P[curr];
			mov++;
			M[mov] = temp;
		}
		// cout<<st<<" "<<temp<<endl;
		if(mov==k)
		{
			ans = max(ans,temp);
		}
		else
		{
			if(k%mov!=0) ans = max({ans, upto*(k/mov) + max(0ll,M[k%mov]),temp});
			else
			{
				ans = max({ans,upto*(k/mov-1)+max(0ll,temp),temp});
			}
		}
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
int N;
cin>>N;
bool judge=true;
long long H[N];
long long h;
for(int i=0;i<N;++i){
  cin>>h;
  H[i]=h;
}
long long now=H[0]-1;
for(int i=1;i<N;i++){
  if(now<=H[i]-1){
    now=H[i]-1;
  }
  else if(now==H[i]){
    now=H[i];
  }
  else{
    judge=false;
    break;
  }
}
if(judge){
  cout<<"Yes"<<"\n";
}
else{
  cout<<"No"<<"\n";
}
return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	int a, b, c, x, y;
	ll cnt = 0;
	cin >> a >> b >> c >> x >> y;
	cnt += min(a + b, 2 * c) * min(x, y);
	if (x > y){
		cnt += min(a, 2 * c)*(x - y);
	}
	if (x < y){
		cnt += min(b, 2 * c)*(y - x);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
N, M = map(int, input().split())
s = input()
INF = 10**18
dp_cnt = [INF]*(N+1)
dp_next = [0]*(N+1)
dp_cnt[N] = 0
q = [(0,N)]

for i in range(N-1, -1, -1):
  while True:
    cnt, j = q[0]
    if j-i>M:
      heappop(q)
    else:
      break
  dp_cnt[i] = cnt
  if s[i]=='1':
    cnt = INF
    j = 0
  cnt += 1
  heappush(q, (cnt, i))
  dp_next[i] = j

if dp_cnt[0]>=INF:
  print(-1)
  exit()

x = 0
ans = []
while x<N:
  y = dp_next[x]
  ans += [str(y-x)]
  x = y

print(*ans)

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

long long INF = 1e18;

int main()
{
    ll x, k;
    cin >> x >> k;
    if(x/k >0){
        x = x % k;
    }
    if(abs(x-k)<x){
        x = abs(x - k);
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1000000007
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n;
char s[300003];
int R[300003],G[300003],B[300003],d[300003];
int main() {
	scanf("%d%s",&n,s);
	for(int i=0,r=0,g=0,b=0;i<3*n;i++)
	{
		if(s[i]=='R')R[r++]=i;
		else if(s[i]=='G')G[g++]=i;
		else B[b++]=i;
	}
	fup(i,0,n-1,1)
	{
		int t[3];
		t[0]=R[i],t[1]=G[i],t[2]=B[i];
		sort(t,t+3);
		fup(j,0,2,1)d[t[j]]=j;
	}
	ll ans=1;
	fup(i,1,n,1)ans=ans*i%MOD;
	int c1=0,c2=0;
	fup(i,0,3*n-1,1)
	{
		if(d[i]==0) c1++;
		else if(d[i]==1)
		{
			ans=ans*c1%MOD;
			c1--,c2++;
		}
		else
		{
			ans=ans*c2%MOD;
			c2--;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#define int long long
#define N 5000005
#define Mod 998244353
using namespace std;
int n,A,B,K,ans,fac[N],inv[N];
inline int ksm(int x,int y){
	int ans1=1;while (y){
		if (y&1) ans1=1ll*ans1*x%Mod;
		y>>=1;x=1ll*x*x%Mod;
	}return ans1;
}
inline int C(int n,int m){return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
signed main(){
	scanf("%lld%lld%lld%lld",&n,&A,&B,&K);
	fac[0]=1;for (int i=1;i<N;i++) fac[i]=fac[i-1]*i%Mod;
	inv[N-1]=ksm(fac[N-1],Mod-2);
	for (int i=N-2;~i;i--) inv[i]=inv[i+1]*(i+1)%Mod;
	for (int i=0;i<=n;i++){
		int res=K-i*A;
		if (res<0) break;
		if (res%B==0){
			int j=res/B;
			if (j>n) continue;
			ans=1ll*(ans+1ll*C(n,i)*C(n,j)%Mod)%Mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
#define MAX 44
int Fib[MAX];

// n番目のフィボナッチ数列を求める(再帰)
// int Calc_Fibonacci(int n1, int n2, int cnt)
// {
//     cnt--;
//     int n3 = n1 + n2;
//     if(cnt == 0) {
//         return n3;
//     } else {
//         return Calc_Fibonacci(n2, n3, cnt);
//     }
// }

int MakeFibonacci(int n)
{
    Fib[0] = Fib[1] = 1;
    for (int i = 2; i <= n; i++)
    {
        Fib[i] = Fib[i-1] + Fib[i-2];
    }
    return Fib[n];
}

int main()
{
    int n = 0;
    int nRes = 0;

    scanf("%d",&n);
    // if (n==0 || n==1) {
    //     printf("1\n");
    // } else {
    //     nRes = Calc_Fibonacci(1, 1, n-1);
    //     printf("%d\n", nRes);        
    // }
    nRes = MakeFibonacci(n);
    printf("%d\n", nRes);  
}


Measured memory_bytes: 3212
N = int(input())
B = list(map(int, input().split()))

A = []

for i in range(len(B)):
    if i == 0:
        A.append(B[i])
    else:
        if B[i-1] < B[i]:
            A.append(B[i-1])
        else:
            A.append(B[i])
A.append(B[i])

ANS = 0

for i in range(len(A)):
    ANS = ANS + A[i]
print(ANS)

Measured memory_bytes: 61952
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define LL long long 
using namespace std;
int main(){  
	int n,i;
	int a[123456],b[12]={};
	cin>>n;
		for(i=0;i<n;i++)
		{
			cin>>a[i];
			a[i]%=4;
			b[a[i]]++;
		}
		int f=0;
		b[2]=b[2]%2;
		//printf("%d %d\n",b[1]+b[2]+b[3],b[0]);
		if(b[0]+1>=b[3]+b[2]+b[1]){
			f=1;
		}
		printf(f?"Yes":"No");	
		puts("");
    return 0;  
}  


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

int main() {
  int A ,B ,C ;
  
  cin >> A >> B >> C ;
  
  if (A==B &&  A!=C ){
    cout << "Yes" << endl ;  
  }
   else if (A==C && B !=C  ){
    cout << "Yes" << endl ;  
  }
     else if (B==C && A !=C  ){
    cout << "Yes" << endl ;  
  }
  else if (A==B && B ==C){
    cout << "No" << endl ;
  }
  else if (A !=B && B !=C){
    cout << "No" << endl ; 
  
  }
  else {
    cout << "No" << endl ; 
  
  }
  
  
  
  
  
  
}


Measured memory_bytes: 3576
#include <iostream>
#include <iomanip>
using namespace std;
int count (int n, int k, int c){
    if(n >= k){
        return c;
    }else{
        return count(n*2, k, c+1);
    }
}
double pow (double x, int n){
    double ans = 1;
    for(int i = 0; i < n; i++){
        ans = x * ans;
    }
    return ans;
}

int main(){
    int n, k;
    double sum = 0;
    cin >> n >> k;
    for(int i = 1 ; i <= n; i++){
        sum += pow(0.5, count(i, k, 0));
    }
    cout << fixed;
    cout << setprecision(10) << sum / (double)n << endl;;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>

int main(void) {
	int a, b, c;
	
	std::cin >> a >> b >> c;

	std::cout << (a * b) / 2 << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int n, i, j, tp=0, hp=0;
    char taro[101], hana[101];
     
    scanf("%d", &n);
     
    for(i=0;i<n;i++){
        scanf("%s %s", taro, hana);
         
        for(j=0;;j++){
            if(taro[j]>hana[j]){
                tp += 3;
                break;
            }
            else if(taro[j]<hana[j]){
                hp += 3;
                break;
            }
            else if(taro[j]+hana[j]==0){
                tp++;
                hp++;
                break;
            }
        }
    }
    printf("%d %d\n", tp, hp);
    return 0;
}




Measured memory_bytes: 2136
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
 
using namespace :: std;
 
const ll maxn=1e5+3100;
const ll mod=1e9+7;
const ll inf=1e9+500;
 
ll a[maxn];
 
int main(){
    ll n;
    cin>>n;
    if(n>1){
        ll ans=0;
        for(ll i=1;i<=n;i++){
            cin>>a[i];
        }
        bool dor=0;
        while(1){
            ll ans=0;
            for(ll i=1;i<=n;i++){
                ans+=a[i]-1;
            }
            if(ans%2==1){
                if(dor==0){
                    cout<<"First\n";
                }else{
                    cout<<"Second\n";
                }
                return 0;
            }
            ll dd=0;
            for(ll i=1;i<=n;i++){
                if(a[i]%2==1 && dd==0 && a[i]>1){
                    dd=1;
                    a[i]--;
                }
            }
            ll gc=a[1];
            for(ll i=2;i<=n;i++){
                gc=__gcd(gc,a[i]);
            }
            if(gc%2==1){
                if(dor==0){
                    cout<<"Second\n";
                }else{
                    cout<<"First\n";
                }
                return 0;
            }
            for(ll i=1;i<=n;i++){
                a[i]/=gc;
            }
            dor=!dor;
        }
    }
    if(n==1){
        cout<<"Second";
        return 0;
    }
}

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

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

    uint64_t A;
    std::map<uint64_t, uint64_t> m;
    for (int i = 0; i < N; ++i) {
        std::cin >> A;
        if (m.count(A) == 0) {
            m[A] = 1;
        } else {
            m[A] = m[A] + 1;
        }
    }

    uint64_t l = 0, w = 0;
    for (auto itr = m.rbegin(); itr != m.rend(); ++itr) {
        if (4 <= itr->second) {
            if (l == 0) {
                l = w = itr->first;
            } else {
                w = itr->first;
            }
            break;

        } else if (2 <= itr->second) {
            if (l == 0) {
                l = itr->first;
            } else {
                w = itr->first;
                break;
            }
        }
    }

    std::printf("%lu\n", l * w);

    return 0;
}


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

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

int main(){

    ll n;
    cin >> n;
    ll ans = 1;

    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,n){
        if(a[i] > 1000000000000000000/ans || a[i]*ans < 0){
            ans = -1;
            break;
        }else{
            ans *= a[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4052
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn mod_pow(x: i64, y: i64, z: i64) -> i64 {
        if y == 0 {
            1
        } else {
            let h = mod_pow(x, y / 2, z);
            let res = (h * h) % z;
            if y % 2 == 0 {
                res
            } else {
                (res * x) % z
            }
        }
    }

fn main() {
    input! {
        n: i64,
        a: [i64; n],
    }

    let mod1: i64 = 1000000007;
    let mut ans: i64 = 0;
    for i in 0..61 {
        let mut c: i64 = 0;
        for a1 in &a {
            if a1 & (1 << i) >= 1 {
                c += 1;
            };
        };
        let zero_c: i64 = n - c;
        let n = mod_pow(2, i, mod1);
        ans = (ans + ((zero_c * c % mod1) * n % mod1)) % mod1;
    };
    println!("{}", ans);
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ok=1;
	cin >>n;
	
	if(n==0) cout<<1<<"\n";
	else cout<<0<<"\n";
	return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  int N;
  cin >> N;
  int ans=0;
  REP(i,N){
    int l,r;
    cin >> l >> r;
    ans += r-l+1;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 50;
vector<ii> a[N];
ii pre[N];

int64 BFS(int s, int t, int n) {
  queue<int> Q;
  Q.push(s);
  fill(pre, pre + n, ii{-1, -1});
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (auto& it : a[u]) {
      int v = it.first, idx = it.second;
      if (pre[v].first >= 0) continue;
      pre[v] = ii{u, idx};
      Q.push(v);
    }
  }
  int64 ret = 0;
  for (int u = t; u != s; u = pre[u].first) {
    ret |= 1LL << pre[u].second;
  }
  return ret;
}

int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].emplace_back(y, i);
    a[y].emplace_back(x, i);
  }
  scanf("%d", &m);
  vector<int64> path;
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    path.push_back(BFS(x, y, n));
  }
  int64 ret = 0;
  for (int k = 0; k < (1 << m); ++k) {
    int parity = __builtin_popcount(k) & 1;
    int64 mask = 0;
    for (int i = 0; i < m; ++i) {
      if (k & (1 << i)) {
        mask |= path[i];
      }
    }
    int cnt = n - 1 - __builtin_popcountll(mask);
    if (parity) {
      ret -= 1LL << cnt;
    } else {
      ret += 1LL << cnt;
    }
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 256
num1, num2, target = [int(i) for i in input().split()]

smaller = min([num1, num2])


common_div_num = 0
for i in reversed(range(1, smaller + 1)):
    if num1 % i == 0 and num2 % i == 0:
        common_div_num += 1
        if common_div_num == target:
            break


print(i)

Measured memory_bytes: 2940
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
cnt = 0

n.times do |i|
  (n - 1).downto(i + 1) do |j|
    if a[j - 1] > a[j]
      tmp = a[j - 1]
      a[j - 1] = a[j]
      a[j] = tmp

      cnt += 1
    end
  end
end

puts a.map(&:to_s).join(' ')
puts cnt


Measured memory_bytes: 6864
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
//#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b)
        swap(a, b);
    if (a <= c && b >= c) {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>cnt(30,1e9);
  rep(i,n){
    string s;
    cin>>s;
    vector<int>tcnt(30);
    for(auto c:s){
      tcnt[c-'a']++;
    }
    rep(i,27){
      chmin(cnt[i],tcnt[i]);
    }
  }
  string res="";
  rep(i,27){
    rep(j,cnt[i])res+=(char)('a'+i);
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323
#define M           998244353


void solve()
{
      ll r,d,x;
      cin>>r>>d>>x;
      ll tmp=x;
      rep(i,1,11)
      {
             ll k = tmp*r - d;
             cout<<k<<endl;
             tmp=k;
      }
}


int main()
{
       speed_up;
       //pre();
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
    int n,a[100000],b[100000],c[100000];
    ll ans=0,l,r,mid,add;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%d",&c[i]);
    }
    sort(a,a+n);
    sort(b,b+n);
    sort(c,c+n);
    for(int i=0;i<n;i++){
        l=0;
        r=n-1;
        while(l<=r){
            mid=(l+r)/2;
            if(a[mid]<b[i]){
                l=mid+1;
            }
            else{
                r=mid-1;
            }
        }
        
        add=l;
        l=0;
        r=n-1;
        while(l<=r){
            mid=(l+r)/2;
            if(c[mid]<=b[i]){
                l=mid+1;
            }
            else{
                r=mid-1;
            }
        }//printf("%lld\n",add);
        add*=(ll)(n-l);
        ans+=add;//printf("%lld\n",ans);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 50
#define NIL -1

static char M[MAX][MAX];
static int color[MAX][MAX];
int W, H;

void dfs(int h, int w, int c) {
	color[h][w] = c;
	if (h != H - 1 && M[h + 1][w] == '1'&&color[h + 1][w] == NIL)
		dfs(h + 1, w, c);
	if (h != 0 && M[h - 1][w] == '1'&&color[h - 1][w] == NIL)
		dfs(h - 1, w, c);
	if (w != W - 1 && M[h][w + 1] == '1'&&color[h][w + 1] == NIL)
		dfs(h, w + 1, c);
	if (w != 0 && M[h][w - 1] == '1'&&color[h][w - 1] == NIL)
		dfs(h, w - 1, c);

	if (h != H - 1 && w != W - 1 && M[h + 1][w + 1] == '1'&&color[h + 1][w] == NIL)
		dfs(h + 1, w + 1, c);
	if (h != 0 && w != 0 && M[h - 1][w - 1] == '1'&&color[h - 1][w - 1] == NIL)
		dfs(h - 1, w - 1, c);
	if (h != 0 && w != W - 1 && M[h - 1][w + 1] == '1'&&color[h - 1][w + 1] == NIL)
		dfs(h - 1, w + 1, c);
	if (h != H - 1 && w != 0 && M[h + 1][w - 1] == '1'&&color[h + 1][w - 1] == NIL)
		dfs(h + 1, w - 1, c);
}


int main() {
	while (cin >> W >> H&&H&&W) {
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				cin >> M[h][w];
			}
		}
		fill(color[0], color[MAX], NIL);
		int c = 0;
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				if (color[h][w] == NIL&&M[h][w] == '1') { dfs(h, w, c++); }
			}
		}
		cout << c << endl;
	}
	return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100000];
map<int, int> m;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	inc(i, n) { m[a[i]]++; }
	
	int ans = 0;
	FOR(it, m) {
		int f = it -> FI;
		int s = it -> SE;
		if(f < s) { ans += s - f; }
		if(f > s) { ans += s; }
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 5120
# Setup
import sys
import heapq
sys.setrecursionlimit(4100000)
n = int(input())
a = [int(input()) for i in range(n)]
heap = []
for i in range(n):
    heapq.heappush(heap,-a[i])
for i in range(n):
    temp = heapq.heappop(heap)
    if -a[i] == temp:
        temp2 = heapq.heappop(heap)
        print(-temp2)
        heapq.heappush(heap,temp)
        heapq.heappush(heap,temp2)
    else:
        print(-temp)
        heapq.heappush(heap,temp)

Measured memory_bytes: 20640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

double snk(ll x){
	ll tmp = x;
	ll denom = 0;
	while(tmp){
		denom += tmp%10;
		tmp /= 10;
	}
	return (double)x/denom;
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	set<ll> st;
	
	zep(i, 0, 14){
		ll nine = pow(10, i)-1;
		rep(j, 1, 999){
			st.insert(j*pow(10, i)+nine);
		}
	}
	
	vector<ll> ans;
	double mx = INF;
	for(auto it = st.rbegin(); it != st.rend(); it++){
		if(snk(*it) <= mx){
			ans.push_back(*it);
			mx = snk(*it);
		}
	}
	reverse(ans.begin(), ans.end());
	
	ll k;
	cin >> k;
	zep(i, 0, k){
		print(ans[i])
	}
	return 0;
}

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

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

    string ans;
    for (int i = 0; i < s.size(); i += 2) {
        ans += s.at(i);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	vector<float> h;
	float tmp,max,min;

	while (cin >> tmp) h.push_back(tmp);

	max = min = h[0];
	for (vector<float>::iterator it = h.begin() + 1; it != h.end(); ++it) {
		if (*it > max) max = *it;
		if (*it < min) min = *it;
	}

	cout << max - min << endl;
	
	return 0;
}

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

int main() {
    int H, W;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j) % 2 == 0) cout << '#'; else cout << '.';
            }
            cout << endl;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

int main(void){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  REP(i, n) REP(j, d) cin >> x[i][j];

  int ans = 0;
  REP(i, n-1){
    FOR(j, i+1, n){
      double dist = 0;
      REP(k, d) dist += pow(x[i][k]-x[j][k], 2);
      dist = sqrt(dist);
      if(floor(dist) == dist) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* -- Aditya0412-- */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
int  main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	int n;
 	cin>>n;
 	int arr[n+1];
 	for(int i=1;i<=n;i++)
 		cin>>arr[i];
 	int brr[n+1];
 	brr[0]=0;
 	brr[1]=0;
 	brr[2]=abs(arr[1]-arr[2]);
 	for(int i=3;i<=n;i++)
 	{
 		brr[i]=min(brr[i-2]+abs(arr[i-2]-arr[i]),brr[i-1]+abs(arr[i-1]-arr[i]));
 	}
 	cout<<brr[n];
}

Measured memory_bytes: 1024
from heapq import heappush, heappop
import sys
input = sys.stdin.readline

def dijkstra(edges, size, source):
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance

def main():
    N, M, S = map(int, input().split())
    AB = [[None] * N for _ in range(N)]
    s = 0
    for _ in range(M):
        U, V, A, B = map(int, input().split())
        U -= 1
        V -= 1
        AB[U][V] = AB[V][U] = (A, B)
        s += A
    MAX = s + 1
    CD = [tuple(map(int, input().split())) for _ in range(N)]
    edges = [[] for _ in range(N*MAX)]
    for v in range(N):
        C, D = CD[v]
        for i in range(MAX-1):
            edges[v*MAX+i].append((min(v*MAX+i+C, (v+1)*MAX-1), D))
    for u in range(N-1):
        for v in range(u+1, N):
            if not AB[u][v]:
                continue
            A, B = AB[u][v]
            for i in range(A, MAX):
                edges[u*MAX+i].append((v*MAX+i-A, B))
                edges[v*MAX+i].append((u*MAX+i-A, B))
    dist = dijkstra(edges, N*MAX, min(S, MAX-1))
    for v in range(1, N):
        print(min(dist[v*MAX:(v+1)*MAX]))
main()

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    int N;
    cin >> N;
    for(int a = 0; a * 4 <= N; a++){
        if((N - a * 4) % 7 == 0){
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
}


Measured memory_bytes: 256
from operator import add, mul, sub, or_


class SegmentTree:
    '''
    セグメント木(遅延ではない)
    1-indexd セグメント木
    values : 値の配列
    op : 区間に対する関数
    ie : 初期値
    '''

    def __init__(self, values):
        self.values = values
        vlen = len(values)
        self.size = 2 ** (vlen-1).bit_length()
        self.tree = [0]*self.size + self.values + [0]*(self.size-vlen)

        for i in range(self.size-1, 0, -1):
            self.tree[i] = self.tree[i*2] + self.tree[i*2+1]

    def update(self, i, v):
        i += self.size
        self.tree[i] = v
        while i > 0:
            i //= 2
            self.tree[i] = self.tree[i*2] + self.tree[i*2+1]

    def query(self, l, r):
        l += self.size
        r += self.size
        ret = 0
        while l < r:
            if l & 1:
                ret += self.tree[l]
                l += 1
            if r & 1:
                r -= 1
                ret += self.tree[r]
            l //= 2
            r //= 2
        return ret


N, Q = map(int, input().split())
*c, = map(int, input().split())

q = [[] for _ in range(N+1)]
for i in range(Q):
    x, y = map(int, input().split())
    q[y-1].append([i, x-1])

st = SegmentTree([0]*(N+1))
finds = [-1]*(N+1)
ans = [0]*Q
for i in range(N):
    if finds[c[i]] != -1:
        st.update(finds[c[i]], 0)

    finds[c[i]] = i
    st.update(finds[c[i]], 1)

    for j, x in q[i]:
        ans[j] = st.query(x, i+1)

for a in ans:
    print(a)


Measured memory_bytes: 201644
#include <stdio.h>

int main()
{
	int h1, w1, h2, w2, remain;

	scanf("%d%d", &h1, &w1);
	scanf("%d%d", &h2, &w2);

	remain = h1 * w1;
	remain -= h2 * w1;
	remain -= h1 * w2;
	remain += h2 * w2;

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

	return 0;
}


Measured memory_bytes: 128