akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import defaultdict, deque

sys.stdin.readline().split()
A = defaultdict(deque)
ans = []

for query in sys.stdin:
    if query[0] == '0':
        t, x = query[2:].split()
        A[t].append(x)
    elif query[0] == '1':
        ans.append(' '.join(A[query[2:-1]]) + '\n')
    else:
        s, t = query[2:].split()
        if A[t]:
            if len(A[s]) == 1:
                A[t].append(A[s][0])
            elif len(A[t]) == 1:
                A[s].appendleft(A[t][0])
                A[t] = A[s]
            else:
                A[t].extend(A[s])
        else:
            A[t] = A[s]
        A[s] = deque()

sys.stdout.writelines(ans)



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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

ll tri(ll N)
{
    if(N < 2) return 0;
    else return N * (N - 1) / 2;
}

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

    map<ll,ll> A;
    vector<ll> NUM(N);
    for(int i=0;i<N;i++)
    {
        ll x;
        cin >> x;
        NUM.at(i)=x;
        A[x]++;
    }

    vector<ll> val(A.size(),0);

    int counter = 0;

    for(auto x : A)
    {
        val.at(counter) += x.second;
        counter++;
    }

    ll ALL = 0;

    for(int i=0;i<val.size();i++)
    {
        ALL += tri(val.at(i));
    }

    for(int i=0;i<NUM.size();i++)
    {
        cout << ALL - (A.at(NUM.at(i))-1) << endl;
    }

    return 0;
}

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

using namespace std;

int dis(char c) {
    return 'a' + 26 - c;
}

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

    int sz = s.size();
    for (int i = 0; i < sz - 1; i++) {
        if (s[i] == 'a') continue;
        if (dis(s[i]) > K) continue;
        K -= dis(s[i]);
        s[i] = 'a';
    }
    K %= 26;
    s[sz - 1] = (s[sz - 1] + K - 'a') % 26 + 'a';

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

Measured memory_bytes: 35808
# 2019-11-14 17:27:23(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left as bi_l, bisect_right as bi_r
import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n, x, *l = [int(i) for i in sys.stdin.read().split()]
    
    culmative_sum = list(itertools.accumulate(l))
    ans = 1 + bi_r(culmative_sum, x)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}


int main() {
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;

}



Measured memory_bytes: 256
import numpy as np
import math
import collections
import fractions
import itertools

def solve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = math.ceil((n-k)/(k-1)+1)
    print(ans)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 23780
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>>p(N);
	for (int i = 0; i < N; i++)cin >> p[i].first >> p[i].second;
	sort(all(p));

	priority_queue<ll>pq;
	ll ans = 0;
	int cur = 0;
	for (int i = 1; i <= M; i++) {
		while (cur < N && p[cur].first <= i){
			pq.push(p[cur].second);
			cur++;
		}
		if (pq.size()) {
			ans += pq.top();
			pq.pop();
		}
	}
	puts(ans);

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n+2, 0);
    for(int i = 2; i <= n; ++i){
        int a;
        cin >> a;
        x[a]++;
    }
    for(int i = 1; i <= n; ++i) {
        cout << x[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3960
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define freq           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005
ll freq[N];
ll n,x,y;

ll fun(ll u,ll v)
{
	return min(v-u,min(abs(v-x)+abs(y-u)+1,abs(v-y)+abs(x-u)+1));
	// if(u==x && v==y)
	// 	return 1;
	// if(v<=x || u>=y)
	// {
	// 	return (v-u);
	// }
	// if((u>x && v<y))
	// {
	// 	return min(v-u,x-u+y-v+1);
	// }
	// if((u>x && u<y))
	// {
	// 	return min(v-u,u-x+v-y+1);
	// }
	// if((v>x && v<y))
	// {
	// 	return min(v-u,y-v+x-u+1);
	// }
	// return min(x-u+v-y+1,v-u);	
}

void solve()
{
	cin>>n>>x>>y;
	// ll ans=0;
	rep(i,1,n+1)
	{
		rep(j,i+1,n+1)
		{
			freq[fun(i,j)]++;
			// if(fun(i,j)==5)
			// {
			// 	cout<<i<<" "<<j<<endl;
			// }
		}
	}
	rep(i,1,n)
	{
		cout<<freq[i]<<endl;
	}
	return;
}
int main()
{
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.root[x-1] < 0:
            return x
        else:
            self.root[x-1] = self.find(self.root[x-1])
            return self.root[x-1]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
        else:
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]

N,M=map(int,input().split())
T=[tuple(map(int,input().split())) for i in range(M)]
u=UnionFind(N)
for a,b in T:
    u.union(a,b)
ans=0
for i in range(1,N+1):
    ans=max(ans,u.count(i))
print(ans)

Measured memory_bytes: 108316
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>
#include <cstdlib>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//DP処理用
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; }

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))
sort(変数名.begin(), 変数名.end());*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<ll> data(3);
REP(i,3) cin>>data[i];
sort(data.begin(), data.end());
cout<<data[0]+data[1];
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>

int main(int argc, char const *argv[])
{
    int input_x, input_y;
    std::vector<int> x;
    std::vector<int> y;

    while (1)
    {
        std::cin >> input_x >> input_y;
        if (input_x == 0 && input_y == 0)
        {
            break;
        }
        else
        {
            x.push_back(input_x);
            y.push_back(input_y);
        }
    }

    for (int i = 0; i < x.size(); i++)
    {
        if (x[i] < y[i])
        {
            std::cout << x[i] << " " << y[i] << std::endl;
        }
        else
        {
            std::cout << y[i] << " " << x[i] << std::endl;
        }
    }

    return 0;
}



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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;


int main(){

    int N,K;
    cin>>N>>K;

    long long A[N];

    rep(i,N)cin>>A[i];

    long long buildings[N];
    buildings[0]=1;
    rep(i,N-1)buildings[i+1]=buildings[i]*2;

    long long ans=INF;

    vector<int>v(N);
    for(int i=0;i<(1<<N);i++){
        bool seen[N]={};

        rep(k,N)if(buildings[k]&i)seen[k]=true;

        long long now=0;
        long long total=0;
        int see=0;

        for(int l=0;l<N;l++)
        {
            
            if(seen[l]){
                see++;
                if(now>=A[l]){
                    now++;
                    total+=now-A[l];
                }
                else{
                    now=max(A[l],now);
                }
            }
            else{
                now=max(A[l],now);
            }
        }

        if(see>=K){
            if(ans>=total){
            ans=total;
                /*
                rep(l,N){
                    if(seen[l])v[l]=1;
                    else{
                    v[l]=0;
                    }
                }
                */
            }
        
        }

    }
    
    cout<<ans<<endl;
    //rep(i,N)cout<<v[i]<<" ";
    //cout<<endl;
    return 0;

}
/*


*/


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseArray(x::Array{SubString{String}, 1}) = map(parseInt, x)

function main()
  a, v = readline() |> split |> parseArray
  b, w = readline() |> split |> parseArray
  t = readline() |> parseInt

  ans="NO"
  if v > w && abs(a-b)/(v-w)<=t
    ans="YES"
  end

  println(ans)
end

main()


Measured memory_bytes: 161544
from itertools import permutations

N, M, R = map(int, input().split())
R = list(map(lambda a: int(a) - 1, input().split()))

minDist = [[10**18] * N for _ in range(N)]
for _ in range(M):
    fr, to, cost = map(int, input().split())
    fr -= 1
    to -= 1
    minDist[fr][to] = cost
    minDist[to][fr] = cost
for i in range(N):
    minDist[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            d = minDist[i][k] + minDist[k][j]
            if minDist[i][j] > d:
                minDist[i][j] = d

ans = 10**18
for P in permutations(R, r=len(R)):
    cost = 0
    for fr, to in zip(P, P[1:]):
        cost += minDist[fr][to]
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 46552
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(void) {
    int n, l;
    cin >> n >> l;
    string s[n];
    rep (i, n) cin >> s[i];

    sort(s, s + n);

    string ans = "";
    rep (i, n) ans += s[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

class UnionFindTree{
private:
  int* mParent;
  int* mRank;
  int mSize;

public:
  UnionFindTree(int n){
    mSize = n;
    mParent = new int[n];
    mRank = new int[n];

    for(int i=0; i < n; i++){
      mParent[i] = i;
      mRank[i] = 0;
    }
  }

  ~UnionFindTree(){
    delete[] mParent;
    delete[] mRank;
  }

  bool same(int lhs,int rhs){
    return (find(lhs) == find(rhs) ? true : false);
  }

  int find(int pos){
    if(pos == mParent[pos]) return pos;
    return find(mParent[pos]);
  }
  
  void unite(int lhs,int rhs){
    lhs = find(lhs);
    rhs = find(rhs);
    
    if(lhs == rhs) return;
    
    if(mRank[lhs] > mRank[rhs]){
      mParent[rhs] = lhs;
    }
    else{
      mParent[rhs] = lhs;
      if(mRank[lhs] == mRank[rhs]) mRank[lhs]++;
    }
  }

  int size() const{
    return mSize;
  }
};

class State{
public:
  int from;
  int to;
  int cost;
  State(int _f,int _t,int _c) :
    from(_f), to(_t), cost(_c) {}
  bool operator<(const State& s) const{
    return cost < s.cost;
  }
  bool operator>(const State& s) const{
    return cost > s.cost;
  }
};

int main(){
  int num_of_nodes;
  int num_of_edges;
  while(~scanf("%d %d",&num_of_nodes,&num_of_edges)){
    if(num_of_nodes == 0 && num_of_edges == 0) break;

    priority_queue<State,vector<State>,greater<State> > que;
    for(int edge_idx = 0; edge_idx < num_of_edges; edge_idx++){
      int from,to,cost;
      scanf("%d %d %d",&from,&to,&cost);
      from--; to--;
      que.push(State(from,to,cost));
    }

    UnionFindTree uft(num_of_nodes);

    vector<int> log;
    while(!que.empty()){
      State s = que.top();
      que.pop();
      if(!uft.same(s.from,s.to)){
        uft.unite(s.from,s.to);
        log.push_back(s.cost);
      }
    }

    printf("%d\n",log[log.size()/2]);
  }
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
using namespace std;
const int maxn=200020;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,k,len[26],mxlen[26];
char s[maxn];
long long ans;
int main(){
	scanf("%s",s+1);n=strlen(s+1);k=read();
	if(s[1]==s[n]){
		int cnt1=0,cnt2=0;
		FOR(i,1,n) if(s[i]==s[1]) cnt1++;
		else break;
		ROF(i,n,1) if(s[i]==s[n]) cnt2++;
		else break;
		if(cnt1==n){
			printf("%lld\n",1ll*n*k/2);
			return 0;
		}
		ans-=1ll*cnt1/2*k+1ll*cnt2/2*k;
		ans+=cnt1/2+cnt2/2+1ll*(cnt1+cnt2)/2*(k-1);
	}
	FOR(i,1,n+1){
		FOR(j,0,25) if(s[i]==j+'a') len[j]++;
		else{
			if(len[j]) ans+=1ll*len[j]/2*k;
			len[j]=0;
		}
	}
	printf("%lld\n",ans);
}

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

using ll=long long;

int main() {
  int N,K; cin >>N >>K;
  vector<int> A(N);
  rep(i,0,N) {
    cin >>A[i];
  }
  vector<int> c(N+1);
  rep(i,0,N) {
    c[A[i]]++;
  }
  sort(c.rbegin(),c.rend());
  int ans=N;
  rep(i,0,K) {
    ans-=c[i];
  }
  cout <<ans <<endl;
  return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 100010, mod = 1e9 + 7;

int n, a[N];
LL sum, res, ans;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);

    sum = 0;
    for(int i = 1, s = 1; i <= n; i++, s *= -1)
    {
        sum += a[i];
        if(sum * s <= 0) res += abs(sum - s), sum = s;
    }

    sum = 0;
    for(int i = 1, s = -1; i <= n; i++, s *= -1)
    {
        sum += a[i];
        if(sum * s <= 0) ans += abs(sum - s), sum = s;
    }

    printf("%lld\n", min(res, ans));
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
typedef long long LL;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y)((x)>(y)?(x):(y))
#define mi(x,y)((x)<(y)?(x):(y))
int upLL(const void*a,const void*b){return*(LL*)a-*(LL*)b;}

int main(){
  LL a[2],ans=1e11;
  scanf("%lld%lld",a,a+1);
  if(!(a[0]%3*a[1]%3)){printf("0");return 0;}
  rep(i,2){//たてよこ対等
    LL x=a[i],y=a[i?0:1],z[3],s=x*y;
    Rep(j,Ma(1,x/3-2),mi(x,x/3+3)){//||,|-
      z[0]=y*j,z[1]=y*((x-j)/2),z[2]=s-z[0]-z[1];
      qsort(z,3,8,upLL);
      ans=mi(ans,z[2]-z[0]);
      z[0]=y*j,z[1]=(y/2)*(x-j),z[2]=s-z[0]-z[1];
      qsort(z,3,8,upLL);
      ans=mi(ans,z[2]-z[0]);
    }
  }
  printf("%lld",ans);
  return 0;
}

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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

bool IsPrime(ll num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    
    string t1, t2;
    t1 = s.substr(0, n/2);
    t2 = s.substr(n/2);
    //cout << t1 << " " << t2 << endl;

    if(t1 == t2) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
  n,m = ints()
  dig = [None]*(n);flg = False
  for _ in range(m):
    s,c=ints()
    if dig[s-1]==None:
      dig[s-1]=c
    elif dig[s-1]!=c:
      flg = True
  if flg or (n!=1and dig[0]==0):
    print(-1)
  else:
    num=0
    for i in range(n):
      if i==0 and dig[0]==None and n!=1:
        dig[0]=1
      elif dig[i]==None:
        dig[i]=0
      num += dig[i]*10**(n-1-i)
    print(num)
      
if __name__ == '__main__':
  main()

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

int main()
{
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	while(n--){
		int t;
		cin >> t;
		if(t >= k) cnt++; 
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int p=0,q,sum=0;
  for(int i=0;i<3;i++){
    int a;
    cin>>a;
    sum+=a;
    if(p<a){
      q=a;
      p=a;
    }
  }
  int k;
  cin>>k;
  for(int i=0;i<k;i++){
    p*=2;
  }
  cout<<p+sum-q<<endl;
  return(0);
}

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

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

    int r, d, x;
    cin >>r >> d >> x;
    for (int i = 0; i < 10; i++) {
        x = r * x - d;
        cout <<x << '\n';
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

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

    map<ll, ll> dist;
    ll sum = 0;
    dist[sum]++;

    rep(i, n){
        sum += a[i];
        dist[sum%m]++;
    }

    ll ans = 0;
    for(auto itr = dist.begin(); itr != dist.end(); ++itr){
        ans += itr->second*(itr->second-1)/2;
    }

    cout << ans << endl;

}

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

signed main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n);
	int pi, qi;
	for (int i = 0; i < n; ++i)cin >> p[i];
	for (int i = 0; i < n; ++i)cin >> q[i];
	int i = 0;
	vector<int> v;
	for (int i = 1; i <= n; ++i)v.push_back(i);
	do {
		if (p == v)pi = i;
		if (q == v)qi = i;
		++i;
	} while (next_permutation(v.begin(), v.end()));
	cout << std::abs(pi - qi) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
ll a, b, n;

int main(){
	IOS
	cin >> a >> b >> n;
	ll x=min(n, b-1);
	cout << (a*x)/b << '\n';
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    int n, t;
    cin >> n;
    char s[101];

    pair<pair<string, int>, int> p[110];

    for ( int i = 0; i < n; i++ ) {
        cin >> s >> t;
        p[i] = make_pair(make_pair(s, -t), i);
    }

    sort(p, p+n);
    // firstが小さい順、secondが小さい順にソート
    for ( int i = 0; i < n; i++ ) {
        cout << p[i].second+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>

using namespace std;

bool check(vector<string> S, int i, int j, int H,int W){
	if(S[i][j]=='.')
		return true;
	if(i>0){
		if(S[i-1][j]=='#'){
			return true;
		}
	}
	if(i<H-1){
		if(S[i+1][j]=='#'){
			return true;
		}
	}
	if(j>0){
		if(S[i][j-1]=='#'){
			return true;
		}
	}
	if(j<W-1){
		if(S[i][j+1]=='#'){
			return true;
		}
	}
	//cout<<i<<" "<<j<<endl;
	return false;
}

int main(){
	int H,W;
	cin>>H>>W;
	vector<string> S(H);
	for(int i=0;i<H;i++){
		cin>>S[i];
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(!check(S,i,j,H,W)){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n,cnt;
void solve(){
	cin>>n;
	queue<ll> q;
	rep(i,1,10)q.push(i);
	while(1){
		int m = q.size();
		for(int i=0;i<m;i++){
			ll s = q.front();
			q.pop();
			if(++cnt==n){
				cout<<s;
				return ; 
			}
			if(s%10==0)q.push(s*10),q.push(s*10+1);
			else if(s%10==9)q.push(s*10+8),q.push(s*10+9);
			else q.push(s*10+(s%10)-1),q.push(s*10+s%10),q.push(s*10+(s%10)+1);
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#define ISTRUE(a) (a)?"T":"F"
using namespace std;

int N;
int N_digit;

//digit 何桁目を決めるか
//num   ここまでで作った数
int count753(int digit, int num, bool f3, bool f5, bool f7){
    //cout << digit << " " << num << " " << f3 << f5 << f7 << endl;
    if(digit == 0){
        if(f3||f5||f7){
            //失敗
            return 0;
        }else{
            //成功
            //cout << num << endl;
            return 1;
        }
    }else{
        int ret = 0;
        if(num == 0){
            ret += count753(digit-1, num, f3, f5, f7);
        }
        if((num + 3 * pow(10,digit-1)) <= N){
            ret += count753(digit-1, num + 3 * pow(10,digit-1), false, f5, f7);
        }
        if((num + 5 * pow(10,digit-1)) <= N){
            ret += count753(digit-1, num + 5 * pow(10,digit-1), f3, false, f7);
        }
        if((num + 7 * pow(10,digit-1)) <= N){
            ret += count753(digit-1, num + 7 * pow(10,digit-1), f3, f5, false);
        }
        return ret;
    }
    return 0;
}

int main(void){
    cin >> N;
    for(int i=N;i>0;i/=10){
        N_digit++;
    }
    int ret = count753(N_digit, 0, true, true, true);
    cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int H = in(),W = in();
    vector<string> s(H);
    REP(i,H)s[i] = in<string>();
    bool ok = 1;
    REP(i,H){
        REP(l,W){
            bool chin = 0;
            if(s[i][l] == '.')chin = 1;
            if(i != 0){
                if(s[i-1][l] == '#')chin = 1;
            }
            if(l != 0){
                if(s[i][l-1] == '#')chin = 1;
            }
            if(i != H-1){
                if(s[i+1][l] == '#')chin = 1;
            }
            if(l != W-1){
                if(s[i][l+1] == '#')chin = 1;
            }
            chmin(ok,chin);
        }
    }
    cout << (ok ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N;
int mn=200000;
int cnt;

int main()
{
	cin >> N;
	for (int i=1; i<=N; i++)
	{
		int tmp;
		cin >> tmp;
		if (tmp<=mn) cnt++;
		mn=min(mn,tmp);
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import math, decimal
a, b, c = map(int, input().split())
root_ab = decimal.Decimal.sqrt(decimal.Decimal(a)) + decimal.Decimal.sqrt(decimal.Decimal(b))
root_c = decimal.Decimal.sqrt(decimal.Decimal(c))
if root_ab < root_c:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 59500
n = int(input())
s = []
for i in range(n):
    line = list(map(int, list(input())))
    s.append(line)

ans = -1

# @GDaigo さんのコメントより関数の追加 2017/03/18
def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1

for k in range(n):
    unsearched_nodes = list(range(n)) # 未探索ノード
    distance = [300] * n # ノードごとの距離のリスト
    previous_nodes = [-1] * n # 最短経路でそのノードのひとつ前に到達するノードのリスト
    distance[k] = 0 # 初期のノードの距離は0とする

    while(len(unsearched_nodes) != 0): #未探索ノードがなくなるまで繰り返す
        # まず未探索ノードのうちdistanceが最小のものを選択する
        posible_min_distance = 300 # 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
        for node_index in unsearched_nodes: # 未探索のノードのループ
            if posible_min_distance > distance[node_index]: 
                posible_min_distance = distance[node_index] # より小さい値が見つかれば更新
        target_min_index = get_target_min_index(posible_min_distance, distance, unsearched_nodes) # 未探索ノードのうちで最小のindex番号を取得
        unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去

        target_edge = s[target_min_index] # ターゲットになるノードからのびるエッジのリスト
        for index, route_dis in enumerate(target_edge):
            if route_dis != 0:
                if distance[index] > (distance[ target_min_index] + route_dis):
                    distance[index] = distance[ target_min_index] + route_dis # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
                    previous_nodes[index] =  target_min_index #　ひとつ前に到達するノードのリストも更新

    marubatu = 1
    for i in range(n-1):
        if marubatu == 0:
            break
        for j in range(i+1, n):
            if distance[i] == distance[j] and s[i][j] == 1:
                marubatu = 0
                break
    if marubatu == 1:
        ans = max(ans, len(list(set(distance))))

print(ans)

Measured memory_bytes: 46872
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int main(){
    int l; cin>>l;
    int b[20]={};
    FOR(i,0,20){
        b[i]=(l>>i)&1;
    }
    int v;
    vector<int> edge[3];
    bool flag=true;
    int nowl=0;
    ROF(i,0,20){
        if(b[i]){
            if(flag){
                v=i;
                FOR(j,0,i){
                    edge[0].PB(j);
                    edge[1].PB(j+1);
                    edge[2].PB(0);
                    edge[0].PB(j);
                    edge[1].PB(j+1);
                    edge[2].PB(1<<j);
                }
                flag=false;
            }else{
                edge[0].PB(i);
                edge[1].PB(v);
                edge[2].PB(nowl);
            }
            nowl+=(1<<i);
        }
    }
    cout<<v+1<<" "<<edge[0].size()<<endl;
    FOR(i,0,edge[0].size()){
        printf("%d %d %d\n",edge[0][i]+1,edge[1][i]+1,edge[2][i]);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll a;
    cin >> a;
    string b;
    cin >> b;
    ll b1 = b.at(0) - '0';
    ll b2 = stoi(b.substr(2, 2));
    cout << a * b1 + a * b2 / 100 << endl;
    return 0;
}


Measured memory_bytes: 3600
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	s=II()
	A=[0,0,0]
	mod=10**9+7
	for i in range(3,s+10):
		A.append((1+sum(A[:i-2]))%mod)
	print(A[s])







if __name__=="__main__":
	main()


Measured memory_bytes: 9268
#include<stdio.h>

int partition(int,int);

int a[100000];

int main(){
  int i,n,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i==q){
      printf("[%d]",a[i]);
    }else{
      printf("%d",a[i]);
    }
    if(i==n-1){
      printf("\n");
    }else{
      printf(" ");
    }
  }
}

int partition(int p,int r){
  int j,x,i,temp;
  x=a[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
  }
  temp=a[i+1];
  a[i+1]=a[r];
  a[r]=temp;
  return i+1;
}



Measured memory_bytes: 2108
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };



int main(void) {
	int a[5], k;
	bool flag = true;

	FOR(i, 0, 4) {
		cin >> a[i];
	}
	cin >> k;

	if (a[4] - a[0] > k) {
		flag = false;
	}

	if (flag) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	

	return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll N, X;
    cin >> N >> X;
    ll ans = N;
    ll a = X, b = N - X;
    for(;;){
        if(a > b)swap(a, b);
        if(a == b){
            ans += a;
            break;
        }
        ll c = b / a;
        if(c > 1)c--;
        ans += 2 * c * a;
        b -= c * a;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b= 1
c = 0
if min(a)==0:
    print(0)
else:
    for i in range(n):
        b *=a[i]
        if b>10**18:
            print(-1)
            c =1
            break
    if c ==0:
        print(b)

Measured memory_bytes: 21640
w,h,n=map(int,input().split())
x_b=w
x_s=0
y_b=h
y_s=0
for i in range(1,n+1):
  x,y,a=map(int,input().split())
  if a==2:
    x_b=min(x,x_b)
  elif a==1:
    x_s=max(x,x_s)
  elif a==4:
    y_b=min(y,y_b)
  else:
    y_s=max(y,y_s)

if x_b<=x_s or y_b<=y_s:
  print(0)
else:  
  print((x_b-x_s)*(y_b-y_s))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int a[10] = { 0,2,5,5,4,5,6,3,7,6 };
int dp[10010] = { INF };

int main(void) {
	string ans = "";
	int n, m;
	cin >> n >> m;
	vector<int>digit(m);
	for (int i = 0;i < m;i++) {
		cin >> digit[i];
	}
	sort(digit.begin(), digit.end());
	reverse(digit.begin(), digit.end());
	dp[0] = 0;
	for (int i = 1;i <= n;i++) {
		for (int j = 0;j < m;j++) {
			if (i - a[digit[j]] == 0) {
				dp[i] = 1;
			}
			else {
				if ((i - a[digit[j]]) > 0) {
					if (dp[i - a[digit[j]]] > 0) {
						dp[i] = max(dp[i], dp[i - a[digit[j]]] + 1);
					}
				}
			}
		}
		if (dp[i] == INF)dp[i] = 0;
	}
	int size = n;
	string t = "";
	for (int i = 0;i < dp[n];i++) {
		if(i + 1 == dp[n]) {
			for (int j = 0;j < m;j++) {
				if (size - a[digit[j]] == 0) {
					if (dp[size] == dp[size - a[digit[j]]] + 1) {
						size -= a[digit[j]];
						t = digit[j] + '0';
						ans += t;
						break;
					}
				}
			}
		}
		else {
			for (int j = 0;j < m;j++) {
				if ((size - a[digit[j]] >= 0) && (dp[size] == dp[size - a[digit[j]]] + 1)) {
					size -= a[digit[j]];
					t = digit[j] + '0';
					ans += t;
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

    int N;
    cin >> N;
    int d[N];
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }

    sort(d, d+N);
    int l = d[(N-1)/2];
    int r = d[N/2];
    
    int ans = 0;
    if(l != r){
        for(int i = l+1; i <= r; i++){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a,a+N);
  reverse(a,a+N);
  int A=0,B=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=a[i];
    }else{
      B+=a[i];
    }

  }
  printf("%d",A-B);

}


Measured memory_bytes: 256
N,M = map(int,input().split())
A= set(int(input()) for _ in [0]*M)
mod = 10**9+7
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    dp[i] = (dp[i-1]+dp[i-2])%mod
    if i in A:dp[i]=0
print(dp[N])

Measured memory_bytes: 59096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

int a[sz], ans[sz];
vector <int> g[sz];
multiset <int> mst;

void dfs(int u = 1, int p = 0)
{
    mst.insert(a[u]);
    auto it = mst.lower_bound(a[u]);
    it++;
    int x = 0;
    if(it != mst.end()) x = *it, mst.erase(it);

    for(int v : g[u]) if(v ^ p) dfs(v, u);

    ans[u] = mst.size();
    if(x) mst.insert(x);
    mst.erase(mst.find(a[u]));
}

int main()
{
    int n;
    cin >> n;
    for(int i=1; i<=n; i++) scanf("%d", &a[i]);

    for(int i=1; i<n; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs();

    for(int i=1; i<=n; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 33320
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  int dist = B-A;
  int st = A % K;
  if(((st+dist) >= K) || st == 0) cout <<"OK" <<endl;
  else cout <<"NG" << endl;

}

Measured memory_bytes: 3628
def main():
    n, y = map(int, input().split())

    for i in range(n + 1):
        for j in range(n - i + 1):
            k = n - i - j
            if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n:
                print('{} {} {}'.format(i, j, k))
                return
    print('-1 -1 -1')


if __name__ == '__main__':
    main()

Measured memory_bytes: 64560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  vector<int> changed(N);
  for (int i = 0; i < N; i++) {
    int S = 0, k = 0;
    for (int j = 0; j < N; j++) {
      if (vec.at(j) > S) {
        S = vec.at(j);
        k = j;
      }
    }
    changed.at(i) = S;
    vec.at(k) = 0;
  }
  int A = 1;
  for (int i = 0; i < N - 1; i++) {
    if (changed.at(i) > changed.at(i + 1)) {A++;}
  }
  cout << A << endl;
}

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

public class Main {
	static double D = 0;
	static double P = 0;
	static void rec(int n , double xs[] , double ys[], boolean vis[] , int pass[]){
		int N = xs.length;
		if(n == N){
			P++;
//			System.out.println(Arrays.toString(pass));
			double dist = 0;
			for(int i = 1 ; i < N ; ++i){
				double x0 = xs[pass[i - 1]];
				double y0 = ys[pass[i - 1]];
				double x1 = xs[pass[i]];
				double y1 = ys[pass[i]];
				double d = Math.hypot(x0 - x1, y0 - y1);
				dist += d;
			}
			D += dist;
			return ;
		}
		for(int i = 0 ; i < N ; ++i){
			if(vis[i]){
				continue;
			}
			vis[i] = true;
			pass[n] = i;
			rec(n + 1 , xs , ys , vis , pass);
			vis[i] = false;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double xs[] = new double[N];
		double ys[] = new double[N];		
		for(int i = 0 ; i < N ; ++i){
			xs[i] = sc.nextDouble();
			ys[i] = sc.nextDouble();
		}
		boolean vis[] = new boolean[N];
		int pass[] = new int[N];
		rec(0 , xs , ys , vis , pass);
		System.out.println(D / P);
	}
}


Measured memory_bytes: 25284
#include <bits/stdc++.h>
#define LL long long
const LL MOD = 1000000007;
const int SQRT = 66000;
using namespace std;

int N, K;
LL dp[2][SQRT];
int refer[SQRT];
vector<int> ps;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	
	cin >> N >> K;
	
	int l = 1;
	ps.push_back(0);
	map<int, int> m;
	while (l <= N) {
		ps.push_back(N / (N / l));
		m[ps.back()] = ps.size() - 1;
		l = N / (N / l) + 1;
	}
	
	for (int i = 1; i < ps.size(); i++) {
		dp[1][i] = ps[i];
		refer[i] = m[N / ps[i]];
	}
	for (int i = 2; i <= K; i++) {
		LL *cur = dp[i % 2], *pre = dp[(i - 1) % 2];
		for (int j = 1; j < ps.size(); j++) {
			cur[j] = ((ps[j] - ps[j - 1]) * pre[refer[j]] + cur[j - 1]) % MOD;
		}
	}
	
	cout << dp[K % 2][ps.size() - 1] << '\n';
}

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

class Cube{
    public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1,2,4,3);}
    void roll_y(){roll(0,2,5,3);}
    void roll_x(){roll(0,1,5,4);}
    void roll(int i, int j, int k,int l){
        int t =f[i] ; f[i]= f[j] ;f[j]=f[k]; f[k]=f[l]; f[l]=t;
    }
};

bool eq( Cube c1,Cube c2){
    for (int i=0; i<6; i++)
        if (c1.f[i] != c2.f[i]) return false;
    return true ;
}

bool equal(Cube c1, Cube c2){
    for(int i=0; i<6; i++){
        for(int j =0;j<4;j++){
            if(eq(c1,c2)) return true;
            c1.roll_z();
        }
        if (i%2 ==0) c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

Cube C[100]; int n;

bool check(){
    for (int i=0;i <n-1;i++)
        for (int j =i+1; j<n; j++) if (equal(C[i],C[j])) return false;
    return true;
}

int main(){
    cin>>n;
    for (int i=0; i<n; i++)
      for(int j=0;j<6;j++) cin >> C[i].f[j];
      
    if (check()) cout << "Yes" << endl;
    else cout << "No" << endl;
     return 0;
}




Measured memory_bytes: 3100
N,Y=map(int,input().split())
f=False
for i in range(N+1):
    if f:
        break
    for j in range(N+1-i):
        if f:
            break
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            print(i,j,N-i-j)
            f=True
            break
if not f:
    print(-1,-1,-1)

Measured memory_bytes: 41324