akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
MAX = max(A)

S = set(A)
ok = [1] * (MAX+1)
for a in S:
    for x in range(a+a, MAX+1, a):
        ok[x] = 0

C = Counter(A)
for k, v in C.items():
    if v >= 2:
        ok[k] = 0

ans = 0
for a in A:
    if ok[a]:
        ans += 1
print(ans)


Measured memory_bytes: 155640
#include <iostream>

int main() {
	int num1, num2;
	std::cin >> num1 >> num2;
	
	if(num1 > num2){
		std::cout << "a > b" << std::endl;
	}
	else if (num1 < num2) {
		std::cout << "a < b" << std::endl;
	}
	else
	{
		std::cout << "a == b" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3072
#include "stdio.h"
#include <iostream>

using namespace std;

static int MAX_N = 36;

struct Card {
	char suit;
	int value;
};

void bubbleSort(int n, Card* cardList) {
	for(int i = 0; i < n; i ++) {
		for(int j = n - 1; j >= i + 1; j --) {
			if(cardList[j].value < cardList[j - 1].value) {
				Card temp = cardList[j - 1];
				cardList[j - 1] = cardList[j];
				cardList[j] = temp;
			}
		}
	}
}

void selectionSort(int n, Card* cardList) {

	for(int i = 0; i < n - 1; i ++) {
		int minIndex = i;
		for(int j = i + 1; j < n; j ++) {
			if(cardList[j].value < cardList[minIndex].value) {
				minIndex = j;
			}
		}
		if(minIndex != i) {
			Card temp = cardList[i];
			cardList[i] = cardList[minIndex];
			cardList[minIndex] = temp;
		}

	}

}

bool isStable(Card* cardListA, Card* cardListB, int n) {
	for(int i = 0; i < n; i ++) {
		if(cardListB[i].suit != cardListA[i].suit) {
			return false;
		}
	}
	return true;
}

void print(struct Card cardList[], int n) {
	for(int i = 0; i < n; i ++) {
		if(i > 0) 
			printf(" ");
		printf("%c%d", cardList[i].suit, cardList[i].value);
	}
	printf("\n");
}

int main() {
	int n;
	Card cardList[MAX_N];
	Card cardListA[MAX_N];
	Card cardListB[MAX_N];

	scanf("%d", &n);
	getchar();
	for(int i = 0; i < n - 1; i ++) {
		scanf("%c%d ", &cardList[i].suit, &cardList[i].value);
	}
	scanf("%c%d", &cardList[n - 1].suit, &cardList[n - 1].value);
	
	for(int i = 0; i < n; i ++) {
		cardListA[i] = cardList[i];
		cardListB[i] = cardList[i];
	}

	bubbleSort(n, cardListA);
	print(cardListA, n);
	printf("Stable\n");

	selectionSort(n, cardListB);
	print(cardListB, n);
	bool flag = isStable(cardListA, cardListB, n);
	if(!flag) {
		printf("Not stable\n");
	} else {
		printf("Stable\n");
	}
}

Measured memory_bytes: 3236
package main

import "fmt"

func max(x ...int) int {
	mv := x[0]
	for _, v := range x[1:] {
		if v > mv {
			mv = v
		}
	}
	return mv
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	fmt.Println(a + b + c - max(a, b, c))
}


Measured memory_bytes: 512
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    print(["No","Yes"][N>=30])

    

#%%submit!
resolve()

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  while(N--){
    int G[9], J[9];
    for(int i = 0; i < 9; i++) cin >> G[i];
    for(int i = 0; i < 9; i++) cin >> J[i];
    sort(J, J + 9);
    int gwin = 0, jwin = 0;
    int cnt = 0;
    do {
      cnt++;
      int gscore = 0, jscore = 0;
      for(int i = 0; i < 9; i++){
	if(G[i] > J[i]) gscore += G[i] + J[i];
	else if(G[i] < J[i]) jscore += G[i] + J[i];
      }
      if(gscore > jscore) gwin++;
      else if(gscore < jscore) jwin++;
    }while(next_permutation(J, J + 9));
    printf("%.5f %.5f\n", (double)gwin / cnt, (double)jwin / cnt);
  }
  return 0;
}

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

int main(){
    long long N;
    cin >> N;
    long long A[N];
    for(int i=0;i<N;i++) A[i]=i+1;
    long long sum=0;
    for(int i=0;i<N;i++){
        if(A[i]%3==0 || A[i]%5==0) A[i]=0;

        sum += A[i];
    }
    cout << sum << endl;
    
}



Measured memory_bytes: 11444
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>


using namespace std;


int main() {
	string S, X = "", Y ="";
	cin >> S;
	int count = 0;

	for (int i = 0; i < S.size(); i++) {
		X += S[i];
		if (X != Y) {
			count++;
			Y = X;
			X = "";
			
		}
	}
	

	cout << count;

	return 0;
}


Measured memory_bytes: 832
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

string S, T;

signed main(){
    cin >> S >> T;
    if(S == T.substr(0, S.size())) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<map>
#include<vector>
using namespace std;

int main(){
    int n, m;
    map<int,int> ma;
    cin >> n >> m;
    for(int i = 0; i < n+m; i++){
        int a;  cin >> a;
        ma[a]++;
    }
    vector<int> a, b;
    for(auto p : ma){
        if(p.second == 2)  a.push_back(p.first);
        b.push_back(p.first);
    }
    cout << a.size() << " " << b.size() << endl;
    for(int x : a)  cout << x << endl;
    for(int x : b)  cout << x << endl;
    return 0;
}


Measured memory_bytes: 14196
#include <iostream>

int main()
{
    int x1, y1, x2, y2;
    int x3, y3, x4, y4;
    std::cin >> x1 >> y1 >> x2 >> y2;
    int x2_x1 = x2 - x1;
    int y2_y1 = y2 - y1;
    x3 = x2 - y2_y1;
    y3 = y2 + x2_x1;
    x4 = x1 - y2_y1;
    y4 = y1 + x2_x1;
    std::cout << x3 << " " << y3 << " " << x4 << " " << y4 << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

ll answer = 0;
ll n;

void dfs(ll num,bool seven,bool five, bool three){
    if(num > n)return;
    if(seven and five and three)answer++;
    dfs(num*10+7,true,five,three);
    dfs(num*10+5,seven,true,three);
    dfs(num*10+3,seven,five,true);
}
int main(){
    cin >> n;
    dfs(0,false,false,false);
    cout << answer << endl;
    return 0;
}

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

int main() {
  string S;
  cin>>S;
  int x=S.size();
  
  for(int i=0;i<x;i++){
    if(S.at(i)=='?')
      S.at(i)='D';
  }
  
  cout<<S<<endl;

}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //



void solve(){
	int N;
	cin >> N;
 
	string ans = "";
	int div = N;
	while (div != 0) {
		div--;
		int mod = div % 26;
		div /= 26;
		ans += ('a' + mod);
	}
 
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}




int32_t main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



Measured memory_bytes: 3652
package main

import "fmt"

func sum_digits(n int) int {
	if n < 10 {
		return n
	} else {
		return n%10 + sum_digits(n/10)
	}
}

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	ans := 0
	for i := 1; i <= n; i++ {
		if s := sum_digits(i); a <= s && s <= b {
			ans += i
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
	unsigned char usW_D_str[1200];
	unsigned short usW_C_i;
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		usW_D_str[usW_C_i] = '\0';
	}
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		scanf("%c", &usW_D_str[usW_C_i]);
		if(usW_D_str[usW_C_i] == '\0'){
			break;
		}
	}
	
	for(usW_C_i = 0;usW_C_i < 1200;usW_C_i++){
		if(usW_D_str[usW_C_i] >= 'A' && usW_D_str[usW_C_i] <= 'Z'){
			usW_D_str[usW_C_i] += 32;
		}
		else if(usW_D_str[usW_C_i] >= 'a' && usW_D_str[usW_C_i] <= 'z'){
			usW_D_str[usW_C_i] -= 32;
		}
		else;
	}
	
	for(usW_C_i = 0;usW_D_str[usW_C_i] != '\0';usW_C_i++){
		printf("%c", usW_D_str[usW_C_i]);
	}
	
	return 0;
}


Measured memory_bytes: 2036
from math import sqrt
n, d = map(int, input().split())
x=[]
for _ in range(n):
  x.append(list(map(int, input().split())))

cnt=0
for i in range(n):
  for j in range(i+1, n):
    tmp=0
    for yi, zi in zip(x[i], x[j]):
      tmp+=(yi-zi)**2
    tmp=sqrt(tmp)
    if tmp==int(tmp):
      cnt+=1

print(cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  vector<int> v1(10),v2(10);
  REP(i,10)
    cin >> v1[i];
  REP(i,10)
    cin >> v2[i];
  sort(ALL(v1), greater<int>());
  sort(ALL(v2), greater<int>());
  cout << v1[0]+v1[1]+v1[2] << " " << v2[0]+v2[1]+v2[2] << endl;
}

Measured memory_bytes: 0
def main():
    S = list(input())
    T = list(input())
    ans = float('inf')
    for i in range(len(S)):
        cnt = 0
        flag = True
        for j in range(len(T)):
            if i + j >= len(S):
                flag = False
                break
            if S[i+j] != T[j]:
                cnt += 1
        if flag:
            ans = min(ans, cnt)

    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 67880
package main

import (
	"fmt"
)

func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)
	var ans int
	l := k - a
	if l < 0 {
		ans = k
	} else {
		ans += a
		l -= b
		if l > 0 {
			ans -= l
		}
	}
	fmt.Print(ans)
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,k,d;
int main()
{
    cin>>x>>k>>d;
    if(x<0) x=-x;
    ll ans=x%d;
    ll cnt=(ans-d);
    ll step,pos;
    if(abs(ans)<abs(cnt)) step=x/d,pos=ans;
    else step=x/d+1,pos=cnt;
    if(k<step)
    {   
        //cout<<1<<endl;
        cout<<x-d*k<<endl;
    }
    else
    {
        if((k-step)%2==1)
        {
            cout<<min(abs(pos+d),abs(pos-d))<<endl;
        }
        else cout<<abs(pos)<<endl;
    }
    return 0;
}

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


void solve(long long N, std::string S){

  vector<bool> tab(26);
  tab[S[0] - 'a'] = true;
  long long mymax = 0;

  for(long long i = 1; i < N; i++){
    long long count = 0;

    for(long long j = 0; j < 26; j++){
      if(!tab[j]) continue;
      auto pos = S.substr(i,N-i).find('a'+j);

      if(string::npos != pos) count++;
    }
    mymax = max(mymax, count);
    tab[S[i] - 'a']=true;
  }

  cout << mymax << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::string S;
  std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
using lll = __int128;
const int maxn = 300010, p = 1e9+7;
ll p3[maxn];
ll solve(int bit, ll n) {
	if (bit == -1 || n == 0) return 1;
	//static int cnt;
	static unordered_map<ll,int> cnt[100];
	if (((((lll)2ull<<bit)-1)<<1) <= n) {
		return p3[bit+1];
	}
	if (cnt[bit].count(n)) return cnt[bit][n];
	ll res = 0;
	if (((lll)2ull<<bit) <= n)
		res += solve(bit-1, n - (2ull<<bit));
	if (((lll)1ull<<bit) <= n)
		res += solve(bit-1, n - (1ull<<bit));
	return cnt[bit][n] = (res + solve(bit-1, n)) % p;
}
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll n;
	cin >> n;
	p3[0] = 1;
	for (int i = 1;i < 100;++i)
		p3[i] = p3[i-1] * 3 % p;
	cout << solve(60, n) << '\n';
}



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

int main() {
  int H ,W;
  cin >> H >> W;
  string str;
  
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for (int j = 0; j < H; j++) {
    cin >> str;
    cout << '#' << str << "#" << endl;
  }
  
  for (int i = 0; i < W+2; i++) {
    cout << '#';
  }
  cout << endl;
}


Measured memory_bytes: 256
n = 0
N, M = map(int, input().split())
A = []
for i in range(1,N+1):
    S = input().split()
    for j in range(len(S)):
        S[j] = int(S[j])
    A = A + S[1:]
    
for i in range(1, M+1): 
    cnt = A.count(i)
    if cnt == N:
        n += 1 
print("{}".format(n))


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    
    int tmp;
    if( b > c )
    {
        tmp = b;
        b = c;
        c = tmp;
    }
    if( a > b )
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    if( b > c )
    {
        tmp = b;
        b = c;
        c = tmp;
    }
    
    cout << a <<" "<< b << " "<< c << endl;
}



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

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

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

Measured memory_bytes: 4376
N, M = map(int, input().split())
A=[]
total=0
money=0
point=-1
over=0
for i in range(N):
    A.append(list(map(int, input().split())))

A.sort()

while(total<M):
    point +=1
    money+=A[point][0]*A[point][1]
    total +=A[point][1]

over=total-M
money -= over*A[point][0]

print(money)



Measured memory_bytes: 27760
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	int n, m,tmp=0,k;
	string str, str2[5000];
	cin >> str;
	n = str.length();
	for (int i = 0; i < n; i++) {
		if (tmp == 0 && str[i] == 'A') { tmp++; m = i; }
		if ( str[i] == 'Z') { k = i; }
	}
	cout <<k-m+1;
}

Measured memory_bytes: 644
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
const int N = 1e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;

ll d[N];
int n, m;
vector<pair<int, ll>> G[N];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i < n; ++i)
        G[i + 1].emplace_back(i, 0);
    while (m--) {
        int u, v, w;
        cin >> u >> v >> w;
        G[u].emplace_back(v, w);
    }
    memset(d, 0x3f, sizeof d);
    d[1] = 0;
    priority_queue<pli, vector<pli>, greater<pli>> pq;
    pq.emplace(0, 1);
    while (pq.size()) {
        auto p = pq.top(); pq.pop();
        ll cur = p.first;
        int u = p.second;
        if (cur > d[u]) continue;
        for (auto e : G[u]) {
            int v = e.first;
            ll w = e.second;
            if (d[v] > cur + w) {
                d[v] = cur + w;
                pq.emplace(d[v], v);
            }
        }
    }
    cout << (d[n] == INF ? -1 : d[n]) << '\n';
}

Measured memory_bytes: 10232
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

vvi G = vv(200001, 0, 0, int);
vvi p = vv(200001, 2, 0, int);
std::vector<int> c(200001);

int main(int argc, char const *argv[]) {
  int N, M, a, b;
  std::cin >> N >> M;
  string S;
  std::cin >> S;
  for(int i=0;i<N;i++) c[i+1] = (S[i]=='A'?1:0);
  for(int i=0;i<M;i++){
    std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
    (c[b]==1?p[a][0]:p[a][1]) += 1;
    (c[a]==1?p[b][0]:p[b][1]) += 1;
  }
  //for(int i=1;i<=N;i++) std::cout << i << " " <<p[i][0] << " " << p[i][1] << '\n';
  deque<int> q;
  for(int i=1;i<=N;i++) if(p[i][0]==0||p[i][1]==0) q.push_back(i);
  set<int> num;
  for(int i=1;i<=N;i++) num.insert(i);

  while(!q.empty()){
    int x = q.front();
    q.pop_front();
    if(num.find(x)==num.end()) continue;
    num.erase(x);
    //std::cout << x << '\n';
    for(int i=0;i<G[x].size();i++){
      if(num.find(G[x][i])==num.end()) continue;
      (c[x]==1?p[G[x][i]][0]:p[G[x][i]][1])-=1;
      if(p[G[x][i]][0]==0||p[G[x][i]][1]==0) q.push_back(G[x][i]);
    }
    p[x][0] = p[x][1] = 0;
  }
  //for(int i=1;i<=N;i++) std::cout << i << " " << p[i][0] << " " << p[i][1] << '\n';
  //for(auto itr = num.begin(); itr!=num.end();itr++) std::cout << *itr << " ";
  std::cout << (num.empty()?"No":"Yes") << '\n';
  return 0;
}


Measured memory_bytes: 31552
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__

int dN(int a){
  int n=0;
  while(a>0){
    n++;
    a /=10;
  }
  return n;
}

void solve(void){
  
  int N;
  cin >> N;
  
  int ans=0;
  
  if(N<10){
    ans=N;
  }
  else if(N<100){
    ans=9;
  }
  else if(N<1000){
    ans=N-99+9;
  }
  else if(N<10000){
    ans=909;
  }
  else if(N<100000){
  	ans=N-9999+900+9;
  }
  else
  {
    ans=90909;
  }
 
  cout << ans << endl;
  
  return;
   
}

#define TESTCASES	1

int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

  	REP(i,TESTCASES){
    	solve();
    } 
  
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
      
        int a =X%500;
        int b =X/500;
        int c =a/5;
      
      System.out.println((500*b)*2+5*c);
    }
 }
      
 

Measured memory_bytes: 23892
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int n = ri();
	int k = ri();
	int a[n];
	for (int i = 0; i < n; i++) {
		a[i] = ri();
	}
	
	int res = 1+ (n-2)/(k-1);
	wi(res);
	
	return 0;
}


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

using lli = long long int;

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

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    int kk[10][10];
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            kk[i][j] = i*j;
        }
    }
    int n;
    cin >> n;
    bool can = false;
    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(kk[i][j] == n) can = true;
        }
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef pair<long long int, int> P;

int main() {
	int w, h;
	cin >> w >> h;
	long long int s[2] = { 0,0 };
	long long int ans = 0;
	vector<P>v(w+h);
	for (int i = 0; i < w; i++) {
		cin >> v[i].first;
		v[i].second = 0;
	}
	for (int i = w; i < w+h; i++) {
		cin >> v[i].first;
		v[i].second = 1;
	}
	sort(v.begin(), v.end());
	for (auto r : v) {
		if (r.second == 0) {
			ans += (h+1 - s[1])*r.first;
			s[0]++;
		}
		else {
			ans += (w+1 - s[0])*r.first;
			s[1]++;
		}
	}
	cout << ans << endl;
}

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

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

    string s;
    cin >> s;
    long long k;
    cin >> k;

    for(int i = 0; i < k; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;

    return 0;
}

Measured memory_bytes: 256
n ,m = list(map(int, input().split()))

a = list(map(int, input().split()))
total_a = 0

for i in range(n):
    total_a = total_a + a[i]

a.sort(reverse=True)
choice_flag = True

for i in range(m):
    aa = a[i]

    if aa < total_a / (4 * m):
        choice_flag = False
        break

if choice_flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
def resolve():
    N = int(input())
    H = list(reversed([int(i) for i in input().split()]))
    for i in range(N - 1):
        if H[i + 1] > H[i] + 1:
            print("No")
            return
        elif H[i + 1] == H[i] + 1:
            H[i + 1] -= 1
    else:
        print("Yes")


resolve()


Measured memory_bytes: 20728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
main()
{
    long long int a,b,temp,ans,i,k=0;
    vector <ll>v1,v2;
    cin>>a;
    for(i=0;i<a;i++)
    {
        cin>>b;
        v1.push_back(b);
         v2.push_back(b);

    }
    sort(v2.rbegin(),v2.rend());

     for(i=0;i<a;i++)
    {   if(v1[i]==v2[k]) k++;
        cout<<v2[k]<<endl;
        k=0;
    }




}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

int main()
{
	
	fast;
	ll a,b,c;
	cin >> a >> b >> c;
	cout << c << " " <<a <<" " << b << endl;
}

Measured memory_bytes: 256
b_1,b_2,b_3 = map(int,input().split())
if b_1 == 1 and b_2 == 1 and b_3 == 0:
    print('Open')
else:
    if b_1 == 0 and b_2 == 0 and b_3==1:
        print('Open')
    else:
        print('Close')


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=10e9+7;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}

int main(void){
    vector<char> XY(2);
    vector<int> xy(2);
    rep(i,2) {
        cin>>XY.at(i);
        if(XY.at(i)=='A') xy.at(i)=10;
        if(XY.at(i)=='B') xy.at(i)=11;
        if(XY.at(i)=='C') xy.at(i)=12;
        if(XY.at(i)=='D') xy.at(i)=13;
        if(XY.at(i)=='E') xy.at(i)=14;
        if(XY.at(i)=='F') xy.at(i)=15;
    }
    if(xy.at(0)<xy.at(1)) cout<<"<"<<endl;
    else if(xy.at(0)==xy.at(1)) cout<<"="<<endl;
    else if(xy.at(0)>xy.at(1)) cout<<">"<<endl;
    return 0;
}

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



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
   
    int N, C;
    cin >> N >> C;
    
    priority_queue<pii, vector<pii>, greater<pii> > q[C];
    rep(i, N) {
        int s, t, c;
        cin >> s >> t >> c;
        c--;
        q[c].push(pii{s, t});
    }
    
    
    vector<vector<pii> > cha(C);
    
    rep(i, C) {
        if (sz(q[i]) == 0) continue;
        int bs, bt;
        bs = q[i].top().F;
        bt = q[i].top().S;
        q[i].pop();
        while (!q[i].empty()) {
            int s, t;
            s = q[i].top().F;
            t = q[i].top().S;
            q[i].pop();
            // out(bs << " " << bt << " " << s << " " << t);
            
            if (s == bt) {
                bt = t;
            } else {
                cha[i].eb(pii{bs, bt});
                bs = s;
                bt = t;
            }
            
        }
        cha[i].eb(pii{bs, bt});
    }
    
    // rep(i, C) rep(j, sz(cha[i])) cout << cha[i][j].F << " " << cha[i][j].S << endl;
    
    /*
    map<pii, int> mp;
    rep(i, C) rep(j, sz(cha[i])) mp[pii{cha[i][j].F, cha[i][j].S}] = i;
    */
    
    
    vector<pii> v;
    rep(i, C) rep(j, sz(cha[i])) v.eb(pii{cha[i][j].F, cha[i][j].S});
    
    sort(all(v));
    
    // outp(v, sz(v));
    // return 0;
    
    const int MAX_N = 100002;
    
    int table[MAX_N] = {0};
    
    int ans = 0;
    rep(i, sz(v)) {
        table[v[i].F - 1]++;
        table[v[i].S]--;
    }
    rep3(i, 1, MAX_N) table[i] += table[i - 1];
    
    rep(i, MAX_N) chmax(ans, table[i]);
    
    out(ans);
}



Measured memory_bytes: 3608
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}


/// My Code -------------------------------------------------
long long gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    long long N; cin>>N;
  long long ans=0;
  for(int i=0;i<N;i++){
    long long a;cin>>a;
    if(i==0)ans=a;
    ans=lcm(ans,a);
  }
  cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m;
pair<int, int> a[N];

int32_t main()
{
	IOS;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i].first>>a[i].second;
	sort(a+1, a+n+1);
	int ans = 0;
	for(int i=1;i<=n;i++)
	{
		int take = min(m, a[i].second);
		ans += take * a[i].first;
		m -= take;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
n = gets.to_i
x = gets.chomp
popcount = x.count('1')
x = '0' * (n - x.size) + x if x.size < n
x_lower = popcount > 1 ? x.to_i(2) % (popcount - 1) : -1
x_more = x.to_i(2) % (popcount + 1)

n.times do |i|
  if x[i] == '1' && x_lower == -1
    puts 0
    next
  end
  y = if x[i] == '1'
        (x_lower - 2.pow((n - 1 - i), popcount - 1)) % (popcount - 1)
      else
        (x_more + 2.pow((n - 1 - i), popcount + 1)) % (popcount + 1)
      end
  ans = 1
  while y > 0
    y %= y.to_s(2).count('1')
    ans += 1
  end
  puts ans
end

Measured memory_bytes: 14680
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const ll mod=1000000007;
     
    ll powmod(ll x,ll y){
        ll res=1;
        for(ll i=0;i<y;i++){
            res=res*x%mod;
        }
        return res;
    }
    int main(){
        ll n;
        cin>>n;
        ll ans=powmod(10,n)-powmod(9,n)-powmod(9,n)+powmod(8,n);
        ans%=mod;
        ans=(ans+mod)%mod;
        cout<<ans<<"\n";
    }

Measured memory_bytes: 3576
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
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;}
using namespace std;
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int>m(n);
  rep(i,n)m[i]=k-q;
  rep(i,q){
    int a;
    cin>>a;
    m[a-1]++;
  }

  rep(i,n){
    int ans;
    ans=m[i];
    if(ans>0)cout<<"Yes";
    else cout<<"No";
    if(i<n-1)cout<<endl;
  }
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int H,N;
    cin>>H>>N;
    while(N--){
        int a;
        cin>>a;
        H-=a;
    }
    if(H<=0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }

void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

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

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m);
}

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

	int N,A[200000];
	ll sum=0,answer=INFL;
	cin>>N;
	REP(i,N){
		cin>>A[i];
		sum+=A[i];
	}

	ll tem=0;
	REP(i,N-1){
		tem+=A[i];
		chmin(answer,abs(tem-abs(sum-tem)));
	}
	print(answer);

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,k;
  cin>>n>>k;
  vll d(k),s(n,0);
  REP(i,k){
    cin>>d[i];
    REP(j,d[i]){
      ll a;
      cin>>a;
      a--;
      s[a]++;
    }
  }

  ll ans=0;
  REP(i,n){
    if(s[i]==0)
      ans++;
  }

  cout<<ans<<endl;
}



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

#define ff first
#define ss second
// #define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
	uniform_int_distribution<int> uid(l, r);
	return uid(rng);
}
signed main(void)
{
	IOS;
	int a,b,k;
	cin>>a>>b>>k;
	if(a<=k) {
		k-=a;
		a=0;
	} else {
		a=a-k;
		cout<<a<<" "<<b<<endl;
		return 0;
	}
	if(b<=k) {
		b=0;
		cout<<a<<" "<<b<<endl;
		return 0;
	} else {
		b-=k;
		cout<<a<<" "<<b<<endl;
		return 0; 
	}
	
	time();
	return 0;
}

Measured memory_bytes: 256
//import java.lang.Math;
import java.util.*;
import java.util.List;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;


class Main{
	
	public static void main(String[] arg){
	
		Scanner sc=new Scanner(System.in);
		int cnt=sc.nextInt();
		LinkedList<Integer> list= new LinkedList<Integer>();
		ListIterator<Integer> iterator =list.listIterator();
		
		for(int i=0;i<cnt;i++)
		{
		int sum=sc.nextInt();
			switch(sum){
			case 0:
				
				iterator.add(sc.nextInt());
				iterator.previous();
				break;
			case 1:
				int a=sc.nextInt();
				
				if(a>0){
					for(int j=0;j<a;j++){
						iterator.next();
						
						}
					}else {
					for(int j=0;j<-a;j++){
						iterator.previous();
						}
				}break;
			case 2:
				iterator.next();
				iterator.remove();
				break;
				
				}	
			
		}
			for(Integer x:list) System.out.println(x);
			
		
	}}


Measured memory_bytes: 309172
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	_ = intScanner()
	w := intScanner()
	as := intSliceScanner(n)
	if n == 1 {
		fmt.Println(abs(w - as[n-1]))
	} else {
		fmt.Println(larger(abs(w-as[n-1]), abs(as[n-1]-as[n-2])))
	}
}


Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n,k; cin>>n>>k;
  k++; // どこかの桁で必ずlt=trueにする必要がある
  vector<ll> cnt(40);
  rep(i,n){
    ll a; cin>>a;
    rep(d,40) cnt[d]+=(a>>d)&1;
  }
  ll ans=0;
  rep(j,39,-1,-1){ // j 桁目でltをtrueにする
    if(!((k>>j)&1)) continue;
    ll res=0;
    rep(d,39,-1,-1){
      if(d>j){
        res+=((k>>d)&1?(n-cnt[d])<<d:cnt[d]<<d);
      }else if(d==j){
        res+=cnt[d]<<d;
      }else{
        res+=max(cnt[d],n-cnt[d])<<d;
      }
    }
    chmax(ans,res);
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
void warshall_froid(int n, VVL& D) {
	for (int k = 0; k < n; k++) { // 経由
		for (int i = 0; i < n; i++) { // 始点
			for (int j = 0; j < n; j++) { // 終点
				chmin(D[i][j], D[i][k] + D[k][j]);
			}
		}
	}
}
int main() {
	int n, m, r;
	cin >> n >> m >> r;
	V ord(r);
	rep(i, r) {
		cin >> ord[i];
		ord[i]--;
	}
	VVL dist(n, VL(n, UPPER / 2));
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	warshall_froid(n, dist);
	ll ans = UPPER;
	V per(r);
	rep(i, r) per[i] = i;
	do {
		ll tmp = 0;
		rep(i, r - 1) {
			tmp += dist[ord[per[i]]][ord[per[i + 1]]];
		}
		chmin(ans, tmp);
	} while (next_permutation(all(per)));
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  int n,a,b,sum,t;
  int count=0;
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++){
    sum=0;
    t=i;
    for(int j=0;j<5;j++){
      sum+=t%10;
      t/=10;
    }
    if(a<=sum&&sum<=b){
      count+=i;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
  int cnt = 0;
  vector<pair<int, int>> p(5);
  
  for(int i=0; i<5; i++)
  {
    int t;
    cin >> t;
    p[i] = {(10 - (t % 10)) % 10, t};
  }
  
  sort(p.begin(), p.end());
  for(int i=0; i<5; i++)
  {
    cnt += p[i].second;
    
    if(i == 4)
      break;
    
    while((cnt % 10) != 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3612
def main():
    n=int(input())
    h = list(map(int,input().split()))
    dp=[0 for _ in range(n)]
    dp[1]=abs(h[0]-h[1])
    for i in range(n-2):
        i+=2
        dp[i]=min( dp[i-1]+abs(h[i]-h[i-1]) , dp[i-2]+abs(h[i]-h[i-2]) )
    print(dp[n-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 52720
#include <iostream>
using namespace std;
int P[10010]; 
void init(int N) { 
    for (int i=0; i<N; ++i) P[i] = i;
}
int root(int a) { 
    if (P[a] == a) return a; 
    return (P[a] = root(P[a])); 
}
bool is_same_set(int a, int b) {
    return root(a) == root(b);
}
void unite(int a, int b) {
    P[root(a)] = root(b);
}
int main(void){
    int n,q,com,x,y;
    cin >> n >> q;
    init(n);
    for(int i=0;i<q;i++){
        cin >> com;
        if(com == 0){
            cin >> x >> y;
            unite(x,y);
        } else if(com == 1){
            cin >> x >> y;
            cout << is_same_set(x,y) << endl;
        }
    }
}


Measured memory_bytes: 3184