akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> T(N), A(N), cmp;
    for(int i=0; i<N; i++) {
        cin >> T[i] >> A[i];
        cmp.emplace_back(T[i]);
        cmp.emplace_back(T[i] + 1);
    }
    int Q; cin >> Q;
    vector<int> L(Q), R(Q);
    for(int i=0; i<Q; i++) {
        cin >> L[i] >> R[i];
        cmp.emplace_back(L[i] - 1);
        cmp.emplace_back(L[i]);
        cmp.emplace_back(R[i]);
        cmp.emplace_back(R[i] + 1);
    }

    sort(cmp.begin(), cmp.end());
    cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());

    for(int i=0; i<N; i++) T[i] = lower_bound(cmp.begin(), cmp.end(), T[i]) - cmp.begin();
    for(int i=0; i<Q; i++) {
        L[i] = lower_bound(cmp.begin(), cmp.end(), L[i]) - cmp.begin();
        R[i] = lower_bound(cmp.begin(), cmp.end(), R[i]) - cmp.begin();
    }

    int M = cmp.size();
    vector<long double> acc(M+1);
    for(int i=0; i<N; i++) {
        acc[ T[i] ] += log10((long double)(100 - 10 * A[i]) / 100.0);
    }
    for(int i=1; i<=M; i++) acc[i] += acc[i-1];

    for(int i=0; i<Q; i++) {
        int l = L[i] - 1, r = R[i];
        long double p = acc[r] - acc[l];
        printf("%.12Lf\n", 1e9 * pow(10, p));
    }
    return 0;
}



Measured memory_bytes: 16088
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void testCase();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void testCase() {
	ll n, m;
	cin >> n >> m;
	vector < pll > v;
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		v.eb(num, 1);
	}
	while (m--) {
		int a, b;
		cin >> a >> b;
		v.eb(b, a);
	}
	sort(rall(v));
	ll sum = 0, done = 0, ctr = 0;
	while (done < n) {
		ll take = min(v[ctr].second, n - done);
		done += take;
		sum += take * v[ctr++].first;
	}
	cout << sum << "\n";
}

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

int main()
{
    char ch;
    int cnt[26]={};

    while(cin>>ch){

        ch = tolower(ch);

        cnt[ch-'a']++;

    }

    for(int i=0;i<26;i++){
        char x = 'a'+i;

        cout<<x<<" : "<<cnt[i]<<endl;

    }

    return 0;
}


Measured memory_bytes: 3092
L,R,i,c[555][555],s;main(n){for(scanf("%*d%d%*d",&n);~scanf("%d%d",&L,&R);i++)for(s=0;i/n?R/L||!printf("%d\n",s):R<501;)i/n?s+=c[L++][R]:c[L][R++]++;}

Measured memory_bytes: 1920
import sys
sys.setrecursionlimit(10**6)

s = input()
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

s_low = s.lower()

if s == s_low:
    print('a')
else:
    print('A')

Measured memory_bytes: 9064
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

int n, m, r, q, t[10000][1300];

int main() {

	
	while (1) {

		for (int i = 0; i < 10000; i++) {
			for (int j = 0; j < 1300; j++) {
				t[i][j] = 0;
			}
		}

		cin >> n >> m;
		if (n==0 && m==0) break;

		cin >> r;
		for (int i = 0; i < r; i++) {
				int tt, tn, tm, ts;
				cin >> tt >> tn >> tm >> ts;
				if (ts == 1) t[tm-1][tt]++;
				else t[tm - 1][tt+1]--;
		}

		for (int i = 0; i < m; i++) {
			for (int j = 1; j <1300; j++) {
				t[i][j] += t[i][j-1];
			}
		}

		vector<int> v;
		cin >> q;
		for (int i = 0; i < q; i++) {
			int ts, te, tm;
			cin >> ts >> te >> tm;
			int ans=0;
			bool flag = false;
			for (int j = ts; j < te; j++) {
				if (t[tm - 1][j]>0 && t[tm - 1][j+1]>0) ans++, flag = true;
				//if (flag && (t[tm - 1][j]==0 || (j==te&&t[tm-1][te+1]<1))) ans--, flag = false;
			}
			v.push_back(ans);
		}

		for (int h = 0; h < v.size(); h++) {
			cout << v[h] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 53836
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e10+7;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;

    int n,k,val;
    cin>>n>>k;
    vi v;
    vector<bool> vis(n+2,false);
    map<int,int> mpp;
    mpp[1]=0;
    vi pos;
    pos.pb(1);
    vis[1]=true;
    rep(i,n)
    {
        cin>>val;
        v.pb(val);
    }
    int cnt=1,cycle,start,curr=1;
    while(1)
    {
        int next=v[curr-1];
        if(!vis[next])
        {
            curr=next;
            vis[curr]=true;
            mpp[curr]=cnt;
            cnt++;
            pos.pb(curr);
        }
        else
        {
            cycle=cnt-mpp[next];
            start=mpp[next];
            break;
        }
    }
    //cout<<start<<" "<<cycle<<endl;
    if(k<=start) cout<<pos[k];
    else
    {
        val=(k-start)%cycle+start;
        cout<<pos[val];
    }
}

Measured memory_bytes: 18720
import numpy as np
import math
N,K = map(int, input().split()) 
Logs = np.array([int(x) for x in input().split()])
ave = sum(Logs)/(N+K)
cut = np.array([max(1,int(x/ave)) for x in Logs])
chip = Logs/cut
chip=np.sort(chip)[::-1]
print(math.ceil(chip[N+K-sum(cut)]))

Measured memory_bytes: 49464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,k,a;
  cin >> n >> k;
  vector<ll> cnt(k+1);
  cnt[0] = 1;
  for(int i = 0; i < n; ++i){
    cin >> a;
    ll tmp = 0;
    for(int j = k; j >= k-a; --j) tmp = (tmp+cnt[j])%mod;
    for(int j = k; j > 0; --j){
      tmp = (tmp-cnt[j])%mod;
      cnt[j] = (cnt[j]+tmp)%mod;
      if(j-a > 0) tmp = (tmp+cnt[j-a-1])%mod;
    }
  }
  cout << (cnt[k]+mod)%mod;
  return 0;
}

Measured memory_bytes: 3972
fun main(args : Array<String>) {
	val (h, a) = readLine()!!.split(" ")
	var H : Int = h.toInt()
	val A : Int = a.toInt()
	var cnt : Int = 0
	while (H > 0) {
		H -= A
		cnt++
	}
	println("${cnt}")
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 200010

enum Direction { Up = 0, Down, Left, Right };

ll H, W, N;
ll Sr, Sc;
string S, T;

pair<ll, ll> dp_w[2][MAX_N];
pair<ll, ll> dp_h[2][MAX_N];

// S か T が st で、 S[i]/T[i] をチェックしているときの、
// はみ出ることがない範囲
pair<ll, ll> dfs_w(ll st = 0, ll i = 0) {
    if(i >= N) {
        return make_pair(0, W-1);
    }

    pair<ll, ll>& ret = dp_w[st][i];
    if(ret.first != LLINF && ret.second != LLINF) { return ret; }


    ll next_st = (st == 0) ? 1 : 0;
    ll next_i = (st == 0) ? i : (i + 1);
    ret = dfs_w(next_st, next_i);

    if(st == 0) {   // S を見る
        if(S[i] == 'R') {
            // 右側の OK 範囲が -1
            ret.second--;
        }
        else if(S[i] == 'L') {
            // 左側の OK 範囲が +1
            ret.first++;
        }
    }
    else {  // T を見る
        if(T[i] == 'R') {
            // 左側の OK 範囲が -1
            if(ret.first > 0) { ret.first--; }
        }
        else if(T[i] == 'L') {
            // 右側の OK 範囲が +1
            if(ret.second < W-1) { ret.second++; }
        }
    }

    return ret;
}
pair<ll, ll> dfs_h(ll st = 0, ll i = 0) {
    if(i >= N) { return make_pair(0, H-1); }

    pair<ll, ll>& ret = dp_h[st][i];
    if(ret.first != LLINF && ret.second != LLINF) { return ret; }

    ll next_st = (st == 0) ? 1 : 0;
    ll next_i = (st == 0) ? i : (i + 1);
    ret = dfs_h(next_st, next_i);

    if(st == 0) {
        if(S[i] == 'D') { ret.second--; }
        else if(S[i] == 'U') { ret.first++; }
    }
    else {
        if(T[i] == 'D') { if(ret.first > 0) { ret.first--; } }
        else if(T[i] == 'U') { if(ret.second < H-1) { ret.second++; } }
    }
    return ret;
}

signed main()
{
    cin >> H >> W >> N >> Sr >> Sc >> S >> T;
    Sr--; Sc--;

    REP(i, 2) {
        REP(j, N) {
            dp_w[i][j] = make_pair(LLINF, LLINF);
            dp_h[i][j] = make_pair(LLINF, LLINF);
        }
    }

    dfs_w();
    dfs_h();

    // dfs の結果範囲がなくなっている or i = 0時点での範囲が Sr/Sc の外なら、
    // 高橋君の勝ち
    if(dp_w[0][0].first <= Sc && Sc <= dp_w[0][0].second &&
            dp_h[0][0].first <= Sr && Sr <= dp_h[0][0].second)
    {
        // OK
    }
    else {
        printf("NO\n");
        return 0;
    }
    REP(i, 2) {
        REP(j, N) {
            //DBG("dp_w[%lld][%lld]: (%lld, %lld)\n", i, j, dp_w[i][j].first, dp_w[i][j].second);
            if(dp_w[i][j].first > dp_w[i][j].second ||
                dp_h[i][j].first > dp_h[i][j].second)
            {
                printf("NO\n");
                return 0;
            }
        }
    }

    printf("YES\n");
    return 0;
}


Measured memory_bytes: 25736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e6+5;
unordered_map<int,int> head[maxn];
struct EDGE{
	int v,nex,c;
}edge[maxn];
int ecnt;
inline void add_edge(int u,int v,int c){
	edge[++ecnt]={v,head[u][c],c};head[u][c]=ecnt;
	edge[++ecnt]={u,head[v][c],c};head[v][c]=ecnt;
}
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,m;cin>>n>>m;
	bool vis[maxn],vvis[maxn];
	vector<vector<int>> nex(maxn);
	int vcnt=n;
	for(int i=1;i<=m;i++) {
		int u,v,c;cin>>u>>v>>c;
		add_edge(u,v,c);
	}
	std::function<void(int,int)> dfs= [&] (int u,int col) {
		nex[u].push_back(vcnt);
		nex[vcnt].push_back(u);
		vvis[u]=1;
		for(int i=head[u][col];i;i=edge[i].nex) if(!vis[i]){
			vis[i]=1;
			int v=edge[i].v;if(vvis[v]) continue;
			dfs(v,col);
		}
	};
	for(int i=1;i<=ecnt;i++) {
		if(!vis[i]) {
			++vcnt;
			dfs(edge[i].v,edge[i].c);
			for(auto x:nex[vcnt]) vvis[x]=0;
			vis[i]=1;
		}
	}

	vector<int> dis(maxn);queue<int> Q;Q.push(1);dis[1]=1;
	while(!Q.empty()) {
		int u=Q.front();Q.pop();
		for(auto v:nex[u]) {
			if(dis[v]) continue;
			dis[v]=dis[u]+1;
			Q.push(v);
		}
	}
	cout<<(dis[n]?(dis[n]-1)/2:-1)<<endl;
    return 0;
}

Measured memory_bytes: 200760
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;
 

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    rep(i,h){
        string s; cin >> s;
        rep(j,w) grid[i][j] = s[j];
    }
    
    
    
        vector<vector<int>> L(h, vector<int>(w));
        vector<vector<int>> R(h, vector<int>(w));
        vector<vector<int>> U(h, vector<int>(w));
        vector<vector<int>> D(h, vector<int>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(grid[i][j] =='#') {
                L[i][j] = 0;
               
                continue;
            }
            if(j == 0){
                L[i][j] = 1;
               
                continue;
            }
            L[i][j] = L[i][j-1] + 1;

        }
    }

    for(int i=0; i<h; i++){
        for(int j=w-1; j>=0; j--){
            if(grid[i][j] =='#') {
                    R[i][j] = 0;

                    continue;
                }
                if(j == w-1){
                    R[i][j] = 1;

                    continue;
                }
                R[i][j] = R[i][j+1] + 1;

            
        }
    }

    
    for(int j=0; j<w; j++){
        for(int i=0; i<h; i++){
            if(grid[i][j]=='#'){
                U[i][j] = 0;

                continue;
            }
            if(i == 0){
                U[i][j] = 1;

                continue;
            }
            U[i][j] = U[i-1][j]+1;

        }
    }

    for(int j=0; j<w; j++){
        for(int i=h-1; i>=0; i--){
          if(grid[i][j]=='#'){
                D[i][j] = 0;

            continue;
            }
            if(i == h-1){
                D[i][j] = 1;

                continue;
            }
            D[i][j] = D[i+1][j]+1;

        }
    }

    int ans = 0;
  
    rep(i, h){
        rep(j, w){
            int a = 0;
            a = L[i][j]+R[i][j]+U[i][j]+D[i][j] - 3;
            ans =max(ans, a);
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 69120
// AOJ 2283: Seishun 18 Kippu
// 2017.11.10 bal4u@uu

#include <stdio.h>
#include <string.h>

#define HASHSIZ 1009
typedef struct { char *s; int id; } HASH;
HASH hash[HASHSIZ+2], *hashend = hash + HASHSIZ;			// Hash table

int lookup(char *s, int id)
{
	int w = strlen(s);
	int i = (101 * *s + 103 * *(s+w-1) + 107 * w) % HASHSIZ;
	HASH *tp = hash + i;

	while (tp->s != NULL) {
		if (!strcmp(tp->s, s)) return tp->id;
		if (++tp == hashend) tp = hash;
	}
	tp->s = s, tp->id = id;
	return -1;
}

typedef struct { int t, node; } QUE;
QUE que[10005]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		QUE t = que[i]; que[i] = que[min]; que[min] = t;
		min_heapify(min);
	}
}

int deq(int *n)
{
	if (qsize == 0) return 0;
	*n = que[0].node;
	que[0] = que[--qsize];
	min_heapify(0);
	return 1;
}

void enq(int n, int t)
{
	int i, min;

	i = qsize++;
	que[i].node = n, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		QUE tt = que[i]; que[i] = que[min]; que[min] = tt;
		i = min;
	}
}

#define MAX 503
typedef struct { int len, to[MAX], cost[MAX]; } TBL;
TBL tbl[MAX];
int node[MAX]; char mk[MAX]; int size;
char name[MAX][22];

int search(int start, int goal)
{
	int i, k, s, e;
	TBL *tp;

	qsize = 0;
	for (i = 0; i < size; i++) node[i] = 1000000, mk[i] = 0;
	node[start] = 0; enq(start, 0);
	while(deq(&s)) {
		if (s == goal) break;
		if (mk[s]) continue;
		mk[s] = 1;
		tp = tbl + s;
		for (i = 0; i < tp->len; i++) {
			e = tp->to[i];
			if (mk[e]) continue;
			k = node[s] + tp->cost[i];
			if (k < node[e]) node[e] = k, enq(e, k); 
		}
	}
	return node[goal];
}

int main()
{
	int n, m, s, p, g;
	int i, j, d, t, ii, jj;

	while (scanf("%d%d", &n, &m) && n > 0) {
		memset(hash, 0, sizeof(hash));
		memset(tbl, 0, sizeof(tbl));

		scanf("%s%s%s", name[0], name[1], name[2]);
		s = 0, p = 1, g = 2;
		lookup(name[0], 0), lookup(name[1], 1), lookup(name[2], 2); size = 3;

		while (m--) {
			scanf("%s", name[size]);
			if ((i = lookup(name[size], size)) < 0) i = size++;
			scanf("%s%d%d", name[size], &d, &t);
			if ((j = lookup(name[size], size)) < 0) j = size++;
			t += d/40;
			ii = tbl[i].len, tbl[i].to[ii] = j, tbl[i].cost[ii] = t, tbl[i].len++;
			jj = tbl[j].len, tbl[j].to[jj] = i, tbl[j].cost[jj] = t, tbl[j].len++;
		}
		printf("%d\n", search(s, p) + search(p, g));
	}
	return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	char* n = (char*)malloc(200000 * sizeof(char));
	int a = 0;
	char c[1];

	scanf("%s", n);

	int b = strlen(n);

	for (int i = 0; i != b; i++)
	{
		c[0] = n[i];
		a += atoi(c);
	}

	(a % 9) ? printf("No") : printf("Yes");

	return 0;
}

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

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 0
#define LIM 1000000007

lli isInclude(lli n,vector<lli> *a){
	while(n){
		lli now = n%10;
		REP(i,a->size()){
			if(a->at(i) == now){
				return 0;
			}
		}
		n/=10;
	}
	return 1;
}

int main(){

	lli n,k;
	cin>>n>>k;
	vector<lli> d(k);
	REP(i,k)cin>>d[i];

	for(lli i=n;i<=200000;i++){
		if(DEBUG)cout<<i<<endl;
		if(isInclude(i,&d)){
			cout<<i<<endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong N,K;
    llong d;
    llong ans=0;
    cin >> N >> K;
    vector<vector<llong> > Table(N, vector<llong>(K,0));
    llong A;
    llong cnt=0;

    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++){
            cin >> A;
            Table[A-1][i] = 1;
        }
    }
    for(int i=0; i<N; i++){
        cnt = 0;
        for(int j=0; j<K; j++){
            if(Table[i][j]==1){
                cnt++;
            }
        }
        if(cnt==0){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3160
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
bool comp (pi a, pi b)
{
    return atan2(a.fi, a.se) < atan2(b.fi, b.se);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	read(n);
	pi a[n + 1];
	FOR (i, 1, n) cin >> a[i].fi >> a[i].se;
	sort(a + 1, a + n + 1, comp);
	
	double ans = 0;
	FOR (i, 1, n)
	{
	    int x = 0, y = 0;
	    FOR (j, i, n)
	    {
	        x += a[j].fi, y += a[j].se;
	        ans = max(ans, sqrt(x*x + y*y));
	    }
	    
	    FOR (j, 1, i - 1)
	    {
	        x += a[j].fi, y += a[j].se;
	        ans = max(ans, sqrt(x*x + y*y));
	    }
	}
	
	cout << fixed << setprecision(15) << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=500005,maxe=maxn<<1;
int n,K,p[maxn],q[maxn],ans[maxn];
int e,lnk[maxn],nxt[maxe],son[maxe],num[maxn];
inline char nc(){
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
inline void add_e(int x,int y){son[++e]=y;nxt[e]=lnk[x];lnk[x]=e;num[y]++;}
struct ST{
#define mid (L+R>>1)
#define ls (rt<<1)
#define rs (ls|1)
	int sum[maxn<<2];
	inline void add(int L,int R,int rt,int x,int y){
		sum[rt]+=y;if(L==R) return;
		if(x<=mid) add(L,mid,ls,x,y);
		else add(mid+1,R,rs,x,y);
	}
	inline int getl(int L,int R,int rt,int x){
		if(L>x||!sum[rt]) return 0;
		if(L==R) return L;
		int now=getl(mid+1,R,rs,x);
		return now?now:getl(L,mid,ls,x);
	}
	inline int getr(int L,int R,int rt,int x){
		if(R<x||!sum[rt]) return 0;
		if(L==R) return L;
		int now=getr(L,mid,ls,x);
		return now?now:getr(mid+1,R,rs,x);
	}
}T;
inline void swap(int&x,int&y){int t=x;x=y;y=t;}
struct HP{
	int h[maxn],len;
	inline void add(int x){
		h[++len]=x;
		for (int i=len;i>1;i>>=1)
		if(h[i]>h[i>>1]) swap(h[i],h[i>>1]);else break;
	}
	inline int get(){
		int ret=h[1];h[1]=h[len--];
		for (int i=1,j;(i<<1)<=len;i=j){
			j=(i<<1)==len||h[(i<<1)]>h[(i<<1|1)]?(i<<1):(i<<1|1);
			if(h[j]>h[i]) swap(h[i],h[j]);else break;
		}
		return ret;
	}
}S;
int main(){
	n=read(),K=read();
	for (int i=1;i<=n;i++) p[i]=read(),q[p[i]]=i;
	for (int i=1;i<=n;i++){
		if(i-K>0) T.add(1,n,1,p[i-K],-1);
		int l=T.getl(1,n,1,p[i]),r=T.getr(1,n,1,p[i]);
		if(l) add_e(i,q[l]);
		if(r) add_e(q[r],i);
		T.add(1,n,1,p[i],1);
	}
	for (int i=1;i<=n;i++) if(!num[i]) S.add(i);
	for (int i=n;i;i--){
		int x=S.get();ans[x]=i;
		for (int j=lnk[x];j;j=nxt[j])
		if(!--num[son[j]]) S.add(son[j]);
	}
	for (int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 27520
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;

//const int MOD=998244353;




int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	
	int n;
	cin>>n;
	
	
	
	vector<long long> a(n+1), st(n+1), nl(n+1);
	for(auto &i:a)cin>>i;
	
	if(!n){
	    cout<<(a[0]==1?1:-1);
	    return 0;
	}
	if(a[0]){
	    cout<<-1;
	    return 0;
	}
	
	
	st[n]=a[n];
	for(int i=n-1; i>=0; i--){
	    st[i]=a[i]+st[i+1];
	}
	
	long long ans=1;
	nl[0]=1;
	for(int i=1; i<=n; i++){
	    long long tot=min(2*nl[i-1],st[i]);
	    if(tot<a[i]){
	        cout<<-1;
	        return 0;
	    }
	    nl[i]=tot-a[i];
	    ans+=tot;
	}
	cout<<ans;
	
	

    return 0;
}

Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define mod 1e9 +7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const double phi = (1 + sqrt(5)) / 2;
const double phi_ = (1 - sqrt(5)) / 2;
ll fib(ll n){
    double res = pow(phi, n+1) - pow(phi_, n+1);
    return res / sqrt(5);
}
ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}
ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}
string to_bin_string(ll n){
    stringstream ss;
    ss << bitset<8>(n); //任意の桁数<m>
    string s = ss.str();
    return s;
}
int main()
{
    int n; cin >> n;
    vector<vi> cnt(n, vi(26, 0));
    rep(i,n){
        string s;
        cin >> s;
        rep(j,s.size())cnt[i][s[j] - 'a']++;
    }
    //rep(i,n)rep(j,26)cout << cnt[i][j] << ((j == 25)?"\n":" ");

    vi ans(26, 0);
    rep(i,26){
        int mi = 100000;
        rep(j,n)mi = min(mi, cnt[j][i]);
        ans[i] = mi;
    }
    //rep(i,26)cout << ans[i] << ((i == 25)?"\n":" ");
    rep(i,26){
        char c = 'a' + i;
        rep(j,ans[i])cout << c;
    }
    cout << endl;
    return 0;
} 

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		int ans = 0;
		bool lf = false, rf = false;
		bool f = false;
		for (int i = 0; i < n;i++) {
			string F; cin >> F;
			if (F == "lu") lf = true;
			if (F == "ru") rf = true;
			if (F == "ld") lf = false;
			if (F == "rd") rf = false;

			if (lf == rf) {
				if (f != lf) {
					ans++;
					f = lf;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,mx,mn;
    vector<int>v;
    cin>>a>>b>>c;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(v.begin(),v.end());

    cout<<v[0]<<" "<<v[v.size()-1]<<endl;
}



Measured memory_bytes: 3164
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] minfactor = new int[1000001];
        boolean[] ng = new boolean[1000001];
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (minfactor[num] == 0) {
                minfactor[num] = num;
            } else {
                ng[num] = true;
            }
        }
        
        int ans = 0;
        for (int i = 1; i < 1000001; i++) {
            if (minfactor[i] == i) {
                if (!ng[i]) ans ++;
                
                for (int j = i; j < 1000001; j += i) {
                    minfactor[j] = i;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 64652
#include <bits/stdc++.h>
using namespace std;
int n,ans;
int main()
{
	int x,y=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x==y+1)
		y++;
		else
		ans++;
	}
	if(y)
	printf("%d",ans);
	else
	printf("-1");
	return 0;
}

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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
/*--------------------------------------------*/

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  
  vector<vector<pair<int,int>>> P(N);   //P[i]はi番目の人の証言を格納
  
  
  rep(i,N){
    int num;
    cin >> num;
    rep(j,num){
      int a,b;
      cin >> a >> b;
      a--;
      P[i].PB(MP(a,b));
    }
  }

  int ans = 0;
  
  bool flag = false;
        
  for(int bit = 0;bit < (1<<N);++bit){
    vector<int> fact(N,0); //正直者かどうかを整理
    bool flag = false;
    int tmp = 0;   //正直者の人数
    
    rep(i,N){
      if(bit & (1<<i)){   //i番目が正直者だとすると
        fact[i] = 1;
        tmp++;
      }
    }
    
    rep(i,N){
      if(fact[i]){   //i番目が正直者だとすると
        rep(j,sz(P[i])){
          if(fact[P[i][j].first] != P[i][j].second){ //矛盾あり
            flag = true;
            break;
          }
        }
        if(flag)break;
      }
      if(flag)break;
    }
    if(flag)continue;
    
    
    //矛盾なしなのでok
    chmax(ans,tmp);
    
  }

  cout << ans << endl;
    


}


Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1347
// ICPC: アジア地区予選2014C
// Shopping

/*
Problem.
スタート地点:0, ゴール地点: N+1であるとして、
地点1~Nに存在するN個あるノードを全て訪れるときの最短距離を求めよ、
ただし、M個の以下の内容の制約が与えられる。
- 制約(C, D)：ノードCの前にノードDを訪れなければならない。

Point.
preceder[i]:iの最も後ろの先行ノード
- preceder[i]より前のiの先行ノードについては、
  preceder[i]を訪れる際にコスト0で訪れることが可能であるため、
  iの先行ノードはpreceder[i]のみ考慮すれば良い。

dp[j][i]: 最大jまで経由した時の、0~iまでを巡る最短距離.
- dp[i][i]は、0~iまでの全てかつ0~iのみのノードを巡る最短距離であり、
  dp[i][i] < INF なら、0~iまでのノードで完結させることが可能と言える。
  この時、i+1については、明らかにdp[i][i]の値を元に最短距離が求まる。
以上より、値の更新は
if(dp[i-1][i-1] < INF)dp[j][i] = dp[i-1][i-1] + j-(i-1) + j-i; //i-1 -> j -> i
else dp[j][i] = dp[j][i-1]+1; //素直に前のノードから１つ移動
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

#define INF 1e9

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n, m; cin >> n >> m;
  vector<vector<int>> dp(n+2, vector<int>(n+2, INF));

  vector<int> preceder(n+2);
  for(int i = 0; i < n+2; i++) preceder[i] = i;
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    preceder[a] = max(preceder[a], b);
  }

  dp[0][0] = 0;
  for(int i = 1; i <= n+1; i++){
    for(int j = preceder[i]; j <= n+1; j++){
      if(dp[i-1][i-1] < INF) dp[j][i] = dp[i-1][i-1] + j-(i-1) + j-i;
      else dp[j][i] = dp[j][i-1] + 1;
    }
  }
  cout << dp[n+1][n+1] << endl;
  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



Measured memory_bytes: 6848
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-9;
long double pi = acos(-1);

ll mod = 1e9+7;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,a,b;
    cin>>n>>a>>b;
    if(a<b)swap(a,b);
    ll s[n];
    for(int i=0;i<n;i++)cin>>s[i];

    ll dp[n+1][2]={};
    int dif[n+1]={};
    int dif_A[n+1]={};
    dif_A[0] = 1;
    dif[0] = 1;
    for(int i=1;i<n;i++){
        dif_A[i] = dif_A[i-1] + (s[i] - s[i-1] >= a);
        dif[i] = dif[i-1] + (s[i]-s[i-1]>=b);
    }
    int pre_A[n+1]={};
    int pre_B[n+1]={};
    int now = 0;
    for(int i=0;i<n;i++){
        while(now<n && s[now]-s[i]<a){
            pre_A[now] = i;
            now++;
        }
    }
    now = 0;
    for(int i=0;i<n;i++){
        while(now<n && s[now]-s[i]<b){
            pre_B[now] = i;
            now++;
        }
    }
    dp[0][1] = 1;
    dp[1][0]=1;
    dp[1][1]=1;
    for(int i=1;i<n;i++){
        // B
        if(i && s[i]-s[i-1]>=b) add(dp[i+1][0],dp[i][0]);
        bool okB = (i==pre_B[i] || ((dif_A[i-1] - dif_A[pre_B[i]]) == i-pre_B[i]-1));
        if(okB) add(dp[i+1][0],dp[i][1]);

        // A
        bool ok = 0;
        ok=((dif[i-1] - dif[pre_A[i]]) == i-pre_A[i]-1); 
        if(ok) add(dp[i+1][1],dp[pre_A[i]][1]);
        if(pre_A[i]==0)continue;

        bool dist = dif[pre_A[i]] - dif[pre_A[i]-1];
        if(ok && dist) add(dp[i+1][1],dp[pre_A[i]][0]);

    }
    ll ans = (dp[n][0]+dp[n][1])%mod;
    cout << ans << endl;
}

Measured memory_bytes: 7524
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

struct Edge {
    int from, to;
    long long cost;
    Edge(int _to, long long _cost) :
        from(-1), to(_to), cost(_cost) {}
    Edge(int _from, int _to, long long _cost) :
        from(_from), to(_to), cost(_cost) {}
};

template<class T>
vector<T> Bell(const vector<Edge> &edges, int N, int s, T def) {
    vector<T> dist(N, def);
    vector<bool> negative(N);
    dist[s] = 0;
    for(int loop = 0; loop < 2 * N - 1; ++loop) {
        for(auto &e : edges) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                if(loop > N - 1) negative[e.to] = true;
            }
            if(loop > N - 1 && negative[e.from]) negative[e.to] = true;
        }
    }
    for(int i = 0; i < N; ++i) {
        if(negative[i]) dist[i] = -INF;
    }
    return dist;
}

void solve() {
    int V, E, r;
    cin >> V >> E >> r;
    vector<Edge> edges;
    for(int i = 0; i < E; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        edges.emplace_back(a, b, c);
    }
    auto dist = Bell(edges, V, r, INF);
    for(auto &d : dist) if(d == -INF) {
        cout << "NEGATIVE CYCLE" << '\n';
        return;
    }
    for(auto &d : dist) {
        if(d == INF) cout << "INF" << '\n';
        else cout << d << '\n';
    }
}

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



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define nl cout<<"\n"
#define dbg(x) cout<<x<<" ";
#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define UM unordered_map<int,int>
#define ULL unordered_map<ll,int>
void fun(){
    string s;   cin>>s;
    sort(s.begin(),s.end());
    if(s=="abc")
        cout<<"Yes";
    else
        cout<<"No";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    fun();
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

map_org = []
for i in range(N):
    map_org.append([0 for _ in range(N)])

for a,b in ab:
    map_org[a-1][b-1] = 1
    map_org[b-1][a-1] = 1

def dfs(v):
    visited[v] = 1
    for i in range(N):
        if map_org[v][i] == 1:
            if visited[i] == 0:
                dfs(i)

bridge_cnt = 0
for i in range(M):
    visited = [0 for _ in range(N)]
    del_a,del_b = ab[i]
    map_org[del_a-1][del_b-1] = 0
    map_org[del_b-1][del_a-1] = 0
    dfs(0)
    if min(visited) == 0:
        bridge_cnt += 1
    map_org[del_a-1][del_b-1] = 1
    map_org[del_b-1][del_a-1] = 1


print(bridge_cnt)


Measured memory_bytes: 3064
// 2020-09-03 00:24:50
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
const int inf = 1e9;
int n, a, b, c, l[8], ans;
void dfs(int i, int j, int x, int y, int z) {
  if (i == n) {
    if (x > 0 && y > 0 && z > 0) {
      chmin(ans, abs(a - x) + abs(b - y) + abs(c - z) + j - 30);
    }
    return;
  }
  dfs(i + 1, j, x, y, z);
  dfs(i + 1, j + 10, x + l[i], y, z);
  dfs(i + 1, j + 10, x, y + l[i], z);
  dfs(i + 1, j + 10, x, y, z + l[i]);
}
void answer() {
  cin >> n >> a >> b >> c;
  rep(i, n) cin >> l[i];
  ans = inf;
  dfs(0, 0, 0, 0, 0);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(long long i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef unsigned long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-2;
const ll inf=1e19;
int main(){
	ll n;
	string s;
	while(cin>>n>>s,n){
		ll m=strtoll(&s[0],NULL,n);
		vi a,b;
		loop(i,2,n+1){
			if(n%i)continue;
			a.pb(i);
			b.pb(0);
			while(n%i==0)b[b.size()-1]++,n/=i;
		}
		ll out=inf;
		rep(i,a.size()){
			ll tmp=m;
			ll t=0;
			while(tmp){
				tmp/=a[i];
				t+=tmp;
			}
			out=min(out,t/b[i]);
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1220
def f(n):
    if n==0:
        x[-1]="0"
        return
    if n==1:
        x[-1]="1"
        return
    if n>0:
        k = 0
        while True:
            if 2**k>=n:
                break
            k += 2
        if n<=(2**k-1)//3:
            k -= 2
        x[K-k]= "1"
        f(n-2**k)
    else:
        k = 1
        while True:
            if (-2)**k<=n:
                break
            k += 2
        if n>=((-2)**k+2)//3:
            k -= 2
        x[K-k] = "1" 
        f(n-(-2)**k)
K = 31
x = ["0" for _ in range(K+1)]      
N = int(input())
f(N)
for i in range(K+1):
    if x[i]=="1":
        ind = i
        break
if N!=0:
    print("".join(x[ind:]))
else:
    print(N)

Measured memory_bytes: 3064
n,m,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
if min(y)<=X:
  print("War")
elif Y<=max(x):
  print("War")
else:
  if max(x)>=min(y):
    print("War")
  else:
    print("No War")

Measured memory_bytes: 38384
import numpy as np
from itertools import combinations_with_replacement

N,M,X = map(int,input().split())
CA = []
for i in range(N):
  CA.append(list(map(int,input().split())))

OK = True
CA = np.array(CA)
sums = np.sum(CA,axis=0)
for i in range(1,M+1):
  if sums[i] < X:
    OK = False
    break

if OK == False:
  print(-1)
else:
  As = []
  for A in combinations_with_replacement(range(0, N),N):
    As.append(tuple(set(A)))
  As = list(map(list, set(As)))
  min_ = sums[0]
  for i in As:
    mini_CA = []
    for j in i:
      mini_CA.append(CA[j-1])
    mini_CA = np.array(mini_CA)
    OK2 = True
    sums = np.sum(mini_CA,axis=0)
    for k in range(1,M+1):
      if sums[k] < X:
        OK2 = False
        break
    if OK2 == True and sums[0] < min_:
      min_ = sums[0]
  print(min_)


Measured memory_bytes: 164612
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-20;
const long double INF = 1e18;

int dx[]={1,0,0,1,1,0,1, 1, 0,-1, 1, 1,-1};
int dy[]={0,1,0,1,0,1,1,-1, 1, 0, 1,-1, 1};
int dz[]={0,0,1,0,1,1,1, 0,-1, 1,-1, 1, 1};
int main(){
	int n,m,p;
	while(cin>>n>>m>>p&&n){
		int pos[7][7][7];CLR(pos);
		pair<string,int>res=MP("NA",0);
		REP(pp,p){
			int x,y;
			cin>>x>>y;
			x--;y--;
			if(res.second!=0)continue;
			int t=0;
			while(pos[x][y][t]!=0)t++;
			pos[x][y][t]=(pp%2)*2-1;
			REP(i,n)REP(j,n)REP(k,n){
				REP(d,13){
					bool flag=true;
					int nx=i,ny=j,nz=k;
					int sum=0;
					REP(cnt,m){
						if(nx>=n||ny>=n||nz>=n||nx<0||ny<0||nz<0)break;
						//if(pp==0)cout<<nx<<ny<<nz<<" "<<pos[nx][ny][nz]<<endl;
						sum+=pos[nx][ny][nz];
						nx+=dx[d];ny+=dy[d];nz+=dz[d];
					}
					if(abs(sum)==m){
						//cout<<sum<<endl;
						res=MP((pp%2)?"White":"Black",pp+1);
						i=j=k=n;
					}
				}
			}
		}
		if(res.second==0)cout<<"Draw"<<endl;
		else cout<<res.first<<" "<<res.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6;
int pre[N];
int col[N];
int n;
vector<int>q[N];
bool flag = false;
int cnt = 0;
int ans = 0;
int vis[N];


void dfs(int u,int fa) {
	if(u == n) {
		int t = u;
		while(pre[t] != 1) {
			t = pre[t];
			cnt ++;
		}
		int tmp = cnt / 2;
		for(int i=1;i<=cnt;i++) {
			if(i <= tmp) {
				col[pre[u]] = 0;
			}else col[pre[u]] = 1;
			u = pre[u];
		}
		flag = true;
		return;
	}
	for(int i=0;i<q[u].size();i++) {
		int v = q[u][i];
		if(v == fa)continue;
		pre[v] = u;
		dfs(v,u);
		if(flag)return;
	}
}

void find(int u) {
	ans ++;
	vis[u] = 1;
	for(int i=0;i<q[u].size();i++) {
		int v = q[u][i];
		if(col[v] == 0 || vis[v])continue;
		col[v] = 1;
		find(v);
	}
}
int main(int argc, char** argv) {
	//freopen("in.txt","r",stdin);
	memset(col,-1,sizeof(col));
	memset(vis,0,sizeof(vis));
	cin>>n;
	col[1] = 1;col[n] = 0;
	int u,v;
	for(int i=0;i<n;i++) {
		scanf("%d%d",&u,&v);
		q[u].push_back(v);
		q[v].push_back(u);
	}
	dfs(1,-1);
	//for(int i=1;i<=7;i++)cout<<col[i]<<endl;
	for(int i=1;i<=n;i++) {
		if(col[i] == 1 && !vis[i])find(i);
	}
	if(ans <= n / 2)puts("Snuke");
	else puts("Fennec");
	return 0;
}

Measured memory_bytes: 40832
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define LL long long
using namespace std;
const int d[2] = {1, -1};
char s[4];
int a[4];
int main() {
	int i, j, k;
	scanf("%s", s);
	for(i = 0; i < 4; i++) a[i] = s[i]-'0';
	for(i = 0; i < 2; i++){
		for(j = 0; j < 2; j++){
			for(k = 0; k < 2; k++){
				int t = a[0]+d[i]*a[1]+d[j]*a[2]+d[k]*a[3];
				if(t == 7){
					printf("%d%c%d%c%d%c%d=7\n", a[0], i==0?'+':'-', a[1], j==0?'+':'-', a[2], k==0?'+':'-', a[3]);
					return 0;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int long long ans=0;
  for(int i=1;i<=N;i++){
    if(i%3==0&&i%5==0)continue;
    else if(i%3==0)continue;
    else if(i%5==0)continue;
    ans+=i;
  }
  cout << ans << endl;
}

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

using i64 = int64_t;

int main(){
    int n, t;
    cin >> n >> t;
    vector<i64> v;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }

    vector<i64> cummax(n+1);
    for(int i=n-1;i>=0;--i){
        cummax[i] = max(cummax[i+1], v[i]);
    }

    int cnt = 0, maxi = 0;
    for(int i=0;i<n;++i){
        int d = cummax[i+1] - v[i];
        if(d > maxi){
            cnt = 1;
            maxi = d;
        }else if(d == maxi){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
ll cnt = 0;
ll int gcd(ll x,ll y){
   return y ? gcd( y , x%y ) : x;
}
ll ngcd(vector<int> a){/*gcd呼ぶのを忘れない*/
int res;  res=a[0];
for(int i=0;i<a.size() && res != 1 ; i++){
   res = gcd( a[i] , res );
}
return res;
}
int main(){
 int n;
 cin >> n ;
 vector<int>a;
 for(int i=0;i<n;i++){
     int b;cin>>b;
     a.push_back(b);
 }
 cout << ngcd(a) << endl;
}

Measured memory_bytes: 1144