akhauriyash/Code-Regression huggingface dataset:
/*  -*- coding: utf-8 -*-
 *
 * b.cc: D: 11
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

typedef long long ll;
const ll MOD = 1000000007;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;

/* global variables */

int used[MAX_N + 2];
ll fs[MAX_N + 2], invfs[MAX_N + 2];

/* subroutines */

ll powmod(ll a, ll n) {  // a^n % MOD
  ll pm = 1LL;
  while (n > 0LL) {
    if ((n & 1LL) != 0LL) pm = (pm * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return pm;
}

inline ll comb(int n, int k) {
  if (n < k) return 0LL;
  return fs[n] * invfs[k] % MOD * invfs[n - k] % MOD;
}

/* main */

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

  memset(used, -1, sizeof(used));

  int al, ar;
  for (int i = 0; i <= n; i++) {
    int ai;
    scanf("%d", &ai);
    if (used[ai] >= 0) {
      al = used[ai], ar = i;
      break;
    }
    used[ai] = i;
  }
  //printf("al=%d, ar=%d\n", al, ar);

  fs[0] = invfs[0] = 1;
  for (int i = 1; i <= n + 1; i++) {
    fs[i] = fs[i - 1] * i % MOD;
    invfs[i] = powmod(fs[i], MOD - 2);
  }

  int m = al + n - ar;
  for (int k = 1; k <= n + 1; k++) {
    ll ans = (comb(n + 1, k) + MOD - comb(m, k - 1)) % MOD;
    printf("%lld\n", ans);
  }
  return 0;
}


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

long jump(long arr[],long n,long k){
	long dp[100004];
 //initialization
  dp[0]=0;
  
 for(int i=1;i<n;i++){
 	long ans=LONG_MAX;
	for(long j=1;j<=k;j++){
		if(i-j<0)break;
		ans=min(ans,abs(arr[i]-arr[i-j])+dp[i-j]);
	}
	dp[i]=ans;
 }
 
    return dp[n-1];
}


int main(){
  //memset(dp,-1,sizeof(dp));
	long n;
	cin>>n;
  	long k;
  	cin>>k;
	long arr[n];
	for(long i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<jump(arr,n,k);
}

Measured memory_bytes: 1792
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let (n, m) = {
        let nm: Vec<_> = st.trim().split(" ").map(|x| x.parse::<i64>().unwrap()).collect();
        (nm[0], nm[1])
    };
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let mut a:Vec<i64> = st.trim().split(" ").map(|x| x.parse().unwrap()).collect();
    let mut result: i64 = a.iter().sum();
    if result <= n {
        println!("{}", n-result);
    } else {
        println!("-1");
    };   
}


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

int main()
{
  string s; cin>>s;
  vector<int> cnt(3);
  for (auto c:s) cnt[c-'a']++;
  int x = 0;
  int y = s.size();
  rep(i, 3) {
    x = max(x, cnt[i]);
    y = min(y, cnt[i]);
  }
  if (x-y > 1) cout << "NO" << endl;
  else cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 512
n=int(input())
b=[bin(int(i))[2:] for i in input().split()]
ind=0
i=0
l=[0]*20
ans=0
tmp=0
for i in range(n):
    if i>0 and ind<n:
        for j in range(len(b[i-1]))[::-1]:
            if b[i-1][j]=="1":
                l[j-len(b[i-1])]-=1
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]-=1
    ans+=ind-i
    while ind<n:
        for j in range(len(b[ind]))[::-1]:
            if b[ind][j]=="1":
                l[j-len(b[ind])]+=1
        if 2 in l:
            break
        else:
            ind+=1
            ans+=1
print(ans)

    










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

const int S_MAX = 1e5*2;
const int K = 2019;
int dp[2][K];

int main() {

    // input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    string S;
    cin >> S;
    int s = S.size();
  
    int ans = 0;
    
    dp[0][S.at(0) - '0'] = 1;
    for(int i=1; i<s; i++){
        int x = S.at(i) - '0';
        dp[1][x]++;
        for(int j=0; j<K; j++){
            dp[1][(j*10+x)%K] += dp[0][j];
        }
        ans += dp[1][0];
        for(int j=0; j<K; j++){
          dp[0][j] = dp[1][j];
          dp[1][j] = 0;
        }
    }
    
    cout << ans << endl;
    
}



Measured memory_bytes: 3708
import java.util.Scanner;

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



Measured memory_bytes: 26416
#include<stdio.h>

#include<queue>
#include<string.h>
#include<iostream>
using namespace std;
struct PP{
	int x;
	int y;
	int Z;
	int c;
};
char s[1002][1002],C[11]={"0123456789"};
int A[1002][1002],d;
int main(){
	PP S;
	queue<PP> P;
	int  w,h;
	int d=0,i=0,j=0,l=-1;
	int x[4]={ 1, 0,-1,0};
	int y[4]={ 0 ,1,0,-1};
	scanf("%d %d %d",&h,&w,&d);
	//memset(A,0,sizeof(A));
		for(i=0;i<h;i++){
		scanf("%s",s[i]);
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){

		if(s[i][j]=='S'){
			S.x=j;
			S.y=i;
			S.Z=0;
			S.c=1;
			A[S.y][S.x]=1;
			P.push(S);
		}
		}
	}
	while(1){
		l++;
		
		if(l==4) {
			l=0;
			P.pop();
		}
		S=P.front();

		S.x+=x[l];
		S.y+=y[l];
		S.Z++;
		if(s[S.y][S.x]=='X'||S.y==h||S.x==w||S.x==-1||S.y==-1){
		continue;
		}
		if(A[S.y][S.x]==1){
			continue;
		}
				A[S.y][S.x]=1;
		if(C[S.c]==s[S.y][S.x]){
				S.c++;
				if(S.c==d+1){
				break;
				}
				while(!P.empty()){
				P.pop();
				
				}
			memset(A,0,sizeof(A));
			l=-1;
		

		} 
		P.push(S);
	}
	printf("%d\n",S.Z);
	return 0;
}

Measured memory_bytes: 6116
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
n=int(input())
l1=make_divisors(n-1)
l2=make_divisors(n)[2:]
for i in l2:
  j=n/i
  while j%i==0:
    j/=i
  if j%i==1 and n/i not in l1:
    l1.append(n/i)
print(len(l1))

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;

int n,r[4001],g[4001],b[4001],ans;
string s;

signed main() {
    cin >> n >> s;
    rep(i,n) {
        if (s[i] == 'R') r[i]++;
        if (s[i] == 'G') g[i]++;
        if (s[i] == 'B') b[i]++;
    }
    repm(i,n-1) {
        r[i] += r[i+1];
        g[i] += g[i+1];
        b[i] += b[i+1];
    }
    rep(i,n-2) repo(j,i+1,n-1) {
        if (s[i] != s[j]) {
            set<char> st;
            st.insert(s[i]);
            st.insert(s[j]);
            if (st.count('R') == 0) {
                ans += r[j+1];
                if (j + (j-i) < n) {
                    if (s[j+(j-i)] == 'R') --ans;
                }
            }
            if (st.count('G') == 0) {
                ans += g[j+1];
                if (j + (j-i) < n) {
                    if (s[j+(j-i)] == 'G') --ans;
                }
            }
            if (st.count('B') == 0) {
                ans += b[j+1];
                if (j + (j-i) < n) {
                    if (s[j+(j-i)] == 'B') --ans;
                }
            }
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 3700
#include <bits/stdc++.h>
 
using namespace std;
 
#define x first
#define y second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
 
const ll MOD = 1e9+7;
const ll INF = 1e9+5;
 
int main() {
	int n, m, a, b, c, d, e;
	string s, t, r;
	cin >>a>>b;
  for (int i=0 ; i<a ; i++) s+=char(b+'0');
  for (int i=0 ; i<b ; i++) t+=char(a+'0');
  cout <<min(s, t)<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int ret;

        if (n % k == 0) {
            ret = 0;
        } else {
            ret = 1;
        }

        System.out.println(ret);
    }
}

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

int main() {
    using vi = vector<long>;
    
    long n,m,x;
    cin >> n >> m >> x;
    vi c(n);
    vector<vi> a(n);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            long aa;
            cin >> aa;
            a[i].push_back(aa);
        }
    }
    long min = 1000000000;

    for (int bit = 0; bit < (1<<n); ++bit) {
        vi xx(m,x);
        long cost = 0;
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                cost += c[i];
                rep(j,m){
                    xx[j] -= a[i][j];
                }
            }
        }
        int check = 0;
        rep(i,m){
            if(xx[i] > 0){
                check = 1;
                break;
            }
        }
        if(check==0&&cost<min){
            min = cost;
        }
    }
    if(min == 1000000000){
        cout << -1 << endl;
    }else{
        cout << min << endl;
    }
}

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

h = [0] + [int(i) for i in input().split()]


cost_list = [[] for i in range(N+1)]
cost_list[1].append(0)
for i in range(1, N):
    cost = min(cost_list[i])
    cost_list[i+1].append(cost + abs(h[i+1] - h[i]))
    if i < N-1:
        cost_list[i+2].append(cost + abs(h[i+2] - h[i]))
print(min(cost_list[N]))


Measured memory_bytes: 59896
#include <stdio.h>
int t[24][3]={
{1,2,3},{1,3,5},{1,5,4},{1,4,2},
{2,1,4},{2,4,6},{2,6,3},{2,3,1},
{3,1,2},{3,2,6},{3,6,5},{3,5,1},
{4,1,5},{4,5,6},{4,6,2},{4,2,1},
{5,1,3},{5,3,6},{5,6,4},{5,4,1},
{6,2,4},{6,4,5},{6,5,3},{6,3,2}
},i,j,a,b,f,n,N[100][7];
int h(x,y){
    for(a=0;a<24;a++)
    if(N[x][1]==N[y][t[a][0]]&&
       N[x][2]==N[y][t[a][1]]&&
       N[x][3]==N[y][t[a][2]]&&
       N[x][4]==N[y][7-t[a][2]]&&
       N[x][5]==N[y][7-t[a][1]]&&
       N[x][6]==N[y][7-t[a][0]])
       f=1;
     return 0;
}
int main(void){
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=1;j<7;j++){
            scanf("%d",&N[i][j]);
        }
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            h(i,j);
        }
    }
    printf("%s\n",f==1?"No":"Yes");
}

Measured memory_bytes: 1860
import math

A, B, C, D = map(int, input().split())

lcm = C * (D // math.gcd(C, D))

cntA = (A - 1) // C + (A - 1) // D - (A - 1) // lcm
cntB = B // C + B // D - B // lcm
ans = B - A + 1 - (cntB - cntA)
print(ans)

Measured memory_bytes: 9156
//delicious QYF
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,M,f[100004];
ll a[100004];
vector <ll> v[100004];
int Find(int x){return x==f[x]?x:f[x]=Find(f[x]);} 
void Union(int x,int y){x=Find(x),y=Find(y);f[x]=y;}
int main(void){
	cin>>N>>M;
	for (int i=0;i<N;i++){
		cin>>a[i];
		f[i]=i;
	}
	for (int i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		Union(x,y);
	}
	for (int i=0;i<N;i++)
		v[Find(i)].push_back(a[i]);
	int num=0;
	ll ans=0;
	vector <ll> cnts;
	for (int i=0;i<N;i++)
		if (!v[i].empty()){
			sort (v[i].begin(),v[i].end());
			num++;
			ans+=v[i][0];
			for (int j=1;j<v[i].size();j++)
				cnts.push_back(v[i][j]);
		}
	int needed=num-2;
	if (num==1){
		puts("0");
		return 0;
	}
	if (needed>int(cnts.size())){
		puts("Impossible");
		return 0;
	}
	sort (cnts.begin(),cnts.end());
	for (int i=0;i<needed;i++)
		ans+=cnts[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>

using namespace std; 

int n;
int s[111];
int tot;

int main(void)
{
	
	int max = -1;
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &s[i]);
		tot += s[i];
	}
	int check = tot;
	if (tot % 10 != 0)
	{
		printf("%d\n", tot);
		return false;
	}
	sort(s + 1, s + 1 + n);
	for (int i=1; i<=n; i++)
		if (s[i] % 10 != 0)
		{
			tot -= s[i];
			break;
		}
	if (check == tot)
		printf("0\n");
	else printf("%d\n", tot);
	return false;


}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;



struct Node{
  ll a;
  ll b;
  bool operator< (const Node &r) const{
    if(b != r.b) return b < r.b;
    return a < r.a;
  }
};

int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<pair<ll, ll>> v;
  rep(i, n) v.push_back({a[i], b[i]});

  sort(all(v));
  
  ll idx = 0;
  ll sum = 0;
  priority_queue<Node> que;
  for(; idx < n; idx++){
    if(1 < v[idx].first) break;
    que.push({v[idx].first, v[idx].second});
  }

  rep(i, m){
    if(!que.empty()){
      Node node = que.top(); que.pop();
      sum += node.b;
    }
    for(; idx < n; idx++){
      if(i+2 < v[idx].first) break;
      que.push({v[idx].first, v[idx].second});
    }
  }

  cout << sum << endl;



  return 0;
}



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

const ll mod = 1000000007;

ll powmod(ll a, ll n, ll m){ //a^nのmodを計算する
	ll res = 1;
	while (n > 0){
		if(n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

ll facmod(int a, int b, ll m){ //a*(a+1)*...*(b-1)*bのmod
	ll res = 1;
	for(int i = a; i <= b; i++){
		res *= i;
		if(res > mod) res %= mod;
	}
	return res;
}

ll solve(ll k, ll n){ // nCk = s/t % mod == k2/k1について逆元を使ってnCkを出す
	ll k1, k2;
	k1 = facmod(1, k, mod);
	k2 = facmod(n - k + 1, n, mod);
	ll res = powmod(k1, mod - 2, mod); //k1の逆元
	res = res * k2 % mod;
	return res;
}

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int n; cin >> n;
	int a, b; cin >> a >> b;
	ll tmp = powmod(2, n, mod) - 1; //制約なし（何本使ってもいい）時
	ll a1 = solve(a, n), b1 = solve(b, n);
	ll ans = tmp - a1 - b1;
	while(ans < 0) ans += mod;
	cout << ans << endl;
} 

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<iterator>
#include<string>
#include<sstream>
#include <unordered_map>
#include<cmath>
using namespace std;
#define ll long long
int __gcd(int a,int b){return b==0 ? a : __gcd(b,a%b);}
ll __gcd(ll a,ll b){return b==0 ? a : __gcd(b,a%b);}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int _=1;
    while(_--){
        string a,b; cin>>a>>b;
        int n=a.size(),cnt=0;
        for(int i=0;i<n;++i) if(a[i]!=b[i]) ++cnt;
        cout<<cnt<<"\n";
    }
}

Measured memory_bytes: 3792
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
const ll inf = 1000000007;
int main() {
  ll n; cin >>n;
  string s; cin >>s;
  vector<ll> dp(n);
  rep2(i,1,n)if(s[i]=='W')dp[0]++;
  rep2(i,1,n){
    dp[i]=dp[i-1];
    if(s[i]=='W')dp[i]--;
    if(s[i-1]=='E')dp[i]++;
  }
  sort(all(dp));
  cout <<n-1-dp[n-1]<<endl;
}

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

#define F(i, a, b) for (int i = a; i <= b; i ++)
#define add(a, b) ((a) = (a + b) % Mo)

const int N = 55 * 2;
const int Mo = 1e9 + 7;

using namespace std;

int n, Ans;
int a[N], f[N][N][N];

int main() {
	scanf("%d", &n);
	F(i, 1, 2 * n - 1)
		scanf("%d", &a[i]);
	sort(a + 1, a + 2 * n);

	f[1][1][1] = 1;
	F(i, 1, n - 1) {
		int pl = a[n - i] != a[n - i + 1];
		int pr = a[n + i] != a[n + i - 1];
		F(j, 1, i * 2 - 1)
			F(k, 1, j)
				if (f[i][j][k]) {
					int t = j + pl + pr;
					F(p, 1, k + pl - 1)
						add(f[i + 1][t - (k + pl - p) + 1][p], f[i][j][k]);
					add(f[i + 1][t][k + pl], f[i][j][k]);
					F(p, k + pl + 1, t)
						add(f[i + 1][t - (p - k - pl) + 1][k + pl + 1], f[i][j][k]);
				}
	}

	F(j, 1, 2 * n - 1)
		F(k, 1, j)
			add(Ans, f[n][j][k]);

	printf("%d\n", Ans);
}

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

/*
Nの階乗の10^9+7のあまりを求める問題。
i=n-1のとき、
(n-1)! = p * (10^9+7) + c
cはあまり。

i = nのとき、
n * (n-1)! = n * p * (10^9+7) + n * c

よってn!のあまりは、n * cを(10^9+7)でわったときのあまりを計算すればよい。
したがったあまりはそのつど計算できる。
*/

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

    long dev = 1e9 + 7;
    long mod = 1;
    for (int i = 1; i <= N; i++)
    {
        mod = mod * i % dev;
    }
    cout << mod << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
    long maxBinary = 1 << 20;//2進数で32桁かつ全部の桁が1の数
    maxBinary = maxBinary << 12;
    maxBinary--;
    
		long x = long.Parse(Console.ReadLine());

		Console.WriteLine(Convert.ToString(x, 2).PadLeft(32, '0'));

    long y = 0;
    y = x ^ maxBinary;
    Console.WriteLine(Convert.ToString(y, 2).PadLeft(32, '0'));

    y = x << 1;
    y = y & maxBinary;//32桁に制限
    Console.WriteLine(Convert.ToString(y, 2).PadLeft(32, '0'));

    y = x >> 1;

    Console.WriteLine(Convert.ToString(y, 2).PadLeft(32, '0'));
	}
}


Measured memory_bytes: 17956
cnt = 0
a, b, n = map(int, input().split())
w, h = map(int, input().split())

for i in range(1, n):
    mw, mh = map(int, input().split())

    if h < mh and w > mw or h > mh and w < mw:
        cnt += abs(mh - h) + abs(mw - w)
    else:
        cnt += max(abs(h - mh), abs(w - mw))

    w = mw
    h = mh

print(cnt)

Measured memory_bytes: 7692
#include <iostream>
#include <string>

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])    
        cout << "Yes\n";
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n%mod

    X = Y = 1
    for i in range(n - r + 1, n + 1):
        X *= i
        X %= mod
    for i in range(1, r + 1):
        Y *= i
        Y %= mod
    return (X * RepeatingSquare(Y, mod - 2, mod)) % mod

def RepeatingSquare(n, p, mod):
    if p == 0:
        return 1
    elif p%2 == 0:
        t = RepeatingSquare(n, p//2, mod)
        return (t * t) % mod
    return n * RepeatingSquare(n, p - 1, mod)

def solve(mod):
    n, a, b = [int(_) for _ in input().split()]
    nb = cmb(n, b, mod)
    na = cmb(n, a, mod)
    return RepeatingSquare(2, n, mod) - 1 - na - nb

if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    print(solve(MOD)%MOD)


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n);
    int cnt = 0;

    REP(i,0,n) cin >> a[i];
    REP(i,0,n){
        if(a[i]>=k) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
MOD = 10**9 + 7
N, M = map(int,input().split())
a = [int(input()) for k in range(M)]
dp = [0]*(N+2)
dp[0] = 1
for e in a:
    dp[e] = -1
for k in range(N):
    if dp[k] != -1:
        if dp[k+1] != -1:
            dp[k+1] += dp[k]
            dp[k+1] %= MOD
        if dp[k+2] != -1:
            dp[k+2] += dp[k]
            dp[k+2] %= MOD
print(max(0,dp[N]))


Measured memory_bytes: 80740
#include <algorithm>
#include <bitset>
#include <iostream>
#include <vector>

int64_t getResult(const std::vector<std::bitset<1001>> &map, const int w) {
  std::vector<std::vector<int64_t>> scores(map.size());
  for (auto &row : scores) {
    row.resize(w + 1, 0L);
  }
  scores[0][1] = 1;
  static const int64_t NUM = 1000000007L;
  for (int i = 1; i < static_cast<int>(map.size()); ++i) {
    for (int j = 1; j <= w; ++j) {
      if (map[i][j]) {
        scores[i][j] = (scores[i][j - 1] + scores[i - 1][j]) % NUM;
      }
    }
  }
  return scores.back()[w];
}

int main() {
  int h;
  int w;
  std::cin >> h >> w;
  std::vector<std::bitset<1001>> map(h + 1);
  for (int i = 0; i < h; ++i) {
    std::string row;
    std::cin >> row;
    for (int j = 0; j < static_cast<int>(row.size()); ++j) {
      if (row[j] == '.') {
        map[i + 1].set(j + 1);
      }
    }
  }
  std::cout << getResult(map, w) << std::endl;
  return 0;
}


Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
void mmin(int &a, int b) {
	a = min(a, b);
}
void mmax(int &a, int b) {
	a = max(a, b);
}
void sor(vel &v) {
	sort(v.begin(), v.end());
}
int ser(vel &v, int tan) {
	int si = v.size() - 1;
	if (tan == v[si]) {
		return si;
	}
	int lo = 0;
	int up = si;
	while (up - lo > 1) {
		int mi = (lo + up) / 2;
		if (v[mi] <= tan) {
			lo = mi;
		}
		else {
			up = mi;
		}
	}
	return lo;
}
signed main() {
	int n, li;
	cin >> n >> li;
	vel x(2 * n);
	vel y(2 * n);
	vel d(2 * n);
	for (int i = 0; i < 2*n; i++) {
		cin >> x[i] >> y[i] >> d[i];
	}
	vel mhx = x;
	vel mhy = y;
	vel mhd = d;
	sor(mhx);
	sor(mhy);
	sor(mhd);
	int kox=1;
	int koy=1;
	int kod=1;
	for (int i = 1; i < 2*n; i++) {
		if (mhx[i] != mhx[kox - 1]) {
			mhx[kox] = mhx[i];
			kox++;
		}
		if (mhy[i] != mhy[koy - 1]) {
			mhy[koy] = mhy[i];
			koy++;
		}
		if (mhd[i] != mhd[kod - 1]) {
			mhd[kod] = mhd[i];
			kod++;
		}
	}
	vel hx(kox);
	vel hy(koy);
	vel hd(kod);
	for (int i = 0; i < kox; i++) hx[i] = mhx[i];
	for (int i = 0; i < koy; i++) hy[i] = mhy[i];
	for (int i = 0; i < kod; i++) hd[i] = mhd[i];
	vvvel di(kox, vvel(koy, vel(kod, 0)));
	for (int i = 0; i < n; i++) {
		int sx = ser(hx, x[2 * i]);
		int sy = ser(hy, y[2 * i]);
		int sd = ser(hd, d[2 * i]);
		int tx = ser(hx, x[2 * i+1]);
		int ty = ser(hy, y[2 * i+1]);
		int td = ser(hd, d[2 * i+1]);
		di[sx][sy][sd]++;
		di[tx][ty][sd]++;
		di[sx][ty][td]++;
		di[tx][sy][td]++;
		di[tx][sy][sd]--;
		di[sx][ty][sd]--;
		di[sx][sy][td]--;
		di[tx][ty][td]--;
	}
	vvvel su(kox, vvel(koy, vel(kod, 0)));
	int ans = 0;
	for (int i = 1; i < kox; i++) {
		for (int j = 1; j < koy; j++) {
			for (int k = 1; k < kod; k++) {
				int xx = di[i - 1][j - 1][k - 1];
				xx += su[i - 1][j][k] + su[i][j - 1][k] + su[i][j][k - 1];
				xx -= su[i - 1][j - 1][k] + su[i][j - 1][k - 1] + su[i - 1][j][k - 1];
				xx += su[i - 1][j - 1][k - 1];
				su[i][j][k] = xx;
				if (xx >=li) {
					ans += (hx[i] - hx[i - 1])*(hy[j] - hy[j - 1])*(hd[k] - hd[k - 1]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 19476
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
const int MAX_N=100001;
vector<pair<int, int> > edge;
ll N,M;
int par[MAX_N];  //親
ll sizes[MAX_N]; //木の深さ
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        sizes[i] = 1;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}
//併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(par[x] > par[y]) swap(x, y); // merge technique
    par[y] = x;
    sizes[x] += sizes[y];
    }

bool same(int x,int y){
    return find(x)==find(y);
}

void solve(){
    init(N);
    ll ans[MAX_N];
    ans[M-1]=(ll)(N*(N-1)/2);
    for(int i=M-1;i>0;i--){
        int a=edge[i].first;
        int b=edge[i].second;
        if(!same(a,b)){
        ans[i-1]=ans[i]-(ll)(sizes[find(a)]*sizes[find(b)]);
        unite(a,b);
        }
        else ans[i-1]=ans[i];
    }
    for(int i=0;i<M;i++) cout<<ans[i]<<'\n';
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    for(int i=0;i<M;i++) {
        int a,b;
        cin>>a>>b;
        a=a-1;
        b=b-1;
        edge.push_back(make_pair(a,b));
    }
    solve();
    return 0;
}


Measured memory_bytes: 4212
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

VS vs;
VVI vi;
void dfs(int n, int d){
  REP(i,d) cout << ".";
  cout << vs[n] << endl;
  for(int i: vi[n])
	dfs(i, d+1);
}

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

  int N; cin >> N;
  vs.assign(N, "");
  vi.assign(N, VI());
  REP(i,N){
	int k; cin >> k;
	cin >> vs[i];
	if(i != 0)
	  vi[k-1].PB(i);
  }

  dfs(0, 0);
  
  return 0;
}

Measured memory_bytes: 1412
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ARC094C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var ABC = ss.Next(int.Parse, 3);
            var max = ABC.Max();
            var inc2 = ABC.Sum(x => (max - x) / 2);
            var dec1 = ABC.Count(x => x % 2 == max % 2) % 3;
            sw.WriteLine(inc2 + dec1);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;
const int MOD = 1e9;
vector<int> adj[200005];
int n,q;
int en[200005];
int ex[200005];
/*void dfs1(int par, int u)
{
	en[u]=(++curr);
	for(int x:adj[u])
	{
		if(x==par)
			continue;
		dis[x]=dis[u]+1;
		dfs1(u,x);
	}
	ex[u]=curr;
}
bool isancestor(int x,int y)
{
	if(en[x]<=en[y] && ex[x]>=ex[y])
		return true;
	return false;
}*/
int32_t main()
{       
	IOS;
    string s;
    cin>>s;
    n=s.length();
    int func[n];
    vector<int> vec(2019,0);
    int base=1;
    int curr=0;
    vec[curr]++;
    for(int i=0;i<n;i++)
    {
    	int add=s[n-1-i]-'0';
    	curr=(curr+base*add)%2019;
    	base=(base*10)%2019;
        vec[curr]++;
    }

   // for(int i=0;i<2019;i++)
    //	cout<<vec[i]<<endl;
    int ans=0;
    for(int i=0;i<2019;i++)
       ans+=(vec[i]*(vec[i]-1))/2;

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

Measured memory_bytes: 8452
n = int(input())

ps = [2]
for i in range(3, 100, 2):
    f = True
    for j in range(2, i):
        if i < j * j:
            break
        elif i % j == 0:
            f = False
            break
    if f:
        ps.append(i)

ls = [0 for _ in range(len(ps))]
for i in range(2, n + 1):
    k = i
    for j in range(len(ps)):
        while k % ps[j] == 0:
            ls[j] += 1
            k //= ps[j]

ans = 1 if 74 <= ls[0] else 0

for i in range(len(ps)):
    for j in range(len(ps)):
        if i == j:
            continue
        if 2 <= ls[i] and 24 <= ls[j]:
            ans += 1
        if 4 <= ls[i] and 14 <= ls[j]:
            ans += 1

for i in range(len(ps)):
    for j in range(len(ps) - 1):
        if i == j:
            continue
        for k in range(j + 1, len(ps)):
            if i == k:
                continue
            if 2 <= ls[i] and 4 <= ls[j] and 4 <= ls[k]:
                ans += 1
print(ans)

Measured memory_bytes: 40048
plus, zero, minus, getNum = map(int, input().split())

ans = 0

if getNum <= plus:
    ans += getNum
    print(ans)
    quit()
else:
    ans += plus
    getNum -= plus

if getNum <= zero:
    print(ans)
    quit()
else:
    getNum -= zero

if getNum <= minus:
    ans -= getNum
else:
    ans -= minus
print(ans)

Measured memory_bytes: 8996
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

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

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

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

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

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)5e3 + 7;
const int MAXN = (int)3e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

void solve() {
	int k; cin >> k;
	string s; cin >> s;
	if (size(s) <= k) {
		cout << s;
		return;
	}
	for (int i = 0; i < k; i++)
		cout << s[i];
	cout << "...";
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long int LL;
vector<int> path[100005];
int num[100005];
queue<pair<int,int> > q1;

int check(int a){
	int i,j,k;
	int s=0;
	int b,c;
	q1.push(make_pair(a,1));
	while(!q1.empty()){
		a=q1.front().first,b=q1.front().second,q1.pop();
		if(num[a]!=0){
			if(num[a]!=b)s=1;
			continue;
		}
		num[a]=b;
		for(i=0;i<path[a].size();i++){
			q1.push(make_pair(path[a][i],3-b));
		}
	}
	return s;
}

int main(){
	LL n,m;
	int i,j,k;
	int a,b,c;
	LL t[5]={0};
	LL s=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a>>b;
		a--,b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	for(i=0;i<n;i++){
		if(num[i]==0){
			if(path[i].size()==0)t[2]++;
			else t[check(i)]++;
		}
	}
	s=(t[0]+t[1])*(t[0]+t[1]);
	s+=t[0]*t[0];
	s+=n*n-(n-t[2])*(n-t[2]);
	cout<<s<<endl;
	return 0;
}



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

int main() {

  int len;
  cin >> len;

  int j = 0, n, seq[len];
  while(cin >> n) {
    seq[j++] = n;
    if (len == j) break; 
  }

  for (int i = len-1; i >= 0; i--) {
    cout << seq[i];
    if (i != 0) cout << " ";
    else cout << endl; 
  }

}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >>N;
  long long int H[N];
  for(int i=0;i<N;i++)
    cin >> H[i];
  
  for(int i=N-1;i>0;i--){
  if(H[i]<H[i-1]){
    if(H[i-1]-H[i]==1)
      H[i-1]--;
    else{
      cout <<"No"<<endl;
      return 0;
    }}
    
  }
  cout <<"Yes"<<endl;

  
    
  return 0;
 }


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007
 
// // for using in pairs
#define F first
#define S second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T>& v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2>& p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

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

template<typename T>
istream& operator>>(istream &istream, vector<T>& a)
{
	for (auto &it : a)
		istream >> it;
	return istream;
}

// Utility functions.

int GCD(int a, int b)
{
	if (!b)
		return a;
	return GCD(b, a % b);
}

int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}

int modpow(int x, int n, int m = MOD)
{
	if (n == 0) return 1 % m;
	long long u = modpow(x, n / 2, m);
	u = (u * u) % m;
	if (n % 2 == 1)
		u = (u * x) % m;
	return u;	
}

//////////////////// START CODE HERE ///////////////////////////


void solve(int tc)
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * d);
	ans = max(ans, b * c);

	cout << ans;
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


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

int main(){
    ll n;
    cin>>n;
/*    ll i,j,r=-1,c=1e12+1;
    for(i=1;i<=n;i++){
    	for(j=1;j<=n;j++){
    		if(i*j==n&&max(i,j)-min(i,j)<max(r,c)-min(r,c)){
    			r=i;c=j;
			}
		}
	}
	cout<<r+c-2<<endl;*/
	ll i,j,r=-1,c=1e12+1;
	for(i=1;i<=sqrt(n);i++){
		if(n%i==0&&max(i,n/i)-min(i,n/i)<max(r,c)-min(r,c)){
			r=i;c=n/i;
		}
	}
	cout<<r+c-2<<endl;
	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans=0;

  int n; cin >> n;
  int k; cin >> k;
  vector<int> a(n); REP(i, n) cin >> a[i];
  vector<int> cnt(n+1, 0);
  vector<int> b=a;
  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());
  int cc = 1* b.size();

  for (int i=0; i<n; i++) {
    cnt[a[i]]++;
  }
  sort(cnt.begin(), cnt.end());
  cnt.erase(cnt.begin(), cnt.end()-cc);
  for (int i=0; i<cc-k; i++) {
    ans += cnt[i];
  }

  cout << ans << endl;
}

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


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto idx(0); idx < n; ++idx) {
    cin >> a[idx];
  }
  auto r = accumulate(a.cbegin() + 1, a.cend(), a[0], [](int x, int y){ return x ^ y; });
  if (r == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define cp_io ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long int
#define oo 1000000010
#define MAX 1000000
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define nl "\n"

int main()
{
    cp_io;
    #ifndef ONLINE_JUDGE
    freopen("z_input.txt","rt",stdin);
    freopen("z_output.txt","wt",stdout);
    #endif
    ll x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    ll p = k;
    ll q = abs(x);
    if(x%d==0)
    {
        k -= x/d;
        if(k>0){
            if(k%2==0)
                cout << 0;
            else
                cout << d;
        }
        else
            cout << abs(x - p*d);
    }
    else
    {
        k -= x/d;
        x = x - d*(x/d);
        x = abs(x); 
        if(k>0){
            if(k%2==0)
                cout << x;
            else
                cout << abs(x-d);
        }
        else
            cout << abs(q - p*d);
    }
    
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>


int main(void){
	int a , b ;
	scanf("%d %d",&a,&b);
	if(a>b){
		printf("a > b\n");
	}else if(a<b){
		printf("a < b\n");
	}else{printf("a == b\n");}

	return 0;
}

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

int main(){
    int N,X,T;
    cin>>N>>X>>T;
    
    cout<<((N+X-1)/X)*T<<endl;
}


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

int main() {
	string s,t;
	cin >> s >> t;
	int a[26]={},b[26]={};
	for (char c:s) {
		a[c-'a']++;
	}
	for (char c:t) {
		b[c-'a']++;
	}
	sort(a,a+26);
	sort(b,b+26);
	for (int i=0; i<26; i++) {
		if ( a[i]!=b[i] ) {
			cout << "No" << '\n';
			return 0;
		}
	}
	cout << "Yes" << '\n';
    return 0;
}

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

#define INF 3223372036854775807LL

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<long long> a(n + 1);
	for (int i = 0; i < n + 1; i++) {
		cin >> a[i];
	}

	if (n == 0) {
		cout << (a[0] == 1 ? 1 : -1) << endl;
		return 0;
	} else {
		if (a[0] != 0) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<long long> p(n + 1);
	p[0] = 1;
	for (int i = 1; i < n + 1; i++) {
		if (a[i] > p[i - 1] * 2) {
			cout << -1 << endl;
			return 0;
		} else {
			p[i] = min(INF, p[i - 1] * 2 - a[i]);
		}
	}

	vector<long long> pw(n + 1);
	pw[0] = 1;
	for (int i = 1; i <= n; i++) {
		pw[i] = min(INF, pw[i - 1] * 2);
	}

	vector<long long> node(n + 1);
	for (int i = n - 1; i >= 0; i--) {
		if (pw[i] == INF) {
			node[i] = node[i + 1] + a[i + 1];
		} else {
			node[i] = min(node[i + 1] + a[i + 1], pw[i] - a[i]);
		}
	}

	vector<long long> ans(n + 1);
	ans[0] = 1;
	for (int i = 1; i <= n; i++) {
		ans[i] = min(p[i - 1] * 2 - a[i], node[i]);
	}

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

	return 0;
}


Measured memory_bytes: 7212
/**
*	created: 22.08.2020 21:11:41
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int h, w, m; cin >> h >> w >> m;
    map<int,int> mph;
    map<int,int> mpw;
    set<P> v;
    rep(i,m) {
        int a, b; cin >> a >> b;
        mph[a]++;
        mpw[b]++;
        v.insert(make_pair(a,b));
    }
    int hmax = -1, wmax = -1;
    for (auto p : mph) chmax(hmax,p.second);
    for (auto p : mpw) chmax(wmax,p.second);
    vector<int> hm, wm;
    for (auto p : mph) if (p.second == hmax) hm.push_back(p.first);
    for (auto p : mpw) if (p.second == wmax) wm.push_back(p.first);
    if (hm.size() * wm.size() > m) cout << hmax + wmax << endl;
    else {
        bool ok = false;
        rep(i,hm.size()) rep(j,wm.size()) {
            if (!v.count(make_pair(hm[i],wm[j]))) ok = true;
        }
        if (ok) cout << hmax + wmax << endl;
        else cout << hmax + wmax - 1 << endl;
        
    }
    return 0;
}

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

int main() {
	for(int n, m; cin >> n >> m && n * m!= 0; ) {
		vector<int> taro(n), hanako(m);
		
		for(int i = 0; i < n; i++) {
			cin >> taro[i];
		}
		
		for(int i = 0; i < m; i++) {
			cin >> hanako[i];
		}
		
		int ts = accumulate(taro.begin(), taro.end(), 0);
		int hs = accumulate(hanako.begin(), hanako.end(), 0);
		int t = 101, h = 101;
		
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(ts - taro[i] + hanako[j] == hs - hanako[j] + taro[i] &&
           taro[i] + hanako[j] < t + h) {
					t = taro[i];
					h = hanako[j];
				}
			}
		}
		
		if(t == 101 && h == 101) {
			cout << -1 << endl;
		} else {
			cout << t << " " << h << endl;
		}
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define N 50
using namespace std;
int x,y,n;  
char a[N+N+5][N+5];  
void make(char x,char y,int num){
    for(int i=n+1;i<=n+N;i++) 
        for(int j=1;j<=N;j++)  
            if(((i-n)&1)||(j&1))a[i][j]=x;
    for(int i=n+1;i<=n+N;i++) 
        for(int j=1;j<=N;j++)if(a[i][j]==0)
            if(num)a[i][j]=y,num--;else a[i][j]=x;
}  
int main(){
    scanf("%d%d",&x,&y);
    n=0;
    if(x==1)make('.','#',y);  
    else if(y==1)make('#','.',x);  
    else{  
        make('.','#',y-1);  
        n+=N;make('#','.',x-1);  
    }  
    printf("%d %d\n",n+N,N);  
    for(int i=1;i<=n+N;i++)puts(a[i]+1);
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  int a;
  int count5=0,count7=0;
  for(int i=0;i<3;i++){
   cin>>a;
    if(a==5)count5++;
    else if(a==7)count7++;
  }
  if(count5==2&&count7==1)
    cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using pii = pair< int, int>;


bool flag[1000000];

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

    deque< pii> deq;
    deq.push_back(make_pair(1, 1));

    while (true) {
        pii z = deq.front();
        deq.pop_front();

        if (flag[z.second]) continue;
        flag[z.second] = true;
        
        if (z.second == 0) {
            printf("%d\n", z.first);
            break;
        }
        deq.push_back(make_pair(z.first + 1, z.second + 1));
        deq.push_front(make_pair(z.first, z.second * 10 % n));
    }
}

Measured memory_bytes: 1152
#include<algorithm>
#include<cstdio>
#define s(A) std::sort(A,A+10);
main(){
int Z[20];
for(int i=0;i<20;)
scanf("%d",Z+i++);
s(Z);
s(Z+10);
printf("%d %d\n",Z[7]+Z[8]+Z[9],Z[17]+Z[18]+Z[19]);
}

Measured memory_bytes: 0