akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=1;i<=(n);i++)
#define rep3(i,i0,n) for(ll i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool comparex(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<1>(a) < get<1>(b);
        
}
bool comparey(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<2>(a) < get<2>(b);
        
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

vector<Pi> pf(ll N){
    vector<Pi> res;
    for(ll a= 2; a*a <= N; ++a){
        if(N%a != 0) continue;
        ll ex= 0;

        while(N%a == 0){
            ++ex;
            N /= a;
        }

        res.pb(mp(a,ex));
    }
    if(N!=1) res.pb(mp(N,1));
    return res;
}

int main() {

    ll N;
    cin >> N;
    vector<Pi> ans;
    ans = pf(N);

    cout <<N<<":";

    rep(i,ans.size()){
        rep(j,ans[i].second){
            cout<<" "<<ans[i].first;
        }
    }

    cout<< endl;
  
    return 0;
    

}



Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#define rep(i,n) for(int i = 0;i < (n);i++)
using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    
    return true;
}

int main(){
    int X;
    cin >> X;
    
    for(int i = X;i < 100004;i++){
        if(IsPrime(i)) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	LLONG A, B;
	get2int<LLONG>(A, B);
	
	if ((A + B) % 2) {
		printf("IMPOSSIBLE\n");
	}
	else {
		printf("%lld\n", (A + B) / 2);
	}
}


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

using namespace std;

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i : (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
int arr[3005];
int dp[105][100005];
const int mod = 1e9 + 7;
signed main()
{
    clock_t beg = clock();
    // cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    int a,k;
    cin >> a>>k;
    int arr[a];
    for (int i = 0; i < a; i++)
    {
        cin >> arr[i];
    }
    // memset(dp,0, sizeof(dp));
    for (int i = 0; i <= arr[0]; i++)
    {
        dp[0][i] = 1;
    }
    for (int i = 1; i < a; i++)
    {
        vector<int> prefixsum(k + 1);
        prefixsum[0] = dp[i - 1][0];
        for (int j = 1; j <= k; j++)
        {
            prefixsum[j] = (prefixsum[j - 1] + dp[i - 1][j])%mod;
        }
        for (int j = 0; j <= k; j++)
        {
            if (arr[i] >= j)
            {
                dp[i][j] = prefixsum[j];
            }
            else
            {
                int lol = j - arr[i] - 1;
                dp[i][j] = (prefixsum[j] +mod- prefixsum[lol]) % mod;
            }
        }
        prefixsum.clear();
    }
    cout << dp[a-1][k] << endl;
    return 0;
}


Measured memory_bytes: 82412
INF = 10 ** 10
n, m = gets.split.map(&:to_i)
cost_num = []
keys = []
m.times do
  cost_num << gets.split.map(&:to_i)
  keys << gets.split.map(&:to_i).inject(0) { |res, num| res | 2 ** (num - 1) }
end
dp = Array.new(2 ** n, INF)
dp[0] = 0
keys.each_with_index do |key, i|
  (0...2 ** n).each do |opened|
    current_opened = opened
    next_opened = (opened | key)
    dp[next_opened] = [dp[next_opened], dp[current_opened] + cost_num[i][0]].min
  end
end
puts dp.last == INF ? - 1 : dp.last


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    ll n,x,y;
    cin >> n>> x >> y;
    vector<ll>ans(n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll ii = i+1,jj=j+1;
            ll che = jj-ii;
            che = min(che,abs(x-ii)+abs(y-jj)+1);
            ans.at(che)++;
        }
    }
    for(int i=1;i<n;i++){
     cout << ans.at(i)<<endl;
    }

}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, k := r.nextInt(), r.nextInt()
	r.Scan(true)
	pi := r.nextStringArray().toInts()

	p := make([]float64, n)
	for i := range pi {
		p[i] = (float64(pi[i]) + 1) / 2
	}

	s := float64(0)
	for i := 0; i < k; i++ {
		s += p[i]
	}

	ans := s
	for i := k; i < n; i++ {

		ns := s - p[i-k] + p[i]
		if ans < ns {
			ans = ns
		}
		s = ns
	}
	fmt.Fprintf(stdout, "%.12f\n", ans)
}


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

int main()
{
    long long int N, K;
    cin >> N >> K;

    vector<pair<int, int>> pairs;

    for(int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        pairs.push_back(make_pair(a, b));
    }

    sort(pairs.begin(), pairs.end());

    long long int cnt = 0;
    for(int i = 0; i < N; i++)
    {
        cnt += pairs[i].second;
        if(K <= cnt)
        {
            cout << pairs[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n;
    ll K;
    cin >> n >> K;
    vector<ll> arr(n, 0);
    for(auto& val: arr) {
        cin >> val;
    }
    ll M = *max_element(arr.begin(), arr.end());
    if (K > M)
        cout << "IMPOSSIBLE" << endl;
    else {
        ll GCD = arr[0];
        for(int i = 1; i < n; i++)
            GCD = __gcd(GCD, arr[i]);
        if (GCD > 1 && __gcd(GCD, K) == 1) {
            cout << "IMPOSSIBLE" << endl;
        } else {
            cout << "POSSIBLE" << endl;
        }
    }
    return 0;
}




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

struct RS {
	using t1 = int;
	using t2 = int;
	static t2 id2() { return 0; }
	static t1 op2(const t1& l, const t2& r) { return l + r; }
	static t2 op3(const t2& l, const t2& r) { return l + r; }
};

template <typename M>
class lazy_segment_tree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int h, n;
	vector<T1> data;
	vector<T2> lazy;
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		lazy[node << 1] = M::op3(lazy[node << 1], lazy[node]);
		lazy[(node << 1) | 1] = M::op3(lazy[(node << 1) | 1], lazy[node]);
		lazy[node] = M::id2();
	}
public:
	lazy_segment_tree(int n_, T1 v1)
		: h(ceil(log2(n_))), n(1 << h), data(n_, v1), lazy(n << 1, M::id2()) {}
	lazy_segment_tree(const vector<T1>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(data_), lazy(n << 1, M::id2()) {}
	void update(int l, int r, T2 val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		while (l < r) {
			if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
			if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
			l >>= 1; r >>= 1;
		}
	}
	T1 find(int p) {
		T1 res = data[p]; p += n;
		while (p) res = M::op2(res, lazy[p]), p >>= 1;
		return res;
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	lazy_segment_tree<RS> lst(n, 0);
	while (q--) {
		int com;
		cin >> com;
		if (com == 0) {
			int s, t, x;
			cin >> s >> t >> x; s--, t--;
			lst.update(s, t, x);
		}
		else {
			int p;
			cin >> p; p--;
			printf("%d\n", lst.find(p));
		}
	}
	return 0;
}



Measured memory_bytes: 4556
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        if(d==7||d==5||d==3) System.out.println("YES");
        else System.out.println("NO");

    }
}


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

using namespace std;
int main() {
	int N;
	cin >> N;
	int out = 0;
	for(int i = 0; i < N; i++) {
		int a;
		cin >> a;
		while(a > 0 && a % 2 == 0) {
			out++;
			a /= 2;
		}
	}
	cout << out << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int n, a;
int ans[3];

int go(int a) {
	if (a % 4 == 0)
		return 2;
	if (a % 2 == 0)
		return 1;
	else
		return 0;
}

int main(){
	scanf("%d ",&n);
	FORI(0, n) {
		scanf("%d ", &a);
		ans[go(a)]++;
	}
	bool flg = false;
	if (ans[1] > 0)
		flg = (ans[0] <= ans[2]);
	else
		flg = (ans[0] <= ans[2]+1);
	cout << (flg ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
#define debug(x) {cout<<(#x)<<" "<<x<<endl;}
using namespace std;
typedef long long LL;

inline int read() {
    int 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*10+(ch-'0'); ch=getchar();}
    return x*f;
}

const int N = 400005;
const int INF = 1000000007;

int n,tot=0;
struct bag{
	int a,b;
} a[N];
LL ans;

bool cmp(bag a,bag b) {
	if (a.a==b.a) return a.b<b.b;
	return a.a<b.a;
}

int main() {

	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif

	n=read(); rep(i,1,n) a[i]={read(),read()};
	int mxb=0,mxr=0,mnb=INF,mnr=INF;
	rep(i,1,n) {
		int mx=max(a[i].a,a[i].b);
		int mn=min(a[i].a,a[i].b);
		a[i].a=mn,a[i].b=mx;
		mxb=max(mxb,mx); mnb=min(mnb,mx);
		mxr=max(mxr,mn); mnr=min(mnr,mn);
	}
	ans=(LL)(mxb-mnb)*(mxr-mnr);
	
	sort(a+1,a+n+1,cmp);
	int tmp=mxb-mnr;
	mnb=INF; mxb=a[n].a;
	rep(i,1,n-1) {
		mnb=min(mnb,a[i].b);
		mxb=max(mxb,a[i].b);
		ans=min(ans,(LL)tmp*(mxb-min(mnb,a[i+1].a)));
	}
	
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1792
import math

zeikomi = int(input())
zeinuki_mae = zeikomi / 1.08
zeinuki = math.ceil(zeinuki_mae)
zeikomi_ato = math.floor(zeinuki * 1.08)

if zeikomi != zeikomi_ato:
    print(':(')
else:
    print(zeinuki)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n; cin >>n;
    set<char> s;

    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        s.insert(c);
    }

    if(s.size() == 3) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    } 
    
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
a = list(map(int, input().split()))

max_a = max(a)
min_a = min(a)

if K > max_a:
    print('IMPOSSIBLE')
else:
    is_found = False
    while (not is_found):
        is_found = True
        for i, a_i in enumerate(a):
            m = a[i] % min_a
            if m != 0:
                a[i] = m
                is_found = False
        min_a = min(a)
    if K % min_a == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

Measured memory_bytes: 14224
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = 9*6
for i in range(1, N):
    k = N - i
    m = min(m, sumDigits(i) + sumDigits(k))

print(m)

Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

class UnionFind{
public:
	vector<int> par,num;

	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};

int main(){
	int n,m; cin >>n>>m;
	vector<int> p(n);
	cinf(n,p);

	UnionFind Uf(n);

	for(int i=0;i<m;i++){
		int x,y;
		cin >> x >> y;
		Uf.unite(x-1,y-1);
	}
	int cnt=0;
	for(int i=0;i<n;i++){
		if(Uf.same(i,p[i]-1)) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define eps 1e-10
#define gcd(a,b) __gcd(a,b)
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    string s;
    cin >> s;
    forn(i , 0 , s.len - 1) {
       if(s[i] == 'g') s[i] = 'r';
    }
    ll cnt = 0 ;
    string ans = "" ;
    ll n = s.len ;
    forn(i , 0 , n - 1 ){
       if(i == 0){
        ans = ans + "r" ;
        ++cnt;
        con ;
       }
       else{
         if(s[i] == 'r'){
            if(cnt > 0 ){
                --cnt ;
                ans = ans + "p";
            }
            else if(cnt <= 0){
                ans = ans + "r";
                ++cnt;
            }
         }
         else if(s[i] == 'p'){
            if(cnt > 0 ) {
                --cnt ;
                ans = ans + "p";
            }
            else if(cnt <= 0 ){
                ++cnt;
                ans = ans + "r";
            }
         }
       }
    }
    ll foo = 0 ;
    forn(i , 0 , n - 1 ) {
       if(s[i] == ans[i]){
        con ;
       }
       else{
        if(s[i] == 'r'){
            ++foo;
        }
        else if(s[i] == 'p'){
            --foo;
        }
       }
    }
    cout << foo << el ;
    ro ;
}































Measured memory_bytes: 904
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    
    int mini=INF, goal;
    
    int p = 0;
    rep(i,s.size()){
        if(s[i]=='(')p++;
        else p--;
        mini = min(mini,p);
    }
    mini = max(0,-mini);
    goal = p + mini;
    
    cout<<string(mini,'(')<<s<<string(goal,')')<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main()
{
    int A, B;
    cin >> A >> B;
    if (2 * B >= A)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << A - 2 * B << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
s=input()
if len(s)>10:
    print('NO')
    exit()

for bit in range(2**(len(s)+1)):
    T = ""
    for j in range(len(s)+1):
        if ((bit >> j) & 1):
            T += "A"
        if j<(len(s)):
            T += s[j]
    if T=='AKIHABARA':
        print('YES')
        exit()

print('NO')    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main() {
    int n; cin >> n;
    vector<vector<int>> v(n,vector<int>(26));
    for(int i=0;i<n;i++){
        string s; cin >> s;
        for(int j=0;j<s.size();j++) v[i][s[j]-'a']++;
    }
    for(int i=0;i<26;i++){
        int MIN=INFI;
        for(int j=0;j<n;j++){
            if(MIN>v[j][i]) MIN=v[j][i];
        }
        char ans='a'+i;
        for(int j=0;j<MIN;j++) cout << ans;
    }
    cout << endl;
}



Measured memory_bytes: 256
#include<cstdio>
#include<complex>

typedef std::complex<double> point;

double InnerProd(point x,point y);
point projection(point x,point y);
point reflection(point x,point y,point z);
int main(){
        point p1,p2,p,ans;
        double x1,y1,x2,y2;
        int q;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
        p1=point(x1,y1);
        p2=point(x2,y2);
        scanf("%d",&q);
        for(int i=0;i<q;i++){
                scanf("%lf%lf",&x1,&y1);
                p=point(x1,y1);
                ans=reflection(p1,p2,p);
                printf("%.10lf %.10lf\n",ans.real(),ans.imag());
        }
        return 0;
}

double InnerProd(point x,point y){
        return (std::conj(x)*y).real();
}

/*x??????y???????°???±*/
point projection(point x,point y){
        return y/std::norm(y)*InnerProd(x,y);
}

/*xy????????????????????¨??????z???????§°???*/
point reflection(point x,point y,point z){
        return 2.0*(projection(z-x,y-x)-(z-x))+z;
}

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

ll N;
vector<ll> a;

ll getexep2(ll num){
    ll count = 0;
    while(!(num%2)) {
        count++;
        num /= 2;
    }
    return count;
}

int main() {
    scanf("%Ld", &N);
    a.resize(N);
    for (int i = 0; i < N; i++) scanf("%Ld", &a[i]);
    ll ans = 0;
    for (int i = 0; i < N; i++) ans += getexep2(a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
s = input()
n = len(s)


def dfs(i, f):
    if i == n - 1:
        return sum(list(map(int, f.split("+"))))

    return dfs(i + 1, f + s[i + 1]) + dfs(i + 1, f + "+" + s[i + 1])


print(dfs(0, s[0]))

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

int p[20010];
long long  a[20010];
long long  b[20010];
int main(){
    int N;
    cin>>N;
    for(int i = 1; i<=N; i++){
        a[i]=i*N;
        b[i]=(N-i+1)*N;
    }
    for(int i = 1; i<=N; i++){
        cin>>p[i];
        b[p[i]]+=i;

    }
    cout<<a[1];
    for(int i = 2; i<=N; i++)
        cout<<" "<<a[i];
    cout<<endl;
    cout<<b[1];

    for(int i = 2; i<=N; i++)
        cout<<" "<<b[i];





}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pi 3.1415926536
#define pb push_back
#define N 1000000007
#define M 998244353
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define nrep(i,a,b) for(int i=a;i>=b;i--)
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t,i,j,k,q,x,y,l,r,z,n,m;
    ld side;
    cin>>side;
    ld vol = (side/3)*(side/3)*(side/3);
    cout<<fixed<<setprecision(10)<<vol;
}

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

using namespace std;

using ll = long long;

bool dfs(int cur, int par, vector<int>& ban, vector< vector<int> >& g, string& s) {
    int& res = ban[cur];
    res = (s[cur] == 'B');
    for (int nex : g[cur]) {
        if (nex == par) continue;
        if (!dfs(nex, cur, ban, g, s)) {
            res = false;
        }
    }
    return res;
}

const int WHITE = 0;
const int BLACK = 1;

int dfs2(int cur, int par, vector<int>& dp, vector< vector<int> >& g, vector<int>& color) {
    int& res = dp[cur];
    bool f = false;

    for (int nex : g[cur]) {
        if (par == nex) continue;
        f = true;
        res = max(res, dfs2(nex, cur, dp, g, color));
    }

    if (!f) return 0;

    if (color[cur] == WHITE) res += 2;
    return res;
}

void dfs3(int cur, int par, int dp_par, vector<int>& dp, vector< vector<int> >& g, vector<int>& color, vector<int>& dp2) {
    dp2[cur] = max(dp_par + (par != -1 && color[cur] == WHITE) * 2, dp[cur]);

    vector<int> v;
    v.push_back(dp_par);
    for (int nex : g[cur]) {
        if (nex == par) continue;
        v.push_back(dp[nex]);
    }
    sort(v.begin(), v.end(), greater<>());

    if (v.size() <= 1) return;

    for (int nex : g[cur]) {
        if (nex == par) continue;
        dfs3(nex, cur, (v[0] == dp[nex] ? v[1] : v[0]) + (color[cur] == WHITE) * 2, dp, g, color, dp2);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< vector<int> > g(n);
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    string s;
    cin >> s;
    
    int idx = -1;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'W') {
            idx = i;
            break;
        }
    }

    if (idx == -1) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> ban(n, true);
    dfs(idx, -1, ban, g, s);

    vector< vector<int> > g2(n);
    int edge_num = 0;
    for (int i = 0; i < n; i++) {
        if (ban[i]) continue;
        for (int j : g[i]) {
            if (ban[j]) continue;
            g2[i].push_back(j);
            edge_num++;
        }
    }
    edge_num /= 2;

    vector<int> color(n, WHITE);
    int ans = edge_num * 2;

    for (int i = 0; i < n; i++) {
        if (ban[i]) continue;
        if (s[i] == 'B') color[i] = BLACK;
        if (g2[i].size() % 2 == 1) {
            color[i] = !color[i];
        }

        ans += (color[i] == WHITE);
    }

    vector<int> dp(n, 0);
    dfs2(idx, -1, dp, g2, color);

    vector<int> dp2(n, 0);
    dfs3(idx, -1, 0, dp, g2, color, dp2);

    int tmp = 0;
    for (int i = 0; i < n; i++) {
        if (ban[i]) continue;
        tmp = max(tmp, dp2[i]);
    }
    ans -= tmp;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31568
h, w, a, b = map(int, input().split())
res = 0
kai = min(w - b, h - a)
mod = 10 ** 9 + 7

kaijo = [0] * (h + w + 1)
kaijo[0] = 1
for i in range(1, h + w + 1):
    kaijo[i] = (kaijo[i - 1] * i) % mod
gyaku = [0] * (h + w + 1)
gyaku[h + w] = pow(kaijo[h + w], mod - 2, mod)
for i in range(h + w, 0, -1):
    gyaku[i - 1] = (gyaku[i] * i) % mod


def conb(x, k):
    return (kaijo[x] * gyaku[k] * gyaku[x - k]) % mod


conb1 = conb(h - a - 1 + b, b)
conb2 = conb(a + w - b - 1, a)
combi = conb1 * conb2
res = combi

for i in range(1, kai):
    res += conb(h - a - 1 + b, b + i) * conb(a + w - b - 1, a + i)

res %= mod
print(int(res))


Measured memory_bytes: 18804
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

ll dp[401][401], po[401][401];

ll eval(int num, int lo, int hi) {
	ll x = (po[hi][num]-po[lo-1][num]) % MOD;
	while (x<0) x += MOD;
	return x;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N,C; cin >> N >> C;
	vi A(N+1), B(N+1);
	FOR(i,1,N+1) cin >> A[i];
	FOR(i,1,N+1) cin >> B[i];
	FOR(i,1,401) F0R(j,401) {
		if (j == 0) po[i][j] = 1;
		else po[i][j] = (po[i][j-1]*i) % MOD;
	}
	FOR(i,1,401) F0R(j,401) {
		po[i][j] = (po[i][j]+po[i-1][j]) % MOD;
	}
	dp[N][C] = 1;
	for (int i = (N-1); i >= 0; --i) {
		for (int j = C; j >= 0; --j) {
			for (int k = j; k <= C; ++k) {
				dp[i][j] = (dp[i][j]+dp[i+1][k]*eval(k-j,A[i+1],B[i+1])) % MOD;
			}
			// cout << i << " " << j << " " << dp[i][j] << "\n";
		}
	}
	cout << dp[0][0];
}

Measured memory_bytes: 2816
def main():
    n,m = map(int,input().split())
    g = {}
    for i in range(m):
        x,y,z = map(int,input().split())
        if x-1 not in g.keys():
            g[x-1] = [y-1]
        else:
            g[x-1] += [y-1]
        if y-1 not in g.keys():
            g[y-1] = [x-1]
        else:
            g[y-1] += [x-1]
    t = [-1 for i in range(n)]
    def bfs(s,t):
        t[s] = 0
        que = [s]
        while len(que)>0:
            v = que.pop(0)
            for nv in g[v]:
                if t[nv]!=-1:
                    continue
                t[nv]=0
                que.append(nv)
        return t

    ans = 0
    for i in range(n):
        s = i
        if t[s]!=-1:
            continue
        if s not in g.keys():
            ans += 1
            continue
        t[s]=0
        ans += 1
        t = bfs(s,t)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31072
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> ps(n);
    for (auto &p : ps)
    {
        cin >> p;
    }
    int count = 0;
    for (int i = 1; i < n - 1; i++)
    {
        vector<int> vs = {ps[i - 1], ps[i], ps[i + 1]};
        sort(vs.begin(), vs.end());
        if (vs[1] == ps[i])
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

bool check(char c, string s){
  bool res = true;
  rep(i, s.length()){
    if(s[i] != c) res = false;
  }
  return res;
}

int main()
{
  string s;
  cin >> s;
  int res = INF;

  for(char c = 'a'; c <= 'z'; c++) {
    auto it = find(s.begin(),s.end(), c);
    if(it==s.end()) continue;
    string S = s;
    int num = 0;
    bool isAllC = check(c, S);
    while(!isAllC){
      string ss;
      rep(i, S.length()-1){
        if(S[i] == c || S[i+1] == c) {
          ss += c;
        } else {
          ss += S[i];
        }
      }
      S = ss;
      num++;
      isAllC = check(c, S);
    }
    res = min(res, num);
  }

  cout << res << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int h,w,d;
	cin>>h>>w>>d;
	int a[333][333]={},pl[91234][2]={},dp[91234]={};
	FORQ(i,1,h){
		FORQ(j,1,w){
			cin>>a[i][j];
			pl[a[i][j]][0]=i;
			pl[a[i][j]][1]=j;
		}
	}
	FORQ(i,1+d,h*w){
		dp[i]=dp[i-d]+fabs(pl[i][0]-pl[i-d][0])+fabs(pl[i][1]-pl[i-d][1]);
	}
	int q,l,r;
	cin>>q;
	FOR(i,0,q){
		cin>>l>>r;
		cout<<dp[r]-dp[l]<<endl;
	}

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
#include <string>
#include <algorithm>
#define ll long long
int main()
{
    ll sx,sy,x,y;
    ll mx,my;
    cin>>sx>>sy>>x>>y;
    mx=sx;my=sy;
    while(my!=y)
    {
            if(my<y)
            {
                my++;
                cout<<"U";
                continue;
            }
    }

    while(mx!=x)
    {
        if(mx<x)
        {
            mx++;
            cout<<"R";
            continue;
        }
    }
    while(my!=sy)
    {
            if(my>sy)
            {
                my--;
                cout<<"D";
                continue;
            }
    }
       while(mx!=sx)
    {
        if(mx>sx)
        {
            mx--;
            cout<<"L";
            continue;
        }
    }
    cout<<"L";
    for(int i=0;i<y-sy+1;i++)
    {
        cout<<"U";
    }
    for(int i=0;i<x-sx+1;i++)
    {
        cout<<"R";
    }
    cout<<"DR";
    for(int i=0;i<y-sy+1;i++)
    {
        cout<<"D";
    }
     for(int i=0;i<x-sx+1;i++)
    {
        cout<<"L";
    }
    cout<<"U";
    return 0;
}



Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main()
{
	string S, T;
	cin >> S >> T;
	int counter = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] != T[i])
		{
			counter++;
		}
	}
	cout << counter << endl;
}

Measured memory_bytes: 3920
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

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

		List<C> list = new ArrayList<>();
		// x-l と x + l は判定上セーフ つまり、siとejが同じでもOK
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int l = sc.nextInt();
			list.add(new C(Math.max(0, x - l), x + l));
		}
		list.sort(new Comparator<C>() {
			@Override
			public int compare(C o1, C o2) {
				// TODO Auto-generated method stub
				return o1.e.compareTo(o2.e);
			}
		});

		int posXL = 0;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			C c = list.get(i);
			if (posXL <= c.s) {
				sum++;
				posXL = c.e;
			}
		}
		System.out.println(sum);
	}

	public static class C {
		public Integer s;
		public Integer e;

		public C(int s, int e) {
			this.s = s;
			this.e = e;
		}
	}
}


Measured memory_bytes: 98204
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;

ll a,b;

int main()
{

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

    cin >> a >> b;
    if( b>=a ){
        cout << "unsafe";
    }else{
        cout << "safe";
    }

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

typedef long long ll;

ll A, ans;
string B;

int inte(string x);
int dec(string x);

int main(void) {
  cin >> A >> B;
  ll intb = inte(B);
  ll decb = dec(B);
  ll ans = A*intb + A*decb/100;
  cout << ans << endl;
  return 0;
}

int inte(string x){
  int n = x.size();
  istringstream ss;
  ss = istringstream(x.substr(0,n-2));
  int num;
  ss >> num;
  return num;
}

int dec(string x) {
  int n = x.size();
  istringstream ss;
  ss = istringstream(x.substr(n-2,2));
  int num;
  ss >> num;
  return num;
}


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

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

  string s; cin >> s;

  int w = 0;
  int l = 0;
  int g = 0;
  int p = 0;
  rep(i, s.size()) {
    if(s[i] == 'g') {
      if(g == p) {
        g++;
      } else {
        p++;
        w++;
      }
    } else {
      if(g == p) {
        g++;
        l++;
      } else {
        p++;
      }
    }
  }

  cout << w - l << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;
 
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}
 
int main() {
	int W,a,b;
  	cin >> W>>a>>b;
  	int ans;
	if(b >= a+W) ans = b-a-W;
  	else if (b<a+W && b > a - W) ans =0;
  	else ans = a-b-W;
  	cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
edges = [[] for i in range(N)]
e_list = []

for i in range(N-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    e_list.append((a,b))
    edges[a].append((b,i))
    edges[b].append((a,i))
ans = [0] * (N-1)

"""
bfs pattern
"""
q = deque()
next_v = edges[0]
for c, (u,i) in enumerate(next_v):
    q.append((u, i, c+1))
    ans[i] = c+1

while q:
    u_p, _, c_p = q.popleft()
    next_v = edges[u_p]
    cnt = 1
    for u, i in next_v:
        # すでに彩色されている辺はダメ
        if ans[i] > 0:
            continue
        # 親と色がかぶったら+1
        if cnt == c_p:
            cnt += 1
        ans[i] = cnt
        q.append((u,i,cnt))
        
        cnt += 1

print(max(ans))
for a in ans:
    print(a)

Measured memory_bytes: 47400
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=2005;
const int MOD=998244353;

int n,k,a[N*3],rev[N*3],f[N][N*3],g[N][N*3],L,ny,w1[N*3],w2[N*3],ans[N];

int ksm(int x,int y)
{
	int ans=1;
	while (y)
	{
		if (y&1) ans=(LL)ans*x%MOD;
		x=(LL)x*x%MOD;y>>=1;
	}
	return ans;
}

void NTT(int *a,int f)
{
	for (int i=0;i<L;i++) if (i<rev[i]) std::swap(a[i],a[rev[i]]);
	for (int i=1;i<L;i<<=1)
	{
		int wn=(f==1?w1[i]:w2[i]);
		for (int j=0;j<L;j+=(i<<1))
		{
			int w=1;
			for (int k=0;k<i;k++)
			{
				int u=a[j+k],v=(LL)a[j+k+i]*w%MOD;
				a[j+k]=(u+v)%MOD;a[j+k+i]=(u+MOD-v)%MOD;
				w=(LL)w*wn%MOD;
			}
		}
	}
	if (f==-1) for (int i=0;i<L;i++) a[i]=(LL)a[i]*ny%MOD;
}

void pre()
{
	int lg=0;
	for (L=1;L<=n*2;L<<=1,lg++);
	for (int i=0;i<L;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg-1));
	for (int i=1;i<L;i<<=1) w1[i]=ksm(3,(MOD-1)/i/2),w2[i]=ksm(3,MOD-1-(MOD-1)/i/2);
	ny=ksm(L,MOD-2);
	for (int i=0;i<=n;i++) f[1][i]=1,g[1][i]=2;
	g[1][0]=f[0][0]=g[0][0]=1;
	NTT(f[1],1);NTT(g[1],1);NTT(f[0],1);NTT(g[0],1);
	for (int i=2;i<=k/2;i++)
	{
		for (int j=0;j<L;j++) f[i][j]=(LL)f[i-1][j]*f[1][j]%MOD,g[i][j]=(LL)g[i-1][j]*g[1][j]%MOD;
		NTT(f[i],-1);NTT(g[i],-1);
		for (int j=n+1;j<=n*2;j++) f[i][j]=g[i][j]=0;
		NTT(f[i],1);NTT(g[i],1);
	}
	for (int i=k/2+1;i<=k;i++)
	{
		for (int j=0;j<L;j++) f[i][j]=(LL)f[i-1][j]*f[1][j]%MOD;
		NTT(f[i],-1);
		for (int j=n+1;j<=n*2;j++) f[i][j]=0;
		NTT(f[i],1);
	}
}

int main()
{
	scanf("%d%d",&k,&n);
	pre();
	for (int i=2;i<=k+1;i++)
	{
		int s=0;
		for (int j=1;j<=k;j++) if (j*2!=i&&j<i&&i-j<=k) s++;
		for (int j=0;j<L;j++) a[j]=(LL)f[std::max(0,k-s-((i&1)?0:1))][j]*g[s/2][j]%MOD;
		NTT(a,-1);
		if (i&1) printf("%d\n",ans[i]=a[n]);
		else printf("%d\n",ans[i]=(a[n]+a[n-1])%MOD);
	}
	for (int i=k+2;i<=k*2;i++) printf("%d\n",ans[k-(i-(k+2))]);
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  ll t = 8*n+1;
  ll fac = 0;

  for(int i=1; i*i<=t; i++){
    if(i*i==t){
      fac = i;
      break;
    }
  }
  if(!fac){ cout<<"No"; return 0; }

  ll k = (fac+1)/2;
  vector<vector<ll>> results(k, vector<ll>(k-1));

  ll s = 1;
  rep(i, k-1){
    rep(j, k-1-i){
      results[i][j+i]=s;
      results[j+1+i][i]=s;
      s++;
    }
  }

  cout<<"Yes"<<endl;
  cout<<k<<endl;

  rep(i, k){
    cout<<k-1<<' ';
    rep(j, k-1){
      cout<<results[i][j]<<' ';
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll A, B, C, D;
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
    printf("%lld\n", min(A,B)+min(C,D));
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if((a + b + c ) >= 22){
			System.out.println("bust");
		}else{
			System.out.println("win");
		}
		
	}
		
		
}

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

Ai.sort(key=lambda x:x[0])

cost = 0
remain = M
for a in Ai:
    if remain == 0:
        break
    buy_num = min(a[1], remain)
    cost += a[0] * buy_num
    remain -= buy_num
print(cost)

Measured memory_bytes: 29028
#include <bits/stdc++.h>
	using namespace std;
	#define mod 1000000007
	#define fi first
	#define se second
	#define mp make_pair
	#define pb push_back
	#define ps push
	#define pll pair<long,long>
	typedef long long ll;
	#define PI 3.14159265
	
	ll n,m,s1,t;
	const ll INF=(ll)1e16;
	
	
	int main()
	{
		ios::sync_with_stdio(0); 
		cin.tie(0); 
		cout.tie(0);
		
		cin>>n>>m>>s1>>t;
		
		vector<pll> g1[100050];
		vector<pll> g2[100050];
		for(ll i=0;i<m;i++)
		{
			ll u,v,c1,c2;
			cin>>u>>v>>c1>>c2;
			g1[u].pb({v,c1});
			g1[v].pb({u,c1});
			g2[u].pb({v,c2});
			g2[v].pb({u,c2});
		}
		multiset<pair<ll,ll> > s;
		vector<ll> dist1(n+1,INF),dist2(n+2,INF);
		bool vis[100050];
		memset(vis,false,sizeof(vis));
		s.insert({0,s1});
		dist1[s1]=0;
		dist2[t]=0;
		
		
			 while(!s.empty()){

        pair <ll , ll> p = *s.begin();        
        s.erase(s.begin());

        ll x = p.se; ll wei = p.fi;
        if( vis[x] ) continue;                 
         vis[x] = true;
        for(ll i = 0; i < g1[x].size(); i++){
            ll e = g1[x][i].fi; ll w = g1[x][i].se;
            if(dist1[x] + w < dist1[e]  ){            
                dist1[e] = dist1[x] + w;
                s.insert({dist1[e],  e} );           
        }
			
		}
		}
		
		memset(vis,false,sizeof(vis));	
		s.insert({0,t});
	
			 while(!s.empty()){

        pair <ll , ll> p = *s.begin();        
        s.erase(s.begin());

        ll x = p.se; ll wei = p.fi;
        if( vis[x] ) continue;                 
         vis[x] = true;

        for(ll i = 0; i < g2[x].size(); i++){
            ll e = g2[x][i].fi; ll w = g2[x][i].se;
            if(dist2[x] + w < dist2[e]  ){            
                dist2[e] = dist2[x] + w;
                s.insert({dist2[e],  e} );           
        }
			
		}
		}
		
		set<pll> dist;
		for(ll i=1;i<=n;i++)
		{
			dist.insert({dist1[i]+dist2[i],i});
		}
		ll ans=1e15;
		ll cnt=1;
		for(auto i:dist)
		{
			if(i.se<cnt)
				continue;
			if(i.se>=cnt)
			{
				//cout<<i.se<<" "<<i.fi<<endl;
				for(;cnt<=i.se;cnt++)
				{
					cout<<ans-i.fi<<endl;
				}
			}
			
		}
	}		


Measured memory_bytes: 24448
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

solve :: Int -> Int -> Int
solve !x !a | x < a  = 0
            | x >= a = 10

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (x, a) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  print $ solve x a


Measured memory_bytes: 380
n = int(input())

x, y = divmod(n, 100)

can_month1 = 1 <= x <= 12
can_month2 = 1 <= y <= 12

ans = "NA"
if can_month1 and can_month2:
    ans = "AMBIGUOUS"
elif can_month1:
    ans = "MMYY"
elif can_month2:
    ans = "YYMM"

print(ans)


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N, C;
  cin >> N >> C;
  int s, t, c;
  vector<vector<int>> d(C + 10, vector<int>(100100));
  for (int i = 0; i < N; i++) {
    cin >> s >> t >> c;
    d[c - 1][s] += 1;
    d[c - 1][t + 1] += -1;
  }
  for (int i = 0; i < C; i++) {
    for (int j = 1; j < 100001; j++) {
      d[i][j] += d[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 0; i < 100001; i++) {
    int tmp = 0;
    for (int j = 0; j < C; j++) {
      if (d[j][i])
        tmp++;
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 16256