akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int N,M;
    cin>>N>>M;
    vector<vector<int>> lig(M,vector<int>(N));
    rep(i,M){
        int k;
        cin>>k;
        rep(j,k){
            int s;
            cin>>s;
            --s;
            lig.at(i).at(s)=1;
        }
    }
    vector<int> p(M);
    rep(i,M)cin>>p.at(i);
    ll count=0;
    rep(tmp,1<<N){
        bitset<10> x(tmp);
        vector<int> onoff(N);
        rep(i,N){
            onoff.at(i)=x.test(i);
        }
        bool judge=true;
        rep(i,M){
            int sta=0;
            rep(j,N){
                sta+=onoff.at(j)*lig.at(i).at(j);
            }
            if(sta%2!=p.at(i))judge=false;
//cout<<sta<<" ";
        }
        if(judge==true){
            count++;
//rep(l,N){cout<<onoff.at(l);}cout<<endl;
        }
    }
    cout<<count<<endl;
}

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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define in(type,a) type a;cin >> a
using ll = long long;

int main() {
    in(int, a);
    in(int, p);
    cout << (a*3+p)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		char c = sc.next().charAt(0);
		StringBuilder sb = new StringBuilder();
		sb.append("+");
		for(int i = 0; i < w-2; i++) {
			sb.append("-");
		}
		sb.append("+\n");
		for(int y = 1; y < h-1; y++) {
			sb.append("|");
			for(int x = 1; x < w-1; x++) {
				if(y==h/2 && x==w/2) {
					sb.append(c);
				} else {
					sb.append(".");
				}
			}
			sb.append("|\n");
		}
		sb.append("+");
		for(int i = 0; i < w-2; i++) {
			sb.append("-");
		}
		sb.append("+");

		System.out.println(sb);
	}
}


Measured memory_bytes: 26452
import java.util.Scanner;

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

		int value = sc.nextInt();

		System.out.println(withdraw(value));

	}

	static int withdraw(int value) {
		if (value == 0) {
			return 0;
		}
		if (value == 1) {
			return 1;
		}

		int num9 = (int) Math.pow(9, 5);
		int num6 = (int) Math.pow(6, 6);

		int num = 0;

		while (num9 > value) {
			num9 /= 9;
		}

		while (num6 > value) {
			num6 /= 6;
		}

		int tmp9 = withdraw(value - num9);
		int tmp6 = withdraw(value - num6);

		if (tmp9 > tmp6) {
			num = tmp6;
		} else {
			num = tmp9;
		}

		return num + 1;
	}

}


Measured memory_bytes: 23252
import bisect as bi

def ispr(n):
    if n==1:
        return False
    elif n==2:
        return True
    elif n%2==0:
        return False
    else:
        k=3
        while k**2<=n:
            if n%k==0:
                return False
            else:
                k+=2
        return True

def is2007like(n):
    return ispr(n) and ispr((n+1)//2)

p=[n for n in range(3,10**5+1,2) if is2007like(n)]

for i in range(int(input())):
    l,r=map(int,input().split())
    jl=bi.bisect(p,l-1)
    jr=bi.bisect(p,r+1)-1
    print(jr-jl+1)

Measured memory_bytes: 56412
#入力
N,M = map(int,input().split())
X = [int(i) for i in input().split()]
#ソートする
X.sort()
if N>=M:
    print("0")
else:
    L = list()
    for i in range(M-1):
        L.append(X[i+1]-X[i])
    a=0 
    L.sort()
    for i in range(N-1):
        L.pop(-1)
    for i in L:
        a+=i
    print(a)

Measured memory_bytes: 13840
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

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

  bool ans = false;
  ll i=0;
  ll j=0;
  erep(i,0,25){
    erep(j,0,15){
      if(4*i+7*j == N) ans = true;
    }
    if(4*i+7*j > N) break;
  }

  if(ans) Yes;
  else No;

  return 0;
}


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

int main() {
  
  int N, x;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    x = x + r - l + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
n=int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

l=factorization(n)
cnt=0

if n==1:
    print(0)
else:
    for num,i in l:
        p=1
        while i>0:
            cnt+=1
            i-=p
            p+=1
            if i<p:
                break
    print(cnt)


Measured memory_bytes: 9484
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Tramp tramp = new Tramp();
    try (Scanner scanner = new Scanner(System.in)) {
      int n = scanner.nextInt();
      for (int i = 0; i < n; i++) {
        tramp.appendFoundedCard(scanner.next(), scanner.nextInt());
      }
    }
    System.out.print(tramp);
  }
}

class Tramp {
  final Map<String, List<Boolean>> cards;

  Tramp() {
    cards = new HashMap<>();
    cards.put("S", new ArrayList<>());
    cards.put("H", new ArrayList<>());
    cards.put("C", new ArrayList<>());
    cards.put("D", new ArrayList<>());

    for (int i = 0; i < 13; i++) {
      cards.get("S").add(false);
      cards.get("H").add(false);
      cards.get("C").add(false);
      cards.get("D").add(false);
    }
  }

  void appendFoundedCard(String type, int number) {
    cards.get(type).set(number - 1, true);
  }

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    String[] strings = {"S", "H", "C", "D"};
    Arrays.stream(strings).forEach(it -> {
      for (int i = 0; i < cards.get(it).size(); i++) {
        boolean hasCard = cards.get(it).get(i);
        if (hasCard) {
          continue;
        }
        builder.append(String.format("%s %d\n", it, i + 1));
      }
    });
    return builder.toString();
  }
}

Measured memory_bytes: 32088
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();int m=sc.nextInt();
      int[]a=new int[m];
      for(int i=0;i<n;i++){
      	int b=sc.nextInt();
        for(int j=0;j<b;j++){
        	a[sc.nextInt()-1]++;
        }
      }
      int count=0;
      for(int i=0;i<m;i++)if(a[i]==n)count++;
      System.out.println(count);
	}
}


Measured memory_bytes: 22228
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;

double cum[200020];
int p[200020];
void solve() {
	int N, K; cin >> N >> K;
	REP(i, N) {
		cin >> p[i];
		int sum = p[i] * (p[i] + 1) / 2;
		cum[i + 1] += (double)sum / p[i];
		cum[i + 1] += cum[i];
	}
	double sum = 0;
	double mx = 0;
	REP(i, N - K + 1) {
		sum = cum[i + K] - cum[i];
		if (sum > mx)mx = sum;
	}
	sum /= (N - K + 1);
	cout << setprecision(10) << mx << endl;
}

signed main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int inf=2147483647;
LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return x*f;
}
LL n,x;
LL calc(LL a,LL b)
{
	if(b%a==0)return (b/a*2LL-1LL)*a;
	return b/a*2LL*a+calc(b%a,a);
}
int main()
{
	n=read(),x=read();
	LL ans=n+calc(x,n-x);
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include<vector>
#include<algorithm>
#include<cstdio>
#define Z{vector<int>b;for(j=0;j<i;j++)b.push_back(x++);if(c)reverse(b.begin(),b.end());c^=1;a.push_back(b);}
using namespace std;main(){for(int t=1,x,c,n,i,j;scanf("%d",&n),n;){
vector<vector<int> >a;
for(printf("Case %d:\n",t++),x=c=i=1;i<=n;i++)Z
for(i-=2;i;i--)Z
for(i=0;i<n;puts(""),i++)for(j=0;j<n;j++)printf("%3d",a[i+j][0]),a[i+j].erase(a[i+j].begin());
}}

Measured memory_bytes: 1076
n, w = map(int, input().split())

dp = [[0 for _ in range(w+1)] for __ in range(n)]

for i in range(n):
    wi, vi = map(int, input().split())
    if i == 0:
        for x in range(wi, w+1):
            dp[i][x] = vi
    else:
        for j in range(w+1):
            if j < wi:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-wi] + vi)

print(dp[n-1][w])


Measured memory_bytes: 171272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
int a[100100];
int main(){
	int n;
	scanf("%d",&n);int ans=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if((i&1) && (a[i]&1)) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main() {

	//ifstream cin("INPUT.txt");
	//ofstream cout("OUTPUT.txt");

	int i, h, m, s, t;
	for(i = 0; i < 3; i++) {
		cin >> h >> m >> s;
		t = (h * 3600) + (m * 60) + s;
		cin >> h >> m >> s;
		t = ( (h * 3600) + (m * 60) + s ) - t;
		cout << t / 3600 << " " << (t % 3600) / 60 << " " << t % 60 << endl;
	}

	return 0;

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int k, s, ans = 0;
    cin >> k >> s;
    fore(i,0,k+1) {
        fore(j,0,k+1) {
            if (s-i-j >= 0 && s-i-j <= k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char m[100][100];
int main(){
	int h,w;
	scanf("%d%d%*c",&h,&w);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%c",&m[i][j]);
		}
		getchar();
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(m[i][j]=='.')continue;
			else if(m[i][j]=='%'){
				if(j<w-1&&m[i][j+1]=='#'){
					m[i][j]=m[i][j+1]='%';
				}
				if(i<h-1&&m[i+1][j]=='#'){
					m[i][j]=m[i+1][j]='%';
				}
			}
			else if(m[i][j]=='#'){
				if(j<w-1&&(m[i][j+1]=='#'||m[i][j+1]=='%')){
					m[i][j]=m[i][j+1]='%';
				}
				if(i<h-1&&m[i+1][j]=='#'){
					m[i][j]=m[i+1][j]='%';
				}
				if(m[i][j]=='#'){
					printf("No");
					return 0;
				}
			}
		}
		/*
		printf("\n");
		for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",m[i][j]);
		}
		printf("\n");
		}
		printf("\n");*/
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
const int N=1e5+10;
long long int a[N*4];
int f[N*4];
bool b[N*4];
void add(int n,int x,int l,int r,int L,int R){
    if(L<=l&&r<=R){
        f[n]=x;
        b[n]=true;
        a[n]=(long long int)x*(r-l+1);
    }
    else if(!(L>r||l>R)){
        int mid=(l+r)>>1;
        if(b[n]){
            f[n*2+1]=f[n*2+2]=f[n];
            a[n*2+1]=(long long int)f[n]*(mid-l+1);
            a[n*2+2]=(long long int)f[n]*(r-mid);
            b[n*2+1]=b[n*2+2]=true;
            b[n]=false;
        }
        add(n*2+1,x,l,mid,L,R);
        add(n*2+2,x,mid+1,r,L,R);
        a[n]=a[n*2+1]+a[n*2+2];
    }
    return ;
}
long long int sum(int n,int l,int r,int L,int R){
    if(L<=l&&r<=R)return a[n];
    else if(L>r||l>R)return 0;
    int mid=(l+r)>>1;
    if(b[n]){
        f[n*2+1]=f[n*2+2]=f[n];
        a[n*2+1]=(long long int)f[n]*(mid-l+1);
        a[n*2+2]=(long long int)f[n]*(r-mid);
        b[n*2+1]=b[n*2+2]=true;
        b[n]=false;
    }
    return sum(n*2+1,l,mid,L,R)+sum(n*2+2,mid+1,r,L,R);
}
int main(){
    int n,q,k,l,r;
    memset(a,0,sizeof(a));
    memset(f,0,sizeof(f));
    memset(b,false,sizeof(b));
    scanf("%d%d",&n,&q);
    n--;
    while(q--){
        scanf("%d",&k);
        if(k==0){
            scanf("%d%d%d",&l,&r,&k);
            add(0,k,0,n,l,r);
        }
        else {
            scanf("%d%d",&l,&r);
            printf("%lld\n",sum(0,0,n,l,r));
        }
    }
}


Measured memory_bytes: 7832
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <complex>
using namespace std;
#define EPS 1.0e-10
typedef complex<double> P;

struct L { P pos, dir; };

inline int signum(double x) {
	return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1);
}

inline double outp(const P& a, const P& b) {
	return (conj(a) * b).imag();
}

inline int ccw(const P& p, const P& r, const P& s) {
	P a(r - p), b(s - p);
	int sgn = signum(outp(a, b));
	if (sgn != 0)
		return sgn;
	if (a.real() * b.real() < -EPS || a.imag() * b.imag() < -EPS)
		return -1;
	if (norm(a) < norm(b) - EPS)
		return 1;
	return 0;
}


bool ss_intersects(const L& s, const L& t) {
	return (ccw(s.pos, s.pos + s.dir, t.pos) *
		ccw(s.pos, s.pos + s.dir, t.pos + t.dir) <= 0 &&
		ccw(t.pos, t.pos + t.dir, s.pos) *
		ccw(t.pos, t.pos + t.dir, s.pos + s.dir) <= 0);
}

P line_cross(const L& l, const L& m) {
	double num = outp(m.dir, m.pos - l.pos);
	double denom = outp(m.dir, l.dir);
	return P(l.pos + l.dir * num / denom);
}

struct S {
	P p;
	bool up;
};

bool comp(S s1, S s2) {
	return s1.p.real() < s2.p.real();
}

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

	int T;
	cin >> T;
	for (int loop = 0; loop < T; loop++) {
		int xa, ya, xb, yb, n;
		cin >> xa >> ya >> xb >> yb >> n;
		vector<S> vs;
		L line = L{P(xa, ya), P(xb, yb) - P(xa, ya)};
		//vs.push_back(S{line.pos, false});
		//vs.push_back(S{line.pos + line.dir, false});

		for (int i = 0; i < n; i++) {
			int xs, ys, xt, yt, o, l;
			cin >> xs >> ys >> xt >> yt >> o >> l;
			if (l == 1) o = 1 - o;

			L t = L{P(xs, ys), P(xt, yt) - P(xs, ys)};
			if (ss_intersects(line, t)) {
				P p = line_cross(line, t);
				vs.push_back(S{p, o});
			}
		}

		sort(vs.begin(), vs.end(), comp);
		int ans = 0;
		for (int i = 0; i < (int)vs.size() - 1; i++) {
			ans += vs[i].up != vs[i + 1].up;
		}
		//ans += vs[0].up != vs[vs.size() - 1].up;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
	string s;
	cin >> s;
	vector<int> a(s.size()+1, 0);
	// int count = 0;
	// if(s[0] == '>'){
	// 	count = 1;
	// 	rep(i, s.size()){
	// 		if(s[i] == '<')break;
	// 		count++;
	// 	}
	// }
	// a.at(0) = count;
	rep(i, s.size()){
		char now = s[i];
		if(now == '<') a.at(i+1) = a.at(i)+1;
		else a.at(i+1) = 0;
	}
	// rep(i, a.size()){
	// 	cerr << a.at(i);
	// }
	// cerr << endl;
	ll ans = a.back();
	rrep(i, s.size()){
		char now = s[i];
		if(now == '>'){
			a.at(i) = max(a.at(i), a.at(i+1) + 1);
		}
		ans += a.at(i);
	}
	// rep(i, a.size()){
	// 	cerr << a.at(i);
	// }
	// cerr << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2820
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
int i,N;
long long Z,W;
cin >> N >> Z >> W;
vector<long long> a(N);
for(i=0;i<N;i++){
cin >> a[i];
}
	if(N==1){
		cout << abs(a[N-1]-W) << endl;
	}else {
		cout << max(abs(a[N-1]-a[N-2]),abs(W-a[N-1])) << endl;
}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,k,l;
bool check(int i,int x)
{
	if (i%2==0)
	{
		if (x%2==0) return 1;
		return 0;
	}
	if (i%2==1)
	{
		return 0;
	}
}
void dfs(int i,int j,int k,int x,int y)
{
	if (i+x>10000||j+y>5000) return;
	if (j%2==0&&check(i,x))
	{
		int cnt=0;
		for (l=1;l<i;l++)
		{
			cnt+=2;
			while (cnt%6==0) cnt+=2;
			cout<<cnt<<' ';
		}
		while (x>=0)
		{
			x--;
			cnt+=2;
			while (cnt%6==0) cnt+=2;
		}
		cout<<cnt<<' ';
		cnt=0;
		for (l=1;l<j;l++)
		{
			cnt+=3;
			while (cnt%6==0) cnt+=3;
			cout<<cnt<<' ';
		}
		while (y>=0)
		{
			y--;
			cnt+=3;
			while (cnt%6==0) cnt+=3;
		}
		cout<<cnt<<' ';
		cnt=0;
		for (l=1;l<=k;l++)
		{
			cnt+=6;
			cout<<cnt<<' ';
		}
		exit(0);
	}
	if ((j+y)%2!=0) return;
	dfs(i,j,k,x+1,y);
}
int main()
{
	cin>>n;
	if (n==3)
	{
		cout<<"2 5 63";
		return 0;
	}
	/*if (n==20000)
	{
		int cnt=0;
		for (i=1;i<=30000;i++)
		{
			if ((i%2==0)||(i%3==0))
			{
				cout<<i<<' ';
				cnt++;
			}
		}
		if (cnt==20000) return 0; else return -1;
	}*/
	for (i=1;i<=n;i++)
	{
		if (i>10000) continue;
		for (j=1;i+j<=n;j++)
		{
			if (j>5000) continue;
			k=n-i-j;
			if (k>5000) continue;
			dfs(i,j,k,0,0);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int x = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            if (a - b >= 0) {
                out.println("delicious");
            } else if (x + a - b >= 0) {
                out.println("safe");
            } else {
                out.println("dangerous");
            }
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21460
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			BigInteger x = new BigInteger(scanner.next());
			int count = 0;
			BigInteger denominator = BigInteger.valueOf(100L);
			BigInteger balance = denominator;
			BigInteger molecule = BigInteger.valueOf(101L);
			while (balance.compareTo(x) < 0) {
				balance = balance.multiply(molecule).divide(denominator);
				count++;
			}
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 36632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hh   puts("");
#define db double
#define ull unsigned long long
#define maxn 1000010
int main(){
    ll a,b;
    cin>>a>>b;
    ll m[a];
    for (ll i = 0; i <a ; ++i) {
        cin>>m[i];
    }
    sort(m,m+a);
    ll ans=0;
    for (ll j = 0; j <a-b ; ++j) {
        ans+=m[j];
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#define SIZE 50000
char primes[SIZE];

int main(){
  int i,j,sq,ne,n;
  sq=sqrt(SIZE)+1;
  for(i=2;i<=25000;i++) primes[i*2-1]=1;
  for(i=3;i<=sq;i+=2){
    ne=SIZE/i+1;
    for(j=2;j<=ne;j++){
      primes[j*i-1]=1;
    }
  }

  do{
    scanf("%d",&n);
    if(n==0) break;
    ne=n/2;
    for(i=1,j=0;i<ne;i++){
      if(primes[i]==0&&primes[n-i-2]==0)
	j++;
    }
    printf("%d\n",j);
  }while(1);
  return 0;
}

Measured memory_bytes: 452
#include <bits/stdc++.h>
#define MAXN 10005
using namespace std;
int cnt;
int N;

void DFS(int start, int ch){
    if(start > N) return;
    if(ch == 7) cnt++;
    if(start < 99999999){
        DFS(start*10 + 3, ch|1);
        DFS(start*10 + 5, ch|2);
        DFS(start*10 + 7, ch|4);
    }
}
int main()
{
    cin >> N;
    DFS(0, 0);
    cout << cnt;
    return 0;
}


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

int main() {
	while(1){
	int a;int b;
	cin >> a >> b;
	if(a== 0&b==0){break;}
	if(a>b){swap(a,b);}
	cout << a <<" "<<b<<endl;
	}	
	return 0;

}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	ll n; cin >> n;
	ll a, b; cin >> a >> b;
	ll h[100005];
	for (ll i = 0; i < n; ++i) {
		cin >> h[i];
	}
	ll lo = -1, hi = 1e9 + 1;
	while (hi - lo > 1) {
		ll mid = lo + (hi - lo) / 2;
		vector<ll> v;
		for (ll i = 0; i < n; ++i) {
			if (h[i] - mid*b <= 0) continue;
			v.push_back(h[i] - mid*b);
		}
		ll cnt = 0;
		for (ll i = 0; i < (ll)v.size(); ++i) {
			cnt += (v[i] / (a - b) + (v[i] % (a - b) == 0 ? 0 : 1));
		}
		if (cnt > mid) lo = mid;
		else hi = mid;
	}
	cout << hi << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int groups = 1;
    char currentStone = s[0];
    for(int i=1; i<s.length(); i++){
        char nextStone = s[i];
        if(currentStone != nextStone){
            currentStone = nextStone;
            groups++;
        }
    }
    cout << (groups-1) << '\n';
}

Measured memory_bytes: 3320
/*input

*/


// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pii         pair<ll ,ll >
#define vpii        vector< pii >
#define vi          vector<ll >
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repr(i,a,b) for(ll  i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define debug(x)     cout << #x << " " << x << endl;
#define debug_p(x)   cout << #x << " " << x.F << " " << x.S << endl;
#define debug_v(x)   {cout << #x << " "; for (auto ioi : x) cout << ioi << " "; cout << endl;}
#define debug_vp(x)  {cout << #x << " "; for (auto ioi : x) cout << '[' << ioi.F << " " << ioi.S << ']'; cout << endl;}
#define debug_v_v(x) {cout << #x << "/*\n"; for (auto ioi : x) { for (auto ioi2 : ioi) cout << ioi2 << " "; cout << '\n';} cout << "*/" << #x << endl;}

int solve()
{
	ll n,m;cin>>n>>m;
	vi a(m);
	ll sum=0;
	rep(i,0,m) 
	{
		cin>>a[i];
		sum+=a[i];
	}
	cout<<(n>=sum?n-sum:-1)<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	//cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

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

int gcd(int A, int B){
  long a=max(A,B),b=min(A,B),c=b;
  while(b!=0){
    b=a%b;
    a=c;
    c=b;
  }
  return a;
}

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(C%gcd(A,B)==0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        String a=scn.next();
        String b=scn.next();
        scn.close();
        String answer="=";
        int ai=0;
        int bi=0;
        switch(a){
            case "A":
                ai=10;
                break;
            case "B":
                ai=11;
                break;
            case "C":
                ai=12;
                break;
            case "D":
                ai=13;
                break;
            case "E":
                ai=14;
                break;
            case "F":
                ai=15;
                break;
            default:
                ai=Integer.parseInt(a);
        }
        switch(b){
            case "A":
                bi=10;
                break;
            case "B":
                bi=11;
                break;
            case "C":
                bi=12;
                break;
            case "D":
                bi=13;
                break;
            case "E":
                bi=14;
                break;
            case "F":
                bi=15;
                break;
            default:
                bi=Integer.parseInt(b);
        }
        if(ai>bi){
            answer = ">";
        }
        else if(ai<bi){
            answer = "<";
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
n = int(input())
A = tuple(map(int, input().split()))
from itertools import accumulate
AA = [0] + list(accumulate(A))
mod = 10**9+7

ans = 0
for i in range(n):
    ans += A[i] * (AA[-1]-AA[i+1]) % mod
    ans %= mod
print(ans)

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

int n; //number of stones
int k; //farthest the frog can jump
vector<int> h; //height of the stones
vector<int> dp; //memorize heck

int jump(int stone){
	if(dp[stone]==-1){
		if(stone == n-1){
			return 0;
		}
		else{
			dp[stone] = INT_MAX;
			for(int i=1; i<=k && stone+i<n; i++){
				dp[stone] = min(dp[stone], jump(stone+i) + abs(h[stone]-h[stone+i]));
			}
			return dp[stone];
		}
	}
	else{
		return dp[stone];
	}
}

main(){
	cin >> n >> k;
	
	dp.assign(n, -1);
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		h.push_back(x);
	}

	cout << jump(0) << "\n";
}

Measured memory_bytes: 6644
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define drep(i,n) for (int i = n-1; i >= 0; --i)
#define pb push_back
#define sz(x) int(x.size())
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
using namespace std;
inline int in() { int x; scanf("%d", &x); return x;}
typedef vector<int> vi;
typedef vector<vi> vvi;

struct Lowlink {
  int n, k;
  vvi to, st, br;
  vi ord, low;
  Lowlink(int n=0):n(n),to(n),st(n),br(n),ord(n,-1),low(n){}
  void add(int a, int b) {
    to[a].pb(b); st[a].pb(0);
    to[b].pb(a); st[b].pb(0);
  }
  void dfs(int v, int p=-1) {
    ord[v] = low[v] = k++;
    rep(i,sz(to[v])) {
      int u = to[v][i];
      if (u == p) continue;
      if (ord[u] == -1) {
        st[v][i] = 1;
        dfs(u,v);
        mins(low[v],low[u]);
      } else {
        st[v][i] = -1;
        mins(low[v],ord[u]);
      }
    }
  }
  int init() {
    k = 0;
    dfs(0);
    int res = 0;
    rep(i,n)rep(j,sz(to[i])) {
      int v = i, u = to[i][j];
      if (ord[v] > ord[u]) swap(v,u);
      if (ord[u] == low[u]) res++;
      br[i].pb(ord[u] == low[u]);
    }
    return res/2;
  }
};

int n, m;
vvi to;
vi used, vs;

int rv;
bool cfs(vvi& to, int v) {
  if (used[v]) {
    if (used[v] == 2) return false;
    rv = v;
    return true;
  }
  used[v] = 1;
  for (int u : to[v]) {
    if (cfs(to,u)) {
      if (rv != -1) vs.pb(v);
      if (rv == v) rv = -1;
      return true;
    }
  }
  used[v] = 2;
  return false;
}
bool findCycle(vvi& to) {
  used = vi(n);
  rv = -1;
  rep(i,n) if (!used[i]) {
    if (cfs(to,i)) return true;
  }
  return false;
}
bool solve1(int u, int v) {
  // printf("%d %d\n", v, u);
  vvi t(n);
  rep(i,n) for (int j : to[i]) {
    if (i == v && j == u) continue;
    t[i].pb(j);
    // printf("edge %d %d\n", i, j);
  }
  if (findCycle(t)) return false;
  // printf("%d %d\n", v, u);
  Lowlink g(n);
  rep(i,n) for (int j : to[i]) {
    if (i == v && j == u) continue;
    g.add(i,j);
  }
  return g.init() >= 2;
}
bool solve2(Lowlink& g, int ei, int ej) {
  Lowlink t(n);
  rep(i,n)rep(j,sz(g.to[i])) {
    if (ei == i && ej == j) continue;
    int u = g.to[i][j];
    if (!g.st[i][j]) continue;
    if (g.st[i][j] == -1 && i < u) continue;
    t.add(i,u);
  }
  return t.init() >= 2;
}

int main() {
  n = in(); m = in();
  to = vvi(n);
  rep(i,m) {
    int a = in(), b = in();
    --a; --b;
    to[a].pb(b);
  }
  if (findCycle(to)) {
    int s = sz(vs);
    rep(i,s) {
      if (solve1(vs[i],vs[(i+1)%s])) {
        puts("YES");
        return 0;
      }
    }
  } else if (m >= n) {
    Lowlink g(n);
    rep(i,n) for (int u : to[i]) g.add(i,u);
    if (g.init() >= 2) {
      puts("YES");
      return 0;
    }
    rep(i,n) rep(j,sz(g.to[i])) {
      if (g.st[i][j] != 1 || g.br[i][j]) continue;
      if (solve2(g,i,j)) {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
  return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vl = vector<ll>; using vvl = vector<vl>;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
const ll INF = 9223372036854775807;

int main() {
    string s;cin >> s;
    ll a,b;a,b=0;
    rep(i,s.size()) {
        if(s[i]=='1') a++;
        else b++;
    }
    cout << 2*min(a,b) << endl;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            ans += d[i] * d[j];
        }
    }
    cout << ans << "\n";
    return 0;
}

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

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

int find(string str, const string& word) {
  int count = 0;
  for (string::size_type pos = 0; (pos = str.find(word, pos)) != string::npos; pos += word.size()) {
    ++count;
  }
  return count;
}

int main(){
    int n , m;
    int  min_val, max_val;
    int min_ans = 1, max_ans = n;
    cin >> n >> m;
    vector<int> l(m), r(m);
    for (int i =0 ; i < m; ++i){
        cin >> l[i] >> r[i];
    }
    for(int i = 0; i < m; ++i){
        min_val = l[i];
        max_val = r[i];
        if(min_val > min_ans) min_ans = min_val;
        if(max_val < max_ans) max_ans = max_val;
    }
    if(max_ans >= min_ans)  cout<<max_ans - min_ans + 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
// Problem : E - Almost Everywhere Zero
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 102

//Solution

string s;
int dp[102][2][5],k;

void solve(){
    cin>>s>>k;
    dp[0][0][0] = 1;
    for(int i=0;i<sz(s);i++){
        for(int j=0;j<2;j++){
            for(int l=0;l<=k;l++){
                int limit = (j ? 9 : (s[i]-'0'));
                for(int dig=0;dig<=limit;dig++){
                    dp[i+1][j||dig<limit][l+(dig!=0)] += dp[i][j][l];
                }
            }
        }
    }
    cout<<dp[sz(s)][0][k]+dp[sz(s)][1][k]<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#75c
import copy  
  
N,M = map(int, input().split())#M<=50

lines = set()
for _ in range(M):
    a,b = map(int, input().split())
    lines.add((a,b))

#union findを使う###############################################   
def connection_check(lines,start,goal):
    
    #接続追加
    def add_connect(A,B):
        A_parent = get_parent(A)
        B_parent = get_parent(B)

        if A_parent != B_parent:
            parent_dict[B_parent] = A_parent
    #接続有無判断
    def judge_connection(A,B):
        A_parent = get_parent(A) #未更新状態でも、ここで更新される
        B_parent = get_parent(B)

        if A_parent != B_parent:
            return False
        else:
            return True
    #親の取得
    def get_parent(child):
        if child not in parent_dict: #初出なら自分自身を親として追加
            parent_dict[child] = child
        parent = parent_dict[child]
        if parent == child:
            return parent
        else: 
            #最上位の親なら上の等式が成り立つ。不成立ならさらに上位の親を辿る。
            parent_dict[child] = get_parent(parent)
            return parent_dict[child]
    

    parent_dict = dict()
    
    for line in lines:
        A = line[0]
        B = line[1]
        add_connect(A,B)
    
    if judge_connection(start,goal) == True:
        return True
    else:
        return False
        
#################################################################
ans = 0

for line in lines:
    start = line[0]
    goal = line[1]
    remain_lines = copy.copy(lines) 
    remain_lines.remove(line)
    
    #print(start,goal)
    #print(remain_lines)
    
    if connection_check(remain_lines,start,goal) is False:
        ans += 1

print(ans)

Measured memory_bytes: 3696
import collections

n = int(input())
n_array = []
for i in range(n):
    n_array.append(input())

n_dict = collections.Counter(n_array)

m = int(input())
m_array = []
for i in range(m):
    m_array.append(input())
m_dict = collections.Counter(m_array)

res = 0
for i, j in n_dict.items():
    if j - m_array.count(i) > res:
        res = j - m_array.count(i)

print(res)


Measured memory_bytes: 3572
n = int(input())
a_list = [int(x) for x in input().split()]
b_list = [int(x) for x in input().split()]
c_list = [int(x) for x in input().split()]

ans = 0
a_old = a_list[0] - 1
for i in range(n):
    a = a_list[i] - 1
    ans += b_list[a]
    if a - a_old == 1:
        ans += c_list[a_old]
    a_old = a
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s,t;
    cin >> n >> s >> t;
    int p = 0;
    for(int i = 1; i <= n; i++) if(s.substr(n-i) == t.substr(0,i)) p = i;
    cout << 2 * n - p << endl;
}

Measured memory_bytes: 256
'''ika tako  色は1～からの番号で表すとする。
適当な頂点①から、順に辺で繋がった頂点を探索し、辺の色を、
まだ使われてない最小の色で確定していけば、条件を満たすように作れる。
①--- 1 ---②--- 2 ---⑤
 |           `-- 3 ---⑥
 |--- 2 ---③--- 1 ---⑦
 |           `-- 3 ---⑧
 `--- 3 ---④--- 1 ---⑨
             `-- 2 ---⑩
木の場合は、根から順に確定する限り、相手先の頂点の他の辺が必ず
未確定である（後でその頂点の処理時に何とでも調整できる）ので、
この方法が使える。
'''
import sys
 
n = int(input())#頂点数
links = [set() for _ in range(n)]#この入力はABC166Cでも使う
for i, line in enumerate(sys.stdin):
    a, b = map(int, line.split())
    a -= 1#0-indexへ、abc165Cも同様
    b -= 1
    links[a].add((i, b))
    #リストlinksの中身のa番目のセットにindexと共に連結先を追加add
    links[b].add((i, a))

ans = [-1] * (n - 1)#初期値は存在しえない数値、頂点-1個で足りる
k = max(map(len, links))#リストlinksの長さの最大(セットの要素数の最大)
q = [(0, -1)]
fixed = set()
 
while q:
    v, c = q.pop()#頂点vと色cをキューから取り出す
    color = 1
    if c == color:#取り出した色が使っている色なら、新しい色を使う
        color += 1
    for i, u in links[v]:#リストlinksからindexと連結先を取り出す
        if ans[i] != -1:#色が決まっていたら何もしない
            continue
        ans[i] = color#色を決めて、ansに入れる
        q.append((u, color))#キューに連結先と使った色を入れる
        color += 1#色を新しい色にしておく
        if c == color:
        #これがないとサンプルはOKだが、他はダメ。
        #複数の連結先がある場合がダメか？
        #使った色と同じだった場合、新しい色にするということか？
            color += 1
print(k)
print('\n'.join(map(str, ans)))

Measured memory_bytes: 57148
//
//AtCoder Beginner Contest 081
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> cnt(200001,0);
    REP(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    int orgCnt=0;
    REP(i, cnt.size()){
        if (cnt[i]>0) orgCnt++;
        if (cnt[i]==0) cnt[i]=200001;
    }
    sort(ALL(cnt));
    int ans = 0;
    if (orgCnt>k){
        REP(i,orgCnt-k){
            ans += cnt[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	int N,Rcou,cou,Bcou;
	Bcou = 0;
	cou = 0;
	Rcou = 0;
	string S;
	cin >> S;
	N = S.length();
	for (int i = 0; i < N; i++) {
		if (S[i] == '0'&&Bcou > 0) {
			cou++;
			Bcou--;
		}
		else if (S[i] == '0')Rcou++;
		
		if (S[i] == '1'&&Rcou > 0) {
			cou++;
			Rcou--;
		}
		else if (S[i] == '1')Bcou++;
	}
	cout << cou*2 << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int t[128],s[128],n=0,r1=0,r3,r;
	double r2;
	while(scanf("%d,%d",&t[n],&s[n])!=EOF){
		n++;
	}
	for(int i=0;i<n;i++){
		r1+=(t[i]*s[i]);
		r3+=s[i];
	}
	r2=(double)r3/(double)n;
	r=(int)r2+0.5/10*10+1;
	printf("%d\n%d\n",r1,r);
}

Measured memory_bytes: 2684
#include <stdio.h>

int main()
{
  int a, b, c;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);

  if (a > b && a > c) {
    if (b > c) {
      printf("%d %d %d\n", c, b, a);
    } else {
      printf("%d %d %d\n", b, c, a);
     }
  } else if (b > a && b > c) {
    if (a > c) {
      printf("%d %d %d\n", c, a, b);
    } else {
      printf("%d %d %d\n", a, c, b);
    }
  } else {
    if (a > b) {
      printf("%d %d %d\n", b, a, c);
    } else {
      printf("%d %d %d\n", a, b, c);
    }
  }

  return 0;
}

Measured memory_bytes: 596
def main():

    N, M = map(int, input().split())
    parent = [i for i in range(N)]
    level = [1 for _ in range(N)]

    def find(i):
        if parent[i] != i:
            parent[i] = find(parent[i])
        return parent[i]

    def union(i, j):
        pi, pj = find(i), find(j)
        if pi != pj:
            if level[pi] < level[pj]:
                parent[pi] = pj
                level[pj] = max(1+level[pi], level[pj])
            else:
                parent[pj] = pi
                level[pi] = max(1+level[pj], level[pi])

    for _ in range(M):
        i, j, z = map(int, input().split())
        union(i-1, j-1)

    # print(parent)
    for i in range(N): find(i)
    # print(parent)

    ans = len(set(parent))
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 13984
import java.util.*;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] a = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int result = 1;
		long sum = a[0];
		for (int i = 1; i < n; i++) {
			if((2 * sum) >= a[i]) {
				result++;
			}
			else {
				result = 1;
			}
			sum += a[i];
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 50576
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n,m,a[N][N],b[N][N],c[N][N],hav[N][N];
// const int S = 0 , T = 10001 , M = 10005;
// struct node{int to,next,val;}e[M<<5];
// int head[N],cnt,dep[N],q[N];
// void add(int x,int y,int z){e[cnt]=(node){y,head[x],z};head[x]=cnt++;}
// void insert(int x,int y,int z){add(x,y,z),add(y,x,0);}
// int bfs()
// {
// 	memset(dep,-1,sizeof(dep));dep[S]=0;int l=0,r=0;q[r++]=S;
// 	while(l<r)
// 	{
// 		int x=q[l++];
// 		for(int i=head[x];i!=-1;i=e[i].next)
// 		{
// 			int to1=e[i].to;
// 			if(dep[to1]==-1&&e[i].val)dep[to1]=dep[x]+1,q[r++]=to1;
// 		}
// 	}return dep[T]==-1?0:1;
// }
// int dfs(int x,int maxf)
// {
// 	if(x==T)return maxf;int tflow=maxf,nowf;
// 	for(int i=head[x];i!=-1;i=e[i].next)
// 	{
// 		int to1=e[i].to;
// 		if(dep[to1]==dep[x]+1&&e[i].val)
// 		{
// 			nowf=dfs(to1,min(tflow,e[i].val));
// 			e[i].val-=nowf,e[i^1].val+=nowf,tflow-=nowf;
// 			if(!tflow)break;
// 		}
// 	}return maxf-tflow;
// }
int cnt[N][N],e[N][N],vis[N],mat[N];vector<int >v[N][N];
bool find(int x)
{
	for(int i=1;i<=n;i++)
		if (e[x][i]&&!vis[i]){
			vis[i]=1;
			if (!mat[i]||find(mat[i])){
				mat[i]=x;
				return 1;
			}
		}
	return 0;
} 
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x;i<=n;i++)for(int j=1;j<=m;j++)
		scanf("%d",&a[i][j]),x=a[i][j],cnt[i][(x-1)/m+1]++,v[i][(x-1)/m+1].push_back(a[i][j]);
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=n;i++)
			for(int k=1;k<=n;k++)
				e[i][k] = (cnt[i][k]!=0);
		memset(mat,0,sizeof(mat));
		for(int i=1;i<=n;i++)
		{
			memset(vis,0,sizeof(vis));
			find(i);
		}
		for(int i=1;i<=n;i++)
		{
			int to=mat[i];
			b[to][j] = v[to][i].back();
			v[to][i].pop_back();--cnt[to][i];
		}
		// puts("----");
	}
	for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=m;j++)printf("%d ",b[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			int lin = (b[i][j]-1)/m+1;
			c[lin][j]=b[i][j];
		}
		// puts("----");
	for(int i=1;i<=n;i++,puts(""))for(int j=1;j<=m;j++)printf("%d ",c[i][j]);
}

Measured memory_bytes: 1280
N, K = map(int, input().split())


def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X % n)
    return str(X % n)


x2 = Base_10_to_n(N, K)
test = list(x2)
print(len(x2))


Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

#include <climits>

using namespace std;


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

	vector<long long> arr(3*n);
	
	for (int i = 0; i < 3 * n; i++) cin>>arr[i];

	sort(arr.begin(), arr.end(), greater<long long>());

	int i = 1;
	long long sum = 0;
	while (i<=n) {
		int m = 2 * i - 1;
		sum = sum + arr[m];
		i++;
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 5544