akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 200000 + 10;

int n, h[maxn], ecnt;
struct enode{
	int v, n;
	enode() {}
	enode(int _v, int _n):v(_v), n(_n) {}
}e[maxn << 1];

inline void addedge(int u, int v) { ecnt ++; e[ecnt] = enode(v,h[u]); h[u] = ecnt; }

int mx[maxn], sz[maxn];
ll f1[maxn], f2[maxn];

void dfs(int u, int fa, int mx) {
	f2[u] = 1;
	for(int i = h[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(v == fa || v >= mx) continue;
		dfs(v,u,mx);
		f2[u] += f2[v];
	}
}

void dfs1(int u, int fa) {
	mx[u] = max(mx[fa],u); sz[u] = 1;
	for(int i = h[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(v == fa) continue;
		dfs1(v,u);
		f1[u] += f1[v];
		sz[u] += sz[v];
	}
	if(mx[u] == u) {
		f1[u] = - sz[u];
		dfs(u,fa,mx[fa]);
	}
	if(mx[fa] == fa) f1[u] += sz[u];
}

ll c[maxn];
void dfs2(int u, int fa) {
	c[u] = c[fa];
	if(mx[u] == u) c[u] += f2[u];
	else if(mx[fa] == fa) c[u] += f1[u] - f2[u];
	for(int i = h[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(v == fa) continue;
		dfs2(v,u);
	}
}

int main() {
	scanf("%d", &n); ecnt = 0;
	memset(h,-1,sizeof(h));
	for(int i = 1;i < n;i ++) {
		int u, v;
		scanf("%d%d", &u, &v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs1(1,0);
	dfs2(1,0);
	for(int i = 2;i <= n;i ++) printf("%lld ", c[i] - 1);
	puts("");
	return 0;
}


Measured memory_bytes: 23808
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int MAXN = 2001;
const int mod = 1e9 + 7;
long long a[MAXN],ans,ans2;
int main()
{
	int i,j,n;
	long long k;
	scanf("%d%lld",&n,&k);
	for(i = 1;i <= n;i++)
		scanf("%lld",&a[i]);
	for(i = 1;i <= n;i++)
	{
		for(j = i + 1;j <= n;j++)
			if(a[i] > a[j]) ans++;
		int cnt = 0;
		for(j = 1;j <= n;j++)
			if(a[i] > a[j]) cnt++;
		ans2 = (ans2 + 1ll * cnt * (k * (k - 1) / 2 % mod)) % mod;
	}
	printf("%lld",(ans2 + ans * k % mod) % mod);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n, k;
	scanf("%d %d",&n, &k);
	
	bool a[105] = {0};
	
	int answer = n;
	
	for(int i =0;i<k;i++){
		int d=0;
		scanf("%d",&d);
		while(d--){
			int aij;
			scanf("%d", &aij);
			if(a[aij] == false){
				answer--;
				a[aij] = true;
			}
		}
	}
	
	printf("%d",answer);
	return 0;
}

Measured memory_bytes: 1736
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int n;
	map<int, int> a;
	for (cin >> n; n--;)
	{
		int x;
		cin >> x;
		a[x] ++;
	}

	int odd = 0;
	for (map<int, int>::iterator it = a.begin(); it != a.end(); it++)
	{
		pair<int, int> p = *it;
		if (p.second % 2 == 1)
		{
			odd++;
		}
	}

	cout << odd << endl;
}

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

int d;
vector<int> c(26);
vector<vector<int>> s;
int score;

void input() {
    cin >> d;
    s = vector<vector<int>>(d, vector<int>(26));

    for (int& i : c) cin >> i;
    for (auto& v : s)
        for (int& i : v) cin >> i;
}

int _f(int contest, int day, vector<int>& last) {
    int k = 0;

    for (int i = 0; i < 26; ++i) {
        if (i == contest)
            k += s[day][i];
        else
            k -= c[i] * (day - last[i]);
    }
    return k;
}

int f(vector<int>& schedule) {
    int k = 0;
    vector<int> last(26, -1);
    for (int day = 0; day < d; ++day) {
        int dk = _f(schedule[day], day, last);
        k += dk;
        last[schedule[day]] = day;
    }
    return k;
}

vector<int> greedy() {
    vector<int> last(26, -1), t(d);
    for (int day = 0; day < d; ++day) {
        int opt = 0, optv = _f(opt, day, last);
        for (int i = 1; i < 26; ++i) {
            int iv = _f(i, day, last);
            if (optv < iv) opt = i, optv = iv;
        }
        t[day] = opt;
    }
    return t;
}

int main() {
    input();
    vector<int> t(greedy());
    for (int i : t) cout << i + 1 << endl;
}

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

int main(){
    ll H,W; cin >> H >> W;
    if (H==1 || W==1) cout << 1 << endl;
    else cout << (H*W+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f;
int main()
{
    ll n,m,ma;
    scanf("%lld%lld%lld",&n,&m,&ma);
    if(n==1&&m!=ma)
    {
        printf("0\n");
        return 0;
    }
    printf("%lld\n",max(ma*n-ma+m-(m*n-m+ma)+1,0ll));
    return 0;

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};


int main(){
  ll n;
  cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll g=0;
  rep(i,n)g=__gcd(g,a[i]);
  cout<<g<<endl;
}

Measured memory_bytes: 1024
package main
 
import (
	"fmt"
)
 
func main() {
    var h, w, a, b int
	fmt.Scan(&h, &w, &a, &b)
	s0 := ""
	s1 := ""
 
	for j := 0; j < w-a; j++ {
		s0 += "1"
		s1 += "0"
	}
	for j := 0; j < a; j++ {
		s0 += "0"
		s1 += "1"
	}
 
	for i := 0; i < h-b; i++ {
		fmt.Println(s0)
	}
	for i := 0; i < b; i++ {
		fmt.Println(s1)
	}
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    int n ; cin >> n;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    sort(a + 1 , a + 1 + n);
    int cnt = 0;
    for (int i = 1 ; i <= n ; i++)
        for (int j = i + 1 ; j <= n ; j++)
            for (int k = j + 1 ; k <= n ; k++){
                if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k]){
                    if (a[i] + a[j] > a[k]){
                        cnt++;
                    }
                }
            }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3656
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mountains = s.split_whitespace();

    let mut max = -1;
    let mut count = 0;

    for m in mountains {
        let m: i32 = m.to_string().parse().unwrap();
        if max <= m {
            count += 1;
            max = m;
        }
    }

    print!("{}", count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <sstream>
#include <list>

using namespace std;

int main()
{
	int m, n;
	list<int> players;
	string say;

	while (cin >> m >> n, m){
		
		// initialize
		players.clear();
		for (int i = 0; i < m; i++){
			players.push_back(i + 1);
		}

		list<int>::iterator player = players.begin();
		for (int i = 1; i <= n; i++){
			ostringstream stream;
			
			cin >> say;
			if (players.size() == 1) continue;

			stream << i;

			if (i % 15 == 0) if (say != "FizzBuzz") player = players.erase(player); else player++;
			else if (i % 3 == 0) if (say != "Fizz") player = players.erase(player);	else player++;
			else if (i % 5 == 0) if (say != "Buzz") player = players.erase(player); else player++;
			else if (stream.str() != say) player = players.erase(player); 
			else player++;

			if (player == players.end()) player = players.begin(); 
		}


		cout << *players.begin();
		for (list<int>::iterator it = players.begin(); ++it != players.end(); ){
			cout << " " << *it;
		}
		cout << endl;
	}
	return (0);
}

Measured memory_bytes: 1260
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#include <bits/stdc++.h>

using std::cerr;
using std::cin;
using std::cout;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ff first
#define ss second
#define pb emplace_back
#define sqr(x) ((x) * (x))
#ifdef LOCAL
#define dbg(as...) {\
    vector<string> _v; \
    std::stringstream _ss(#as);\
    string _cur, _loc;\
    while (getline(_ss, _cur, ',')) {\
        while (count(_cur.begin(), _cur.end(), '(') != count(_cur.begin(), _cur.end(), ')')) {\
            getline(_ss, _loc, ',');\
            _cur += "," + _loc;\
        }\
    _v.pb(_cur);\
    }\
    err(_v.begin(), as);\
}
#else
#define dbg(as...)
#endif

template<typename T>
void err(vector<string>::iterator it, T a) {
    cerr << it->substr((*it)[0] == ' ') << " = " << a << '\n';
}
template<typename T, typename...Ts>
void err(vector<string>::iterator it, T a, Ts...as) {
    cerr << it->substr((*it)[0] == ' ') << " = " << a << ", ";
    err(++it, as...);
}

struct init {
    init() {
        cin.tie(0);
        std::iostream::sync_with_stdio(0);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(10);
        #ifdef LOCAL
        srand(300); 
        #else
        srand(time(0));
        #endif
    }
    ~init() {
        #ifdef LOCAL
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
        #endif
    }
} init;

const int MOD = 1e9 + 7;

ll bp(ll a, ll pw) { 
    ll res(1);
    for (; pw; a = sqr(a) % MOD, pw /= 2) 
        if (pw & 1) 
            res = (res * a) % MOD;
    return res;
}
ll reverse(ll a) {return bp(a, MOD - 2); }

const int MAXC = 1e5 + 15;

ll f[MAXC], rev[MAXC];

struct prepare{
    prepare() {
        f[0] = 1;
        for (int i = 1; i < MAXC; ++i) f[i] = (f[i - 1] * i) % MOD;
        rev[MAXC - 1] = reverse(f[MAXC - 1]);
        for (int i = MAXC - 2; i >= 0; --i) rev[i] = (rev[i + 1] * (i + 1)) % MOD;
    }
} prepare;

ll C(ll n, ll k) {
    if (k > n) return 0;
    return (((f[n] * rev[k]) % MOD) * rev[n - k]) % MOD;
}

int a[MAXC];
int w[MAXC];

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        w[i] = -1;

    int skip;
    for (int i = 0; i <= n; ++i) {
        cin >> a[i];
        if (w[a[i]] != -1) 
            skip = i - w[a[i]] + 1;
        w[a[i]] = i;
    }

    for (int k = 1; k <= n + 1; ++k) {
        ll rep = C(n + 1 - skip, k - 1);
        cout << (C(n + 1, k) - rep + MOD) % MOD << '\n';
    }

    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << max(a*b,c*d) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;

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

  for(int i = 0;i < 10;i++){
    cin >> s;
    ans += s;
  }

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


Measured memory_bytes: 3160
N,M=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(M)]

D={}
for py in PY:
    try:
        if D[py[0]]=='':
            pass
    except:
        D[py[0]]=[py[1]]
        continue
    D[py[0]].append(py[1])

for k in D.keys():
    D[k].sort()

def binary_tree(lst,key):
    left=0
    right=len(lst)-1
    while left<=right:
        mid=(left+right)//2
        if lst[mid]==key:
            return mid+1
        elif lst[mid]<key:
            left=mid+1
        else:
            right=mid-1
    return -1

for py in PY:
    l=D[py[0]]
    ans=str(py[0]).zfill(6)
    ans+=str(binary_tree(l,py[1])).zfill(6)
    print(ans)

Measured memory_bytes: 42240
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

int main(){
    int a[4];
    rep(i, 4){
        a[i] = 0;
    }
    int n;
    cin >> n;
    string s[n];
    rep(i, n){
        cin >> s[i];
        if(s[i] == "AC") a[0]++;
        else if(s[i] == "WA") a[1]++;
        else if(s[i] == "TLE") a[2]++;
        else a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;

    
}

Measured memory_bytes: 6752
#include<bits/stdc++.h>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
using namespace std;

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

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

int main(){
    int N;
    cin >> N;
    vector<ll> A(101, 0);
    rep(i,N) cin >> A[i];

    int max_dif = 0;
    rep(i,N){
        rep(j,N){
            if(abs(A[i]-A[j])>max_dif) max_dif = abs(A[i]-A[j]);
        }
    }
    cout << max_dif << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for k := 1; k <= n; k++ {
		sc.Scan()
		m[k], _ = strconv.Atoi(sc.Text())
	}
	ans := 0
	for i, v := range m {
		if m[v] == i {
			ans++
			m[v] = -1
		}
	}
	fmt.Println(ans)
}


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

using namespace std;

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

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

    int res = -1;
    vector<bool> trained(n, false);
    for (int i = 0, r = 0; !trained[i]; i = a[i] - 1, r++) {
        trained[i] = true;
        if (i == 1) {
            res = r;
            break;
        }
    }

    cout << res << endl;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i = 0; i < M; i++) {
        cin >> A[i];
    }
    long long int sum = 0;
    for(int i = 0; i < M; i++) {
        sum += A[i];
    }
    int ans = N - sum;
    if(ans < 0) {
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3660
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>*/
 
using ll = long long;
using ld = long double;
const ll MOD = 998244353;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 200001;
map<int, int> mp;
multiset<int> vals;
int h, w;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>h>>w;
    int a, b;
    owo(i, 0, w) {
        mp[i] = i;
        vals.insert(0);
    }
    owo(i, 0, h) {
        cin>>a>>b;
        a--;
        int x = -1;
        for(auto it = mp.lower_bound(a); it!=mp.end() && it->first <= b; it = mp.erase(it)) {
           x = max(x, it -> second);
           vals.erase(vals.find(it -> first - it -> second));
        }
        if(x!=-1&&b!=w) {
            vals.insert(b-x);
            mp[b] = x;
        }
        cout<<(vals.empty() ? -1 : *vals.begin() + i + 1)<<"\n";
    }
    return 0;
}

Measured memory_bytes: 22388
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    long long int ans = 0;
    int tmp;
    queue<long long int> q;
    REP1(i,9) q.push(i);
    int n;
    cin >> n;
    REP(i,n){
        ans = q.front();
        if(ans % 10 != 0) q.push(ans * 10 + ans % 10 - 1);
        q.push(ans * 10 + ans % 10);
        if(ans % 10 != 9) q.push(ans * 10 + ans % 10 + 1);
        q.pop();
    }
    
    cout << ans << endl;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N;
    cin >> N;
    
    vector<ll> L(N);
    REP(i, N) { 
        cin >> L[i];
    }
    sort(ALL(L));
    ll ans = 0;
    REP(i, N-1) {
        FOR(j, i+1, N) {
            ll low = L[j] - L[i];
            ll high = L[j] + L[i];
            auto iter1 = upper_bound(ALL(L), low);
            auto iter2 = lower_bound(ALL(L), high);
            if (iter1 == L.end()) continue;
            ll tmp1 = distance(L.begin(), iter1);
            ll tmp2 = distance(L.begin(), iter2);
            ans += max(0LL, tmp2 - max(tmp1, j+1));
        }
    }
    PRINT(ans);
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll x[110000],y[110000];
main(){
  ll n,k,cut,ans=1e9;
  cin>>n>>k;
  rep(i,0,n)cin>>x[i];
  sort(x,x+n);
  rep(i,0,n-k+1)ans=min(ans,x[i+k-1]-x[i]);
  cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

//const ll mod = 998244353;
const ll mod = 1e9 + 7;
const ll MAX_SIZE = 1000005;
array<ll, MAX_SIZE> fac, inv, finv;
ll fac_init() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % mod;
    finv[0] = modpow(fac[MAX_SIZE - 1], mod - 2, mod);
    repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % mod;
    reverse(all(finv));

    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, mod - 2, mod);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % mod; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % mod * finv[a - b] % mod; }

int main() {
    init();
    ll n,a,b;
    cin >> n >> a >> b;

    fac_init();

    ll ans = modpow(2, n, mod);
    ans = (ans + mod - 1) % mod;

    ll aa = 1;
    rep(i,a){
        aa *= n - i;
        aa %= mod;
    }
    aa = (aa * finv[a]) % mod;
    ll bb = 1;
    rep(i,b){
        bb *= n - i;
        bb %= mod;
    }
    bb = (bb * finv[b]) % mod;

    ans = (ans - aa + mod) % mod;
    ans = (ans - bb + mod) % mod;


    cout << ans << endl;
}

Measured memory_bytes: 23680
import java.util.Scanner;

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

int m = scan.nextInt();
int f = scan.nextInt();
int r = scan.nextInt();

while(m!=-1 || f!=-1 || r!=-1){
    if(m==-1 || f==-1){
        System.out.println("F");
    }else if(m+f>=65){
        if(m+f>=80){
            System.out.println("A");
        }else{
            System.out.println("B");
        }
    }else if(m+f>=50){
        System.out.println("C");
        }else{
            if(m+f>=30){
            if(r>=50){
                System.out.println("C");
            }else{
                System.out.println("D");
            }
        }else{
            System.out.println("F");
        }
    }
        m = scan.nextInt();
        f = scan.nextInt();
        r = scan.nextInt();
    }
}
}


Measured memory_bytes: 26292
#include <iostream>
#include <stdio.h>
using namespace std;

struct Node {
	int left;
	int right;
	int parent;
	int depth;
	int height;
	int sibling;
	int degree;
};

int max(int a, int b) {
	return a < b ? b : a;
}

int depthHeight(Node* arr, int id, int d) {
	arr[id].depth = d;
	if ((arr[id].left != -1) && (arr[id].right != -1)) {
		arr[id].degree = 2;
		return arr[id].height = max(depthHeight(arr, arr[id].left, d + 1), depthHeight(arr, arr[id].right, d + 1)) + 1;
	}
	else if (arr[id].left != -1) {
		arr[id].degree = 1;
		return arr[id].height = depthHeight(arr, arr[id].left, d + 1) + 1;
	}
	else if (arr[id].right != -1) {
		arr[id].degree = 1;
		return (arr[id].height = depthHeight(arr, arr[id].right, d + 1) + 1);
	}
	else
		return arr[id].degree = arr[id].height = 0;
}

void print(Node* arr, int id) {
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
		, id, arr[id].parent, arr[id].sibling, arr[id].degree, arr[id].depth, arr[id].height);
	if (arr[id].parent == -1)
		cout << "root\n";
	else if (arr[id].height == 0)
		cout << "leaf\n";
	else
		cout << "internal node\n";
}

int main() {
	int len;
	cin >> len;
	Node* arr = new Node[len];
	
	//set all the fields to -1 (in order to represent the root and the leaf of the tree)
	for (int i = 0; i < len; i++)
		arr[i].parent = arr[i].left = arr[i].right = arr[i].sibling = -1;
	
	int id;
	for (int i = 0; i < len; i++) {
		cin >> id;
		cin >> arr[id].left >> arr[id].right;
		arr[arr[id].left].parent = arr[arr[id].right].parent = id;
		arr[arr[id].left].sibling = arr[id].right;
		arr[arr[id].right].sibling = arr[id].left;
	}

	int r;
	for (r = 0; arr[r].parent != -1; r = arr[r].parent);
	arr[r].height = depthHeight(arr, r, 0);

	for (int i = 0; i < len; i++)
		print(arr, i);

	return 0;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
struct QuickFind{
  vector<int> r,p;
  vector<vector<int> > v;
  QuickFind(){}
  QuickFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    v.resize(size);
    for(int i=0;i<size;i++){
      r[i]=1,p[i]=i;
      v[i].resize(1,i);
    }
  }
  bool same(int x,int y){
    return p[x]==p[y];
  }
  void unite(int x,int y){
    x=p[x];y=p[y];
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    for(int i=0;i<(int)v[y].size();i++){
      p[v[y][i]]=x;
      v[x].push_back(v[y][i]);
    }
    v[y].clear();
  }
};
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<int> b(a);
  sort(b.begin(),b.end());
  map<int,int> p,q;
  for(int i=0;i<n;i++){
    p[a[i]]=i;
    q[b[i]]=i;
  }
  QuickFind qf(n);
  for(int i=0;i<n;i++) 
    qf.unite(i,p[b[i]]);
  //for(int i=0;i<n;i++) cout<<i<<" "<<p[b[i]]<<endl;
  int ans=0;
  for(int i=0;i<n;i++){
    int k=qf.v[i].size();
    if(qf.p[i]!=i||k==1) continue;
    int m=a[qf.v[i][0]];
    int tmp=0;
    for(int j=0;j<k;j++){
      //cout<<" "<<a[qf.v[i][j]];
      tmp+=a[qf.v[i][j]];
      m=min(m,a[qf.v[i][j]]);
    }
    //cout<<endl;
    ans+=min(tmp+m*(k-2),tmp+m+b[0]*(k+1));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3424
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int X;
    X=in.nextInt();
    int p,m,t,s;
   
      m=X/500;
     	p=X%500;
    t=p/5;
    s=m*1000+t*5;
    System.out.println(s);
  }
}
      
      


Measured memory_bytes: 22868
#include <iostream>
#include <cmath>
#include <string>
using namespace std;


int main()
{
    string s, t, u;
    int a, b;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (s.compare(u) == 0) {
        a--;
    }
    else {
        b--;
    }
  

    cout << a << " " << b;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
  
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;
      
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s;
  int sum=0,n;
  cin>>n>>s;
  rep(i,n){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      sum++;
    }
  }
  cout<<sum<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
    int a;
    int b;
    int c;
    scanf("%d %d %d", &a, &b, &c);
    if (a<b && b<c) {
        printf("Yes\n");
    }else {
        printf("No\n");
    
    }
    
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

	int N; cin >> N;
	vei b(N); rep(i,N) cin >> b[i];
	vei ans;

	rep(loop, N) for(int i = N; i >= 1; i--) {
		if( i - 1 <= b.size() - 1 and b[i - 1] == i ) { ans.pub(i); remove(b, i - 1); break;}
	}
	if(!b.empty()) cout << -1 << endl;
	else rep(i,ans.size()) cout << ans[ans.size() - i - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int h, w;
char a[105][105];
int main(){
	scanf("%d%d", &h, &w);
	for(int i = 1; i <= h; i++){
		getchar();
		for(int j = 1; j <= w; j++){
			scanf("%c", &a[i][j]);
		}
	}
	for(int i = 0; i <= w + 1; i++){
		a[0][i] = '#';
		a[h + 1][i] = '#';
	}
	for(int i = 0; i <= h + 1; i++){
		a[i][0] = '#';
		a[i][w + 1] = '#';
	}
	for(int i = 0; i <= h + 1; i++){
		for(int j = 0; j <= w + 1; j++){
			printf("%c", a[i][j]);
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 128
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 (a + b == 15) {
    	System.out.println("+");
	}
    else if(a * b == 15){
    	System.out.println("*");
    }
    else{
    	System.out.println("x");
    }
  }
}

Measured memory_bytes: 23892
#include <stdio.h>
int main(void){
	int x,y,i;
	int tmp;
	for(i=0;;i++){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0)break;
		if(x > y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int a[] = new int[3];
		for (int i=0;i<3;i++) {
			a[s.charAt(i)-'a']++;
		}
		for(int i=0;i<3;i++) {
			if (a[i]!=1) {
				System.out.println("No");
				return ;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21844
a, b = map(int, raw_input().split())
if a < 0 < b or a == 0 or b == 0:
    print "Zero"
else:
    if a > 0:
        print "Positive"
    else:
        if (a - b) % 2 == 0:
            print "Negative"
        else:
            print "Positive"

Measured memory_bytes: 2568
#input
A = int(input())
B = int(input())
C = int(input())
X = int(input())
#A = list(map(int,input().split()))
#b = int(input())

#s = [0,0,0]
#s[0] = int(input/100)
#s[1] = int(input/10 - s[0]*10)
#[2] = int(input%10)



count = 0
#flag = 0

for i in range(A+1): #loop for 500円
  for j in range(B+1): #loop for 100円
    temp = X - i*500 - j*100
    if (temp >= 0 ):
      if (temp == 0) or (temp/50 <= C):
        count += 1
        #print('BINGO')
        #print(i)
        #print(j)
        #print(temp)
  
  #judge

#print('result')
#print(A)
print(count)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
80 70
)");
#define cin input
#endif

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

	int r = 0;
	REP (i, n)
	{
		if (i % 2 == 1)
			continue;
		int c = 0;
		REP (j, i + 1)
			if ((i + 1) % (j + 1) == 0)
				++c;
		if (c == 8)
			++r;
	}

	cout << r << endl;

	return 0;
}


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

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, k;
  cin >> n >> k;
  ll res = 0;
  if (k) {
    rep(i, n) {
      ll b = i+1;
      if (b <= k) continue;
      res += (b-k)*(n/b);
      if (n%b >= k) res += (n%b)-k+1;
    }
  } else {
    res = n*n;
  }
  cout << res << endl;
}

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

namespace CompetitiveProgCsLib
{
	class MainProg
	{
		static string R => Console.ReadLine();
		static int RI => int.Parse(R);
		static double RD => double.Parse(R);
		static int[] RIs => R.Split(' ').Select(int.Parse).ToArray();
		static double[] RDs => R.Split(' ').Select(double.Parse).ToArray();
		static void Out(object obj) => Console.WriteLine(obj);
		static void OutLine<T>(IEnumerable<T> obj, string separateChar) => Out(String.Join(separateChar, obj));
		static void Outb(bool b) => Out(b ? "Yes" : "No");
		static void OutB(bool b) => Out(b ? "YES" : "NO");
		static bool IsIn(int y, int x, int h, int w) => 0 <= x && x < w && 0 <= y && y < h;

		static void Main(string[] args)
		{
			var n = RI;
			var ab = RIs;
			var ps = RIs;
			var a = ab[0];
			var b = ab[1];
			var A = ps.Count(x => x <= a);
			var B = ps.Count(x => a < x && x <= b);
			var C = ps.Count(x => b < x);
			Out(Math.Min(Math.Min(A, B), C));
		}
	}
}


Measured memory_bytes: 13396
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for aa in range(a+1):
    for bb in range(b+1):
        for cc in range(c+1):
            if 500*aa + bb*100 +cc*50 ==x:
                ans += 1
print(ans)

Measured memory_bytes: 3316
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        int a = Integer.parseInt(line1[0]);
        int b = Integer.parseInt(line1[1]);
        int c = Integer.parseInt(line1[2]);
        for(int i = 0; i < 10; i++){
            System.out.println(a * c - b);
            c = a * c - b;
        }
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if(a+b>c+d){
    cout<<"Left"<<endl;
  }else if(a+b==c+d){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Right"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
cnt_A=0
cnt_B=0
cnt_O=0
cnt_AB=0
while True:
	try:
		x,y=input().split(',')
		if y=='A':
			cnt_A+=1
		elif y=='O':
			cnt_O+=1
		elif y=='B':
			cnt_B+=1
		else:
			cnt_AB+=1
	except EOFError:
		break

print(cnt_A)
print(cnt_B)
print(cnt_AB)
print(cnt_O)

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

int main() {
    int x,y;
    cin>>x>>y;
    bool ok = false;
    for(int i=0; i<=x; i++) {
        if((2 * i) + (4 * (x - i)) == y) {
            ok = true;
        }
    }
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main() {
  int n; cin>>n;
  string s; cin>>s;
  int len = s.length();
  for(int i=0;i<len;i++) {
    char c = s[i];
    for(int j=0;j<n;j++) {
      if(c=='Z') c='A';
      else c++;
    }
    putchar(c);
  }
  putchar('\n');
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  int n,m;
  map<string,int> red,blue;
  int ans=0;
  cin>>n;
  while(n--){
    string s;
    cin>>s;
    red[s]++;
  }
  cin>>m;
  while(m--){
    string t;
    cin>>t;
    blue[t]++;
  }
  for(auto s:red){
    ans=max(ans,red[s.first]-blue[s.first]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){

	int n;
	cin>>n;

	int card[4][13] = {};
	for(int i=0;i<n;i++){
		string suit;
		int num;
		cin>>suit>>num;

		if(suit == "S") card[0][num-1] = 1;
		if(suit == "H") card[1][num-1] = 1;
		if(suit == "C") card[2][num-1] = 1;
		if(suit == "D") card[3][num-1] = 1;
	}
	string str[4] = {"S", "H" , "C", "D"};
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(card[i][j] == 1) continue;
			cout<<str[i]<<" "<<j+1<<endl;
		}
	}

	return 0;
}
	


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  frn(i,n) cin>>a[i];
  sort(a.begin(), a.end());
  set<int> s;
  for(int x: a) {
    s.insert(x);
  }
  cout<<s.size();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a[2006], ans;
bool cond;
char c;
string s;
int main()
{
    //I am Monim, a tiny creature of Allah
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a[0] = 1;
    for(i=1;i<=n;i++)
    {
        for(j=3;j<=i;j++)
        {
            if(i-j>=0)
                a[i] = (a[i]%1000000007+a[i-j]%1000000007)%1000000007;
        }
    }
    cout << a[n] << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/25/2018
 
 15:00-15:20 analysis
 15:35 submit and got 1WA
 15:36-16:10 bug fix and got AC
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
int N;
//LL A[MAX_N];

const string s0="Vacant", s1="Male", s2="Female";
unordered_map<string,int> T={
  {s0,0},{s1,1},{s2,2}
};

string S;

int cnt=0;
int fetch(int i) {
  ++cnt;
  assert(cnt<=20);
  cout<<i<<endl;
  string s; cin>>s;
  return T[s];

//  return S[i]-'0';
}

void solve() {
  int l=0,r=N;
  int x=fetch(0);
  if(x==0) return;
  
  while(abs(r-l)>1) {
    int mid=(l+r)/2;
    int xmid=fetch(mid);

    bool par=abs(mid-l-1)%2;
    
//    dump4(l,r,mid,xmid);
//    dump4(l,r,par,x);
    
    if(xmid==0) return;
    
    if((par&&x==xmid)||(!par&&x!=xmid)) {
      l=mid;
      x=xmid;
    } else {
      r=mid+1;
    }
    if(l>r) swap(l,r);
  }

  x=fetch(l);
  assert(x==0);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  //cin>>S;
  //N=SZ(S);
  
  solve();
  return 0;
}


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

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

int main(void) {
    const int INF = 1e9;
    int n, a, ans = INF;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) {
        int cnt = 0;
        cin >> a;
        while (a % 2 == 0) {
            cnt++;
            a /= 2;
        }

        ans = min(ans, cnt);
    }

    cout << ans << "\n";
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;

int main() {
    string s, t;
    cin >> s;
    cin >> t;
    
    int q;
    cin >> q;
    int a[q], b[q], c[q], d[q];
    for (int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    
    int sumS[s.size() + 1];
    sumS[0] = 0;
    for (int i = 1; i <= s.size(); i++) {
        if (s[i - 1] == 'A') {
            sumS[i] = sumS[i - 1] + 1;
        } else {
            sumS[i] = sumS[i - 1] + 2;
        }
    }
    
    int sumT[t.size() + 1];
    sumT[0] = 0;
    for (int i = 1; i <= t.size(); i++) {
        if (t[i - 1] == 'A') {
            sumT[i] = sumT[i - 1] + 1;
        } else {
            sumT[i] = sumT[i - 1] + 2;
        }
    }
    const int MOD = 3;
    for (int i = 0; i < q; i++) {
        int modS = (sumS[b[i]] - sumS[a[i] - 1]) % MOD;
        int modT = (sumT[d[i]] - sumT[c[i] - 1]) % MOD;
        if (modS == modT) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } 
    
    
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n,m; cin >> n >> m;
  ll k; cin >> k;
  vector<ll> a(n),b(m);
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];

  vector<ll> asum(n+1);
  asum[0] = 0;
  rep(i,n) asum[i+1] = asum[i] + a[i];
  vector<ll> bsum(m+1);
  bsum[0] = 0;
  rep(i,m) bsum[i+1] = bsum[i] + b[i];  

  int res = 0;
  rep(i,n+1) {
    ll x = k - asum[i];
    if(x < 0) continue;
    int lb = -1, ub = m+1;
    while(ub - lb > 1) {
      int mid = (ub + lb) / 2;
      (bsum[mid] <= x ? lb : ub) = mid;
    }
    chmax(res, i + lb);
  }
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 9556
n,q = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
sum = [0]
for i in 1...s.length do
    sum[i] = sum[i-1]
    if (s[i-1] + s[i]).eql?('AC') then sum[i]+=1 end
end

q.times do
    l,r = gets.chomp.split(" ").map(&:to_i)
    ans = sum[r-1] - sum[l-1]
    puts ans
end

Measured memory_bytes: 3452
#include <iostream>

int main() {
	int n, *m, c = 0;
	std::cin >> n;
	m = new int[n];
	for (int i = 0; i < n; ++i) {
		std::cin >> m[i];
		if (m[i] <= i && m[m[i] - 1] == i + 1)
			++c;
	}
	std::cout << c;
	return 0;
}


Measured memory_bytes: 640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    MOD = 998244353
    a, b, c, d = map(int, readline().split())
    h, w = c - a, d - b

    dp = [[1] * (d + 1) for _ in range(c + 1)]

    for row in range(a + 1, c + 1):
        dp[row][b] = (dp[row - 1][b] * b) % MOD

    for col in range(b + 1, d + 1):
        dp[a][col] = (dp[a][col - 1] * a) % MOD

    for row in range(a + 1, c + 1):
        for col in range(b + 1, d + 1):
            x = dp[row - 1][col] * col + dp[row][col - 1] * row
            y = dp[row - 1][col - 1] * (row - 1) * (col - 1)
            dp[row][col] = (x - y) % MOD

    print(dp[c][d])


if __name__ == '__main__':
    main()


Measured memory_bytes: 133176
"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)

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

# range = xrange
# input = raw_input


def main():
    n, k = lin()
    a = lin()
    a.sort(reverse=True)
    for i in range(min(k, n)):
        a[i]=0
    
    print(sum(a))



            
        

        
main()
# threading.Thread(target=main).start()


Measured memory_bytes: 80232
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.Stream;
import static java.util.stream.Collectors.joining;

class Main {
    final static int k = 10001;
  static int[] C = new int[k];

  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int current = 0;
    int[] A = new int[size];
    int[] B = new int[size];

    for (int i = 0; i < size; i++) {
      A[i] = Integer.parseInt(sc.next());
      C[A[i]]++;
    } 

    for (int i = 1; i < k; i++) C[i] += C[i - 1];
    for (int i = size - 1; i >= 0; i--) B[--C[A[i]]] = A[i];
    System.out.println(Arrays.stream(B).boxed().map(n -> n.toString()).collect(joining(" ")));
  }
}


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

int main(void)
{
    int n, l;
    cin  >> n >> l;
    vector <string> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < n; i++)
    {
        cout << a.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256