akhauriyash/Code-Regression huggingface dataset:
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  h,w,i,j,count,x,y,a,b,sw:Integer;
  s:array of string;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(x);

    count:=0;
    a:=0;
    while not(a>=x) do begin
      inc(count);
      a:=a+count;
    end;

    Writeln(count);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 128
Scanf.scanf "%d %d %d %d %d" (fun x y a b c ->
    let p = Array.init a (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    let q = Array.init b (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    let r = Array.init c (fun _ -> Scanf.scanf " %d" (fun i -> i)) in
    Array.sort (fun a b -> compare b a) p;
    Array.sort (fun a b -> compare b a) q;
    Array.sort (fun a b -> compare b a) r;

    let pq = Array.make (x + y) 0 in
    for i = 0 to x - 1 do
        pq.(i) <- p.(i)
    done;
    for i = 0 to y - 1 do
        pq.(i + x) <- q.(i)
    done;
    Array.sort (fun a b -> compare b a) pq;

    let pqacc = Array.make (x + y) 0 in
    pqacc.(0) <- pq.(0);
    for i = 1 to x + y - 1 do
        pqacc.(i) <- pqacc.(i - 1) + pq.(i)
    done;

    let racc = Array.make c 0 in
    racc.(0) <- r.(0);
    for i = 1 to c - 1 do
        racc.(i) <- racc.(i - 1) + r.(i)
    done;

    let rec loop i acc =
        if i > c || x + y - 1 < i then acc else
            loop (i + 1) (max acc (racc.(i - 1) + pqacc.(x + y - 1 - i)))
    in
    loop 1 pqacc.(x + y - 1) |> Printf.printf "%d\n"
)


Measured memory_bytes: 8960
#include <bits/stdc++.h>
#include <deque>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
typedef long long ll;
int main(void)
{
	int n, q, query, t, x;
	cin >> n >> q;
	vector<deque<int> > S(n);
	
	rep(i, q)
	{
		cin >> query >> t;
		if (query == 0)
		{
			cin >> x;
			S[t].push_back(x);
		}
		else if (query == 1)
		{
		    if (S[t].size())
		    {
			    cout << S[t].back() << endl;
		    }
		}
		else
		{
		    if (S[t].size())
			{
			    S[t].pop_back();
			}
		}
	}
}


Measured memory_bytes: 4352
until(n=gets.to_i)==0
a=(1..n).map{gets}
b=a.map{|x|x.scan /^.|(?<=[aiueo])./}
k=(1..50).find{|i|c=b.map{|x|x[0...i].join};c==c.uniq}
puts k||-1
end

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

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

    int a[n+10];
    rep(i,n) cin >> a[i];

    ll ans = 0;
    ll sum = 0;
    rep(i,n)
    {
        sum += a[i];
        if (i % 2 == 0 && sum <= 0)
        {
            ans += -sum + 1;
            sum = 1;
        }
        if (i % 2 == 1 && sum >= 0) 
        {
            ans += sum + 1;
            sum = -1;
        }
    }

    ll anss = 0;
    sum = 0;
    rep(i,n)
    {
        sum += a[i];
        if (i % 2 == 0 && sum >= 0)
        {
            anss += sum + 1;
            sum = -1;
        }
        if (i % 2 == 1 && sum <= 0) 
        {
            anss += -sum + 1;
            sum = 1;
        }
    }
    cout << min(ans, anss) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>

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

typedef long long ll;

int main()
{
  

    int n;
    cin >> n;
    vector<int> x(n), y(n);

    REP(i, n)
    {
        cin >> x[i];
        cin >> y[i];
    }

    auto dist = [&](int i, int j) {
        double dx = x[i] - x[j];
        double dy = y[i] - y[j];
        return sqrt(dx * dx + dy * dy);
    };

    vector<int> p(n);
    REP(i, n)
    p[i] = i;
    double len = 0;
    int cnt = 0;

    do
    {
        REP(i, n - 1)
        {
            len += dist(p[i], p[i + 1]);
        }
        cnt++;

    } while (next_permutation(p.begin(), p.end()));
    double ans = len / cnt;
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 256
class factorization:
    def __init__(self, N=1_000_010):
        """min_factor[i] = iの最小の素因数"""
        self.min_factor = list(range(N))
        for i in range(2, N):
            if i * i > N:
                break
            for j in range(i * i, N, i):
                if self.min_factor[j] == j:
                    # 小さくできるなら小さくするmin_factor[j] != j => i < j
                    self.min_factor[j] = i

    def fact(self, n):
        """nの素因数分解の結果を{素因数:回数}で返す"""
        d = {}
        while n > 1:
            if self.min_factor[n] in d:
                d[self.min_factor[n]] += 1
            else:
                d[self.min_factor[n]] = 1
            n //= self.min_factor[n]
        return d

    def count_divisors(self, n):
        res = 1
        for v in self.fact(n).values():
            res *= v + 1
        return res

    def sum_divisors(self, n):
        res = 1
        for r, Len in self.fact(n).items():
            res *= (r ** (Len + 1) - 1) // (r - 1)
        return res

    def Eulers_function(self, n):
        res = 1
        for i in self.fact(n):
            res *= (i - 1)
            n //= i
        return res * n


n = int(input())
ans = 0
p = factorization(n)
for i in range(1, n):
    ans += p.count_divisors(i)
print(ans)


Measured memory_bytes: 82616
import itertools
import math
N=int(input())
town=[list(map(int,input().split())) for _ in range(N) ]
sum=0
cnt=0
for path in itertools.permutations(town,N):
    cnt+=1
    for i in range(N-1):
        sum+=math.sqrt((path[i][0]-path[i+1][0])**2+(path[i][1]-path[i+1][1])**2)
print(sum/cnt)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	long long a, b, c; scanf ("%lld %lld %lld", &a, &b, &c);

	if (c - a - b <= 0) puts("No");
	else puts(4 * a * b < (c - a - b) * (c - a - b) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 128
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH RANJAN******************************************************
***********************************************************************************************/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<chrono>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i,n) for(int i=0;i<(int)n;i++)
#define frs(i,a,b) for(int i = a;i<b;i++)
#define meme(a,b,c) memset(a,b,sizeof(c)); //works only for 0 and -1
int main(){
  fast();
  string s;
  cin>>s;
  int n = s.size();
  vector<int> v(n);
  fr(i,n)v[i] = s[i]-'0';
  int sum = 0;
  fr(i,n)sum+=v[i];
  if(sum%9==0)cout<<"Yes";
  else cout<<"No";
 return 0;
  
}




Measured memory_bytes: 4272
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define P3(a, b, c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int sub = min(B, D) - max(A, C);
    if(sub<=0){
        P(0);
    }else{
        P(sub);
    }
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
	val n = readLine()
	val N : Int = n!!.toInt()
	val list1 = readLine()!!.split(" ").map(String::toInt)
	val list2 = readLine()!!.split(" ").map(String::toInt)
	var vList : MutableList<Int> = mutableListOf()
	var cList : MutableList<Int> = mutableListOf()
	var X : Int = 0
	var Y : Int = 0
	for (i in 0..N - 1) {
		vList.add(list1[i])
		cList.add(list2[i])
		if (vList[i] > cList[i]) {
			X += vList[i]
			Y += cList[i]
		}
	}
	println("${X - Y}")
}

Measured memory_bytes: 37904
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int N;
  cin >> N;
  vector<pair<ll, ll>> P;
  rep(i, N) {
    ll x, y;
    cin >> x >> y;
    pair<ll, ll> p = make_pair(x, y);
    P.push_back(p);
  }

  map<pair<ll, ll>, int> M;

  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      pair<ll, ll> pi = P[i];
      pair<ll, ll> pj = P[j];
      bool reverse = false;
      if (pi.first > pj.first) {
        reverse = true;
      } else {
        if (pi.first == pj.first && pi.second > pj.second) {
          reverse = true;
        }
      }

      ll x;
      ll y;
      if (reverse) {
        x = pj.first - pi.first;
        y = pj.second - pi.second;
      } else {
        x = pi.first - pj.first;
        y = pi.second - pj.second;
      }

      pair<ll, ll> p_diff = make_pair(x, y);

      if (M.find(p_diff) != M.end()) {
        M[p_diff]++;
      } else {
        M[p_diff] = 1;
      }
    }
  }

  int no_cost = 0;
  for (auto it = M.begin(), end = M.end(); it != end; ++it) {
    // cout << it->first.first << " " << it->first.second << " " << it->second
    //  << endl;
    no_cost = max(no_cost, it->second);
  }

  cout << N - no_cost << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long  //define a macro variable of long long type
# define  loop(x,n)  for(int x = 0; x < n; ++x)  // define a for loop
#define   constloop(x,a,n) for(int x = a; x < n; ++x)  //define a for loop with start a const
#define  revloop(x,a,n)  for(int x = a; x > n; x--) // rev for loop
//#define   vect vector<ll>  // define a vector of longlong type;


int  main() {

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

   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
set<string>s;

int n;
cin>>n;

loop(i,n)
{
    string p;
    cin>>p;
    s.insert(p);

}

cout<<s.size()<<endl;

   return 0;

}


Measured memory_bytes: 19288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(it,o) for(auto it = (o).begin(); it != (o).end(); ++ it)
typedef long long ll;
struct edge { int to; int from; int cost; };
struct vertex { int x; int y; int idx;};

struct UnionFind {
    vector<int> par; // 親
    vector<int> rank; // 木の深さ

    UnionFind() {
    }

    // n要素で初期化
    void init(int n) {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    // 木の根を求める
    int find(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            return par[x] = find(par[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            return;
        }

        if (rank[x] < rank[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int cost(const vertex& v1, const vertex& v2) {
    return min(abs(v1.x - v2.x), abs(v1.y - v2.y));
}

bool compX(const vertex& v1, const vertex& v2) {
    return v1.x < v2.x;
}

bool compY(const vertex& v1, const vertex& v2) {
    return v1.y < v2.y;
}

bool compCost(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

vector<vertex> vt;
vector<edge> es;
UnionFind uf;

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vt.clear();
        vt.resize(n);
        rep(i, n) {
            in >> vt[i].x >> vt[i].y;
            vt[i].idx = i;
        }
        
        es.clear();
        uf.init(n);
        sort(vt.begin(), vt.end(), compX);
        int c;
        edge e;
        rep(i, n - 1) {
            e.from = vt[i + 0].idx;
            e.to = vt[i + 1].idx;
            e.cost = cost(vt[i + 0], vt[i + 1]);
            es.push_back(e);
        }

        sort(vt.begin(), vt.end(), compY);
        rep(i, n - 1) {
            e.from = vt[i + 0].idx;
            e.to = vt[i + 1].idx;
            e.cost = cost(vt[i + 0], vt[i + 1]);
            es.push_back(e);
        }

        sort(es.begin(), es.end(), compCost);

        ll res = 0;
        each(it, es) {
            if (!uf.same(it->to, it->from))
            {
                uf.unite(it->to, it->from);
                res += it->cost;
            }
        }

        out << res << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}

#include <fstream>
#include <iostream>

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 6900
def main():
    n  = int(input())
    s = list(input().split())
    hina = ['P','W','G','Y']
    hina_type = 0
    for i in hina:
        if i in s:
            hina_type += 1
    if hina_type == 3:
        print('Three')
    if hina_type == 4:
        print('Four')



if __name__ == '__main__':
    main()


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

namespace test
{
    public class Stack
    {
        public static void Main(string[] args)
        {
            var stack = new Stack<int>();
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            for (int i = 0; i < str.Length; ++i)
            {
                var s = str[i];
                if (s == "+")
                {
                    var res = stack.Pop() + stack.Pop();
                    stack.Push(res);
                }
                else if (s == "-")
                {
                    var res = -stack.Pop() + stack.Pop();
                    stack.Push(res);

                }
                else if (s == "*")
                {
                    var res = stack.Pop() * stack.Pop();
                    stack.Push(res);
                }
                else
                {
                    stack.Push(int.Parse(s));
                }
            }
            Console.WriteLine(stack.Pop());
        }

    }
}



Measured memory_bytes: 10100
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
#A
def A():
    t,x = LI()
    print(t/x)

#B
def B():
    n= II()
    a = LI()
    m = max(a)
    if m >= sum(a)-m:
        print("No")
    else:
        print("Yes")


#C
def C():
    n,m = LI()
    x = LI()
    x.sort()
    l = [x[i+1]-x[i] for i in range(m-1)]
    l.sort()
    l = l[::-1]
    ans = sum(l[max(n-1,0):])
    print(ans)

#D
def D():
    n,k = LI()
    a = LI()
    k = list(map(int,list(bin(k)[2:])))
    l = len(k)
    for i in range(n):
        a[i] = list(map(int,list(bin(a[i])[2:])))
        l = max(l,len(a[i]))
    for i in range(n):
        for j in range(l-len(a[i])):
            a[i].insert(0,0)
    for j in range(l-len(k)):
        k.insert(0,0)
    s = [[0,0] for i in range(l)]
    pow2 = [1 for i in range(l)]
    for i in range(l-1)[::-1]:
        pow2[i] = pow2[i+1]*2
    for i in a:
        for j in range(l):
            s[j][0] += pow2[j]*i[j]
            s[j][1] += pow2[j]*(not i[j])
    dp = [0 for i in range(l+1)]
    small = False
    for i in range(l):
        if not small:
            if not k[i]:
                dp[i+1] += dp[i]+s[i][0]
            else:
                if s[i][0] >= s[i][1]:
                    dp[i+1] += dp[i]+s[i][0]
                    small = True
                else:
                    dp[i+1] += dp[i]+s[i][1]
        else:
            dp[i+1] += dp[i]+max(s[i])
    print(dp[l])

#E
if __name__ == "__main__":
    A()

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 40560
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            var k = int.Parse(Console.ReadLine());
            var result = "No";
            for (var i = 0; i < k; i++)
            {
                if (a < b)
                {
                    if (b < c)
                    {
                        break;
                    }
                    else
                    {
                        c = c * 2;
                    }
                }
                else
                {
                    b = b * 2;
                }
            }
            if (a < b && b < c)
            {
                result = "Yes";
            }
            Console.WriteLine(result);
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n);i++)
#define all(v) v.begin,v.end
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MX = 1000005;

int main(){
    string n;
    cin>>n;
    int sum=0;
    rep(i,n.size()) sum+=n[i]-'0';
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3756
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_i
  a = InputLine.to_ia

  b = [nil] * n
  n.times{|i| b[i] = []}
  (n - 1).times do |i|
    b[a[i] - 1].push(i + 1)
  end

  n.times{|i| puts b[i].size.to_s}
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 51100
#include <bits/stdc++.h>
using namespace std;
char grid[50][50];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  char grid[50][50];
  
  int h;
  int w;
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> grid[i][j];
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(grid[i][j] == '#' && 
         	(grid[i-1][j] == '#' ||
          	grid[i+1][j] == '#' ||
          	grid[i][j-1] == '#' ||
          	grid[i][j+1] == '#') == false) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
 
inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar()) 
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}
 
ll a, b;
int main () {
	cin >> a >> b;
	cout << a  * b;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
char s[1005];
int len;
int f1,f2,f3,f4;
int main()
{
	scanf("%s",s);
	len=strlen(s);
	for(int i=0;i<len;i++)
	{
		if(s[i]=='W') f1=1;
		else if(s[i]=='N') f2=1;
		else if(s[i]=='E') f3=1;
		else if(s[i]=='S') f4=1;
	}
	if(f1==f3&&f2==f4) puts("Yes");
	else puts("No");
}

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

int		main()
{
	int		N, K, i;
	int		R, S, P;
	char	*T;
	int		*I;
	int		score;

	i = 0;
	score = 0;
	scanf("%d %d\n", &N, &K);
	scanf("%d %d %d\n", &R, &S, &P);
	T = (char *)malloc(sizeof(char) * (N + 1));
	I = (int *)malloc(sizeof(int) * (N + 1));
	scanf("%s\n", T);
	while (i < N)
	{
		if (i >= K && T[i] == T[i - K] && I[i - K])
			I[i] = 0;
		else
		{
			I[i] = 1;
			if (T[i] == 'r')
				score += P;
			else if (T[i] == 's')
				score += R;
			else //if (T[i] == 'p')
				score += S;
		}
		i++;
	}
	printf("%d\n", score);
	free(T);
	free(I);
	return (0);
}


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


int main()
{
    int t=1;
    //cin>>t;
    while( t-- )
    {
        string s,t;
        cin>>s>>t;

        int ctr=0;
        for( int i=0 ; i<s.size() ; i++ )
            if( s[i]!=t[i] )
            ctr++;

        cout<<ctr;
    }
    return 0;
}


Measured memory_bytes: 3856
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,k,i;(n=s.nextInt())>0;){int[]a=new int[k=s.nextInt()];for(i=0;i<k;++i)a[i]=s.nextInt();for(;n-->0;)for(i=0;i<k;++i)a[i]-=s.nextInt();Arrays.sort(a);System.out.println(a[0]<0?"No":"Yes");}}}

Measured memory_bytes: 12000
if __name__ == '__main__':
	n,q = map(int,input().split())
	process = []
	time = []
	for i in range(n):
		p,t = map(str,input().split())
		process.append(p)
		time.append(int(t))
	total = 0
	while len(process) != 0:
		run = process.pop(0)
		t = time.pop(0)
		diff = t - q
		if diff <= 0:
			print("%s %d" % (run,total+t))
			total+=t
		else:
			total += q
			process.append(run)
			time.append(diff)


Measured memory_bytes: 9308
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> P;
int main(){
	int n;
	vector<map<int,int>> mp(2);
	cin>>n;
	for(int i=0;i<n;i++){
		int v;
		cin>>v;
		if(i%2==0) mp[0][v]++;
		else mp[1][v]++;
	}
	vector<vector<P>> V(2);
	for(int i=0;i<2;i++){
		for(auto itr=mp[i].begin();itr!=mp[i].end();++itr){
			V[i].emplace_back(P(itr->second,itr->first));
		}
	}
	for(int i=0;i<2;i++) sort(V[i].rbegin(),V[i].rend());
	if(V[0].size()<2&&V[1].size()<2){
		if(V[0][0].second!=V[1][0].second){ 
			cout<<0;
			return 0;
		}
		else{
			cout<<n/2;
			return 0;
		}	
	}
	for(int i=0;i<2;i++) if(V[i].size()<2){
		if(V[i][0].second!=V[1-i][0].second){
			cout<<n-V[i][0].first-V[1-i][0].first;
			return 0;
		}
		else{
			cout<<n-V[i][0].first-V[1-i][1].first;
			return 0;
		}
	}
	
	
	int ret[2][2][2];
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			ret[i][j][0]=V[i][j].first;
			ret[i][j][1]=V[i][j].second;
		}
	}
	int d0=ret[0][0][0]-ret[0][1][0];
	int d1=ret[1][0][0]-ret[1][1][0];
	if(ret[0][0][1]!=ret[1][0][1]) cout <<n- ret[0][0][0]-ret[1][0][0];
	else if(d0<d1) cout << n - ret[0][1][0] -ret[1][0][0];
	else cout<<n-ret[0][0][0]-ret[1][1][0];
}

Measured memory_bytes: 6136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC087_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int fiveHundredCoin = int.Parse(Console.ReadLine());
            int oneHundredCoin = int.Parse(Console.ReadLine());
            int fiftyCoin = int.Parse(Console.ReadLine());
            int totalFee = int.Parse(Console.ReadLine());

            int wayAmount = 0;
            for (int i = 0; i <= fiveHundredCoin; i++)
            {
                for (int j = 0; j <= oneHundredCoin; j++)
                {
                    for (int k = 0; k <= fiftyCoin; k++)
                    {
                        if (i * 500 + j * 100 + k * 50 == totalFee)
                        {
                            wayAmount++;
                        }
                    }
                }
            }

            Console.WriteLine(wayAmount);
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;

#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(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  REP(i, n) a[i]--;
  vector<int> visit(n, -1);
  int count = 0;
  int now = 0;
  int next = 0;
  REP(i, n){
    count++;
    next = a[now];
    if (next == 1){
      cout << count << endl;
      return 0;
    }
    if (visit[next] != -1) break;
    visit[next] = count;
    now = next;
  }
  cout << -1 << endl;
  return 0;
}



Measured memory_bytes: 3996
use std::collections::BTreeMap;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();

    let mut map = BTreeMap::new();

    for &a_i in a.iter() {
        *map.entry(a_i).or_insert(0) += 1;
    }

    let ans = if a.iter().all(|&x| x == 0)
        || (map.len() == 2 && map.get(&0) == Some(&(n / 3)))
        || (map.len() == 3
            && map.keys().fold(0, |a, x| a ^ x) == 0
            && map.values().all(|x| *x == n / 3))
    {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int h, n, dp[10001], a[1000], b[1000];

int main(){
	cin >> h >> n;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = 1; i <= h; i++){
		dp[i] = INT_MAX;
		for(int j = 0; j < n; j++) dp[i] = min(dp[i], dp[max(0, i - a[j])] + b[j]);
	}
	cout << dp[h] << "\n";
	return 0;
}



Measured memory_bytes: 256
<?php

$is_honban = 1;

if ($is_honban) {
  //----------------------------------------------------------------------------------
  // Input for honban
  //----------------------------------------------------------------------------------
  $sc = new Scanner();
  $n = $sc->nextInt();
  $y = $sc->nextInt();

//  $a = array();
//  for ($i = 0; $i < $n; $i++) {
//    $a[] = $sc->nextInt();
//  }


} else {
  //----------------------------------------------------------------------------------
  // Input for test
  //----------------------------------------------------------------------------------
  error_reporting(E_ERROR | E_WARNING | E_PARSE);

  $n = 9;
  $y = 45000;


}
//----------------------------------------------------------------------------------
// Main
//----------------------------------------------------------------------------------

$ans = 0;

$ok = 0;
for ($i = 0; $i <= $n; $i++) {
  for ($j = 0; $j <= $n - $i; $j++) {
    $k = $n - $i - $j;
    if ($i * 10000 + $j * 5000 + $k * 1000 == $y) { $ok = 1; break 2; }
  }
}

if ($ok == 1) { $ans = $i . ' ' . $j . ' ' . $k; }
else { $ans = '-1 -1 -1'; }


//----------------------------------------------------------------------------------
// Output
//----------------------------------------------------------------------------------
out::println($ans);



//----------------------------------------------------------------------------------
// Ref: https://qiita.com/yoshikyoto/items/6924478283dbdd549e4b
//----------------------------------------------------------------------------------
class Scanner {
  private $arr = array();
  private $count = 0;
  private $pointer = 0;
  public function next() {
    if($this->pointer >= $this->count) {
      $str = trim(fgets(STDIN));
      $this->arr = explode(' ', $str);
      $this->count = count($this->arr);
      $this->pointer = 0;
    }
    $result = $this->arr[$this->pointer];
    $this->pointer++;
    return $result;
  }
  public function hasNext() {
    return $this->pointer < $this->count;
  }
  public function nextInt() {
    return (int)$this->next();
  }
  public function nextDouble() {
    return (double)$this->next();
  }
}

class out {
  public static function println($str = "") {
    echo $str . PHP_EOL;
  }
}

?>


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout<<'\n';
#define pii pair<int,int>

using namespace std;
const int H=1e9;
const int N=1e5+100;

string s,t;

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

   // freopen("test11.INP","r",stdin);
   // freopen("test.OUT","w",stdout);

   cin>>s;
   cin>>t;
   int res=1e4;
   for (int i=0; i<s.size()-t.size()+1; i++)
   {

       int dem=0;
       for (int j=0; j<t.size() ; j++)
            dem+=(t[j]!=s[j+i]);

        res=min(res,dem);
   }
   cout<<res;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    string S,T;
    cin >> S >> T;
    int ret = 0;
    for(int i = 0;i < S.size();i++) {
        if(S.at(i) != T.at(i)) {
            ret++;
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3920
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const LL INF=1e18;
LL k;
LL a[1000001];
int main() {
    scanf("%lld",&k);
    for (int i=1;i<=k;i++) scanf("%lld",&a[i]);
    LL l=2,r=2;
    for (int i=k;i>=1;i--) {
        LL lx=0,rx=INF;
        while (lx<rx) {
            LL mid=(lx+rx)/2;
            if (mid/a[i]*a[i]<l) lx=mid+1;
            else rx=mid;
        }
        LL lx2=0,rx2=INF;
        while (lx2<rx2) {
            LL mid=(lx2+rx2+1)/2;
            if (mid/a[i]*a[i]>r) rx2=mid-1;
            else lx2=mid;
        }
        if (lx>lx2) {
            printf("-1\n");
            return 0;
        }
        l=lx;
        r=lx2;
    }
    printf("%lld %lld\n",l,r);
    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys

n= int(input())
#tmp= float(input())

min=1000000
max=-1000000
total=0

tmp = input().split()
a = list(map(lambda a: int(a), tmp))

#print(a)
for i in range(n):
    if(a[i]<min):
        min=a[i]
    if(a[i]>max):
        max=a[i]
    total+=a[i]
print(min,max,total)





Measured memory_bytes: 6600
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int cmp(int a,int b,int c,int d)
{
    return min(min(a+d,b+c),min(a+c,b+d));
}
int main()
{
    int a,b,c,d;
    while(cin>>a>>b>>c>>d)
    cout<<cmp(a,b,c,d)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL/*ここを埋める (fill this blank)*/) printf("root, ");
  else if(T[u].l == NIL/*ここを埋める(fill this blank)*/) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
 
  if(T[u].l != NIL/*ここを埋める(fill this blank)*/) {
    calcDepth(T[u].l, p+1/*ここを埋める(fill this blank)*/);
   }
 
  if(T[u].r != NIL/*ここを埋める(fill this blank)*/) {
    calcDepth(T[u].r, p/*ここを埋める(fill this blank)*/);
   }
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}




Measured memory_bytes: 3284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String str[] = br.readLine().split(" ");
	int A = Integer.parseInt(str[0]);
	int B = Integer.parseInt(str[1]);

	System.out.println(Math.max(A - 2 * B, 0));
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <map>
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) + 1; i++)
#define all(vecto) vecto.begin(), vecto.end()
#define max3(a, b, c) max(a, max(b, c))
#define min3(a,b,c) min(a,min(b,c))
typedef long long ll;

void ans(bool qus){
    if (qus == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Ans(bool qust){
    if (qust == true)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

////////////////---START---////////////////

void solve(int a, int b){
    if (b < a){
        cout << a - 1 << endl;
    }
    else if (b >= a){
        cout << a << endl;
    }
}

int main(){
    int a,b;
    cin >> a >> b;
    solve(a, b);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
AC
番兵入れて実装軽くした
*/

ll a,b,q,n;
vector<ll> s,t,x;

int main(void){
	cin>>a>>b>>q;
	s.push_back(-1e15);
	t.push_back(-1e15);
	rep(i,a){
		cin>>n;
		s.push_back(n);
	}
	rep(i,b){
		cin>>n;
		t.push_back(n);
	}
	s.push_back(1e15);
	t.push_back(1e15);
	rep(i,q){
		cin>>n;
		x.push_back(n);
	}
	//
	rep(i,q){
		ll y[2],z[2],ans=1e18;
		auto itrs = lower_bound(s.begin(),s.end(),x[i]);
		auto itrt = lower_bound(t.begin(),t.end(),x[i]);
		y[1]=*itrs;
		itrs--;
		y[0]=*itrs;
		z[1]=*itrt;
		itrt--;
		z[0]=*itrt;
		ans=min({
			abs(x[i]-y[0])+abs(y[0]-z[0]),
			abs(x[i]-y[0])+abs(y[0]-z[1]),
			abs(x[i]-y[1])+abs(y[1]-z[0]),
			abs(x[i]-y[1])+abs(y[1]-z[1]),
			abs(x[i]-z[0])+abs(z[0]-y[0]),
			abs(x[i]-z[0])+abs(z[0]-y[1]),
			abs(x[i]-z[1])+abs(z[1]-y[0]),
			abs(x[i]-z[1])+abs(z[1]-y[1])
		});
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

int counter = 9;

int get(int r) {
  if (r <= 399) return 1;
  if (r <= 799) return 2;
  if (r <= 1199) return 3;
  if (r <= 1599) return 4;
  if (r <= 1999) return 5;
  if (r <= 2399) return 6;
  if (r <= 2799) return 7;
  if (r <= 3199) return 8;
  return counter++;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> ratings(n);
  for (int i = 0; i < n; i++) {
    cin >> ratings[i];
  }
  set<int> colors;
  for (int r : ratings) {
    colors.insert(get(r));
  }
  int above = counter - 9;
  int mini = 0;
  int maxi = colors.size();
  while (!colors.empty() && *colors.begin() <= 8) {
    mini++;
    colors.erase(colors.begin());
  }
  if (above == n) mini = 1;
  else {
    // do nothing, color all as others.
  }
  cout << mini << " " << maxi << endl;
  return 0;
}


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

int const MAXab = 2e5;

int64_t MOD = 1e9+7;

int64_t ifact[MAXab+1];
int64_t inv[MAXab+1];

int n, a, b;

void init() {
  ifact[0] = ifact[1] = 1;
  inv[0] = inv[1] = 1;
  int mab = std::max(a, b);
  for(int i = 2; i <= mab; ++i) {
    inv[i] = MOD - (MOD/i)*inv[MOD%i]%MOD;
    ifact[i] = ifact[i-1]*inv[i]%MOD;
  }
}

int64_t comb(int n, int x) {
  int64_t res = 1;
  for(int i = n-x+1; i <= n; ++i) (res *= i) %= MOD;
  (res *= ifact[x]) %= MOD;
  return res;
}

int64_t pow2(int n) {
  switch(n) {
  case 0: return 1;
  case 1: return 2;
  case 2: return 4;
  case 3: return 8;
  default:;
  }
  int64_t res = pow2(n/2);
  (res *= res) %= MOD;
  if(n%2) (res += res) %= MOD;
  return res;
}

int main() {
  std::cin >> n >> a >> b;
  init();
  int64_t ans = pow2(n);
  (ans += (MOD - comb(n, a)) + (MOD - comb(n, b)) - 1) %= MOD;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3456
# coding: utf-8
# Your code here!
N = int(input())
S = [int(i) for i in input().split()]
INF = 10**10

def merge(s, l, m, r):
    cnt = 0
    s1 = list(s[l:m])
    s2 = list(s[m:r])

    s1.append(INF)
    s2.append(INF)
    
    i = 0
    j = 0
    for k in range(l, r):
        #print(s1, s2)
        if s1[i] <= s2[j]:
            s[k] = s1[i]
            i += 1
        else:
            s[k] = s2[j]
            j += 1
            cnt += (m - l - i)
    return cnt

def merge_sort(s, l, r, cnt):
    if l + 1 < r:
        m =  (l + r) // 2
    
        cnt = merge_sort(s, l, m, cnt)
        cnt = merge_sort(s, m, r, cnt)
    
        cnt += merge(s, l, m, r)
    return cnt
    
cc = merge_sort(S, 0, len(S), 0)
print(cc)



Measured memory_bytes: 27488
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
counter = [] #要素の種類別にいくつあるかを並べたもの
x = 0
count = 1
while x < n-1:
	for i in range(n-x-1):
		if a[x] == a[x+1+i]:
			count += 1
		else:
			break
	counter.append(count)
	x = x+1+i
	count = 1
if a[n-2] != a[n-1]:
	counter.append(1)
counter.sort()

y = len(counter)
l = y
answer = 0
for i in range(y): #同じ種類の要素が少ないものから順に書き換える
	if l > k:
		answer += counter[i]
		l = l - 1
	else:
		break
print(answer)

Measured memory_bytes: 25124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using pllll = pair<ll, ll>;

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

//pow(llpow,modpow)
template <class T>
ll llpow(ll x, T n)
{
    ll ans = 1;
    if (x == 0)
        ans = 0;
    while (n)
    {
        if (n & 1)
            ans *= x;
        x *= x;
        n >>= 1;
    }
    return ans;
}
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
template <class T>
inline T gcd(T x, T y)
{
    if (y == 0)
        return x;
    else
    {
        return gcd(y, x % y);
    }
}
//最小公倍数
template <class T>
inline T lcm(T x, T y) { return x / gcd(x, y) * y; }
//逆元
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i - 1; i >= (ll)end_i; i--)
long long INF = 1LL << 60;

vector<ll> yakusu(ll x){
    vll ret;
    for(ll i=1;i*i<=x;i++){
        if(x%i==0){
            if(i!=x/i)
            ret.push_back(i);
            ret.push_back(x/i);
        }
    }
    return ret;
}

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    unordered_map<ll, int> mp;
    vll first=yakusu(n-1);
    for(ll t:first){
        if(mp.count(t)==0&&t!=1){
            ans++;
            mp[t]++;
        }
    }
    //nの約数のうち，操作を行なって最終的にnが1になる数
    vll second=yakusu(n);
    for(ll t:second){
        if(mp.count(t)==0&&t!=1){
            ll cp=n;
            while(cp%t==0){
                cp/=t;
            }
            cp%=t;
            if(cp==1){
                ans++;
                mp[t]++;
            }
       }
    }
    cout << ans << endl;
    return 0;
}


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

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


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

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

    int n = s.size();
    int ans = 0;
    int nextColor = abs((s[0] - '0') - 1);
    for (int i = 1; i < n; i++)
    {
        if (nextColor != (s[i] - '0'))
            ans++;
        nextColor = abs(nextColor - 1);
    }

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

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

using namespace std;

const int N=2e5+5;

typedef long long LL;

int n,tot,h[N],e[N],nxt[N],len[N],Size[N],f[N];

LL dep[N],ans,sum;

char c;

int read()
{
	int x=0,sig=1;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}

void Add(int x,int y,int z)
{
	e[++tot]=y; nxt[tot]=h[x]; h[x]=tot; len[tot]=z;
}

void Init(int x,int y)
{
	for (int i=h[x];i;i=nxt[i]) if (e[i]!=y)
	{
		dep[e[i]]=dep[x]+len[i]; Init(e[i],x);
	}
}

void dfs(int x,int y)
{
	Size[x]=1; f[x]=0;
	for (int i=h[x];i;i=nxt[i]) if (e[i]!=y)
	{
		dfs(e[i],x); Size[x]+=Size[e[i]]; f[x]=max(f[x],Size[e[i]]);
	}
	f[x]=max(f[x],n-Size[x]);
}

int main()
{
	n=read();
	for (int i=1,x,y,z;i<n;i++)
	{
		x=read(); y=read(); z=read();
		Add(x,y,z); Add(y,x,z);
	}
	dfs(1,0);
	int mi=n;
	for (int i=1;i<=n;i++) mi=min(mi,f[i]);
	for (int i=1;i<=n;i++) if (f[i]==mi)
	{
		dep[i]=0; Init(i,0);
		sum=0;
		for (int j=1;j<=n;j++) sum+=dep[j]; sum<<=1;
		int sb=1e9;
		for (int j=h[i];j;j=nxt[j])
		{
			if (f[e[j]]==mi)
			{
				sb=len[j]; break;
			}
			sb=min(sb,len[j]);
		}
		ans=max(ans,sum-sb);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll check[110000];

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  vll v;
  ll cnt = 0LL;
  ll a = x;
  rep(i,m) {
    v.push_back(a);
    cnt += a;
    check[a] = true;
    a *= a;
    a %= m;
    if(check[a]) break;
    if(a==0) {
      cout << cnt << endl;
      return 0;
    }
  }
  if(a==x) {
    ll s = v.size();
    ll ans = 0LL;
    ll c = n - n%s;
    ll b = c/s;
    ans += cnt*b;
    rep(i,n%s) ans += v[i];
    cout << ans << endl;
  }
  else {
    ll ans = 0LL;
    bool swi = true;
    vll vv;
    ll vs = v.size();
    rep(i,vs) {
      if(v[i]==a) swi = false;
      if(swi) {
        ans += v[i];
        n--;
      }
      else vv.push_back(v[i]);
    }
    ll s = vv.size();
    ll sum = 0LL;
    rep(i,s) sum += vv[i];
    ll b = n/s;
    ans += sum*b;
    rep(i,n%s) ans += vv[i];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5056