akhauriyash/Code-Regression huggingface dataset:
main=do
    s1<-getLine
    s2<-getLine
    ana (length s1) s1 s2

ana :: Int->String->String->IO()
ana 0 _ _ = putStrLn "No"
ana a x y = do
    if x==y
    then putStrLn "Yes"
    else ana (a-1) x ((last y):(init y))


Measured memory_bytes: 892
#include<stdio.h>
int main(){
  int a,b,c,d,e,f;
  int tempa,tempb;
  int i,j;
  char cc;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  scanf("%c",&cc);
  while(1){
    scanf("%c",&cc);
    if(cc=='\n')break;
    if(cc=='S'){
      tempa=a;
      a=e;
      e=f;
      f=b;
      b=tempa;
    }
    else if(cc=='N'){
      tempa=a;
      a=b;
      b=f;
      f=e;
      e=tempa;
    }
    else if(cc=='W'){
      tempa=a;
      a=c;
      c=f;
      f=d;
      d=tempa;
    }
    else if(cc=='E'){
      tempa=a;
      a=d;
      d=f;
      f=c;
      c=tempa;
    }
  }
  printf("%d\n",a);
  return(0);
}


Measured memory_bytes: 2104
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int num = (1 << 2) * a + (1 << 1) * b + 1 * c;
	if(num == 6 || num == 1)puts("Open");
	else puts("Close");
	return 0;
}

Measured memory_bytes: 1172
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

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

using namespace std;

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

	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(A.begin(),A.end());

	vector<int> B(N);
	rep(i, N) cin >> B[i];
	sort(B.begin(), B.end());

	vector<int> C(N);
	rep(i, N) cin >> C[i];
	sort(C.begin(), C.end());

	long long count = 0;
	rep(i, N) {
		auto position = upper_bound(C.begin(), C.end(),B[i]);
		long long lower_factor = C.end() - position;

		position = lower_bound(A.begin(), A.end(), B[i]);
		long long upper_factor = position - A.begin();

		count += lower_factor * upper_factor;
	}
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int res = floor(B / A);
    if (A <= B) {
        if (res > C) {
            cout << C;
        }
        else {
            cout << res;
        }
    }
    else {
        cout << 0;
    }

    return 0;
}

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

const ll MAXN = 200000;

ll H, W, ans=0, tmp=0;
queue<pair<ll,ll>> Q;
vector<vector<ll>> color;

void bfs() {
    while(!Q.empty()) {
        pair<ll,ll> p = Q.front();
        Q.pop();
        if(p.first+1<H&&color[p.first+1][p.second]==-1) {
            color[p.first+1][p.second]=color[p.first][p.second]+1;
            Q.push(make_pair(p.first+1,p.second));
            ans = max(ans,color[p.first][p.second]+1);
        }
        if(p.first-1>=0&&color[p.first-1][p.second]==-1) {
            color[p.first-1][p.second]=color[p.first][p.second]+1;
            Q.push(make_pair(p.first-1,p.second));
            ans = max(ans,color[p.first][p.second]+1);
        }
        if(p.second+1<W&&color[p.first][p.second+1]==-1) {
            color[p.first][p.second+1]=color[p.first][p.second]+1;
            Q.push(make_pair(p.first,p.second+1));
            ans = max(ans,color[p.first][p.second]+1);
        }
        if(p.second-1>=0&&color[p.first][p.second-1]==-1) {
            color[p.first][p.second-1]=color[p.first][p.second]+1;
            Q.push(make_pair(p.first,p.second-1));
            ans = max(ans,color[p.first][p.second]+1);
        }
    }
}

signed main(){
    cin >> H >> W;
    color.resize(H);
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            color[i].push_back(-1);
        }
    }
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            char c;
            cin >> c;
            if(c=='#') {
                Q.push(make_pair(i,j));
                color[i][j]=0;
            }
        }
    }
    bfs();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 24628
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    multiset<ll> se;
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        se.insert(a);
    }
    int ans = 0;
    while(se.size() >= 2) {
        ll mx = *se.rbegin();
        se.erase(se.find(mx));
        ll two = 1;
        while(two <= 2 * mx) {
            two <<= 1LL;
        }
        two >>= 1LL;
        auto it = se.find(two - mx);
        if(it != se.end()) {
            se.erase(it);
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 13020
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        String S0 = scan.next();

        int[] S = new int[S0.length()];

        for (int i = 0; i < S0.length(); i++) {
            S[i] = S0.charAt(i) - '0';
        }

        int ans = 0;
        for (int x = 0; x < 1000; x++) {
            int x0 = (x / 100) % 10;
            int x1 = (x / 10) % 10;
            int x2 = x % 10;
            //System.out.println("" + x0 + x1 + x2);

            for (int i = 0; i < N; i++) {
                if (S[i] == x0) {
                    for (int j = i+1; j < N; j++) {
                        if (S[j] == x1) {
                            for (int k = j+1; k < N; k++) {
                                if (S[k] == x2) {
                                   ans++;
                                   break;
                                }
                            }
                            break;
                        }
                    }
                    break;
                }
            }

        }
        System.out.println(ans);

    }

}


Measured memory_bytes: 24752
mod = 1000000007
eps = 10**-9
val_max = 10**9


def main():
    import sys
    input = sys.stdin.readline
    from heapq import heappush, heappop

    # 負辺未対応
    class Mincostflow():
        def __init__(self, N):
            self.N = N
            self.adj = [[] for _ in range(N + 1)]
            self.inf = 1 << 60

        def add_edge(self, fr, to, cap, cost):
            # [to, cap, cost, rev]
            forward = [to, cap, cost, None]
            backward = forward[3] = [fr, 0, -cost, forward]
            self.adj[fr].append(forward)
            self.adj[to].append(backward)

        def flow(self, s, t, f):
            N = self.N
            adj = self.adj
            inf = self.inf

            res = 0
            H = [0] * (N + 1)
            prev_v = [0] * (N + 1)
            prev_e = [None] * (N + 1)

            dist0 = [inf] * (N + 1)
            dist = [inf] * (N + 1)

            while f:
                dist[:] = dist0
                dist[s] = 0
                pq = [(0, s)]
                while pq:
                    d, v = heappop(pq)
                    if d > dist[v]:
                        continue
                    r0 = dist[v] + H[v]
                    for e in adj[v]:
                        u, cap, cost, _ = e
                        if cap > 0 and r0 + cost - H[u] < dist[u]:
                            dist[u] = r = r0 + cost - H[u]
                            heappush(pq, (r, u))
                            prev_v[u] = v
                            prev_e[u] = e

                # flow f doesn't exist
                if dist[t] == inf:
                    return None

                for i in range(1, N + 1):
                    H[i] += dist[i]

                g = f
                v = t
                while v != s:
                    g = min(g, prev_e[v][1])
                    v = prev_v[v]
                f -= g
                res += g * H[t]
                v = t
                while v != s:
                    e = prev_e[v]
                    e[1] -= g
                    e[-1][1] += g
                    v = prev_v[v]

            return res

    N, K = map(int, input().split())
    grid = []
    for _ in range(N):
        grid.append(list(map(int, input().split())))

    s = 2*N+1
    t = 2*N+2
    mcf = Mincostflow(N*2 + 2)
    mcf.add_edge(s, t, N*K, val_max)
    for i in range(1, N+1):
        mcf.add_edge(s, i, K, 0)
        mcf.add_edge(i+N, t, K, 0)
    for i in range(1, N+1):
        for j in range(N+1, 2*N+1):
            mcf.add_edge(i, j, 1, val_max - grid[i-1][j-1-N])

    print(val_max * N * K - mcf.flow(s, t, N*K))
    ans = [["."] * N for _ in range(N)]
    for i in range(1, N+1):
        for j, cap, cost, _ in mcf.adj[i]:
            if cap == 0:
                ans[i-1][j-1-N] = "X"
    for i in range(N):
        print("".join(ans[i]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 73520
d=int(input())
a=[0 for i in range(26)]
c=list(map(int,input().split()))
l=[]
for i in range(d):
    l.append(list(map(int,input().split())))
    #print(c.index(max(c))+1)
p=[0]
for i in range(1,d+1):
    t=int(input())-1
    a[t]=i
    k=0
    for j in range(26):
        k+=c[j]*(i-a[j])
    p.append(p[i-1]+l[i-1][t]-k)
print(*p[1:],sep='\n')

Measured memory_bytes: 9432
#include <string>
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int par[1010];
int gen[1010];
char namex[99], namey[99], rel[99];

bool parent(int x, int y){
	return par[y] == x;
}

bool sibling(int x, int y){
	return par[x] == par[y];
}

bool ancestor(int x, int y){
	while(y != -1){
		y = par[y];
		if( x == y ) return true;
	}
	return false;
}

int main(){
	int n, m;
	string str;

	while( cin >> n >> m, n != 0 ){
		cin.ignore();
		
		map<string,int> names;
		gen[0] = -1;
		
		int indent = 0;
		
		for(int i = 0; i < n; ++i){
			getline(cin, str);
			sscanf(str.c_str(), " %n%s", &indent, namex);
			
			int k = names.size();
			names[namex] = k;
			
			par[k] = gen[indent];
			gen[indent + 1] = k;
		}

		for(int i = 0; i < m; ++i){
			getline(cin, str);
			sscanf(str.c_str(), "%s%*s%*s %s%*s %[^.]", namex, rel, namey);
			
			int x = names[namex];
			int y = names[namey];
			bool f = false;

			switch( rel[0] ){
				case 'c':
					f = parent(y, x);
					break;
				case 'p':
					f = parent(x, y);
					break;
				case 's':
					f = sibling(x, y);
					break;
				case 'd':
					f = ancestor(y, x);
					break;
				case 'a':
					f = ancestor(x, y);
					break;
			}
			
			puts( f ? "True" : "False" );
		}

		puts("");
	}
}

Measured memory_bytes: 1364
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

char c[200];

int cou[50],d[50];


int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n == 0)
            break;
        REP(i,n){
            cin >> c[i];
            c[i] -= 'A';
        }

        REP(i,50)
            cou[i] = 0;

        int a;
        REP(i,n){
            a = i;
            cou[c[i]]++;

            memcpy(d,cou,26 * sizeof(int));


            sort(d,d + 26);

            if(d[25] > d[24] + n - i - 1)
                break;
        }
        if(d[25] == d[24])
            printf("TIE\n");
        else{
            int max = 0,index;
            REP(i,26){
                if(max < cou[i]){
                    max = cou[i];
                    index = i;
                }
            }
            printf("%c %d\n",index + 'A',a + 1);
        }
    }
    return 0;
}

Measured memory_bytes: 3260
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
main()
{
	int n, N, i, j;

	scanf("%d", &n);
	if(n == 25)
		printf("Christmas\n");
	else if(n == 24)
		printf("Christmas Eve\n");
	else if(n == 23)
		printf("Christmas Eve Eve\n");
	else if(n == 22)
		printf("Christmas Eve Eve Eve\n");

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=332748118;
const int M=5e5+10;
#define inf 0x3f3f3f3f
//std::ios::sync_with_stdio(0);
int main()
{
    std::ios::sync_with_stdio(0);
     ll n;
     cin>>n;
     ll a[n];
     for(ll i=0;i<n;i++)
     {
         cin>>a[i];
     }
     ll cnt=0;
     ll maxn=a[0];
     for(ll i=0;i<n;i++)
     {
         if(a[i]<maxn)
            {
              cnt+=maxn-a[i];

            }
        else
            {
                maxn=max(maxn,a[i]);
            }

     }
     cout<<cnt<<endl;

}



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

int main()
{
    int n;
    cin >> n;
    map<int, int> A;
    rep(i, n)
    {
        int a;
        cin >> a;
        A[a]++;
    }

    if (n % 2 == 0)
    {
        for (auto p : A)
        {
            if (p.first <= 0 || p.first >= n || p.second != 2)
            {
                cout << "0" << endl;
                return 0;
            }
        }
    }

    if (n % 2 == 1)
    {
        for (auto p : A)
        {
            if (p.first >= n || (p.second != 2 && p.first != 0))
            {
                cout << "0" << endl;
                return 0;
            }
        }
    }

    int ans = 1;
    rep(i, n / 2) ans = (ans * 2) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 3200
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N; std::cin >> N;
    std::vector<int> A(N);
    for(int i(0); i < N; ++i) std::cin >> A[i];
    std::sort(std::rbegin(A), std::rend(A));
    long long ans(A[0]);
    for(int i(2); i < N; ++i) ans += A[i / 2];
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        char[] input = br.readLine().toCharArray();
        char[] st = br.readLine().toCharArray();
        int size = input.length;
        int size2 = st.length;
        boolean answer = false;
        for (int i = 0; i < size; i++) {
            boolean chk = true;
            int j = 0;
            int k = i;
            while (j < size2 && k < size) {
                if (st[j] != input[k]) {
                    chk = false;
                    break;
                }
                if (++k == size) k %= size;
                j++;
            }
            if (chk) {
                answer = true;
                break;
            }
        }

        bw.append(answer ? "Yes\n" : "No\n");
        bw.flush();
    }


}


Measured memory_bytes: 24520
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

typedef std::pair<int, int> P;

int n;
std::vector<int> edge[100005];
int dist[100005];
bool see[100005];

int fennec, snuke;

int dfs(int vis){
	int ret = 1;
	for(int i = 0; i < edge[vis].size(); i++){
		int next = edge[vis][i];
		if(!see[next]){
			see[next] = true;
			ret += dfs(next);
		}
	}
	return ret;
}

signed main(){
	scanf("%ld", &n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		scanf("%ld %ld", &a, &b);
		edge[a-1].push_back(b-1);
		edge[b-1].push_back(a-1);
	}
	for(int i = 0; i < n; i++){
		dist[i] = -1;
	}
	dist[0] = 0;
	std::priority_queue<int> que;
	que.push(0);
	while(!que.empty()){
		int vis = que.top();
		que.pop();
		for(int i = 0; i < edge[vis].size(); i++){
			int next = edge[vis][i];
			if(dist[next] == -1){
				dist[next] = dist[vis] + 1;
				que.push(next);
			}
		}
	}
	
	/*
	for(int i = 0; i < n; i++){
		printf("%ld ", dist[i]);
	}
	printf("\n");
	//*/
	
	int vis = n-1;
	int next = 0;
	for(int i = 0; i < (dist[n-1]+1)/2; i++){
		for(int j = 0; j < edge[vis].size(); j++){
			next = edge[vis][j];
			if(dist[next] == dist[vis] - 1){
				if(i == (dist[n-1]+1)/2 - 1){
					break;
				}
				vis = next;
				break;
			}
		}
	}

	//printf("  %ld %ld\n", vis, next);
	
	/*
	for(int i = 0; i < edge[vis].size(); i++){
		if(edge[vis][i] == next){
			edge[vis].erase(edge[vis].begin() + i);
			break;
		}
	}
	for(int i = 0; i < edge[next].size(); i++){
		if(edge[next][i] == vis){
			edge[next].erase(edge[next].begin() + i);
			break;
		}
	}
	//*/
	see[vis] = true;
	see[next] = true;
	printf(dfs(next) > dfs(vis) ? "Fennec\n" : "Snuke\n");
	return 0;
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define input(arr, s, n) for (int i = s; i < n; i++) cin >> arr[i]
using namespace std;

int main()
{
       int n;
       cin >> n;
       string x;
       map<string, long long> str;
       long long cnt = 0;
       for (int i = 0; i < n; i++) {
            cin >> x;

            sort(x.begin(), x.end());
            cnt += str[x];
            str[x]++;
       }

       cout << cnt << "\n";
}


Measured memory_bytes: 11136
import itertools

N,K=map(int,input().split())
D=list(map(int,input().split()))

default=[0,1,2,3,4,5,6,7,8,9]

for i in D:
    if i in default:
        default.remove(i)
price=[]
for cost in itertools.product(default, repeat=len(str(N))):
    price.append(int(''.join(list(map(str,list(cost))))))

price.sort()

price=[i for i in price if i>=N]

if len(price)>=1:
    print(price[0])
else:
    N_len=len(str(N))
    default2 = [i for i in default if i >= 1]
    default2.sort()
    default.sort()
    print(str(default2[0])+str(default[0])*(N_len))

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    string s,t;
    cin>>s>>t;
    cout<<t<<s;
}

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

namespace ABC132_E___Hopscotch_Addict
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var nodes = new List<int>[3 * NM[0] + 3];
            for (int i = 1; i < 3 * NM[0] + 3; i++) nodes[i] = new List<int>();
            for (int i = 0; i < NM[1]; i++)
            {
                var edge = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                var from = edge[0];
                var to = edge[1];
                nodes[3 * from].Add(3 * to + 1);
                nodes[3 * from + 1].Add(3 * to + 2);
                nodes[3 * from + 2].Add(3 * to);
            }
            var ST = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var distance = new int[3 * NM[0] + 3];
            for (int i = 0; i < distance.Length; i++) distance[i] = int.MaxValue;
            distance[ST[0] * 3] = 0;
            var queue = new Queue<int>();
            queue.Enqueue(3 * ST[0]);

            while (queue.Count != 0)
            {
                var current = queue.Dequeue();
                foreach (int to in nodes[current])
                {
                    if (distance[to] > distance[current] + 1)
                    {
                        distance[to] = distance[current] + 1;
                        queue.Enqueue(to);
                        if (to == ST[1] * 3) break;
                    }

                }
            }
            Console.WriteLine(distance[3 * ST[1]] == int.MaxValue ? -1 : distance[3 * ST[1]] / 3);
        }
    }
}


Measured memory_bytes: 47080
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char s[400010],d[400010];
int st[100010],ch[400010][26],c[100010][26][26],b[26][26];
int size[400010],f[400010],g[400010];

int main()
{
	int n;scanf("%d",&n);
	int cnt=0;int m=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);int l=strlen(s);
		int k=0;st[i]=m;
		for (int j=0;j<l;j++) d[j+m]=s[j];
		for (int j=0;j<l;j++)
		{
			int x=s[j]-97;
			if (!ch[k][x]) ch[k][x]=++cnt;
			k=ch[k][x];
		}
		m+=l;
		size[k]=1;f[i]=k;g[k]=1;
	}
	st[n+1]=m;
	for (int i=cnt;i>=0;i--)
		for (int j=0;j<26;j++)
			if (ch[i][j]) size[i]+=size[ch[i][j]];
	for (int i=0;i<=cnt;i++)
		for (int j=0;j<26;j++)
			if (ch[i][j])
				g[ch[i][j]]+=g[i];
	for (int i=1;i<=n;i++)
	{
		memset(b,0,sizeof(b));
		int k=0;
		for (int j=st[i];j<st[i+1];j++)
		{
			for (int p=0;p<26;p++)
				if (ch[k][p])
					b[d[j]-97][p]+=size[ch[k][p]];
			k=ch[k][d[j]-97];
		}
		for (int j=0;j<26;j++)
			for (int k=0;k<26;k++)
				c[i][j][k]=b[j][k];
	}
	int q;scanf("%d",&q);
	while (q--)
	{
		int x;scanf("%d",&x);
		scanf("%s",s);
		int ans=g[f[x]];
		for (int i=0;i<26;i++)
			for (int j=0;j<i;j++)
				ans+=c[x][s[i]-97][s[j]-97];
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 276096
#include <stdio.h>

int main(void){
  int num;
  int sen, hyaku, ju, iti;
  scanf("%d", &num);

  sen=num/1000;
  hyaku=(num-sen*1000)/100;
  ju=(num-sen*1000-hyaku*100)/10;
  iti=num%10;

  //printf("%d %d %d %d\n", sen, hyaku, ju, iti);
  if(sen==hyaku||hyaku==ju||ju==iti){
    printf("Bad\n");
  }else{
    printf("Good\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n, l; cin >> n >> l;
    vector<int> apple(n);
    REP(i, n) apple[i] = l + i;
    int ans = 0;
    REP(i, n) ans += apple[i];
    int hiki;
    if(l <= 0 and l + n - 1 >= 0) hiki = 0;
    else if(l < 0 and l + n - 1 < 0) hiki = l + n - 1;
    else if(l > 0) hiki = l;
    cout << ans - hiki << endl;
}

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

int main(){
	int a,k,sum=1;
    cin>>a>>k;
    for(int i=0;i<a;i++){
        if(sum>k){
            sum+=k;
        }
        else 
        sum*=2;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
def divisor(n):
    i = 1
    res = set()
    for i in range(1, int(n**.5) + 1):
        if n%i == 0:
            res.add(i)
            res.add(n//i)
    return res

def main():
    n, m = map(int, input().split())
    md = list(divisor(m))
    md.sort(reverse=True)
    for i in md:
        if i*n <= m:
            print(i)
            exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 9272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, M;

int main()
{
    while (cin >> N >> M)
    {
        if (N == 0 && M == 0)
            return 0;
        int sa = 0, sb = 0;
        vector<int> A(N), B(M);
        for (int i = 0; i < N; i++)
        {
            cin >> A[i];
            sa += A[i];
        }
        for (int i = 0; i < M; i++)
        {
            cin >> B[i];
            sb += B[i];
        }
        int ba = sa, bb = sb;
        pair<int, int> ans = make_pair(inf, inf);
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < M; j++, sa = ba, sb = bb)
            {
                sa += B[j] - A[i], sb += A[i] - B[j];
                if (sa == sb)
                {
                    pair<int, int> p = make_pair(A[i], B[j]);
                    if (A[i] + B[j] < ans.first + ans.second)
                        ans = p;
                }
            }
        }
        if (ans.first == inf)
            cout << -1 << endl;
        else
            cout << ans.first << " " << ans.second << endl;
    }
}


Measured memory_bytes: 3016
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long llong;
int main(){
    int n;
    cin >> n;

    string s[50];
    int t[50];
    int sum = 0;
    for (int i = 0; i < n; i++){
        cin >> s[i] >> t[i];
        sum += t[i];
    }

    string x;
    cin >> x;

    int ans;
    for (int i = 0; i < n; i++){
        ans += t[i];
        if (s[i] == x) break;
    }

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

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

#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)

typedef long long ll;

using namespace std;

int n;

int solve() {
  return (n - 1) / 2;
}

int main() {
  cin >> n;
  cout << solve() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int N, K, M, A, B, C, D;

struct UnionFind{
    vector<int> par;
    vector<int> rank;  // height of tree
    UnionFind(int m) : par(m), rank(m) {
        for(int i = 0; i < m; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }
    int root(int x) {
        return x == par[x] ? x : par[x] = root(par[x]);
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        if(same(x, y)) return;
        if(rank[x] < rank[y]) {
            par[root(x)] = root(y);  // make y above
        } else {
            par[root(y)] = par[root(x)];
            if(rank[x] == rank[y]) ++rank[x];
        }
    }
};



int main() {
    cin >> N >> M >> K;
    vector<vector<int>> f(N+1);
    vector<vector<int>> b(N+1);
    UnionFind uf(N+1);
    for (int i = 0; i < M; ++i) {
        cin >> A >> B;
        uf.unite(A, B);
        f[A].push_back(B);
        f[B].push_back(A);
    }
    for (int i = 0; i < K; ++i) {
        cin >> C >> D;
        b[C].push_back(D);
        b[D].push_back(C);
    }

    unordered_map<int, int> sizes;
    for (int i = 1; i <= N; ++i) sizes[uf.root(i)]++;
    for (int i = 1; i <= N; ++i) {
        int ans = sizes[uf.root(i)] - 1;
        ans -= f[i].size();
        for (auto j : b[i]) if (uf.same(i, j)) --ans;
        cout << ans << " ";
    }

    return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define min(a, b) (a > b ? b : a)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    string s, t;
    cin >> s >> t;
    
    {
        map<char, int> mp;
        rep(i, SZ(s)) mp[s[i]]++;
        rep(i, SZ(t)) if (mp[t[i]] == 0) { out(-1); return 0; }
    }
    
    
    
    vector<int> v[26];
    rep(i, SZ(s)) {
        v[s[i] - 'a'].eb(i);
    }
    
    if (SZ(t) == 1) {
        out(v[t[0] - 'a'][0] + 1);
        return 0;
    }
    
    int now = v[t[0] - 'a'][0];
    // out(now);
    
    ll cnt = 0;
    rep3(i, 1, SZ(t) - 1) {
        int it = UB(v[t[i] - 'a'], now);
        if (it == SZ(v[t[i] - 'a'])) {
            now = v[t[i] - 'a'][0];
            cnt++;
        } else {
            now = v[t[i] - 'a'][it];
        }
        // out(now);
    }
    
    // out(cnt);
    // out(now);
    
    { // 最後の文字
        int it = UB(v[t[SZ(t) - 1] - 'a'], now);
        if (it == SZ(v[t[SZ(t) - 1] - 'a'])) {
            cnt++;
            out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][0] + 1);
        } else {
            now = v[t[SZ(t) - 1] - 'a'][it];
            // out(now);
            out(cnt * SZ(s) + v[t[SZ(t) - 1] - 'a'][it] + 1);
        }
    }
}



Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
if(a>b)
{
    for(int i=0;i<a;i++)
        cout<<b;
}
else
    {
        for(int i=0;i<b;i++)
        cout<<a;
}

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    if ((a - b) % 2 == 0) cout << abs(a - b) / 2 << "\n";
    else {
        ll al = -a, ar = -a + 2 * n;
        b--;
        cout << min(abs(b - al) / 2, (ar - b) / 2) << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

template<typename T>
vector<T> compress(vector<T> v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}
// v = compress(v);


int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  vector<string> vec;
  for(int i=1; i<=min(5,(int)s.size()); i++){
    for(int j=0; j<s.size()-i+1; j++){
      vec.push_back(s.substr(j,i));
    }
  }
  vec = compress(vec);
  sort(vec.begin(),vec.end());
  cout << vec[K-1] << endl;
  return 0;
}


Measured memory_bytes: 1788
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
bool existA[1000010], existB[1000010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int A[1010], B[1010];
    rep(i, n) cin >> A[i];
    rep(i, m) cin >> B[i];
    rep(i, n) {
        if(existA[A[i]]) {
            cout << 0 << endl;
            return 0;
        }
        existA[A[i]] = true;
    }
    rep(i, m) {
        if(existB[B[i]]) {
            cout << 0 << endl;
            return 0;
        }
        existB[B[i]] = true;
    }
    int ans = 1;
    int sumA = 0, sumB = 0;
    RREP(x, n * m, 1) {
        //cout << x << " " << ans << " " << sumA << " " << sumB << endl;
        if(existA[x] && existB[x]) {
            sumA++; sumB++;
            continue;
        }
        if(existA[x]) {
            sumA++;
            ans = (ans * sumB) % mod;
        } else if(existB[x]) {
            sumB++;
            ans = (ans * sumA) % mod;
        } else {
            ans = (ans * max(0LL, sumA * sumB - (n * m - x))) % mod;
        }
    }
    cout << ans << endl;


    return 0;
}
//   9 7 8
// 8   7 8
// 5
// 9 9   

// 9:1
// 8:1
// 7:2
// 6:3*2=6 (3*3-6 = 3)

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int c[3][3];
int main(){
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++)
            cin >> c[i][j];
    for(int i=0;i<2;i++){
        int tmp = c[0][1]-c[0][0];
        for(int j=1;j<3;j++){
            if((c[j][1]-c[j][0])!=tmp){
                cout << "No" << '\n';
                return 0;
            }
        }
        tmp = c[0][2]-c[0][1];
        for(int j=1;j<3;j++){
            if((c[j][2]-c[j][1])!=tmp){
                cout << "No" << '\n';
                return 0;
            }
        }
    }
    for(int i=0;i<2;i++){
        int tmp = c[1][0]-c[0][0];
        for(int j=1;j<3;j++){
            if((c[1][j]-c[0][j])!=tmp){
                cout << "No" << '\n';
                return 0;
            }
        }
        tmp = c[2][0]-c[0][0];
        for(int j=1;j<3;j++){
            if((c[2][j]-c[0][j])!=tmp){
                cout <<"No" << '\n';
                return 0;
            }
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, M;
vector<int> adj[100010];
int pre[100010];
bool visited[100010];

void bfs(){
    queue<pint> que;
    que.push(pint(0, 0));
    while(!que.empty()){
        int p = que.front().first;
        int i = que.front().second;
        que.pop();
        if(visited[i]) continue;
        visited[i] = true;
        pre[i] = p;
        for(int j : adj[i]){
            if(visited[j]) continue;
            que.push(pint(i, j));
        }
    }
}

signed main(){
    cin >> N >> M;
    int a, b;
    REP(i, M){
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    PRINT("Yes");
    bfs();
    FOR(i, 1, N){
        PRINT(pre[i] + 1);
    }
    return 0;
}

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

int h, w;
vector<string> s;
int memo[2005][2005] = {0};

int solve();

int main() {
  cin >> h >> w;
  s.resize(h);
  for(int i = 0; i < h; ++i) cin >> s[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      if(s[i][j] == '.') {
        int cnt = 0, now = j;
        while(now < w && s[i][now] == '.') {
          ++cnt;
          ++now;
        }
        for(int k = j; k < now; ++k) memo[i][k] += cnt;
        j = now - 1;
      }
  for(int i = 0; i < w; ++i)
    for(int j = 0; j < h; ++j)
      if(s[j][i] == '.') {
        int cnt = 0, now = j;
        while(now < h && s[now][i] == '.') {
          ++cnt;
          ++now;
        }
        for(int k = j; k < now; ++k) memo[k][i] += cnt;
        j = now - 1;
      }
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) ans = max(ans, memo[i][j]);

  return ans - 1;
}

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

int main(void){
	int N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	vector<int> v;
	int cnt;
	for(int i=0;i<N;i++){
		if(S[i]=='0'){
			cnt = 1;
			while(S[i+1]=='0'){
				i++;
				cnt++;
			}
			v.push_back(-1*(cnt));
		}else{
			cnt = 1;
			while(S[i+1]=='1'){
				i++;
				cnt++;
			}
			v.push_back(cnt);
		}
	}
	long long b[v.size()];
	b[0]=abs(v[0]);
	for(int i=1;i<v.size();i++){
		b[i]=b[i-1]+abs(v[i]);
	}
	int range = (K*2) + 1;
	long long ans = 0;
	int left = 0;
	int right= 0;
	cnt = 0;
	while(left!=v.size()){
		if(left>right){
			right = left;
		}
		if(left>=v.size())break;
		while(cnt<K){
			if(right==v.size()-1)break;
			if(v[right]<0)cnt++;
			right++;
		}
		if(left>0){
			ans = max(ans,b[right]-b[left-1]);
		}else{
			ans = max(ans,b[right]);
		}
		left++;
		if(v[left]>0)cnt--;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1656
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  ll n,p;
  cin>>n>>p;
  string s;
  cin>>s;
  vector<ll>sum(n+5);
  map<ll,ll>mp;
  ll mul=1;
  if(p==5||p==2){
    ll ans=0;
    rep(i,n){
      ll x=s[i]-'0';
      if(x%p==0){
        ans+=ll(i+1);
      }
    }
    cout<<ans;
    return;
  }
  rep(i,n){
    sum[i+1]=sum[i]+mul*(ll)(s[n-1-i]-'0');
    sum[i+1]%=p;
    mp[sum[i+1]]++;
    mul*=10;
    mul%=p;
  }
  ll ans=mp[0];
  rep(i,n){
    ans+=mp[sum[n-i]]-1;
    mp[sum[n-i]]--;
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	//cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int n, a, b;

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

	cin >> n >> a >> b;
	int ans = n;
	for (int i=0; i<n; i++)
	{
		int x; cin >> x;
		if (a <= x && x < b)
			ans--;
	}
	cout << ans << "\n";

	return 0;
}

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

int main(){
    int N;
    std::cin >> N;
    
    std::vector<int> v;
    int tmp;
    while(std::cin >> tmp){v.push_back(tmp);}
    
    auto print_v = [](std::vector<int> v){ 
        for(int i=0; i<v.size(); i++){
            std::cout << v[i] ;
            if(i<v.size()-1){
                std::cout << " ";
            }else{
                std::cout << std::endl;
            }
        }
    };
    print_v(v);
    
    for(int i=1; i<v.size(); i++){
        int j = i+1;
        while(--j>=0 && v[j-1] > v[j]){
            std::swap(v[j-1], v[j]);
        }
        print_v(v);
    }
    
}


Measured memory_bytes: 3164
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();
        final Map<Integer, Integer> countMap = new HashMap<>();

        for (int i = 0; i < n; i++) {
            countMap.compute(scanner.nextInt(), (key, value) -> value == null ? value = 1 : value + 1);
        }

        final int answer = countMap.values().stream()
                .sorted()
                .limit(Math.max(countMap.size() - k, 0))
                .mapToInt(Integer::intValue)
                .sum();

        System.out.println(answer);
    }
}


Measured memory_bytes: 105716
#include<stdio.h>
#include<math.h>

struct Point{
  double x;
  double y;
};

void koch(int d, struct Point p1, struct Point p2){
  struct Point s, t, u;
  double k;

  if(d == 0) return;

  k = M_PI * 60.0 / 180.0;

  s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
  s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
  t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
  t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;
  u.x = (t.x - s.x) * cos(k) - (t.y - s.y) * sin(k) + s.x;
  u.y = (t.x - s.x) * sin(k) + (t.y - s.y) * cos(k) + s.y;

  koch(d-1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(d-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(d-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(d-1, t, p2);
}

int main(){
  struct Point p1, p2;
  int n;

  scanf("%d", &n);

  p1.x = 0;
  p1.y = 0;
  p2.x = 100;
  p2.y = 0;

 printf("%.8f %.8f\n", p1.x, p1.y);
 koch(n, p1, p2);
 printf("%.8f %.8f\n", p2.x, p2.y);

 return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef tuple<Int, Int,Int> T;
typedef pair<Int, Int> p;
const Int INF = 1e18;

struct edge{Int to, t;};

Int N, M, S;

// 頂点vで銀貨c枚持っている状態を頂点 v*2501+c とする 
vector<vector<edge>> G(51*2501);
vector<Int> dist(51*2501, INF);

void dijkstra(int s){
    // first:最短距離 second:頂点番号
    priority_queue<p, vector<p>, greater<p>> q;
    dist[s] = 0;
    q.push(p(0, s));

    while (!q.empty()){
        int cur_d = q.top().first;
        int cur_v = q.top().second;
        q.pop();

        if (cur_d > dist[cur_v]) continue;

        for (int i = 0; i < G[cur_v].size(); i++){
            edge e = G[cur_v][i];
            if (dist[cur_v] + e.t < dist[e.to]){
                dist[e.to] = dist[cur_v] + e.t;
                q.push(p(dist[e.to], e.to));
            }
        }
    }
}


int main(){
    cin >> N >> M >> S;
    if(S > 2500) S = 2500;

    rep(i,M){
        int u, v; Int a, b;
        cin >> u >> v >> a >> b;
        u--; v--;

        for(int j=a; j<=2500; j++){
            G[u*2501+j].push_back(edge{v*2501+(j-a),b});
            G[v*2501+j].push_back(edge{u*2501+(j-a),b});
        }
    }

    
    rep(i,N){
        Int c, d; cin >> c >> d;
        for(int j=0; j+c<=2500; j++){
            G[i*2501+j].push_back(edge{i*2501+(j+c),d});
        }
    }

    vector<Int> ans(51, INF);

    dijkstra(S);

    rep1(i,N-1){
        Int ans = INF;
        rep(j,2501){
            ans = min(ans, dist[i*2501+j]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 23676
program one_quadrillion_and_one_dalmatians
  implicit none
  integer(8) :: n
  integer :: i = 0, k(20) = 0
  read(*,*) n
  do while (n > 0)
    i = i + 1
    k(i) = int(mod(n - 1, 26) + 97)
    n = (n - 1)/ 26
  end do
  do while (i > 0)
    write(*,'(a)',advance='no') achar(k(i))
    i = i - 1
  end do
  write(*,*)
end program one_quadrillion_and_one_dalmatians

Measured memory_bytes: 2928
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>

bool debug=true;
/*
   Write In New Computer
    By XiaoGeNintendo
	     gwq2017
	Type:
*/

/*
void fo(int id){
	freopen((toString(id)+".txt").c_str(),"w",stdout);
}
*/

string blue[105],red[105];
int n,m; 
int main(int argc,char* argv[]){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>blue[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>red[i];
	}
	
	int mx=0;
	for(int i=0;i<n;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			if(blue[j]==blue[i]){
				cnt++;
			}
		}
		for(int j=0;j<m;j++){
			if(red[j]==blue[i]){
				cnt--;
			}
		}
		
		mx=max(mx,cnt);
	}
	
	cout<<mx<<endl;
	return 0;
}


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

int main(){
  int n,ans=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<n-2;++i){
    string h = s.substr(i,3);
    if(h == "ABC") ans++;
    
  }
  cout << ans << endl;
}


Measured memory_bytes: 256