akhauriyash/Code-Regression huggingface dataset:
n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)

u = arr.uniq.length
if u <= k
  puts 0
else
  h = arr.group_by(&:itself).map { |k, v| [k, v.count] }.to_h
  a = h.values.sort
  puts a[0, u - k].inject(:+)
end


Measured memory_bytes: 69600
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
}; 


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n); readint(k);
        vector<ll> a;
        forr(i,0,n) {
            readll(aa); a.push_back(aa);
        }
        sort(a.begin(), a.end());

        cout << accumulate(a.begin(), a.begin() + max(0LL,n-k), 0LL) << endl;
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 5396
const inputs = require('fs')
  .readFileSync('/dev/stdin', 'utf8')
  .trim()
  .split(/\s+/)
  .map(s => parseInt(s))

const A = inputs[0]
const B = inputs[1]
const H = inputs[2]
const M = inputs[3]

const ratioH = (H * 60 + M) / (12 * 60)
const ratioM = M / 60
const theta = Math.abs(ratioH - ratioM) * (2 * Math.PI)

const C = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(theta))
console.log(C.toFixed(10))


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 5;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const ll N = 1e6+5;
string s;
vector<ll> v[N];
ll n,d;
ll a[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rep(i,n+1) {
    if(i>0) {
      if(10 > i || (i>=100 && i < 1000) || (i>= 10000 && i < 100000)) d++;
    }
  }
  cout << d << endl;
}


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

using namespace std;
typedef long long ll;
const ll MAXN = 15e3;
double nthRoot(ll A, int N) 
{ 
    // intially guessing a random number between 
    // 0 and 9 
    double xPre = rand() % 10; 
  
    //  smaller eps, denotes more accuracy 
    double eps = 1e-3; 
  
    // initializing difference between two 
    // roots by INT_MAX 
    double delX = INT_MAX; 
  
    //  xK denotes current value of x 
    double xK; 
  
    //  loop untill we reach desired accuracy 
    while (delX > eps) 
    { 
        //  calculating current value from previous 
        // value by newton's method 
        xK = ((N - 1.0) * xPre + 
              (double)A/pow(xPre, N-1)) / (double)N; 
        delX = abs(xK - xPre); 
        xPre = xK; 
    } 
  
    return xK; 
} 
int main() {
    
ios::sync_with_stdio(0);
cin.tie(0);

ll x;
cin >> x;
ll Ans = 0;

for(int i = 0 ; i <= MAXN ; i++)
{
    ll w = (x + pow(i,5));
    ll w1 = (x - pow(i,5));
    ll p1 = nthRoot(w,5);
    ll p2 = nthRoot(w1,5);
    if(pow(p1,5) == w)
    {
        
     cout << p1 << ' ' << i ;
     break;
    }
    
      if(pow(p2,5) == w1)
    {
        
     cout << p2 << ' ' << -i ;
     break;
    }
    
    
}
    
    
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'




int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
//     int t;
//      cin >> t;

//      while(t--){
    
// }

int n;
cin >> n;
int a[n];
fo(i,0,n)cin >> a[i];
map<int,int> m;
fo(i,0,n){
	m[a[i]]++;
}
vi arr;
for(auto it = m.begin(); it != m.end();it++){
	if(it->second == 1)arr.pb(it->first);
}
n = arr.size();

// for(int i = 0;i < n;i++)cout << arr[i] << ' ';
// 	cout << endl;

if(n == 0){
	cout << 0 << endl;

}

else{
int mq = 1e6+1;
vi dp(mq,1);
for(auto it = m.begin(); it != m.end();it++){
	if(it->second > 1){arr.pb(it->first);
	dp[it->first] = 0;}	
}

sort(all(arr));
n = arr.size();
int ma = arr[n-1];

if(0){}
else{
// cout << endl;
fo(i,0,n){
	// if(dp[arr[i]]){
	for(int j = arr[i]*2; j <= ma;j += arr[i]){
		dp[j] = 0;
	}
// }
}
int count = 0;
fo(i,0,n){
	if(dp[arr[i]])count++;
}

cout << count << endl;

}
}
return 0;
}




Measured memory_bytes: 26644
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

INF = 10**9+7

if __name__ == "__main__":
    x,k,d = map(int,input().split())
    x = abs(x)
    y = x//d
    x -= min(y,k)*d
    k -= min(y,k)
    if k%2 == 0:
        print(x)
    else:
        print(abs(x-d))

Measured memory_bytes: 68052
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define lson x << 1, l, mid
#define rson x << 1 | 1, mid + 1, r
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 5e5 + 5;
inline int read()
{
	rg int res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, k, cnt;
int p[Maxn], pos[Maxn], fir[Maxn], ind[Maxn], ans[Maxn], tree[Maxn << 2];
struct
{
	int to, last;
} e[2*Maxn];
void con(int u, int v)
{
	e[++cnt].to = v;
	e[cnt].last = fir[u];
	fir[u] = cnt;
	ind[v]++;
}
void Insert(rg int x,rg int l,rg int r,rg int pos,rg int s)
{
	if (l == r)
	{
		tree[x] = s;
		return;
	}
	rg int mid = l + r >> 1;
	if (pos <= mid)
		Insert(lson, pos, s);
	else
		Insert(rson, pos, s);
	tree[x] = min(tree[x << 1], tree[x << 1 | 1]);
}
int Query(rg int x,rg int l,rg int r,rg int nl,rg int nr)
{
	if (nl > nr)
		return Inf;
	if (nl <= l && r <= nr)
		return tree[x];
	rg int mid = l + r >> 1, res = Inf;
	if (nl <= mid)
		res = Query(lson, nl, nr);
	if (nr > mid)
		res = min(res, Query(rson, nl, nr));
	return res;
}
priority_queue<int, vector<int>, greater<int> > q;
void topo_sort()
{
	rg int x;
	for (rg int i = 1; i <= n; i++)
	{
		x = q.top();
		q.pop();
		pos[i] = x;
		for (rg int next = fir[x], nx; next; next = e[next].last)
		{
			nx = e[next].to;
			ind[nx]--;
			if (!ind[nx])
				q.push(nx);
		}
	}
}
int main()
{
	memset(tree, 0x3f, sizeof(tree));
	rg int a;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		a = read();
		p[a] = i;
	}
	Insert(1, 1, n, p[n], n);
	for (rg int i = n - 1; i >= 1; i--)
	{
		a = Query(1, 1, n, max(1, p[i] - k + 1), p[i] - 1);
		if (a != Inf)
			con(p[i], p[a]);
		a = Query(1, 1, n, p[i] + 1, min(p[i] + k - 1, n));
		if (a != Inf)
			con(p[i], p[a]);
		Insert(1, 1, n, p[i], i);
	}
	for (int i = 1; i <= n; i++)
		if (!ind[p[i]])
			q.push(p[i]);
	topo_sort();
	for (int i = 1; i <= n; i++)
		ans[pos[i]] = i;
	for (int i = 1; i <= n; i++)
		printf("%d\n", ans[i]);
	return 0;
}


Measured memory_bytes: 28928
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LI()
    b = LI()
    suma = sum(a)
    sumb = sum(b)
    diff = sumb - suma
    tmp = 0
    for i in range(n):
        tmp += max((b[i] - a[i] + 1) // 2, 0)
    if diff >= tmp:
        print("Yes")
    else:
        print("No")
    return


#main
if __name__ == '__main__':
    solve()


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());

    vector<int64_t> b(n);
    b[0] = a[0];
    for(int i = 1; i < n; i++){
        b[i] = b[i-1]+a[i];
    }

    int ans;
    int64_t suma = b[n-1];
    if(x > suma) ans = n-1;
    else if(x == suma) ans = n;
    else{
        if(b[0] > x) ans = 0;
        else{
            int ok = 0;
            int ng = n-1;
            while(ng-ok > 1){
                int mid = (ok+ng)/2;
                if(b[mid] <= x) ok = mid;
                else ng = mid;
            }
            ans = ng;
        }
        
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import deque
import sys
input=sys.stdin.readline
def main():
  a=int(input())
  b=[[]for i in range(a)]
  for i in range(a):
    b[i]=deque(list(map(int,input().split())))
  c=[[]for i in range(a)]
  ans=0
  d=[i for i in range(a)]
  while d:
    nextd=[]
    f=set()
    ans+=1
    T=0
    for i in d:
      if i not in f and len(b[i])>0:
        e=b[i][0]-1
        if e in c[i]:
          c[i].pop(c[i].index(e))
          T=1
          b[e].popleft()
          b[i].popleft()
          if len(b[i])>0:
            nextd.append(i)
          if len(b[e])>0:
            nextd.append(e)
          f|={i,e}
        else:
          c[e].append(i)
    if T==0:
      print(-1)
      exit()
    d=nextd
      
      
  print(ans)  
if __name__ == '__main__':  
  main()      

        




Measured memory_bytes: 36108
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  long long K;
  cin >> s >> K;
  long long c = 0;
  int i = 0; 
  for(;i < s.size();){
    if(s[i] == '1') c += 1;
    else break;
    i++;
  }
  if(K <= c) cout << 1 << endl;
  else cout << s[i] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N;cin >> N;
    vector<int> A(N);REP(i,N) cin >> A[i];
    sort ALL(A);reverse ALL(A);
    int a = 0,b = 0;
    REP(i,N){
        if(i % 2 == 0) a += A[i];
        else b += A[i];
    }
    cout << abs(a - b) << endl;
}

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

int main()
{
	int X, N;
	cin >> X >> N;
	
	int MAX = 102;
	bool hit[MAX];
	memset( hit, 0, sizeof(hit) );
	rep( i, N ) {
		int p;
		cin >> p;
		hit[p] = true;
	}
	
	int out0 = 0;
	for( int i = X; i >= 0; --i ) {
		if( ! hit[i] ) {
			out0 = i;
			break;
		}
	}
	int out1 = MAX-1;
	for( int i = X+1; i < MAX; ++i ) {
		if( ! hit[i] ) {
			out1 = i;
			break;
		}
	}
	
	int out = out0;
	if( abs(X-out0) > abs(X-out1) ) {
		out = out1;
	}
	cout << out;
	
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<numeric>
#include<map>
#include<limits>
using namespace std;

#define R(i,s,n) for(int i=s;i<n;i++)
#define D(i,n,s) for(int i=n-1;i>=s;i--)
typedef pair<int,int> P;
typedef unsigned long long ull;
typedef long long ll;

int n;
vector<string> w;
int mozi[5]={5,7,5,7,7};

int main() {
  while(cin >> n && n){
    w.resize(n);
    R(i,0,n){
      cin >> w[i];
    }

    int out = 0;
    R(i,0,n){
      int sum=0,ku=0;
      R(j,i,n){
        sum += w[j].size();
        if(sum == mozi[ku]){
          sum=0;
          ku++;
          if(ku==5){
            out=i+1;
            goto A;
          }
        }else if(sum > mozi[ku]){
          break;
        }
      }
    }
    A: ;
    cout << out << endl;
    w.clear();
  }
  return 0;
}



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

int main(){
  while(true){
    int x,y; cin >> x >> y;
    if(x == 0 && y == 0) break;
    cout << min(x,y) << " " << max(x,y) << endl;
  }
  return 0;
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 1000
 
struct State{
    string s;
    int next,l;
    State(string s,int next,int l) 
	: s(s),next(next),l(l) {}
};
 
int idx[MAX_N],len[MAX_N];
vector<State> G[MAX_N];
 
void solve(int x){
    if(len[x] == idx[x]){
	return;
    }
    for(int i = 0 ; i < len[x] ; i++){
	cout << string(G[x][idx[x]].l,'.') + G[x][idx[x]].s << endl;
	solve(G[x][idx[x]++].next);
    }
}
 
int main(){
    int N,K,size[MAX_N] = {0};
    string start,in;
    cin >> N >> size[0] >> start;
    for(int i = 1 ; i < N ; i++){
	cin >> K >> in;
	size[i] = size[K-1]+1;
	G[K-1].push_back(State(in,i,size[i]));
    }
    cout << start << endl;
    for(int i = 0 ; i < N ; i++){
	len[i] = G[i].size();
    }
    solve(0);
    return 0;
}

Measured memory_bytes: 3404
import Data.List

main = interact $ unlines . map (show . red_black) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = (w, filter is_nonred (zip [0.. ] (concat tss))) : read' xs'
   where
    [w,h] = map read (words wh)
    (tss,xs') = splitAt h xs
    is_nonred (_,c) = c /= '#'

red_black :: (Int, [(Int,Char)]) -> Int
red_black (w,ts) = length (filter is_scanned (until_fix scan ts))
 where
  is_scanned (_,c) = c == '@'
  scan ts' = map paint ts'
   where
    paint (i,c) = if c == '.' && is_adjacent i then (i,'@') else (i,c)
    is_adjacent i = any (\i' -> lookup i' ts' == Just '@') neighbors
     where
      neighbors = filter is_inborder [i-1,i+1,i-w,i+w]
      is_inborder i' = div i' w == div i w || abs (i'-i) == w

until_fix f x = if f x == x then x else until_fix f (f x)

Measured memory_bytes: 5408
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

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

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t countDivisors(const size_t n)
{
	size_t count = 1;

	for (size_t i = 2; i <= n; i++) {
		if (n%i == 0) {
			count++;
		}
	}

	return count;
}

int main(void) {
	size_t N, i;

	scanf("%zu %zu", &N, &i);

	printf("%zu\n", N - i + 1);

	return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9 + 7;
const double EPS = 1e-9;

vector<ll> f(200010, 1), rf(200010, 0);

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

ll calc(int n, int k) {
    ll a, b, c;
    ll x, y;
    a = f[n], b = rf[k], c = rf[n - k];
    y = (b * c) % Inf;
    x = (a * y) % Inf;
    return x; 
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h, w, a, b;
    ll ans = 0;
    cin >> h >> w >> a >> b;
    FOR (i, 1, 200001) f[i] = (i * f[i - 1]) % Inf;
    rep (i, 200001) rf[i] = modpow(f[i], Inf - 2, Inf);
    FOR (i, b, w) {
        ans += calc((h - a - 1) + i, i) * calc(a - 1 + (w - i - 1), w - i - 1) % Inf;
        ans %= Inf;
    }
    cout << ans << endl;

    return 0;
}



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

main() {

  int i;
  int n;       //データ数
  int *r;      //データ配列用ポインタ
  int maxv, minv; //最大利益

  scanf("%d", &n);
  
  r = (int *)malloc(sizeof(int) * n);

  for( i=0; i<n; i++) {
    scanf("%d", &r[i]);
  }

  maxv = r[1] - r[0];
  minv = r[0];

  for( i=1; i<n; i++) {
    if(maxv < r[i]-minv) {
      maxv = r[i] - minv;
    }
    if(minv > r[i]) {
      minv = r[i];
    }
  }

  free(r);

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

  return 0;

}

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

int main()
{
	int c1, c2, c3;
	while (cin >> c1 >> c2 >> c3)
	{
		int count = 0;
		for (int i = 1; i <= 10; i++)
		{
			if (c2 + c1 + i <= 20 && i != c1 && i != c2 && i != c3) count++;
		}
		if (count >= 4) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
#define N 100005
int n, k, mi[N], ma[N];
bool has[N];
vector<int> a[N];
void check( int x, int y )
{
    if ( has[y] ) {
        bool flag = 1;
        if ( has[x] && (mi[x]-mi[y])%2==0 ) flag = 0;
        mi[x] = max(mi[x], mi[y]-1);
        ma[x] = min(ma[x], ma[y]+1);
        has[x] = 1;
        if ( mi[x] > ma[x] ) flag = 0;
        if ( ! flag ) {
            cout <<"No\n";
            exit(0);
        }
    }
}
void dfs(int node, int pre)
{
    if ( pre != -1 ) check(node,pre);
    for ( int i = 0; i < a[node].size(); i++) {
        int v = a[node][i];
        if ( v != pre ) {
            dfs(v,node);
            check(node,v);
        }
    }
}

int main()
{
    //freopen("vao.inp","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for ( int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    fill(mi,mi+n,-10000000);
    fill(ma,ma+n, 20000000);
    cin >> k;
    for ( int i = 0; i < k; i++) {
        int u, v; cin >> u >> v;
        u--;
        mi[u] = v;
        ma[u] = v;
        has[u] = 1;
    }
    dfs(0,-1);
    dfs(0,-1);
    cout << "Yes\n";
    for ( int i = 0; i < n; i++) cout << mi[i] << '\n';
}


Measured memory_bytes: 13568
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll mod = 1000000007;

ll N, K;
std::vector<ll> S;
std::map<ll, ll> inv;

int main()
{
  scanf( "%lld%lld", &N, &K );

  for( int j = 1; j*j <= N; ++j )
  {
    S.push_back( j );
    S.push_back( N/j );
  }

  std::sort( all(S) );
  S.erase( std::unique(all(S)), S.end() );

  rep( i, S.size() )
    inv[S[i]] = i;

  std::vector<std::vector<ll>> dp( K+1, std::vector<ll>( S.size()+1, 0 ) );

  rep( j, S.size() )
    dp[0][j] = 1;

  rep( i, K )
  {
    rep( j, S.size() )
    {
      dp[i+1][j] = (dp[i+1][j]+dp[i][inv[N/S[j]]]*(S[j]-(j>0?S[j-1]:0))%mod)%mod;

      dp[i+1][j+1] = (dp[i+1][j+1]+dp[i+1][j])%mod;
    }
  }

  printf( "%lld\n", dp[K][S.size()] );

  return 0;
}

Measured memory_bytes: 55288
S = input()
K = int(input())

lS = len(S)
asc = 97
while True:
    st = set()
    for i in range(lS):
        if S[i] == chr(asc):
            j = i + 1
            while j - i <= 5 and j <= lS:
                st.add(S[i:j])
                j += 1
    if len(st) >= K:
        print(sorted(list(st))[K - 1])
        break
    else:
        K -= len(st)
        asc += 1


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n, k;
    cin>>n>>k;
    Vec x(n);
    rep(i,n)cin>>x[i];
    Vec pl;
    Vec mi;
    pl.pb(0);
    mi.pb(0);
    rep(i,n){
        if(x[i]>=0){
            pl.pb(x[i]);
        }else{
            mi.pb(-x[i]);
        }
    }
    sort(ALL(mi));
    ll ans=INF;

    ll left = min(k+1 ,(ll) mi.size());
    ll right = min(k+1 ,(ll) pl.size());

    rep(i,left){
        if(k-i<pl.size()){
            chmin(ans,2*mi[i]+pl[k-i]);
        }
    }

    rep(i,right){
        if(k-i<mi.size()){
            chmin(ans,mi[k-i] + 2*pl[i]);
        }
    }

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


Measured memory_bytes: 2424
package main

import "fmt"

type problem struct {
	number, bonus int
}

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var D, G int
	fmt.Scan(&D, &G)
	problems := make([]problem, D)
	for i := range problems {
		fmt.Scan(&problems[i].number)
		fmt.Scan(&problems[i].bonus)
	}
	// fmt.Println("D", D, "G", G, "problems", problems)

	ans := 10000
	for bit := 0; bit < (1 << uint(D)); bit++ {
		score := 0
		solved := 0
		ok := false
		for j := 0; j < D; j++ {
			if bit&(1<<uint(j)) != 0 {
				score += (j+1)*100*problems[j].number + problems[j].bonus
				solved += problems[j].number
			}
		}
		if score < G {
			var j int
			for j = D - 1; j >= 0; j-- {
				if bit&(1<<uint(j)) == 0 {
					break
				}
			}
			for k := 0; k < problems[j].number; k++ {
				score += (j + 1) * 100
				solved++
				if score >= G {
					ok = true
					break
				}
			}
			if !ok {
				score += problems[j].bonus
				if score >= G {
					ok = true
				}
			}
		} else {
			ok = true
		}
		if ok {
			ans = min(ans, solved)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<math.h>
#include<iterator>

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


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

const ll INF = 1e18;

int a[200000];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) scanf("%d",&a[i]);

    ll total = 0;
    REP (i,n) total += a[i];
    ll sum = a[0], ans = INF;
    REP (i,1,n-1) {
        ans = min(ans,llabs(total - 2 * sum));
        sum += a[i];
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    ll N, W;
    cin >> N >> W;
    vector<ll> v(N), w(N);
    rep(i,N) cin >> w[i] >> v[i];

    // vector<vector<int>> dp(N+5,vector<int>(W+5));
    vector<ll> dp(W+5);
    for(ll i = 0; i < N; i++){
        for(ll j = W; j >= w[i]; j--){
            dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
        }
    }
    cout << dp[W] << endl;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=100009;
 
// Happy Coding!
void solve(){
    vi arr(3,0);
    cin>>arr[0]>>arr[1]>>arr[2];
    
    sort(all(arr));
    if(arr[0]==5 && arr[1]==5 && arr[2]==7){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    cout<<endl;
    
}
 
int main() {
    faster;
    int t=1;
    // cin>>t;
    
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3612
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 1, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
const int dx[] ={1,0,-1,0};
const int dy[] ={0,-1,0,1};
int w,h;
char board[55][55];
int WS,BS;
bool white[55][55];
bool black[55][55];
void dfsw(int y,int x){
  if(white[y][x]||board[y][x] != '.')
    return;
  white[y][x] =true;
  for(int k = 0;k < 4;k++){
    int nx = x +dx[k];
    int ny = y +dy[k];
    if(nx <=0||nx >w||ny <=0||ny >h)
      continue;
    else
      dfsw(ny,nx); 
  }
}
void dfsb(int y,int x){
  if(black[y][x]||board[y][x] != '.')
    return;
  black[y][x] =true;
  for(int k = 0;k < 4;k++){
    int nx = x +dx[k];
    int ny = y +dy[k];
    if(nx <=0||nx >w||ny <=0||ny >h)
      continue;
    else
      dfsb(ny,nx); 
  }
}
int main()
{
  while(cin>>w>>h,w||h){
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	cin>>board[i][j];
	white[i][j] = false;
	black[i][j] = false;
      }
    }
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	if(board[i][j] =='W'){
	  for(int k = 0;k < 4;k++){
	    int nx = j +dx[k];
	    int ny = i +dy[k];
	    if(nx <=0||nx >w||ny <=0||ny >h)
	      continue;
	    else
	      dfsw(ny,nx);
	}
      }
	if(board[i][j] =='B'){
	  for(int k = 0;k < 4;k++){
	    int nx = j +dx[k];
	    int ny = i +dy[k];
	    if(nx <=0||nx >w||ny <=0||ny >h)
	      continue;
	    else
	      dfsb(ny,nx);
	  }
	}
      }
    }
    WS = 0;
    BS = 0;
    for(int i = 1;i <=h;i++){
      for(int j = 1;j <=w;j++){
	if(board[i][j] !='.'||(white[i][j]&&black[i][j])||
	   (!white[i][j]&&!black[i][j]))
	  continue;
	if(white[i][j])
	  WS++;
	else
	  BS++;
      }
    }
    cout <<BS<<" "<<WS<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,c,k = iim()
time = []
for _ in range(n):
    time.append(ii())

time.sort()

bus = 0
fst = time[0]
ans = 0
for item in time:
    if bus <= c-1 and item <= k+fst:
        bus += 1
    else:
        bus = 1
        ans += 1
        fst = item

print(ans if bus == 0 else ans+1)

Measured memory_bytes: 7388
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    n, k = map(int, input().split())
    A = sorted(list(map(int, input().split())))

    cmb = CmbMod(n, mod)
    cmb.prep()

    min_S = 0
    for i in range(n - 1):
        min_S += (A[i] * cmb.cmb_mod_with_prep(n - (i + 1), k - 1)) % mod
        min_S %= mod

    max_S = 0
    for j in range(1, n):
        max_S += (A[j] * cmb.cmb_mod_with_prep(j, k - 1)) % mod
        max_S %= mod

    res = (max_S - min_S) % mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 26848
N = int(input())

mod = 10**9+7

def powmod(x, y):
    a = 1
    for _ in range(y):
        a *= x
        a %= mod
    return a

# (0も9もある) = (全体) - (0がある/9がない) - (9がある/0がない) - (0も9もない)
ans = powmod(10, N) - powmod(9, N) - powmod(9, N) + powmod(8, N)
ans %= mod

print(ans)

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vi a(N);
    Rep(i,N) Scd(a[i]);

    auto f = []( int a, int b ){ return (a-b)*(a-b); };

    ll ans = INF;
    ll tmp;
    Repe(i,101,-100){
        tmp = 0;
        Rep(ai,N) tmp += f(a[ai],i);
        ans = min(ans, tmp);
    }

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

    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc082/submissions/7855589を参考にも作成
 */
public class Main {

	/** 方向変換するときの文字 */
	private static final char TRANSFER = 'T';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray();
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			int[][] step = new int[2][s.length / 2 + 1];
			IntStream.range(0, 2).forEach(i -> Arrays.fill(step[i], 0));
			// X軸ステップとY軸ステップ数の数
			int[] number = new int[2];
			number[0] = 0;
			number[1] = 1;
			int current = 0;
			int count = 0;
			for (char c : s) {
				if (TRANSFER == c) {
					step[current][number[current]] = count;
					number[current]++;
					count = 0;
					current = 1 - current;
				} else {
					count++;
				}
			}
			if (count > 0) {
				step[current][number[current]] = count;
				number[current]++;
			}
			int n = s.length;
			boolean[][][] dp = new boolean[2][Math.max(number[0], number[1])][2 * n + 1];
			dp[0][0][n + step[0][0]] = dp[1][0][n] = true;
			IntStream.range(0, 2)
					.forEach(i -> IntStream.range(1, number[i])
							.forEach(j -> IntStream.range(0, 2 * n + 1)
									.forEach(k -> dp[i][j][k] = ((k - step[i][j] >= 0) && dp[i][j - 1][k - step[i][j]])
											|| ((k + step[i][j] <= 2 * n) && dp[i][j - 1][k + step[i][j]]))));
			System.out.println((dp[0][number[0] - 1][n + x] && dp[1][number[1] - 1][n + y]) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 166112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
const long long MOD = 10e9 + 7;
typedef long long ll;

int main(){
	ll N, T;
	cin >> N >> T;
	ll sum = T;
	vector<ll> t(N);
	rep(i, N) cin >> t.at(i);
	
	rep(i, N - 1){
		if(t[i + 1] - t[i] >= T){
			sum += T;
		} else {
			sum += abs(t[i + 1] - t[i]);
		}
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int N,K,ans=0;cin>>N>>K;
    REP(i,N){
        int h;cin>>h;
        if(h>=K)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
#include <string>
#include <bitset>
#include <fstream>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
//const ll INF = 100000000000010000;
//const ull B = 998244353;
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

vector<ll> dx = { 0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<ll> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0};

ll bit[800010];

ll sum(ll i)
{
	i += 450000;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void add(ll i, ll x)
{
	i += 450000;
	while (i <= 800005)
	{
		bit[i] += x;
		i += i & -i;
	}
}

void chmin(ll& x, ll y) {
	x = min(x, y);
}

void chmax(ll& x, ll y) {
	x = max(x, y);
}

ll pow_long(ll x, ll y) {
	ll res = 1;
	while (y > 0) {
		if (y % 2 == 1) res *= x;
		x *= x;
		y /= 2;
	}
	return res;
}

void test() {
	cout << "888888888888888888888888" << endl;
}

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}

ll pow_mod(ll x, ll k) {
	x %= mod;
	ll res = 1;
	while (k > 0) {
		if (k % 2) {
			res *= x; res %= mod;
		}
		x *= x; x %= mod;
		k /= 2;
	}
	return res;
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

//コンビネーション
const int MAXcomb = 1000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAXcomb; 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 comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[k] % mod * finv[n - k] % mod;
}

ll n, a[200010];
ll ans;

void solve() {
	cin >> n;
	rep(i, n) cin >> a[i + 1];
	if (a[n] < 230000 && a[n] > -230000) add(-a[n], 1);
	for (ll i = 1; i < n; i++) {
		if (a[n - i] > 230000) continue;
		ans += sum(a[n - i] - i) - sum(a[n - i] - i - 1);
		add(-a[n - i] - i, 1);
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll T = 1;
	//cin >> T;
	rep(i, T) solve();
}


Measured memory_bytes: 8292
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, x;
    cin >> n >> x;
    vll vec(n);
    REP(i, n) cin >> vec.at(i);
    ll count = 0;
    x -= accumulate(ALL(vec), 0);
    count += vec.size();
    sort(ALL(vec));
    count += x / vec.at(0);
    cout << count << endl;
    return 0;
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var ans = "";
        bool ok = false;
        while (!ok)
        {
            ans = n.ToString();
            ok = true;
            var hs = new HashSet<int>();
            for (int i = 0; i < ans.Length; i++)
            {
                if (!hs.Contains(int.Parse(ans[i].ToString())))
                {
                    hs.Add(int.Parse(ans[i].ToString()));
                }
            }

            for (int i = 0; i < d.Length; i++)
            {
                if (hs.Contains(int.Parse(d[i].ToString())))
                {
                    ok = false;
                }
            }
            n++;
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 15456
#include <stdio.h>
int main(){
    int j,n,i,b,tmp,m,e,x;
    char a[8];
    scanf("%d",&n);
    for(b=0;b<n;b++){
        scanf("%s",a);
        for(i=0;i<7;i++){
            for(j=7;j>i;j--){
                if(a[j] > a[j-1]){
                    tmp=a[j];
                    a[j]=a[j-1];
                    a[j-1]=tmp;
                }
            }
        }
        m=0;
        e=0;
        for(i=1,j=7 ; j >= 0; i*=10,j--){
            e=a[j]*i;
            m=e+m;
        }
        e=0;
        x=0;
        for(i=1,j=0 ; j < 8 ; i*=10,j++){
            e=a[j]*i;
            x=e+x;
        }
        printf("%d\n",m-x);
    }
    return (0);
}

Measured memory_bytes: 596
s=input()
sh=int(s[0:2])
sl=int(s[2:4])

jh,jl=False,False
if sh>=1 and sh<=12:
    jh=True
if sl>=1 and sl<=12:
    jl=True

if jh and jl:
    print("AMBIGUOUS")
elif jh:
    print("MMYY")
elif jl:
    print("YYMM")
else :
    print("NA")



Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a;
  int b[1000]={};
  int c[1000]={};
  int sum=0,cnt=0,q;
  cin>>q>>a;
  for(int i=0;i<a.size();i++) b[a[i]-'a']++;
  for(int i=0;i<a.size();i++){
    b[a[i]-'a']--;
    c[a[i]-'a']++;
    cnt=0;
    for(int i=0;i<30;i++){
      if(b[i]!=0&&c[i]!=0) cnt++;
    }
    sum=max(sum,cnt);
  }
  cout<<sum<<"\n";
}

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

bool cmp(int a,int b)
{
	return a>b;
}

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	
	sort(a,a+n,cmp);
	
	long long sum=0ll;
	for(int i=k;i<n;i++)
		sum+=a[i];
	
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    vector<int> vc(3);
    rep(i, 3) cin >> vc[i];
    sort(vc.begin(),vc.end());
    cout << vc[0] + vc[1];
}


Measured memory_bytes: 256
a,b,n=map(int,input().split())
def f(x):
    return ((a*x)//b)-a*(x//b)
if n<b:
    print(f(n))
elif n==b:
    print(f(n-1))
elif n>b:
    t = n
    u = b - 1
    print(max(f(t),f(u)))


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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++){
    cin >> s.at(i);
  }
  int m;
  cin >> m;
  vector<string> t(m);
  for(int i=0; i<m; i++){
    cin >> t.at(i);
  }
  
  int res = 0;
  for (string str: s){
    int cnt = 0;
    for(int i=0; i<n; i++){
      if(str == s.at(i)) cnt++;
    }
    for(int i=0; i<m; i++){
      if(str == t.at(i)) cnt--;
    }
    res = max(res, cnt);
  }
  
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007


void solve(void)
{
  string str;
  cin>>str;
  int N = str.size()/2;
  int count = 0;
  for (int i = 0; i < N; i++)
  {
    if(str[i] != str[str.size()-1-i]) count++;
  }

  cout<<count<<endl;
  
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

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

int main() { 
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll s1,s2,s3,s4;
  s1=a*c; 
  s2=a*d; 
  s3=b*c; 
  s4=b*d; 
  ll ans=max(max(s1,s2),max(s3,s4));
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 3644
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=[int(input()) for i in range(n)]

f="first"
s="second"
for i in range(n):
    if a[i]%2==1:
        print(f)
        break
else:
    print(s)

Measured memory_bytes: 13460
"use strict";
function main(input) {
    const line = input.split("\n");
    const N = parseInt(line[0]);
    const p = line[1].split(" ").map(Number);
    let cnt = 0;
    for (let i = 0; i < N; i++) if (p[i] !== i + 1) cnt++;
    console.log(cnt <= 2 ? "YES" : "NO");
    return;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29556
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    map<int, int> m;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        m[x]++;
    }
    map<int, int> :: iterator it;
    ll ans = 0;
    for(it = m.begin(); it != m.end(); it++){
        if(it->first < it->second){
            ans+=it->second - it->first;
        }
        else if(it->first > it->second){
            ans+=it->second;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4736