akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

double eps = 1e-9;
double pi = acos(-1);

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io

	int n;
	cin >> n;

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

	bool ans = false;
	for(int i = 0; i < n - 1; i++)
	{
		if(a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2])
			ans = true;
	}

	if(ans)
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,a[200009],temp,fl=0,ct[200009]={0};
	string s;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ct[a[i]]++;
	}
	for(int i=0;i<=n;i++)
	{
		if(ct[i]!=0)
		{
			fl+=(ct[i]*(ct[i]-1))/2;
		}
	}
	for(int i=0;i<n;i++)
	{
		temp=fl;
		temp-=(ct[a[i]]*(ct[a[i]]-1))/2;
		if(ct[a[i]]!=1)
			temp+=((ct[a[i]]-1)*(ct[a[i]]-2))/2;
		cout<<temp<<endl;
	}


	
	return 0;
}

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

typedef long long I64;

using namespace std;

const I64 NMAX = 3000;
const I64 MOD  = 1000000007;

I64 v[NMAX+2], cop[NMAX+2], st[NMAX+2], dr[NMAX+2], x[NMAX+2], y[NMAX+2];
I64 dp[NMAX+2][NMAX+2];
I64 N, M, unu;
string s;

int main()
{
    cin >> N >> M;
    cin >> s;
    for( I64 i = 1;  i <= N;  ++i )
        cop[i] = v[i] = (s[i-1] == '1');
    for( I64 i = 1;  i <= M;  ++i ) {
        cin >> x[i] >> y[i];

        I64 cnt = 0;
        for( I64 j = x[i];  j <= y[i];  ++j ) {
            cnt += v[j];
        }
        for( I64 j = y[i];  j >= x[i];  --j, --cnt ) {
            if (cnt > 0)
                v[j] = 1;
            else
                v[j] = 0;
        }
    }
    I64 r_ind = 0;
    for( I64 i = 1;  i <= N;  ++i ) {
        if (v[i])
            dr[++r_ind] = i;
        v[i] = cop[i];
        unu += v[i];
    }
    for( I64 i = 1;  i <= M;  ++i ) {
        I64 cnt = 0;
        for( I64 j = x[i];  j <= y[i];  ++j )
            cnt += v[j];
        for( I64 j = x[i];  j <= y[i];  ++j, --cnt ) {
            if (cnt > 0)
                v[j] = 1;
            else
                v[j] = 0;
        }
    }
    r_ind = 0;
    for( I64 i = 1;  i <= N;  ++i )
        if (v[i])
            st[++r_ind] = i;
    dp[0][0] = 1;
    st[0] = 1;
    dr[0] = N;
    for( I64 i = 0;  i <= unu;  ++i ) {
        for( I64 j = 1;  j <= N;  ++j ) {
            dp[i][j] = dp[i][j-1];
            if (i > 0 && st[i] <= j && j <= dr[i])
                dp[i][j] += dp[i-1][j-1];
            dp[i][j] %= MOD;
        }
    }
    cout << dp[unu][ dr[unu] ] << '\n';
    return 0;
}


Measured memory_bytes: 37248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

ll perm(int n, int k) {
  if(k < 0)       return 0;
  else if(k == 0) return 1;
  else            return (n * perm(n-1, k-1)) % mod;
}

void dfs(vector<vector<int> >& Graph, int v, int par, int k, ll& ans) {
  ans *= perm(k-1-(par >= 0), int(Graph[v].size()-(par >= 0)));
  ans %= mod;
  for(int i=0; i<Graph[v].size(); i++) {
    int w = Graph[v][i];
    if(w != par)
      dfs(Graph, w, v, k, ans);
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N), B(N);
  vector<vector<int> > Graph(N);
  rep(i, N-1) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    Graph[A[i]].push_back(B[i]);
    Graph[B[i]].push_back(A[i]);
  }
  ll ans = K;
  dfs(Graph, 0, -1, K, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
double n, m, d;
int main(){
	scanf("%lf%lf%lf", &n, &m, &d);
	printf("%.10f\n", (d ? (n-d)*2 : n)/n/n*(m-1));
}

Measured memory_bytes: 892
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.next();
        if(line.length()%2 == 0){
          boolean judge = true;
          for(int i = 0; i < line.length()/2; i+=2){
            if(!line.substring(i, i+2).equals("hi")){
              judge = false;
            }
          }
          if(judge == true)
            System.out.println("Yes");
          else
            System.out.println("No");
        }else{
          System.out.println("No");
        }
    }
}

Measured memory_bytes: 23508
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        long x = Math.abs(s.nextLong());
        long k = s.nextLong();
        long d = s.nextLong();
        long q = x/d;
        long r =  (x%d);
        long r1 =  (d-r);
//        System.out.println(q);
//        System.out.println(r+" "+r1);
        long m;
        if(q>=k)
            m = x-k*d;
        else
        {
            k-=q;
            if(k%2==1)
                m=r1;
            else
                m=r;
        }
        System.out.println(m);
    }
}

Measured memory_bytes: 35860
let solve a b =
  match a, b with
    1, 1 -> "Draw"
  | 1, b -> "Alice"
  | a, 1 -> "Bob"
  | _, _ -> if a > b then "Alice"
            else if a = b then "Draw"
            else "Bob";;

let a, b = Scanf.bscanf Scanf.Scanning.stdin "%d %d" (fun x y -> x, y);;

print_string (solve a b);
print_newline ()


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] / (fac[k] * fac[n - k]);
}


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

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll dp[10101][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		cout << 0 << endl;
		return 0;
	}
	if (n == 1) {
		if (a != b) {
			cout << 0 << endl;
			return 0;
		}
		else {
			cout << 1 << endl;
			return 0;
		}
	}
	ll ans = (b - a) * (n - 2) + 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <stdio.h>

int main(){
 int A[1000],N=0;
 scanf("%d", &N);
 for(int i=0;i<N;i++){
  scanf("%d", &A[i]);
 }
 for(int i=0;i<N;i++){
  int v;
  v = A[i];
  int j = i - 1;
  while( j >= 0 && A[j] > v){
   A[j+1] = A[j];
   j--;
   A[j+1] = v;
  }
  for(int i=0;i<N-1;i++){
   printf("%d ", A[i]);
  }
  printf("%d\n", A[N-1]);
 }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    map<ll,ll>a,b;
    ll sum=0;
    rep(i,n){
        int x;cin>>x;
        a[x]++;
        b[x]=x;
        sum+=x;
    }
    int q;cin>>q;
    rep(i,q){
        int x,y;cin>>x>>y;
        sum-=a[x]*x;
        sum+=a[x]*y;
        a[y]+=a[x];
        a[x]=0;
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 13392
def slove():
    import sys
    input = sys.stdin.readline
    ie = False
    s = str(input().rstrip('\n'))
    for i in range(len(s)):
        if s[i] == "C":
            ie = True
        elif ie and s[i] == "F":
            print("Yes")
            exit()
    print("No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
 
#pragma comment(linker, "/STACK:336777216")  
 
using namespace std;

const int MAXN = 10000 + 10;

int N;
int a[MAXN], b[MAXN];
int A[MAXN];
multiset <long long> S;

multiset <long long> :: iterator getmin() { auto MNiter = S.begin(); return MNiter; }
multiset <long long> :: iterator getmax() { auto MXiter = S.end(); MXiter --; return MXiter; }

void Work()
{
	scanf("%d", &N);
	long long delta = 0;
	for (int i = 0; i < N; i ++)
		scanf("%d", &a[i]);
	for (int i = 0; i < N; i ++)
		scanf("%d", &b[i]);
	for (int i = 0; i < N; i ++)
	{
		A[i] = a[i] - b[i];
		delta += (long long) (b - a);
	}
	for (int i = 0; i < N; i ++)
		S.insert((long long) A[i]);

	while (1)
	{
		auto MNiter = getmin(), MXiter = getmax();
		long long d = min((-*MNiter) / 2, *MXiter);
		if (d <= 0 || MNiter == MXiter)
			break;
		S.insert(*MNiter + 2 * d);
		S.insert(*MXiter - d);
		S.erase(MNiter);
		S.erase(MXiter);
	}

	if (*getmin() <= 0 && *getmax() <= 0)
		printf("Yes\n");
	else
		printf("No\n");
}

int main()
{
	Work();
	return 0;
}

Measured memory_bytes: 768
import numpy as np
a, b, h, m = list(map(int, input().split()))
theta = np.abs(2 * np.pi * (h/12 + m/60 /12 - m/60))
if theta > np.pi:
    theta = 2 * np.pi - theta

ans = np.sqrt(a ** 2 + b ** 2 - 2 * a * b * np.cos(theta))
print(ans)

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

int main(void){
    long long N;cin>>N;
    long long A[N];
    vector<int>Y(3);Y={-1,0,1};
    vector<long long>X(pow(10,5)+1,0);
    for(long long i=0;i<N;i++){
        cin>>A[i];
    }
    for(long long i=0;i<N;i++){
        if(A[i]==0){
            for(int j=1;j<3;j++){
                X[A[i]+Y[j]]++;
            }    
        }
        else{
            for(int j=0;j<3;j++){
                X[A[i]+Y[j]]++;
            }
        }
    }
    long long ans=0;
    for(long long i=0;i<=pow(10,5)+1;i++){
        if(ans<X[i]){
            ans=X[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

constexpr int64_t INF = 1e18;
constexpr int D = 365;
constexpr int N = 26;
int c[N];
int s[D + 1][N];
int last[D + 1][N];
int64_t score[D + 1];
int t[D + 1];

constexpr int64_t CYCLES_PER_SEC = 2800000000;
constexpr double TIMELIMIT = 2.05;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};
mt19937 mt{random_device{}()};
uniform_int_distribution<int> rnd_contest(0, N - 1);
// uniform_int_distribution<int> rnd_day(1, D);
normal_distribution<> rnd_day(0, 1);

void input() {
	int _d; cin >> _d;
	for(int i = 0; i < N; ++i) {
		cin >> c[i];
	}
	for(int i = 1; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> s[i][j];
		}
	}
}

void greedy(int day, int contest = -1) {
	if(contest != -1) {
		for(int j = 0; j < N; ++j) {
			last[day][j] = last[day - 1][j];
		}
		last[day][contest] = day;
		++day;
	}
	for(int i = day; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			last[i][j] = last[i - 1][j];
		}
		int64_t loss = 0;
		for(int j = 0; j < N; ++j) {
			loss += c[j] * (i - last[i][j]);
		}
		int64_t maxi = -INF;
		int midx = 0;
		for(int j = 0; j < N; ++j) {
			int64_t los = loss - c[j] * (i - last[i][j]);
			if(s[i][j] - los > maxi) {
				maxi = s[i][j] - los;
				midx = j;
			}
		}
		last[i][midx] = i;
		t[i] = midx;
	}
}

int64_t calc(int day) {
	int64_t ans = score[day - 1];
	for(int i = day; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			last[i][j] = last[i - 1][j];
		}
		last[i][t[i]] = i;
		ans += s[i][t[i]];
		for(int j = 0; j < N; ++j) {
			int64_t loss = c[j] * (i - last[i][j]);
			ans -= loss;
		}
		score[i] = ans;
	}
	return ans;
}

void output() {
	for(int i = 1; i <= D; ++i) {
		cout << t[i] + 1 << '\n';
	}
}

int main() {
	Timer timer;
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	input();
	greedy(1);
	calc(1);
	int cnt = 0, update = 0;
	int valid = D;
	while(timer.get() < TIMELIMIT) {
		int q = rnd_contest(mt);
		double pro = rnd_day(mt);
		if(pro < 0) continue;
		++cnt;
		int d = max<int>(1, D - pro / 2 * D);
		int64_t score_pre = score[D];
		int contest_pre = t[d];
		t[d] = q;
		valid = min(valid, d - 1);
		// greedy(d, q);
		int64_t score_nxt = calc(valid + 1);
		if(score_nxt > score_pre) {
			update++;
			valid = D;
		} else {
			t[d] = contest_pre;
		}
	}
	// cerr << cnt << " " << update << '\n';
	// cerr << score[D] << '\n';
	output();
	return 0;
}


Measured memory_bytes: 4096
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
l=[]
c=Counter(A)
flag=1
ans=1
values=list(c.values())	#aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
key=list(c.keys())	#先のvalue値に相当する要素のリスト(要素1,要素2,…)
p=10**9+7
for i in range(len(key)):
    l.append([key[i],values[i]])#lは[要素i,n_i]の情報を詰めたmatrix
l.sort(key=lambda x:x[0])
for i in range(len(key)):
    if N%2==0:
        if (l[i][0]%2==1)and(0<l[i][0]<N)and(l[i][1]==2):
            ans=(ans*2)%p
        else:
            flag=0
            break
    else:
        if (l[i][0]==0)and(l[i][1]==1):
            ans=ans
        elif (l[i][0]%2==0)and(0<l[i][0]<N)and(l[i][1]==2):
            ans=(ans*2)%p
        else:
            flag=0
            break
if flag==1:
    print(ans%p)
else:
    print("0")

Measured memory_bytes: 65004
#include<cstdio>
#include<cmath>
using namespace std;
#define MAXN 10
bool U[MAXN];
bool C(int n){
	while(n){
		if(U[n%10]) return 0;
		n/=10;
	}
	return 1;
}
int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=k;i++){
		int x;
		scanf("%d",&x);
		U[x]=1;
	}
	while(1){
		if(C(n)){
			printf("%d",n);
			break;
		}
		n++;
	}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	Int r = 0, g = 0, b = 0;
	for (auto c : s) {
		if (c == 'R') { ++r; }
		if (c == 'G') { ++g; }
		if (c == 'B') { ++b; }
	}

	Int ans = r * g * b;
	for (int i = 0; i < N; ++i) {
		for (int j = i + 1; j < N; ++j) {
			if (s[i] == s[j]) { continue; }
			int k = 2 * j - i;
			if (k < 0 || k >= N || s[i] == s[k] || s[j] == s[k]) { continue; }
			--ans;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
a=int(input())
b=list(map(int,input().split()))

c=list(range(1,a+1))
d=[]
for i in range(a):
    d.append([c[i],b[i]])
d.sort(key=lambda x: x[1])
ans=[]
for i in range(a):
    ans.append(d[i][0])
print(' '.join(map(str,ans)))

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000
#define pll pair<ll, ll>
#define vl vector<ll>
#define vll vector< vector<ll> >
#define vb vector<bool>
#define vbb vector< vector<bool> >


ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<bool>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
	ll n, k;
	cin>>n>>k;
	vl a(n);
	for(ll i = 0; i < n; i++) cin>>a[i];
	ll low = 1, high = 0;
	for(auto i : a)
	    high = max(high, i);
	ll ans = -1;
	while(low <= high)
	{
	    ll mid = low + (high - low) / 2;
	    ll need = 0;
	    for(ll i = 0 ; i < n; i++)
	    {
	        need += ceil(1.0 * a[i] / mid) - 1;
	    }
	    if(need <= k)
	    {
	        ans = mid;
	        high = mid - 1;
	    }
	    else
	        low = mid + 1;
	}
	cout<<ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t = 1;
	//cin>>t;
	while(t--)
	{
		solve();		
	}
	return 0;
}

ll mulmod(ll a, ll b)
{
	ll res = 0; 
	a = a % MOD;
	while(b > 0)
	{
		if (b % 2 == 1)
			res = (res + a) % MOD;
 
		a = (a * 2) % MOD; 
		b /= 2;
	} 
	return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a = (a * a) % MOD;
	}
	return res;
}

void getprime(vector<bool>&prime)
{
	prime[0] = false;
	prime[1] = false;
	
	for(ll i = 2; i * i <= MAX; i++)
	{
		if(prime[i])
		{
			for(ll j = i*i; j <= MAX; j += i)
				prime[j] = false;
		}
	}
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
	fact[0] = 1;
	ifact[0] = 1;
	
	for(ll i = 1; i <= MAX; i++)
	{
		fact[i] = (fact[i-1] * i)%MOD;
		ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
	}
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
	ll res;
	res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
	return res;
}

Measured memory_bytes: 4728
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

#define INF 1e+9 //初期化注意
#define MAX_V 100000 //頂点数の最大値

struct edge {
	int to;
	int cost;
	//edge e ={to, cost}
};

// <最短距離, 頂点の番号>
using P = pair<int, int>;

int N;// 頂点の数
vector<edge> G[MAX_V];
int d[MAX_V];

void dijkstra(int s) {
	//sからiへの最短距離をd[i]に保存 i=e.to
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + N, INF);
	d[s] = 0;//初期位置へのコストは0

	que.push(P(0, s));
	//queはmake_pair(cost,to)?

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;//v=e.to	from s to v
		//すでにこの経路よりいい経路が見つかっているなら無視
		if (d[v] < p.first) continue;
		

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			// i 番目の v と v'を結ぶ辺　G=<e.to, e.cost>
			//e.to=v'
	                //e.cost means v to v' cost e.cost
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				//from s to v'> from s to v + from v to v'
				//vを経由したほうがコストが低いなら経由する
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


	//dijkstra(int s); nからの最短距離を計算
	//d[i]はsからiまでの最短距離が保存される the path from s to i cost d[i]



void solve()
{
	int n,m;
	cin>>n>>m;
	vector<vector<int>>g(n);
	vector<int>dist(n,-1);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	queue<int>que;
	que.push(0);
	dist[0]=0;
	vector<int>visited(n);
	while(que.size()){
		int now=que.front();
	//	cout<<now+1<<endl;
		if(visited[now])continue;
		visited[now]=1;
		que.pop();
		
		rep(i,size(g[now])){
			if(dist[g[now][i]]==-1){
				dist[g[now][i]]=dist[now]+1;
				que.push(g[now][i]);
			}
		}
	}
	map<int,int>ans;
	bool ok=true;
	
	rep(i,n){
		if(i){
			bool t=false;
			rep(j,size(g[i])){
				if(dist[i]-1==dist[g[i][j]]){
					ans[i]=g[i][j];
					t=true;
				}
			}
			if(!t){
				ok=false;
			}
		}
	}
	if(ok){
		cout<<"Yes"<<endl;
		rep(i,n){
			if(i){
				//cout<<dist[i]<<" ";
				cout<<ans[i]+1<<endl;
			}
		}
	}else{
		cout<<"No"<<endl;
	}

}

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


Measured memory_bytes: 17368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define OK { cout << "OK" << endl; return 0; }
#define NG { cout << "NG" << endl; return 0; }
#define sz(v) ((int)(v).size())
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void out(T a){cout << a << endl;}
template<class T>void die(T a){cout << a << endl; exit(0);}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

#define SIZE 200005
#define MOD 1000000007
 
typedef pair <int,int> P;
 
ll inv[SIZE], fac[SIZE], finv[SIZE];
void make(){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<SIZE; i++)
	{
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
    return ;
}
ll comb(int a,int b){
	if(a < b) return 0;
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    int N,M;
    cin>>N>>M; vi H(N);	rep(i,N)cin>>H[i];
	vi ok(N,1);
	//cout << M << endl;
	rep(i,M) {
		int a, b; cin >> a >> b;
		--a; --b;
		if(H[a] >= H[b]) ok[b] = 0;
		if(H[a] <= H[b]) ok[a] = 0;
	}
	int ress = 0;
	rep(i,N) if(ok[i] != 0) ress++;
	cout << ress << endl;
}

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

ll rest(ll x, ll y) {
    return x / y;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll tillb = rest(b, c) + rest(b, d) - rest(b, lcm(c, d));
    ll tilla = rest(a - 1, c) + rest(a - 1, d) - rest(a - 1, lcm(c, d));
    ll ans = b - a + 1 - (tillb - tilla);
    cout << ans << endl;
}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

N, M = inpl()
inf = float('inf')
path = [0 for _ in range(M)]
score = [-inf]*N
score[0] = 0
ans = 0
for i in range(M):
    a, b, c = inpl()
    path[i] = (a-1,b-1,c)

for i in range(N-1):
    update = False
    for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
            update = True
    if not update:
        break
ans = score[N-1]
for na, nb, nc in path:
        if score[na] != -inf and score[nb] < score[na] + nc:
            score[nb] = score[na]+nc
print(ans if ans == score[N-1] else 'inf')

Measured memory_bytes: 3316
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;


struct Edge { // {{{
    int src, to;
    i64 cost;
    Edge(int src,  int to, i64 cost) : src(src), to(to), cost(cost) {}
    Edge(int to, i64 cost = 0) : Edge(-1, to, cost) {}
    Edge() {}
    bool operator< (const Edge &o) const { return cost < o.cost; }
    bool operator> (const Edge &o) const { return cost > o.cost; }
};
using Edges = vector<Edge>;
using WGraph = vector<vector<Edge>>;
using UGraph = vector<vector<int>>;
// }}}



struct UnionFind {
    vector<int> u;
    explicit UnionFind(int n): u(n+5, -1) {}
    int  size(int i)        { return (-u[root(i)]); }
    int  root(int x)        { return (u[x] < 0)? x : u[x] = root(u[x]); }
    bool same(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y){ return (x=root(x)) == (y=root(y))? false : (u[x]+=u[y], u[y]=x, true); }
};

i64 kruskal(Edges &es, int V)
{
    UnionFind uf(V);
    i64 costSum = 0;

    sort(es.begin(), es.end());
    for (const auto &e : es) {
        if (uf.unite(e.src, e.to)) costSum += e.cost;
    }

    return costSum;
}

void AOJ_GRL_2_A()
{
    int V, E;
    cin >> V >> E;

    Edges es(E);
    for (int i = 0; i < E; ++i) {
        int s, t, w;
        cin >> s >> t >> w;
        es[i] = Edge(s, t, w);
    }

    cout << kruskal(es, V) << endl;

}

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

    AOJ_GRL_2_A();

    return 0;
}



Measured memory_bytes: 4428
#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
int x,n,p,h;
map<int,int> mp;
signed main(){
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);
//	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>x>>n;
	for(int i=0;i<n;i++){
		cin>>p;
		mp[p]=1;
	}
	while(true){
		if(mp[x-h]==0){
			cout<<x-h;
			return 0;
		}
		if(mp[x+h]==0){
			cout<<x+h;
			return 0;
		}
		h++;
	}
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
int n,m;
char s1[510][510],s2[510][510],s[510];
int main()
{
	n=read();m=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)s1[i][j]=s2[i][j]='.';
	for(int i=1;i<=n;i++)s1[i][1]='#',s2[i][m]='#';
	for(int i=1;i<=n;i+=2)
		for(int j=2;j<m;j++)s1[i][j]='#';
	for(int i=2;i<=n;i+=2)
		for(int j=2;j<m;j++)s2[i][j]='#';
	for(int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++)if(s[j]=='#')s1[i][j]='#',s2[i][j]='#';
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)putchar(s1[i][j]);puts("");
	}
	puts("");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)putchar(s2[i][j]);puts("");
	}
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <math.h>

typedef long long ll;
#define MAX_N (200005)

int uf[MAX_N]; // union-find
int n;

void uf_init()
{
	for (int i = 0; i < n; i++) {
		uf[i] = i;
	}
}

int uf_root(int x)
{
	if (uf[x] == x)
	{
		return x;
	}
	else
	{
		uf[x] = uf_root(uf[x]);
		return uf[x];
	}
	
}

void uf_unite(int x, int y)
{
	int rx = uf_root(x);
	int ry = uf_root(y);
	if (rx == ry)
	{
		return;
	}
	uf[rx] = ry;
}

int main() {
	int m;
	scanf("%d %d", &n, &m);
	
	uf_init();
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--;
		b--;
		uf_unite(a, b);
		
	}
	
	int gr[MAX_N]; // gr[x]: root(i) = x なるiの数(友達軍団の人数)
	for (int i = 0; i < n; i++) {
		gr[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		gr[uf_root(i)]++;
	}
	
	int gr_max = -1;
	for (int i = 0; i < n; i++) {
		if (gr[i] > gr_max) {
			gr_max = gr[i];
		}
	}
	printf("%d", gr_max);
	
	
	return 0;
}


Measured memory_bytes: 9440
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<map>
#include<set>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=3010;
ll g[N][N];
int n,m,k;
ll f[N][N][4];
int main()
{
    cin>>n>>m>>k;
    while(k--)
    {
        int x,y;
        ll w;
        cin>>x>>y>>w;
        g[x][y]=w;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            ll w=max(max(f[i-1][j][0],f[i-1][j][1]),max(f[i-1][j][2],f[i-1][j][3]));
            if(!g[i][j])
            {
                for(int k=0;k<=3;k++) f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
                f[i][j][0]=max(f[i][j][0],w);
            }
            else
            {
                for(int k=1;k<=3;k++) f[i][j][k]=f[i][j-1][k-1]+g[i][j];
                f[i][j][1]=max(f[i][j][1],w+g[i][j]);
                
                for(int k=0;k<=3;k++) f[i][j][k]=max(f[i][j][k],f[i][j-1][k]);
                f[i][j][0]=max(f[i][j][0],w);
            }
        }
    cout<<max(max(f[n][m][0],f[n][m][1]),max(f[n][m][2],f[n][m][3]))<<endl;
    
    return 0;
}

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

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

  int N;
  cin >> N;

  int cnt = 1;
  while (cnt <= N) {
    cnt *= 2;
  }
  cout << cnt / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n;
    string s;
    cin >> n >> s;
    for(int i=0;i<s.size();i++){
        s[i]=char((s[i]-'A'+n)%26+'A');
    }
    cout << s << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args){

		
		Scanner scan = new Scanner(System.in);
		double dbl = Double.parseDouble(scan.next());
		
		
		double p = 3.141592653589;
		double m;
		double c;
		
		m = dbl*dbl*p;
		c = dbl*2*p;
		
		
		
		System.out.printf("%.5f %.5f",m,c);
		}
}

Measured memory_bytes: 26288
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

int main() {
  size_t N;
  scanf("%zu %*d", &N);

  std::vector<std::string> S(N);
  for (auto& s_i: S) std::cin >> s_i;
  std::sort(S.begin(), S.end());
  for (const auto& s_i: S) std::cout << s_i;
  std::cout << std::endl;
}

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

int main(void) {
	int a, n, max = -10000000, min = 10000000, ave;
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a > max) {
			max = a;
		}
		if (a < min) {
			min = a;
		}
		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

bool ask(ll x) {
    cout << "? " << x << endl;
    char ans;
    cin >> ans;
    return ans == 'Y';
}
/*
ll N = 123;
string S = "123";

bool ask(ll x) {
    cout << "? " << x << endl;
    string s = to_string(x);
    return (x > N) == (s > S);
}*/

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

    ll t[19];
    t[0] = 1;
    rep(i, 18) t[i + 1] = t[i] * 10;

    if(ask(t[12])) {
        int ng = -1, ok = 9;
        while(ok - ng > 1) {
            int mid = ng + ok >> 1;
            (ask(t[mid] * 2) ? ok : ng) = mid;
        }
        cout << "! " << t[ok] << endl;
    } else {
        int ok = 0, ng = 10;
        while(ng - ok > 1) {
            int mid = ok + ng >> 1;
            (ask(t[mid]) ? ok : ng) = mid;
        }
        ll l = t[ok], r = t[ng];
        while(r - l > 1) {
            ll mid = l + r >> 1;
            (ask(mid * 10) ? r : l) = mid;
        }
        cout << "! " << r << endl;
    }

    return 0;
}

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

long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

int main() {
	long long int k, s[200050] = {}, a[200050] = {}, left, right, memo = 0;
	scanf("%lld", &k);
	for (int i = 1; i <= k; i++) {
		scanf("%lld", &s[i]);
		a[s[i]] = a[s[i] - 1] + 1;
	}
	for (int i = 1; i <= k; i++) {
		if (memo < a[i]) { memo = a[i]; }
	}
	printf("%lld", k - memo);
}

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

using namespace std;

long long int NUM(long long int A, long long int B) {

	if (A <= 0) { return 0; }
	if (A%B == 0) { return A / B; }

	return A / B + 1;

};

int main(void) {

	long long int N, K;

	cin >> N >> K;

	vector<long long int>A;
	A.push_back(0);

	long long int tmp;
	for (int i = 1; i <= N; i++) {
		cin >> tmp;
		A.push_back(tmp);
	}


	
	/*		long long int num = 0;

			long long int count = 0;

			num += K; count++;

			while (num < N) {
				num += K - 1; count++;

			}

			cout << "ans= " << count << endl;
*/


				long long int m=N/2;

				for (m = 1; m <= N; m++) {
					if (A[m] == 1) { break; }
				}
		

			long long int min_V = N;

			long long int tmp_V;

			
				for (int i = m - K + 1; i <= m; i++) {
					if (i<1 || i + K - 1>N) { continue; }
					tmp_V = NUM(i - 1, K - 1) + 1 + NUM(N - i - K + 1, K - 1);
					if (tmp_V < min_V) { min_V = tmp_V; }
				}

				cout << min_V << endl;
				//cout << "m= " << m << "  " << min_V << endl;
				//if (min_V != count) { cout << "等しい" << endl; }
			

		

	//system("pause");
	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		while(true)
		{
			int a = stdIn.nextInt();
			String op = stdIn.next();
			int b = stdIn.nextInt();
			
			if(op.equals("?"))
			{
				break;
			}
		
			if(op.equals("+"))
			{
				System.out.println(a+b);
			}
			if(op.equals("-"))
			{
				System.out.println(a-b);
			}
			if(op.equals("*"))
			{
				System.out.println(a*b);
			}	
			if(op.equals("/"))
			{
				System.out.println(a/b);
			}
		}
	}

}

Measured memory_bytes: 18024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int N;
  long long sum = 0;
  cin >> N;
  for(int i=1; i<=N; i++) {
    if (i%3!=0 && i%5!=0) {
      sum+=i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "C"
int n;
ll x;
ll start;
class subject{
public:
    ll b, l, u, w;
    void input(){
        read(b);
        read(l);
        read(u);
        start+=b*l;
        w=(x-b)*u+b*l;
    }
    ll cost(ll x){
        if(x<=b*l){
            return (x-1)/l+1;
        }
        else{
            x-=b*l;
            return b+(x-1)/u+1;
        }
    }
} s[100001];
ll f[100001];
int get(int i){
    int res=n;
    int low=0, high=n-1, mid;
    while(low<=high){
        mid=(low+high)/2;
        ll sum=f[mid];
        if(mid<i) sum+=s[i].w;
        if(sum>=start){
            res=mid;
            high=mid-1;
        }
        else low=mid+1;
    }
    return res;
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(x);
    FOR(i, 1, n) s[i].input();
    sort(s+1, s+n+1, [](subject A, subject B){
        return A.w>B.w;
    });
    ll ans=x*n;
    FOR(i, 1, n) f[i]=f[i-1]+s[i].w;
    FOR(i, 1, n){
        int j=get(i);
        ll res=x*j;
        if(j>i) res-=x;
        ll now=start-f[j];
        if(j>i) now+=s[i].w;
        if(now>0) ans=min(ans, res+s[i].cost(now));
        else ans=min(ans, res);
    }
    writeln(ans);
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
using namespace std;
// }}} End Header

lli sigma1(lli n){
	return n*(n+1)/2;
}
lli sigma2(lli s, lli n){
	return sigma1(n) - sigma1(s -1);
}
int main()
{
	double sum=0, sum2=0, half, dist;
	lli n;
	cin >> n;
	vector<lli> w(n);
	rep(i,n){
		cin >> w[i];
		sum+=w[i];
	}
	double min = 1000000000;
	rep(i,n){
		sum2 += w[i];
		half = sum - sum2;
		dist = abs(half - sum2);
		if(min > dist) min = dist;
	}
	printf("%d", (int)min);
	return 0;
}


Measured memory_bytes: 256
def cross(c1, c2):
    return c1.real * c2.imag - c1.imag * c2.real

def ccw(p0, p1, p2):
    if cross(p1 - p0, p2 - p0) > 0:
        return True
    else:
        False

# Andrew's algorithm
import collections

def andrew(point_list):
    point_list.sort(key = lambda c: (c.imag, c.real))
    point_que = collections.deque(point_list)
    convex_hull = []
    rest_points = []
    start_point = point_que.popleft()

    # outward
    convex_hull.append(start_point)
    convex_hull.append(point_que.popleft())

    while point_que:
        new_point = point_que.popleft()
        while ccw(convex_hull[-1], convex_hull[-2], new_point):
            rest_points.append(convex_hull.pop())
            if len(convex_hull) == 1:
                break
        convex_hull.append(new_point)

    # homeward
    rest_points.append(start_point)
    rest_points.sort(key = lambda c: c.imag)

    while rest_points:
        new_point = rest_points.pop()
        while ccw(convex_hull[-1], convex_hull[-2], new_point):
            convex_hull.pop()
        convex_hull.append(new_point)

    # output
    convex_hull.pop()
    print(len(convex_hull))
    print('\n'.join(map(lambda p: "{0:.0f} {1:.0f}".format(p.real, p.imag), convex_hull)))

# Acceptance of input
def string_to_complex(s):
    x, y = map(int, s.split())
    return x + y * 1j

import sys

file_input = sys.stdin

n = int(file_input.readline())

P = [string_to_complex(file_input.readline()) for i in range(n)]

# solve
andrew(P)

Measured memory_bytes: 24488
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    check = Counter(a).items()
    memo = [True] * (2 * 10 ** 6 + 1)
    a = []
    for k, v in check:
        if v == 1:
            a.append(k)
        else:
            memo[k] = False
            for i in range(1, 10 ** 6 + 1):
                if 10 ** 6 + 1 < i * k:
                    break
                memo[i * k] = False
    ans = 0
    a.sort()
    for aa in a:
        if memo[aa]:
            ans += 1
            for i in range(1, 10 ** 6 + 1):
                if 10 ** 6 + 1 < i * aa:
                    break
                memo[i * aa] = False
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 143572
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,sum;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	rep(i,1,n){
		if(i % 3 == 0 || i % 5 == 0) continue;
		sum += 1LL*i;
	}
	cout << sum << endl;
	return 0; 
}
//do smt instead of nothing! never give up!

Measured memory_bytes: 3632
const main = (input) => {
  let [a, b] = input.split(" ").map(Number)
  let r = 0
  for (var i = 0; i < 2; i++) {
    let c = 0
    if (a < b) {
      c = b
      b--
    } else {
      c = a
      a--
    }
    r += c
  }
  return r
}

if (process.env.NODE_ENV !== "test") {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(main(input.trim()))
}

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

const long long inf = 2.345e18;
const int N = 2e5;
const int Z = 59;

int n;
int a[N];

int nxt[Z][N];
long long cnt[Z][N];

int main() {
	ios_base::sync_with_stdio(false);

	memset(nxt, -1, sizeof(nxt));

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

	{
		vector<int> last(N+1, -1);
		for (int i = n-1; i >= 0; i--) {
			int x = a[i];
			if (last[x] != -1) {
				nxt[0][i] = (last[x]+1)%n;
				cnt[0][i] = last[x]+1 - i;
			}
			last[x] = i;
		}
		for (int i = 0; i < n; i++) {
			int x = a[i];
			if (nxt[0][i] == -1) {
				nxt[0][i] = (last[x]+1)%n;
				cnt[0][i] = n-i + last[x]+1;
			}
		}
	}
	for (int z = 1; z < Z; z++) {
		for (int i = 0; i < n; i++) {
			int j = nxt[z-1][i];
			if (cnt[z-1][i] <= inf - cnt[z-1][j]) {
				nxt[z][i] = nxt[z-1][j];
				cnt[z][i] = cnt[z-1][i] + cnt[z-1][j];
			} else {
				cnt[z][i] = inf;
			}
		}
	}

	long long tot = n*k - n;
	int i = 0;
	for (int z = Z-1; z >= 0; z--) {
		if (cnt[z][i] == inf) continue;
		while (tot >= cnt[z][i]) {
			tot -= cnt[z][i];
			i = nxt[z][i];
		}
	}
	tot += n;
	vector<int> ans;
	vector<int> was(N+1);
	while (tot--) {
		int x = a[i];
		if (was[x]) {
			while (true) {
				int y = ans.back();
				ans.pop_back();
				was[y]--;
				if (y == x) {
					break;
				}
			}
		} else {
			ans.push_back(x);
			was[x]++;
		}
		i = (i+1)%n;
	}

	for (int x : ans) {
		cout << x << ' ';
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 143216
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			a.begin(), a.end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define	MAX_QWORD		((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<ll, ll>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int A, B, K;
	cin >> A >> B >> K;

	for (int i = A; i <= B; i++) {
		if (i < A + K || B - K < i) {
			cout << i << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    const int K = 50;

    vector<vector<char>> map(K * 2, vector<char>(K * 2));

    REP(i, 2 * K) {
        REP(j, K)
        map[i][j] = '.';
        REP(j, K)
        map[i][j + K] = '#';
    }

    int A, B;
    cin >> A >> B;

    A--;
    B--;

    for (int i = 0; i < 2 * K; i += 2) {
        for (int j = 1; j < K; j += 2) {
            if (B > 0) {
                map[i][K - j - 1] = '#';
                B--;
            }

            if (A > 0) {
                map[i][K + j] = '.';
                A--;
            }
        }
    }

    cout << 2 * K << " " << 2 * K << endl;
    REP(i, 2 * K) {
        REP(j, 2 * K)
        cout << map[i][j];
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256