akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector.Unboxed as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Char
import qualified Data.List as L

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

 
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getList :: IO [Int]
getList = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readmat :: Int -> IO [[Int]]
readmat rows = replicateM rows getList

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

unionUF :: (Eq a, Ord a) => a -> a -> UF a -> UF a
unionUF l r uf@(UF m) = let lp = findUF l uf
                            rp = findUF r uf
                        in if lp == rp
                           then uf
                           else if size l uf < size r uf
                                then UF $ M.update (const $ Just rp) lp m
                                else UF $ M.update (const $ Just lp) rp m

findUF :: (Eq a, Ord a) => a -> UF a -> a
findUF x uf@(UF m) = let px = m M.! x
                      in if px == x
                         then px
                         else findUF px uf -- TODO 貼り直し

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

genbit :: Int -> [[Int]]
genbit 0 = []
genbit 1 = [[0],[1]]
genbit len = do
  x <- [0,1]
  map (x:) $ genbit (len-1)

base :: Int
base = 10 ^ 9 + 7

forn :: (Num a, Enum a, Monad m) => a -> (a -> m b) -> m [b]
forn x = forM [0..(x-1)]

count :: (Eq a) => a -> [a] -> Int
count y = length . filter (== y)
f :: Int -> Int 
f 0 = 0
f x = if even x then 1+f (x `div` 2)
               else 0
main :: IO()
main = do
  [n] <-getList 
  xs <- getList
  dump xs
  let ys = fmap f xs
  dump ys
  print $ sum ys



Measured memory_bytes: 1148
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,i,j,x,sum=0,sum2=0,mul=1,maxi = INT_MIN;
    cin>>n;
    vector<ll>vi;
    for(i = 0 ;i<n;i++)
    {
        cin>>x;
        vi.push_back(x);
    }
    for(i =1 ;i<n ;i++)
    {
        if(vi[i]>vi[i-1])
        {
            maxi=max(sum,maxi);
            sum=0;
        }
        else
            sum++;
    }
    maxi = max(sum,maxi);
    cout<<maxi<<endl;
}


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

#define print cout <<
#define printl(s) cout << s << endl;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template <typename T>
vector<T> getValues(int num){
    vector<T> values(num);
    for(int i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

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


Measured memory_bytes: 3524
//	http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2415733#1

#include <stdio.h>

#define Rep(i,N) for(int i = 0;i < N;i++)
 
int main( void ){

	int n;			// ????????±??????????????° N(3???N???5000)
	int d[ 5000 ];	// ?????????????????§?????????????£????????????° pi(0???pi???3)
	int w[ 5000 ];	// 
	int cnt;		// ?£????????????°
	int total;		//
	int i, j;

	while ( 1 ) {
		scanf( "%d", &n );	// ???????????±??????????????°????????\???

		if ( n == 0 ) {
			break;			// ??\???????????????
		}

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

		cnt = 5000 * 3 * 2;		// ??¨????????????????£????????????°????????§???????¨????
		
		for ( j = 0 ; j < w[ 0 ] + 1 ; j++ ) {
			total = 0;
			
			w[ 0 ] -= j;
			
			total += j;
			
			for ( i = 0 ; i < n - 1 ; i++ ) {
				total += ( w[ i ] * 2 );
				w[ i + 1 ] -= w[ i ];
				w[ i ] = 0;
				
				if ( w[ i + 1 ] < 0) {
					w[i + 1] = 0;
				}
			}
			
			total += w[ n - 1 ];
			
			if ( cnt > total ) {
				cnt = total;
			}
			
			// ????\???¨????????° w ??? d ??????????????????
			for ( i = 0 ; i < n ; i++ ) {
				w[ i ] = d[ i ];
			}
		}
		
		printf( "%d\n", cnt );
		
		break;
	}
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <unordered_map> 

using namespace std;


vector<int> str2num(string str) {

	int num_int=0;

	unordered_map<char, int> table;
	vector<int> ret(str.size());

	for (int i = 0; i < str.size(); i++) {

		auto itr = table.find(str[i]);

		if (itr != table.end()) {
			ret[i] = itr->second;
		}
		else {
			num_int++;
			table[str[i]] = num_int;
			ret[i] = num_int;
		}
	}

	return ret;
}

int main(void) {
	string str;
	cin >> str;
	auto x_num = str2num(str);
	cin >> str;
	auto y_num = str2num(str);

	for (int i = 0; i < x_num.size(); i++) {
		if (x_num[i] != y_num[i]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; ++i)
#define reps(i,a,n) for(int i = (a); i < n; ++i)
using namespace std;


int n,m;
int p[16][16];
int t[16];
int ret = 0;


vector<int> zz[16];
vector<int> vv[16];

void dfs(int a){
    if(a == n){
        ++ret;
    }
    vector<int>& z = zz[a];
    z.clear();

    int w = 0;
    rep(i, a){
        w += p[a][i];
    }
    reps(i, a+1, n){
        w += p[a][i];
        if(p[a][i] == 0) z.push_back(i);        
    }
    if(abs(w) > z.size()) return;

    vector<int>& v = vv[a];
    v.clear();
    if(w < 0){
        rep(i, -w) v.push_back(1);
    }
    if(w > 0){
        rep(i,  w) v.push_back(-1);
    }
    reps(i, abs(w), z.size()) v.push_back((i&1)*2-1);
    /*
    cout << "Z:"; for(auto&zz:z) cout <<zz <<" ";cout << endl;
    cout << "V:"; for(auto&zz:v) cout <<zz <<" ";cout << endl;
    */
    sort(v.begin(), v.end());
    do{
        rep(i, z.size()){
            p[a][z[i]] = v[i];
            p[z[i]][a] = -v[i];
        }
        dfs(a+1);
        rep(i, z.size()){
            p[a][z[i]] = 0;
            p[z[i]][a] = 0;
        }
    }while( next_permutation(v.begin(), v.end()) );
}


int main(){
    while(cin >> n, n){
        memset(p, 0, sizeof(p));
        cin >> m;
        rep(i, m){
            int x,y;
            cin >> x >> y;
            --x; --y;
            p[x][y] = +1;
            p[y][x] = -1;
        }
        rep(i, n){
            t[i] = 0;
            rep(j, n) t[i] += p[i][j];
        }
        ret = 0;
        dfs(0);
        cout << ret << endl;
        // cerr << "FIN" << endl;
    }
}





Measured memory_bytes: 3104
#include <random>
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int n;
  cin >> n;
  vector<int> per(n * n);
  for (int i = 0; i < n * n; i++) {
    cin >> per[i];
    per[i]--;
  }
  vector<vector<int>> dist(n, vector<int>(n, inf)), cost(n, vector<int>(n, 1));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int d = min({i, n - 1 - i, j, n - 1 - j});
      dist[i][j] = d;
    }
  }
  ll ans = 0;
  const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  for (int i = 0; i < n * n; i++) {
    int x = per[i] / n, y = per[i] % n;
    ans += dist[x][y];
    int mi = dist[x][y];
    for (int j = 0; j < 4; j++) {
      int nx = x + dx[j], ny = y + dy[j];
      if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue;
      mi = min(mi, dist[nx][ny] + cost[nx][ny]);
    }
    dist[x][y] = mi;
    cost[x][y] = 0;
    deque<P> que;
    que.push_back({x, y});
    while (!que.empty()) {
      auto p = que.front();
      que.pop_front();
      for (int j = 0; j < 4; j++) {
        int nx = p.first + dx[j], ny = p.second + dy[j];
        if (nx < 0 || n <= nx || ny < 0 || n <= ny) continue;
        int nd = dist[p.first][p.second] + cost[p.first][p.second];
        if (dist[nx][ny] <= nd) continue;
        dist[nx][ny] = nd;
        if (cost[p.first][p.second])
          que.push_back({nx, ny});
        else
          que.push_front({nx, ny});
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7192
n = gets().to_i
a = gets().split.map(&:to_i)
max = -1
min = 1001
for i in 0..(n-1)
        if max < a[i] then
                max = a[i]
        end
        if min > a[i] then
                min = a[i]
        end
end
puts(max-min)

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  int n;
  cin >> n;
  ll sum = 0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){ 
      for(int k=1;k<=n;k++){ 
        sum += gcd(k,gcd(j,i));
      }
    }
  }
  
  cout << sum << endl;
}




Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

map<pair<string, int>, int> get(string s) {
  map<pair<string, int>, int> r;
  int n = s.size();
  for (int i = 0; i < (1 << n); i++) {
    string t0, t1;
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        t1 += s[j];
      } else {
        t0 += s[j];
      }
    }
    reverse(t1.begin(), t1.end());
    r[{t0 + t1, t0.size()}] += 1;
  }
  return r;
};

int main() {
#ifdef LOCAL
  freopen("c.in", "r", stdin);
  freopen("c.out", "w", stdout);
#endif

  int n;
  static char buf[200];
  while (scanf("%d%s", &n, buf) == 2) {
    string p1 = string(buf, buf + n);
    string p2 = string(buf + n, buf + 2 * n);
    reverse(p2.begin(), p2.end());
    auto cnt1 = get(p1);
    auto cnt2 = get(p2);

    ll ans = 0;
    for (auto x : cnt1) {
      ans += x.second * 1LL * cnt2[x.first];
    }

    printf("%lld\n", ans);
    //break;
  }

  return 0;
}


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

int main() {
	string N;
  	cin >> N;
  
  if (N[0] == N[1] && N[1] == N[2]) {
  	cout << "Yes" << endl;
  }
  else if (N[1] == N[2] && N[2] == N[3]) {
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def brick(): 
    N = wczytaj_liste()[0]
    lista_cegiel = wczytaj_liste()
    odp = 0 
    n = 1
    for cegla in lista_cegiel: 
        if cegla == n: 
            n += 1 
        else: 
            odp +=1 
    if odp < N: 
        print(odp)
    else: 
        print('-1')

brick()

Measured memory_bytes: 76492
// JOI14-quest3.cpp : Defines the entry point for the console application.
//
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main(void)
{
	int height, width, cloud[100][100] = { 0 }, output[100][100] = { 0 };

	scanf("%d %d", &height, &width);

	char c;
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			c = getchar();
			if (c == '\n') {
				j--;
				continue;
			}

			if (c == 'c') {
				cloud[i][j] = 1;
				output[i][j] = 0;
			}
			else {
				cloud[i][j] = 0;
			}
		}
	}

	bool success;
	int time;
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			success = false;
			if (cloud[i][j] == 0) {
				for (int k = j; k >= 0; k--) {
					if (cloud[i][k] == 1) {
						success = true;
						time = j - k;
						break;
					}
				}

				if (success == true) {
					output[i][j] = time;
				}
				else {
					output[i][j] = -1;
				}
			}
		}
	}

	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width - 1; j++) {
			printf("%d ", output[i][j]);
		}
		printf("%d\n", output[i][width - 1]);
	}

	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <climits>
#include <map>
using namespace std;
 
static const long long INFTY = (1LL<<32);
 
 
int main() {
    string str;
    cin >> str;
    
    cout << "ABC" << str << endl;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <unordered_map>
#include <iostream>
using namespace std;

vector<string>split(string s, char delim){
  int len = s.length();
  string currStr = "";
  vector<string>retVec;
  for(int i = 0;i<len;i++){
    char ch = s[i];
    if(ch==delim){
      retVec.push_back(currStr);
      currStr = "";
    }else{
      currStr += ch;
    }
  }
  retVec.push_back(currStr);
  return retVec;
}



vector<int>strToIntVec(string s){
  int len = s.length();
  //  s = s.substr(1,len-2);
    vector<string>strVec = split(s,' ');
  vector<int>retVec;
  for(int i=0;i<strVec.size();i++){
    int el = atoi(strVec[i].c_str());
    retVec.push_back(el);
  }
  return retVec;
}
class Sleep{
public:
  int getAwakeMin(int h1, int m1,int h2,int m2,int k){
    int wakeMin = h1*60+m1;
    int sleepMin = h2*60+m2;
    int lstStartMin = sleepMin-k;
    int nMin = lstStartMin-wakeMin;
    return nMin;
  }
};

int main(int argc, const char*argv[]){
  Sleep s;
  string tLn;
  getline(cin,tLn);
  vector<int>tVec = strToIntVec(tLn);
  int nMin = s.getAwakeMin(tVec[0],tVec[1],tVec[2],tVec[3],tVec[4]);
  cout<<nMin<<endl;
  return 0;
}


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

int main() {
    int N, a, b;
    cin >> N;
    cin >> a >> b;

    for (int i = a; i <= b; i++){
        if (i % N == 0) {
            cout << "OK" << endl;
            break;
        }
        if (i == b) cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
	int N;
	vector<int> As;

	cin >> N;

	int a;
	for (int ni = 0; ni < N; ni++) {
		cin >> a;
		As.push_back(a);
	}

	int ans = 0;
	int bi = 1;
	int flag = 1;
	while (1) {
		flag = 1;
		for (int ni = 0; ni < N; ni++) {
			if (As[ni] % 2 == 0) {
				As[ni] /= 2;
				ans++;
				flag = 0;
			}
		}
		if (flag == 1) break;
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
  cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int alice=0;
  int Bob=0;

  for(int i=0;i<N;i++){
  if(i%2==0){
    alice +=a.at(i);
  }
  
  else{
    Bob +=a.at(i);
  }
  }
  cout<<alice-Bob<<endl;
  
   }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define NIL -1

struct Node{
    int left,right,parent;
};
Node oNode[100000];

int depth(int n){
    int cou = 0;
    int p = oNode[n].parent;
    while(p!= NIL){
        p = oNode[p].parent;
        cou++;
    }
    return cou;
}

void print(int node){
    cout << "node " << node <<": ";
    cout << "parent = " << oNode[node].parent << ", ";
    cout <<  "depth = " << depth(node) << ", ";

    if (oNode[node].parent ==NIL) cout << "root, ";
    else if (oNode[node].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";

     cout << "[" ;
     for(int i = 0,left = oNode[node].left;left != NIL;i++, left =oNode[left].right){
         if(i) cout << ", ";
         cout << left;
     }
     cout << "]" << endl;
 
}

int main(){
    int n,m,num,node,root,left;
    cin >> n;

    for (int i =0;i<n;i++){
        oNode[i].parent = NIL;oNode[i].right= NIL;oNode[i].left=NIL;
    }
    for (int i =0;i<n;i++){
            cin >> num >> m;
            for (int j =0;j<m;j++){
                cin >> node;
                if (j ==0){oNode[num].left= node;}
                else {oNode[left].right=node;}
                left = node;
                oNode[node].parent = num;
            }
        }
    for(int i =0;i<n;i++){
        if(oNode[i].parent == NIL){
            root = i;
        }
    }
    
    for(int i= 0;i<n;i++){
        print(i);
    }
        return 0;
}



Measured memory_bytes: 4248
#include <bits/stdc++.h>
//#define int long long
using namespace std;
int main() {
  int h, w, n;
  cin >> h >> w >> n;
  int tile[h][w];
  int y = 0, x = 0;
  bool right = true;
  int number;
  for (int i = 1; i <=n; i++) {
    cin >> number;
    while(number--) {
      tile[y][x] = i;
      
      if(right) x++;
      else x--;
      
      if (x >= w) {
	y++;
	x = w-1;
	right = false;
      }
      if (x < 0) {
	y++;
	x = 0;
	right = true;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j) cout << " ";
      cout << tile[i][j];
    }
    cout << endl;
  }

  return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

template <typename T> void bfs(const vector<vector<T>>& G, int i, vector<bool>& seen, vector<T>& in_dgree, vector<T>& ans) {
    queue<int> q;
    q.push(i);
    seen[i] = true;

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        ans.push_back(v);
        for (auto u : G[v]) {
            --in_dgree[u];
            if ((!seen[u]) && in_dgree[u] == 0) {
                q.push(u);
                seen[u] = true;
            }
        }
    }
}

template <typename T> void topological_sort(const vector<vector<T>>& G, vector<T>& in_dgree) {
    int v = G.size();
    vector<bool> seen(v, false);
    vector<T> ans;
    rep(i, 0, v) {
        if ((!seen[i]) && in_dgree[i] == 0) { bfs(G, i, seen, in_dgree, ans); }
    }
    for (auto v : ans) { cout << v << endl; }
}

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

    int v, e;
    cin >> v >> e;

    vvi G(v);
    vi in_dgree(v, 0);
    rep(i, 0, e) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
        ++in_dgree[t];
    }
    // for (auto v : in_dgree) { cout << v << endl; }

    topological_sort(G, in_dgree);

    return 0;
}


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

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

  vector<int> bc(n);
  rep(i,n) {
    int bi = b[i];
    auto ub = upper_bound(c.begin(), c.end(), bi);
    bc[i] = distance(ub, c.end());
  }

  vector<ll> bcc(n);
  bcc[n-1] = bc[n-1];
  for(int i=n-2; i>=0; i--) bcc[i] = bcc[i+1] + bc[i];
  
  ll ans = 0;
  rep(i,n) {
    int ai = a[i];
    auto ub = upper_bound(b.begin(), b.end(), ai);
    if(ub==b.end()) continue;
    int j = distance(b.begin(), ub);
    ans +=  bcc[j];
  }
  cout << ans << endl;
}


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

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

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){init(mx);}
    void init(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;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 calc(int n,int k){
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
    }
};

int main(){
    int b,w;
    cin>>b>>w;
    ll half=modpow(2,MOD-2);
    ll s=0,t=0;
    Combination comb(b+w);
    for(int i=1;i<=b+w;i++){
        ll ans=(half*(1+s-t+MOD))%MOD;
        cout<<ans<<endl;
        if(i>=w){
            s=(s+comb.calc(i-1,w-1)*modpow(half,i))%MOD;
        }
        if(i>=b){
            t=(t+comb.calc(i-1,b-1)*modpow(half,i))%MOD;
        }
    }
}


Measured memory_bytes: 6912
#include <iostream>

using namespace std;

typedef long long ll;

ll d[20][20];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string x;
        cin >> x;
        int f = 0;
        int g = 0;
        ll u = 0;
        for (auto c : x) {
            if (c == '.') {f = 1; continue;}
            u = u*10+c-'0';
            if (f) g++;
        }
        while (g < 9) {u = u*10+0; g++;}
        int c2 = 0, c5 = 0;
        while (u%2 == 0) {u /= 2; c2++;}
        while (u%5 == 0) {u /= 5; c5++;}
        if (c2 > 18) c2 = 18;
        if (c5 > 18) c5 = 18;
        d[c2][c5]++;
    }
    ll t = 0;
    for (int a2 = 0; a2 < 19; a2++)
    for (int a5 = 0; a5 < 19; a5++)
    for (int b2 = 0; b2 < 19; b2++)
    for (int b5 = 0; b5 < 19; b5++) {
        if (a2+b2 < 18 || a5+b5 < 18) continue;
        if (a2 == b2 && a5 == b5) {
            t += d[a2][a5]*(d[a2][a5]-1);
        } else {
            t += d[a2][a5]*d[b2][b5];
        }
    }
    cout << t/2 << "\n";
}


Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Scanner;

//Walking Santa
public class Main{

	long res, rx, ry;
	int n;
	int[] x, y;
	int[][] p;
	
	void f(int px, int py){
		long max = 0, sum = 0;
		for(int i=0;i<n;i++){
			long len = Math.abs(px-p[i][0])+Math.abs(py-p[i][1]);
			sum+=2*len;
			max = Math.max(max, len);
		}
		if(sum-max < res){
			res = sum-max;
			rx = px; ry = py;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		sc.nextInt(); sc.nextInt();
		n = sc.nextInt();
		x = new int[n]; y = new int[n];
		p = new int[n][2];
		for(int i=0;i<n;i++){
			x[i] = p[i][0] = sc.nextInt(); y[i] = p[i][1] = sc.nextInt();
		}
		Arrays.sort(x);
		Arrays.sort(y);
		res = 1L<<60;
		f(x[(n-1)/2], y[(n-1)/2]);
		f(x[(n-1)/2], y[n/2]);
		f(x[n/2], y[(n-1)/2]);
		f(x[n/2], y[n/2]);
		System.out.println(res);
		System.out.println(rx+" "+ry);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 16000
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最大公約数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 510000;
const int MOD = 1000000007;

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

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

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


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int eat_c = min(c,(a+b)+1);
  int ans = eat_c + b;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define FOR(i,s,e) for(int i=(s);i<=(e);i++)
#define FORD(i,s,e) for(int i=(s);i>=(e);i--)
#define eb emplace_back
#define MAXN 1000009
#define MOD 1000000007
#define mp(x, y) make_pair(x,y)
#define all(v) (v).begin(),(v).end()
#define pb(x) push_back(x)
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second

using namespace std;

typedef unsigned long long LLU;
typedef long double LD;
typedef pair<int,int> PII;
const bool print=false;
typedef long long ll;

template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

ll a, b, c, k;
int main()
{
	cin >> a >> b >> c >> k;
	if(k & 1ll)
		cout << b - a;
	else
		cout << a - b;
}



Measured memory_bytes: 256
input()
S = [int(i) for i in input()]
cnt = 0
for i in range(0, 1000):
  c = (i//100, (i//10)%10, i%10)
  f = 0
  for s in S:
    if s == c[f]:
      f += 1 
      if f==3:break 
  if f==3:cnt += 1
print(cnt)


Measured memory_bytes: 41708
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
using namespace std;
typedef long long ll ;
const long long N = 1e5,OO=0x3f3f3f3f;
ll n,weight,w[105],v[105];
ll dp[105][N+5];

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

    for(int i=0; i<105; i++)
        for(int j=0; j<=N; j++)
            dp[i][j]=1e18;

    dp[0][v[0]]=w[0];

    for(int i=1; i<n; i++)
    {

        for(int j=0; j<=N; j++)
        {
            ll &ret=dp[i][j];
            ret=min(ret,dp[i-1][j]);
            if(v[i]<=j)
            {   
                if(v[i]==j)
                    ret=min(ret,w[i]);
                else 
                ret=min(ret,w[i]+dp[i-1][j-v[i]]);
            }
        }
    }
    for(int i=N; i>=0; i--)
        if(dp[n-1][i]<=weight)
        {
            cout<<i<<endl;
            break;
        }
}


Measured memory_bytes: 85636
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
 
void faster()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const ll MAXN = 1e6 + 10;
const ll N = 4000 + 10;
const int mod = 1e6;

ll a[MAXN];
ll dp[N][N];

int main()
{
	faster();
	int a , b , c , x;
	cin >> a >> b >> c >> x;
	ll cnt = 0;
	int p[] = {500, 100 , 50};
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				ll sum = (i * p[0]) + (j * p[1]) + (k * p[2]);
				if(sum == x)
					cnt++;
			}
		}
	}
	cout << cnt << endl;
}	

Measured memory_bytes: 256
//And Then There Was One
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
  ll n, k, m;
  while(cin>>n>>k>>m, !(n==0&&k==0&&m==0)){
    queue<ll> q;
    for(ll i=1; i<=n; i++)
      q.push(i);
    for(ll i=0; i<m-1; i++){
      q.push(q.front());
      q.pop();
    }
    q.pop();
    while(q.size()!=1){
      for(ll i=0; i<k-1; i++){
	q.push(q.front());
	q.pop();
      }
      q.pop();
    }
    cout<<q.front()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1304
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,n,i,min=1000000,max=-1000000;
    long sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min>a)
            min=a;
        if(max<a)
            max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int ans[n+1];
    fill(ans, ans+n+1, 0);
    for (int q = 1; q < 101; q++){
        for (int q1 = 1; q1 < 101; q1++){
            for (int q2 = 1; q2 < 101; q2++){
                int w = (q+q1)*(q+q1)+(q+q2)*(q+q2)+(q1+q2)*(q1+q2);
                if (w/2 <= n){
                    ans[w/2]++;
                }
            }
        }
    }
    for (int q = 1; q <= n; q++){
        cout << ans[q] << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
N = int(input())
ans = 0
a = 0
b = 0
ba = 0
for _ in range(N):
    S = input()
    ans += S.count('AB')
    if S[0] == 'B' and S[-1] == 'A':
        ba += 1
    if S[0] != 'B' and S[-1] == 'A':
        a += 1
    if S[0] == 'B' and S[-1] != 'A':
        b += 1

if ba == 0:
    print(ans + min(a, b))
else:
    if a + b == 0:
        print(ans + ba - 1)
    else:
        print(ans + ba + min(a, b))


Measured memory_bytes: 3064
#include <stdio.h>


int main()
{
	int i,n, A, B;
	int sumA=0, sumB=0;

	scanf("%d", &n);

	if(n==0)
		return 0;

	for(i=0; i<n; i++){
		scanf("%d", &A);
		scanf("%d", &B);
		if(A > B)
			sumA += A + B;
		else if(A < B)
			sumB += A + B;
		else{
			sumA += A;
			sumB += B;
		}
	}
	printf("%d %d\n", sumA, sumB);
	main();
}

Measured memory_bytes: 600
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,m,a[100111];
int main()
{
	get2(n,m);
	for(int i=1,l,r;i<=n;i++)
	{
		get2(l,r);
		a[1]++;a[r+1]--;
		if(l==1)continue;
		l--;
		int lower=sqrt(l)+1;
		for(int j=1,s,t;j*j<=l;j++)
		{
			if(r/j==l/j)
			{
				a[j]--;
				a[j+1]++;
			}
			if(j*j==l)continue;
			s=max(lower,r/(j+1)+1);t=l/j;
			if(s<=t)
			{
				a[s]--;
				a[t+1]++;
			}
		}
	}
	for(int i=1;i<=m;i++)
	{
		a[i]+=a[i-1];
		printendl(a[i]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
#define int ll
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=2e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
string s[maxn],q[maxn];
map<string,int>p;
bool cmp(string a,string b){
    return a<b;
}
signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i){
        cin>>s[i];
        p[s[i]]++;
    }//cout<<endl;
    int Max=0,len=0;
    for(int i=1;i<=n;++i)Max=max(Max,p[s[i]]);
    for(int i=1;i<=n;++i){
        if(p[s[i]]==Max){
            p[s[i]]=-1;
            q[++len]=s[i];
        }
    }sort(q+1,q+1+len);
    for(int i=1;i<=len;++i){
        for(int j=0;j<q[i].size();++j){
            cout<<q[i][j];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 37760
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,sum=0;
  cin>>a>>b;
  char k[10][10];
  for(int i=0;i<a;i++){
    for(int m=0;m<b;m++){
      cin>>k[i][m];
      if(k[i][m]=='#') sum++;
    }
  }
  
  if(sum==a+b-1) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, C, x[100010], v[100010];

int solve(int p, int q) {
    int ans = 0;
    set<pii> cloc, anti;
    vector<pii> rec_cloc(N), rec_anti(N);
    cloc.insert(make_pair(0, -1));
    anti.insert(make_pair(0, -1));

    // 時計回り引き返しを入れる
    int sum = 0, prev = 0;
    rep(i,0,N) {
        sum += v[i] - p * (x[i] - prev);
        // printf("sum = %lld\n", sum);
        cloc.insert(make_pair(-sum, i));
        rec_cloc[i] = make_pair(-sum, i);
        prev = x[i];
    }

    // 半時計回り
    sum = 0, prev = C;
    repr(i,N-1,0) {
        sum += v[i] - q * (prev - x[i]);
        // printf("sum - %lld\n", sum);
        rec_anti[i] = make_pair(-sum, i);
        prev = x[i];
    }

    repr(i,N-1,-1) {
        pii vl = *(cloc.begin());
        pii vr = *(anti.begin());
        // printf("vl = %lld, vr = %lld\n", -vl.first, -vr.first);
        chmax(ans, -vl.first-vr.first);

        if(i < 0) break;
        cloc.erase(rec_cloc[i]);
        anti.insert(rec_anti[i]);
    }
    return ans;
}
 
signed main() {
    cin >> N >> C;
    rep(i,0,N) cin >> x[i] >> v[i];

    int ans = 0;
    chmax(ans, solve(1, 2));
    chmax(ans, solve(2, 1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11208
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 2e5+5


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        int e=n/2;
        int o=n/2+n%2;
        cout << e*o << '\n';
        
        

}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector< int > A(N);
    vector< long long > tot(N + 1);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (i == 0)
            tot[i] = A[i];
        else
            tot[i] = tot[i - 1] + A[i];
    }

    long long ans = 1e16;
    for (int i = 1; i < N - 2; i++) {
        // cout << i << endl;
        int l, mid, r;
        long long l_sum, r_sum, P, Q, R, S;
        // left
        // cout << "left" << endl;
        l = 0, r = i;
        while (l != r) {
            mid = (l + r) / 2;
            l_sum = tot[mid];
            r_sum = tot[i] - tot[mid];

            if (l_sum < r_sum)
                l = mid + 1;
            else
                r = mid;
        }

        if (r == 0 || abs(tot[r] - (tot[i] - tot[r])) <
                          abs(tot[r - 1] - (tot[i] - tot[r - 1]))) {
            P = tot[r];
            Q = tot[i] - tot[r];
        } else {
            P = tot[r - 1];
            Q = tot[i] - tot[r - 1];
        }

        // cout << "P: " << P << ", Q: " << Q << endl;

        // right
        // cout << "right" << endl;
        l = i + 1, r = N - 1;
        while (l != r) {
            mid = (l + r) / 2;
            l_sum = tot[mid] - tot[i];
            r_sum = tot[N - 1] - tot[mid];

            if (l_sum < r_sum)
                l = mid + 1;
            else
                r = mid;
        }

        // cout << "r: " << r << ", " << tot[r] << endl;
        if (r == i + 1 ||
            abs(tot[r] - tot[i] - (tot[N - 1] - tot[r])) <
                abs(tot[r - 1] - tot[i] - (tot[N - 1] - tot[r - 1]))) {
            R = tot[r] - tot[i];
            S = tot[N - 1] - tot[r];
        } else {
            R = tot[r - 1] - tot[i];
            S = tot[N - 1] - tot[r - 1];
        }

        // cout << "R: " << R << ", S: " << S << endl;

        long long tmp = max({P, Q, R, S}) - min({P, Q, R, S});
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2688
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		if (n.contentEquals("A"))
			System.out.println("T");
		else if (n.contentEquals("T"))
			System.out.println("A");
		else if (n.contentEquals("G"))
			System.out.println("C");
		else if (n.contentEquals("C"))
			System.out.println("G");
	}

}


Measured memory_bytes: 20948
# coding: utf-8
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
A = lr()
counter = Counter(A)
counter = counter.most_common()
answer = 0
for k, v in counter[K:]:
    answer += v

print(answer)


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


using ll = long long;
int main() {
  ll N;
  cin >> N;
    //N-=1;
    stack<char> c;
    while(N!=0){
        //c.push_back(N%26);
        c.push((char)((N-1)%26+97));
        //cout << (char)((N-1)%26+97);
        N=(N-1)/26;
    }
    while (c.size()) {
        cout << c.top();
        c.pop();
    }
    cout << endl;
}

Measured memory_bytes: 3632
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];
int n, m;

void solve()
{
	int h, n;
	cin >> h >> n;
	for(int i  =0; i < n; i++)
	{
		cin >> arr[i];
		h -= arr[i];
	}
	if(h > 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	} 
}

 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 1024
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
typedef long long ll;
#define P 998244353
int n , m;
int A[MAXN];

int Pow( int x , int a ) {
	int ret = 1;
	while( a ) {
		if( a & 1 ) ret = ret * 1ll * x % P;
		x = 1ll * x * x % P , a >>= 1;
	}
	return ret;
}
int Wn[2][MAXN] , rev[MAXN];
void getwn( int len ) {
    for( int mid = 1 ; mid < len ; mid <<= 1 ) {
        int w0 = Pow( 3 , ( P - 1 ) / ( mid << 1 ) ) , w1 = Pow( 3 , P - 1 - ( P - 1 ) / ( mid << 1 ) );
        Wn[0][mid] = Wn[1][mid] = 1;
        for( int i = 1 ; i < mid ; ++ i )
            Wn[0][mid + i] = 1ll * Wn[0][mid + i - 1] * w0 % P,
            Wn[1][mid + i] = 1ll * Wn[1][mid + i - 1] * w1 % P;
    }
}
void getr( int len ) {
    int t = __builtin_ctz( len ) - 1;
    for( int i = 1 ; i < len ; ++ i ) rev[i] = ( rev[i >> 1] >> 1 ) | ( ( i & 1 ) << t );
}
void NTT( int* A , int len , int typ ) {
    rep( i , 0 , len - 1 ) if( i < rev[i] ) swap( A[i] , A[rev[i]] );
    for( int mid = 1 ; mid < len ; mid <<= 1 )
        for( int i = 0 ; i < len ; i += ( mid << 1 ) )
            for( int k = 0 ; k < mid ; ++ k ) {
                int t1 = A[i + k] , t2 = 1ll * A[i + k + mid] * Wn[typ][mid + k] % P;
                A[i + k] = (t1 + t2) % P , A[i + k + mid] = (t1 + P - t2) % P;
            }
    if( typ == 1 ) for( int inv = Pow( len , P - 2 ) , i = 0 ; i < len ; ++ i ) A[i] = 1ll * A[i] * inv % P;
}

int f[MAXN] , g[MAXN] , t[MAXN];
int J[MAXN] , iJ[MAXN];
int C( int a , int b ) {
	if( a < b ) return 0;
	return J[a] * 1ll * iJ[b] % P * iJ[a - b] % P;
}

int len;

void wkr( ) {
	rep( i , 0 , len - 1 ) f[i] = ( 1 + i + C( i , 2 ) ) % P * 1ll * g[i] % P , g[i] = g[i] * 1ll * iJ[i] % P;
	getr( len ) , getwn( len );
	NTT( g , len , 0 );
	rep( i , 0 , len - 1 ) g[i] = g[i] * 1ll * t[i] % P;
	NTT( g , len , 1 );
	rep( i , 0 , n ) f[i] += J[i + 2] * 1ll * g[i] % P , f[i] %= P;
	rep( i , n + 1 , len - 1 ) f[i] = 0;
	rep( i , 0 , len - 1 ) g[i] = f[i];
}

void solve() {
	cin >> n >> m;
	g[0] = 1;
	J[0] = iJ[0] = 1; rep( i , 1 , MAXN - 1 ) J[i] = J[i - 1] * 1ll * i % P , iJ[i] = Pow( J[i] , P - 2 );
	len = 1; while( len <= n + n ) len <<= 1;
	getr( len ) , getwn( len );
	t[0] = 0;
	rep( i , 1 , n ) t[i] = iJ[i + 2];
	NTT( t , len , 0 );
	rep( i , 1 , m ) wkr();
	int res = 0;
	rep( i , 0 , n ) 
		res += ( C( n , i ) * 1ll * f[i] % P ) , res %= P;
	cout << res << endl;
}

signed main() {
//    int T;cin >> T;while( T-- ) solve();
    solve();
}



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

int main()
{
    int count=0;
    long long int x, y=100;
    cin >> x;
    while(true) {
        count++;
        y *= 1.01;
        if (y >= x) {
            break;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int MOD(1e9 + 7);
int n, p;
long long temp;
int main() {
    cin >> n;
    vector<int> dp(1 << n), g(n);
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < n; ++j) {
            cin >> p;
            g[i] |= p * (1 << j);
        }
    dp[0] = 1;
    for (int x = 1; x < (1 << n); ++x) {
        p = __builtin_popcount(x), temp = 0;
        for (int y = x & g[p - 1]; y; y &= y - 1)
            temp += dp[x & ~(y & -y)];
        dp[x] = temp % MOD;
    }
    cout << dp[(1 << n) - 1];
    return 0;
}

Measured memory_bytes: 8448
#include<stdio.h>
 
int main(){
    int i = 1; int n = 1;
    for(; i < 10; i++) {
        for(; n < 10; n++) {
            printf("%dx%d=%d\n", i, n, i*n);
        }
        n = 1;
    }
 
    return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int T;
    cin >> T;
    while(T--){
        string a, b;
        cin >> a >> b;
        int M = sz(a), N = sz(b);
        int dp[M+1][N+1];
        rep(i, M+1) dp[i][0] = 0;
        rep(j, N+1) dp[0][j] = 0;
        rep(i, M){
            rep(j, N){
                if(a[i] == b[j]) dp[i+1][j+1] = dp[i][j]+1;
                else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
        cout << dp[M][N] << endl;
    }
}


Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
#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(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  	int N , j, u;
  double judge, judge2;
  cin >> N;
  judge = N / 1.08;
  judge2 = (N+1) / 1.08;
  
  j = N / 1.08;
  u = (N+1) / 1.08;
  
  if(judge == j)
    cout << j << endl;
  else if(j == u)
  cout << ":("<< endl;
  else if(u == judge2)
  cout << ":("<< endl;
  else
    cout << u << endl;
      
}

Measured memory_bytes: 256