akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7


def run():
    S = input()
    SS = []
    dic = {'A': -1, 'B' : -2, 'C' : -3}
    chain = False
    skip = False
    for i in range(len(S)):
        if not chain:
            if S[i:i+2] == 'BC':
                chain = True
                skip = True
                SS.append(1)
            else:
                SS.append(dic[S[i]])
        else:
            if skip:
                skip = False
                continue
            else:
                if S[i:i+2] == 'BC':
                    skip = True
                    SS[-1] += 1
                else:
                    SS.append(dic[S[i]])
                    chain = skip = False
    #print(SS)
    ans = 0
    BCbox = 0
    for x in SS[::-1]:
        if x > 0:
            BCbox += x
        elif x == -1:
            ans += BCbox
        else:
            BCbox = 0
    print(ans)



if __name__ == "__main__":
    run()


Measured memory_bytes: 12432
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[1005],b[1005];
bool ok[1005][10];
set<int> v;
int n;
int vis[55][55];
bool dfs(int x,int y)
{
    if (x==y) return true;
    if (x<y*2) return false;
    if (vis[x][y])
    {
        if (vis[x][y]==-1) return false;
        return true;
    }
    vis[x][y]=-1;
    set<int>::iterator ii;
    for (ii=v.begin();ii!=v.end();ii++)
    {
        if (dfs(x%(*ii),y))
        {
            vis[x][y]=true;
            return true;
        }
    }
    return false;
}
bool check()
{
    int i;
    memset(vis,0,sizeof(vis));
    for (i=0;i<n;i++)
    {
        if (!dfs(a[i],b[i])) return false;
    }
    return true;
}
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (i=0;i<n;i++)
    {
        scanf("%d",&b[i]);
    }
    for (i=1;i<=50;i++)
    {
        v.insert(i);
    }
    if (!check())
    {
        printf("-1\n");
        return 0;
    }
    long long ans=0;
    for (i=50;i>=1;i--)
    {
        v.erase(i);
        if (!check())
        {
            v.insert(i);
            ans+=(1ll<<i);
        }
    }
    cout<<ans<<endl;
    return 0;
} 


Measured memory_bytes: 384
a,b,c = gets.chomp.split("/").map(&:to_i)
ret = "Heisei"
tbd = "TBD"
if(a > 2019)
  ret = tbd
elsif(a == 2019 && b > 4)
  ret = tbd
elsif(b == 4 && c > 30)
  ret = tbd
end
puts ret


Measured memory_bytes: 1788
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll N;cin>>N;
    
	// 解法
	ll ans = 0;
	ll count = 0;
	REP(i,N+1){
		if (i%3!=0 & i%5!=0) ans += i;
	}
	//出力
	printf("%lld\n", ans);
}


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

using namespace std;

typedef long long ll;

const ll INF = 1LL << 60;

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

    ll N;
    ll M;
    cin >> N >> M;

    map<pair<ll, ll>, vector<pair<ll, pair<ll, ll>>>> G;
    map<pair<ll, ll>, bool> T; // tmp
    map<pair<ll, ll>, ll> C;

    for (ll i = 0; i < M; ++i) {
        ll p;
        ll q;
        ll c;

        cin >> p >> q >> c;
        p--;
        q--;

        G[make_pair(p, c)].push_back( make_pair(0, make_pair(q, c)) );
        G[make_pair(q, c)].push_back( make_pair(0, make_pair(p, c)) );

        if (!T[make_pair(p, c)]) {
            T[make_pair(p, c)] = true;
            G[make_pair(p, c)].push_back(make_pair(1, make_pair(p, 0)));
            G[make_pair(p, 0)].push_back(make_pair(1, make_pair(p, c)));
            C[make_pair(p, c)] = INF;
            C[make_pair(p, 0)] = INF;
        }
        if (!T[make_pair(q, c)]) {
            T[make_pair(q, c)] = true;
            G[make_pair(q, c)].push_back(make_pair(1, make_pair(q, 0)));
            G[make_pair(q, 0)].push_back(make_pair(1, make_pair(q, c)));
            C[make_pair(q, c)] = INF;
            C[make_pair(q, 0)] = INF;
        }
    }

    for (ll i = 0; i < N; ++i) {
        C[make_pair(i, 0)] = INF;
    }

    priority_queue<pair<ll, pair<ll, ll>>> Q;
    Q.push(make_pair(-0, make_pair(0, 0)));

    ll ans = INF;

    while (!Q.empty()) {
        ll c = -Q.top().first;
        pair<ll, ll> p = Q.top().second;

        Q.pop();
        
        if (c < C[p]) {
            //cout << p.first << ", " << p.second << ", cost: " << c << endl;

            C[p] = c;

            for (pair<ll, pair<ll, ll>> np : G[p]) {
                Q.push(make_pair(- (np.first + c), np.second));
            }

            if (p.first == N-1 && p.second == 0) {
                ans = c;
                break;
            }
        }
    }

    if (ans < INF) {
        cout << ans / 2 << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 141168
#!/usr/bin/env python3

import sys

def solve(n, ls_a):
    numEven = len([a for a in ls_a if a % 2 == 0])
    print(3 ** n - 2 ** numEven)

def readQuestion():
    ws = sys.stdin.readline().strip().split()
    n = int(ws[0])
    ws = sys.stdin.readline().strip().split()
    ls_a = list(map(int, ws))
    return (n, ls_a,)

def main():
    solve(*readQuestion())

# Uncomment before submission
main()


Measured memory_bytes: 2940
<?php

while (true) {
    $dataCount = trim(fgets(STDIN));
    if ($dataCount == 0) { return; }
    
    for ($i = 0; $i < $dataCount; $i++) {
        list($employeeNum, $ratio, $sale) = explode(' ', trim(fgets(STDIN)));
        if (empty($dataSet[$employeeNum])) {
            $dataSet[$employeeNum] = $ratio * $sale;
        } else {
            $dataSet[$employeeNum] += $ratio * $sale;
        }
    }
    
    foreach ($dataSet as $key => $value) {
        if ($value >= 1000000) {
            $okEmployee[] = $key;
        }
    }
    
    if (empty($okEmployee)) {
        echo 'NA', PHP_EOL;
    } else {
        echo implode(PHP_EOL, $okEmployee), PHP_EOL;
    }
    
    unset($i);
    unset($dataSet);
    unset($okEmployee);
    

}

Measured memory_bytes: 15524
import java.util.Scanner;

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

		int N=sc.nextInt();
		int K=sc.nextInt();
		int[] x=new int[N];
		int sum=0;

		int ans=0;
		int inp=0;
		for(int i=0; i<N; i++) {
			inp=sc.nextInt();
			ans=Math.min(inp, K-inp);
			sum+=ans*2;
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21204
// Problem : E - Knapsack 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ll)1e12
#define re 			resize
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n,W;
		cin>>n>>W;
		vi dp(N+1,hell);
		dp[0]=0;
		rep(j,0,n)
		{
		    int w,v;
		    cin>>w>>v;
		    for(int i=N-v;i>=0;i--)
		        dp[i+v]=min(dp[i+v],dp[i]+w);
		}
		int ans=0;
		rep(i,0,N+1) if(dp[i]<=W) ans=i;
		cout<<ans;
	}
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int main() {
    int h, n; cin >> h >> n;
    vector<vector<int>> dp(n+1, vector<int>(h+1, 1e9));
    dp[0][0] = 0;
    rp(i, 1, n+1) {
        int a, b; cin >> a >> b;
        rp(j, 0, h+1) {
            dp[i][j] = min(dp[i-1][j], dp[i][max(0, j-a)] + b);   
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}


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

ll v[3100][3100], dp[3100][3100][4];
int main(){
    ll r,c,k;
    cin >> r >> c >> k;
    for(int i=0; i<3100; i++){
        for(int j=0; j<3100; j++){
            v[i][j]=0;
            for(int k=0; k<4; k++){
                dp[i][j][k]=0;
            }
        }
    }
    for(int i=0; i<k; i++){
        int a,b,c;
        cin >> a >> b;
        a--;b--;
        cin >> c;
        v[a][b]=c;
    }
    if(v[0][0]>0) dp[0][0][1]=v[0][0];
    for(int i=0; i<3100; i++){
        for(int j=0; j<3100; j++){
            for(int k=0; k<4; k++){
                if(i-1>=0){
                    dp[i][j][0]=max(dp[i][j][0], dp[i-1][j][k]);
                    dp[i][j][1]=max(dp[i][j][1], dp[i-1][j][k]+v[i][j]);
                }
                if(j-1>=0){
                    dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k]);
                    if(k>=1){
                        dp[i][j][k]=max(dp[i][j][k], dp[i][j-1][k-1]+v[i][j]);
                    }
                }
            }
        }
    }
    ll ans=0;
    for(int k=0; k<4; k++){
        ans = max(ans, dp[r-1][c-1][k]);
    }
    cout << ans << endl;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

struct CustomCompare
{
    bool operator()(const int& lhs, const int& rhs)
    {
        return lhs < rhs;
    }
};

bool comp(pair<ll, ll>a,pair<ll,ll>b)
{
    return a.fi>=b.fi;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
ll n; cin>>n;
ll cnt = 0;
for(ll i = 1;i<=n;i++)
{
    ll x; cin>>x;
    if(i%2&&x%2)cnt++;
}
cout<<cnt<<endl;
return 0;

}
/*
1
8
1 7 3 4 7 6 2 9
*/


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

using namespace std;

bool ask(int x)
{
    cout << x << "\n";
    string s;   cin >> s;
    if(s[0] == 'V') exit(0);
    return (s[0] == 'M');
}

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

    int n;  cin >> n;

    int l = 0, r = n - 1;

    bool L = ask(l);
    bool R = ask(r);

    while(l < r - 1)    {
        int m = (l + r) / 2;
        bool M = ask(m);
        if((m - l) & 1) {
            if(L == M)  r = m, R = M;
            else        l = m, L = M;
        }
        else    {
            if(L == M)  l = m, L = M;
            else        r = m, R = M;
        }
    }
    ask(l);
    ask(r);
}


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

enum Sauce{ NOT_DETERMINED = 0, Tomato = 1, Cream = 2, Basil = 3 };
enum Seq{ SAME, DIFF };

const int divisor = 10000;

class Pasta{
public:
	Pasta(int _N);
	~Pasta();

	void setSauce(int A, Sauce B){ sauceary[A] = B; }
	int schedule(int i, Sauce yesterday, Seq seq);

private:
	int N;
	int*** memo;
	Sauce* sauceary;
};

Pasta::Pasta(int _N){
	N = _N;
	sauceary = new Sauce[N + 1];
	memo = new int**[N + 1];

	for (int i = 0; i <= N; i++) sauceary[i] = NOT_DETERMINED;

	for (int i = 0; i <= N; i++){
		memo[i] = new int*[4];
		for (int j = 0; j < 4; j++){
			memo[i][j] = new int[2];
			memo[i][j][SAME] = -1;
			memo[i][j][DIFF] = -1;
		}
	}
}

Pasta::~Pasta(){
	delete[] sauceary;
	delete[] memo;
}

int Pasta::schedule(int i, Sauce yesterday, Seq seq){
	if (i == N + 1) return 1;
	if (memo[i][yesterday][seq] >= 0) return memo[i][yesterday][seq];

	if (seq == SAME && yesterday == sauceary[i]){
		memo[i][yesterday][SAME] = 0;
		return 0;
	}

	if (sauceary[i] == NOT_DETERMINED){
		int tmpmemo = 0;

		for (int si = 1; si <= 3; si++){
			if ((Sauce)si == yesterday && seq == SAME) continue;
			else if ((Sauce)si == yesterday && seq == DIFF) tmpmemo += schedule(i + 1, (Sauce)si, SAME) % divisor;
			else tmpmemo += schedule(i + 1, (Sauce)si, DIFF) % divisor;
		}

		memo[i][yesterday][seq] = tmpmemo % divisor;
		return memo[i][yesterday][seq];
	}
	else {
		if (yesterday == sauceary[i]) memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], SAME) % divisor;
		else memo[i][yesterday][seq] = schedule(i + 1, sauceary[i], DIFF) % divisor;
			
		return memo[i][yesterday][seq];
	}
}

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

	Pasta* pasta = new Pasta(N);

	for (int i = 0; i < K; i++){
		int A, B;
		cin >> A >> B;
		pasta->setSauce(A, (Sauce)B);
	}

	cout << pasta->schedule(1, NOT_DETERMINED, DIFF) << endl;

	delete pasta;
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
using Ps=pair<int,string>;

int main(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    sort(rall(a));
    ll ans=a[0];
    int cnt=0;
    int now=1;
    rep(i,n-2){
        if(cnt==2){
            now++;
            cnt=1;
        }
        else{
            cnt++;
        }
        ans+=a[now];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4032
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
#include <cstring>
#include <math.h>

int main() {
	int n, k;
	std::cin >> n >> k;
	std::vector <int> h(n);
	int r = 0;
	for (int i = 0;i < n;++i) {
		std::cin >> h[i];
		if (h[i] >= k) {
			r += 1;
		}
	}
	std::cout << r << std::endl;
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(n)
from collections import Counter
c = Counter(a)
ans = 0
for i in c.keys():
    cnt = 1
    while c[i] >= cnt:
        ans += 1
        c[i] -= cnt
        cnt += 1
print(ans)



Measured memory_bytes: 65800
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

typedef long long ll;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;

const double PI = acos(-1.0);

int N,M;
vector<vector<pair<int,int>>> Graph;
vector<int> A;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin>>N>>M;
    Graph.resize(N);
    A.assign(N,-1);
    print(A);
    rep(i,M){
        int x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        z %= 2;
        Graph[x].push_back({y,z});
        Graph[y].push_back({x,z});
    }
    queue<int> Q;
    int cnt = 0;
    rep(i,N){
        if(A[i]==-1){
            Q.push(i);
            cnt++;
            while(!Q.empty()){
                auto xi = Q.front();
                A[xi] = 0;
                cerr<<xi<<endl;
                Q.pop();
                for(auto nx:Graph[xi]){
                    int cost = nx.second;
                    if(A[nx.first]!=-1)continue;
                    cerr<<'\t'<<nx.first<<endl;
                    if(A[xi] % 2 == 0){
                        if(cost % 2 == 0){
                            A[nx.first] = 0;
                        }
                        else{
                            A[nx.first] = 1;
                        }
                    }
                    else{
                        if(cost%2 == 0){
                            A[nx.first] = 1;
                        }
                        else{
                            A[nx.first] = 0;
                        }
                    }
                    Q.push(nx.first);
                }
            }
        }
    }
    print(A);
    cout<<cnt<<endl;
}

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

typedef long long llint;

using namespace std;

const int MAXN = 100005;
const int INF = 1000000007;

llint n, dva, sol;
int par[MAXN], siz[MAXN];
vector < pair <int, llint> > v[MAXN];

void dfs (int x, int rod) {
    par[x] = rod;
    siz[x] = 1;
    for (int i=0; i<v[x].size(); i++) {
        int sus = v[x] [i].first;
        if (sus == rod) continue;
        dfs(sus, x);
        siz[x] += siz[sus];
    }
}

int nadi (int x) {
    int mx = 0, ind;
    for (int i=0; i<v[x].size(); i++) {
        int sus = v[x] [i].first;
        int val;
        if (sus == par[x]) val = siz[1] - siz[x]; else val = siz[sus];
        if (val > mx) {
            mx = val;
            ind = i;
        }
    }
    if (mx * 2 > n) {
        return nadi(v[x] [ind].first);
    } else {
        if (mx * 2 == n) dva = v[x] [ind].second;
        return x;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i=0; i<n-1; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        v[a].push_back(make_pair(b, c));
        v[b].push_back(make_pair(a, c));
    }
    dfs(1, 0);
    int cen = nadi(1);
    dfs(cen, 0);
    for (int i=1; i<=n; i++) {
        for (int j=0; j<v[i].size(); j++) {
            int sus = v[i] [j].first;
            if (sus == par[i]) continue;
            sol += siz[sus] * v[i] [j].second * 2;
        }
    }
    if (dva) {
        sol -= dva;
    } else {
        llint mn = INF;
        for (int i=0; i<v[cen].size(); i++) {
            mn = min(mn, v[cen] [i].second);
        }
        sol -= mn;
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
double deg60 = M_PI * 60.0 / 180.0;
struct Vec {
  double x;
  double y;
};
void printVec(Vec v) {
  cout << fixed << setprecision(12) << v.x << ' ' << v.y << endl;
}
void koch(int d, Vec p1, Vec p2) {
  if (d == 0) return;
  Vec s, t, u;
  s = Vec{(2 * p1.x + p2.x) / 3, (2 * p1.y + p2.y) / 3};
  t = Vec{(p1.x + 2 * p2.x) / 3, (p1.y + 2 * p2.y) / 3};
  u = Vec{(t.x - s.x) * cos(deg60) - (t.y - s.y) * sin(deg60) + s.x,
          (t.x - s.x) * sin(deg60) + (t.y - s.y) * cos(deg60) + s.y};
  koch(d - 1, p1, s);
  printVec(s);
  koch(d - 1, s, u);
  printVec(u);
  koch(d - 1, u, t);
  printVec(t);
  koch(d - 1, t, p2);
}
int main() {
  int n;
  cin >> n;
  Vec p1{0, 0}, p2{100, 0};
  printVec(p1);
  koch(n, p1, p2);
  printVec(p2);
}


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

namespace geometry {
	using Real = double;
	using Point = complex<Real>;
	constexpr Real EPS = 1e-9;
	// 誤差を考慮した符号
	inline int sgn(const Real x) {
		return (x > EPS) - (x < -EPS);
	}
	// 誤差を考慮した l - r の符号
	inline int sgn(const Real l, const Real r) {
		return sgn(l - r);
	}
	struct Circle {
		Point p;
		Real r;
		Circle(const Point p, const Real r) : p(p), r(r) {}
	};
	struct Line {
		Point a, b;
		Line(const Point a, const Point b) : a(a), b(b) {}
	};
	// 内積
	inline Real dot(const Point& lhs, const Point& rhs) {
		return (conj(lhs) * rhs).real();
	}
	// 外積
	inline Real cross(const Point& lhs, const Point& rhs) {
		return (conj(lhs) * rhs).imag();
	}
	// 円の交点
	vector<Point> intersect(const Circle& c1, const Circle& c2) {
		const Real dist = abs(c1.p - c2.p);
		vector<Point> ret;
		if(dist > c1.r + c2.r) return ret;
		if(dist < abs(c1.r - c2.r)) return ret;
		const Real rc = (dist * dist + c1.r * c1.r - c2.r * c2.r) / (2 * dist);
		const Real rs = sqrt(c1.r * c1.r - rc * rc);
		const Point vec = (c2.p - c1.p) / dist;
		ret.emplace_back(c1.p + vec * Point(rc, rs));
		ret.emplace_back(c1.p + vec * Point(rc, -rs));
		return ret;
	}
	// a の b に対する正射影ベクトル
	inline Point projection(const Point& a, const Point& b) {
		return b * dot(a, b) / norm(b);
	}
	// 点pから直線lに下ろした垂線の足
	inline Point projection(const Line& l, const Point& p) {
		return projection(p - l.a, l.b - l.a) + l.a;
	}
	// 直線lを対称軸として点pと線対称な点
	inline Point reflection(const Line &l, const Point &p) {
		return p + (projection(l, p) - p) * 2.0;
	}
	// 反時計回り(a -> b -> c)
	static constexpr int COUNTER_CLOCKWISE = 0b00001;
	// 時計回り(a -> b -> c)
	static constexpr int CLOCKWISE = 0b00010;
	// 同一直線上(c -> a -> b)
	static constexpr int ONLINE_BACK = 0b00100;
	// 同一直線上(a -> b -> c)
	static constexpr int ONLINE_FRONT = 0b01000;
	// 同一直線上(a -> c -> b)
	static constexpr int ON_SEGMENT = 0b10000;
	// 3点の位置関係
	int ccw(const Point &a, Point b, Point c) {
		b = b - a, c = c - a;
		if(cross(b, c) > EPS) return COUNTER_CLOCKWISE;
		if(cross(b, c) < -EPS) return CLOCKWISE;
		if(dot(b, c) < 0) return ONLINE_BACK;
		if(norm(b) < norm(c)) return ONLINE_FRONT;
		return ON_SEGMENT;
	}
	// 平行判定
	inline bool parallel(const Line& l1, const Line& l2) {
		return sgn(cross(l1.a - l1.b, l2.a - l2.b)) == 0;
	}
	// 直交判定
	inline bool orthogonal(const Line& l1, const Line& l2) {
		return sgn(dot(l1.a - l1.b, l2.a - l2.b)) == 0;
	}


	// 直線の交点
	// Point intersect(const Line& l1, const Line& l2) {
	// 	const Point v1 = l1.p2 - l1.p1;
	// 	const Point v2 = l2.p2 - l2.p1;

	// }

	inline istream& operator>>(istream& is, Point& p) {
		Real x, y;
		is >> x >> y;
		p = Point(x, y);
		return is;
	}
	inline ostream& operator<<(ostream& os, const Point &p) {
		return os << fixed << setprecision(15) << p.real() << " " << p.imag();
	}
}

using namespace geometry;
int main() {
	int q; cin >> q;
	while(q--) {
		Point p[4];
		for(int i = 0; i < 4; ++i) cin >> p[i];
		Line s1(p[0], p[1]);
		Line s2(p[2], p[3]);
		int ans = 0;
		if(parallel(s1, s2)) ans = 2;
		if(orthogonal(s1, s2)) ans = 1;
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 3236
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int X,A,B;
inline void solve(){
  IN3(X,A,B);
  OUT((X-A)%B);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

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

    for(int i = 0; i < s.size(); i++){
        s[i] = (char)(((int)s[i] - 65 + n) % 26 + 65);
    }

    cout << s << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

#define For(i,n) for(int i;i<n;i++)

int main(){
    int n;
    cin>>n;
    vector<int>vec(n);

    For(i,n){
        cin>>vec.at(i);
    }
        sort(vec.begin(),vec.end());
        reverse(vec.begin(),vec.end());
    int alice,bob;
    For(i,n){
        if(i%2==0){
            alice+=vec.at(i);
        }
        else
        {
            bob+=vec.at(i);
        }
    }
    cout<<alice-bob<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<ostream>
using namespace std;
int main(){
	int n,m;
	double sum=0;
	cin>>n>>m;
	double b[n+1];
	b[0]=0;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		b[i]=(b[i]+1)/2;
		b[i]+=b[i-1];
		if(i>=m){
			sum=max(sum,b[i]-b[i-m]);
		}
	}
	cout<<fixed<<setprecision(12)<<sum;
	return 0;
}

Measured memory_bytes: 1792
use proconio::*;
use proconio::marker::*;

#[fastout]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize, M: usize,
        A: [usize; M],
    }
    let ans: usize = A.iter().sum::<usize>();
    println!("{}",
        if N >= ans { (N - ans).to_string() } else { "-1".to_string() }
    )
}


Measured memory_bytes: 2192
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define endl '\n'
#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS() 
#else
#define bug(...)
#define IOS() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
const ll mod = 1e9+7;
const ll inf=1ll<<60;
const ll maxn=1005;

signed main() {
  IOS();
  int n,a,b; cin>>n>>a>>b;
  if (b<a||(b>a&&n==1)){
    cout<<0<<endl;
    return 0;
  }
  if (n<=2){
    cout<<1<<endl;
    return 0;
  }
  n-=2;
  cout<<b*n-a*n+1<<endl;

}

Measured memory_bytes: 256
S = input()
A = [0 for i in range(26)]
f = 0
for i in range(len(S)):
  a = ord(S[i]) - 97
  if A[a] != 0:
    print("no")
    f = 1
    break
  else:
    A[a] = 1
if f == 0:
  print("yes")

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

n = int(input())
exponent = [[0]*(n+1) for i in range(n+1)]

for i in range(2,n+1):
  for j in range(n+1):
    exponent[i][j] += exponent[i-1][j]
  Fi = factorization(i)
  for f in Fi:
    exponent[i][f[0]] += f[1]

c75,c25,c15,c5,c3 = 0,0,0,0,0
for e in exponent[n]:
  if e >= 74:
    c75 += 1
  if e >= 24:
    c25 += 1
  if e >= 14:
    c15 += 1
  if e >= 4:
    c5 += 1
  if e >= 2:
    c3 += 1
print(
  c75 + c25*(c3-c25)+c25*(c25-1) + c15*(c5-c15)+c15*(c15-1) + (c5*(c5-1))//2*(c5-2)+(c5*(c5-1))//2*(c3-c5)
    )

Measured memory_bytes: 39484
#include<stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);

	if (a < b)
	{
		printf("a < b\n");
	}
	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
n, k = (int(x) for x in input().split())
r, s, p = (int(x) for x in input().split())
t_ch = input()
t=[]
for i in range(n):
    t.append(t_ch[i])

for i in range(k, n):
    if t[i] == t[i-k]:
        t[i]=0
for i in range(0,n):
    if t[i]=="r":
        t[i]=p
    elif t[i]=="p":
        t[i]=s
    elif t[i]=="s":
        t[i]=r
print(sum(t))    


Measured memory_bytes: 4212
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = gcd(a,b);
		
		// 計算
		long result = 1;
		//System.out.println("n:" + n + "sqrt:" + sqrt(n));
		for(int m = 2; m <= sqrt(n); m++){
		    if(n == 1) break;
		    if(n%m == 0){
		        result++;
		        while(n%m == 0){
		            n = n/m;
		        }
		    }
		}
		if(n != 1) result++;
		// 出力
		System.out.println(result);
        
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(y == 0) return x;
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
}


Measured memory_bytes: 23124
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_

#define BIG 10000000000 //10

#define LAST 10000000 //10^7


LONG D;
vector<LONG> cost(26);
//vector<vector<ULONG>> sati(D + 1, vector<ULONG>(27));
vector<vector<LONG>> sati;
vector<LONG> answer;
vector<int> lastDate(26, -1);
LONG satVal = 0;


LONG calcSabunScore(int eventType, LONG date) {

	LONG sabun = sati[date][eventType];
	// costsum
	LONG costSum = 0;
	for (int i = 0; i < 26; i++) {
		if (i != eventType) {
			costSum += cost[i] * (date - lastDate[i]);
		}
	}

	sabun -= costSum;
	

	return sabun;

}


int main(void) {
	// for A

	cin >> D;

	vector<LONG> tmpans(D);
	answer = tmpans;


	for (int i = 0; i < 26; i++) {
		cin >> cost[i];
	}



	for (int d = 0; d < D; d++) {
		vector<LONG> tmpsati(26);
		for (int i = 0; i < 26; i++) {
			cin >> tmpsati[i];
		}
		sati.push_back(tmpsati);
	}
	// finish data input


	// answerを決める
	LONG totalScore = 0;
	for (int d = 0; d < D; d++) {
		int maxI = 0;
		LONG maxsabun = -1000000;
		for (int i = 0; i < 26; i++) {
			LONG sabun = calcSabunScore(i, d);
			if (sabun > maxsabun) {
				maxsabun = sabun;
				maxI = i;
			}
		}
		answer[d] = maxI;
		lastDate[maxI] = d;

		totalScore += maxsabun;

	}

	//randomchange
	int changeAtOnce = 2;
	int numChange = 100000;


	for (int c = 0; c < numChange; c++) {
		vector<LONG> answer2(D);

		for (int d = 0; d < D; d++)answer2[d] = answer[d];

		for (int cao = 0; cao < changeAtOnce; cao++) {
			int date = rand() % D;
			int newEvent = rand() % 26;

			answer2[date] = newEvent;
		}

			LONG totalScore2 = 0;

			// calc score
			for (int i = 0; i < 26; i++)lastDate[i] = -1;
			for (int d = 0; d < D; d++) {
				LONG sabun = calcSabunScore(answer2[d], d);
				totalScore2 += sabun;
				lastDate[answer2[d]] = d;
			}

			// これがよさそうならこれにする
			if (totalScore2 > totalScore) {
				totalScore = totalScore2;
				for (int d = 0; d < D; d++)answer[d] = answer2[d];
			}

		
	}


	// output
	for (int d = 0; d < D; d++) {
		cout << answer[d] + 1 << endl;
	}

	return 0;
}



Measured memory_bytes: 3728
import sys
import math
def main():
    A,B,H,M=tuple(map(int,sys.stdin.readline().split()))
    t,p=math.pi*(60.0*H+M)/360.0,math.pi*M/30.0
    xa,ya=A*math.cos(t),A*math.sin(t)
    xb,yb=B*math.cos(p),B*math.sin(p)
    l=math.sqrt((xb-xa)**2+(yb-ya)**2)
    print(l)
if __name__=='__main__':main()

Measured memory_bytes: 9520
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
   int a,b,c;
   scanf("%d%d%d",&a,&b,&c);
   if(a==5 && b==5 && c==7)
      printf("YES");
      
   else if(a==5 && c==5 && b==7)
       printf("YES");
       
    else if(a==7 && b==5 && c==5)
        printf("YES");
        
    else
       printf("NO");
   
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define pp pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define present(c,x) ((c).find(x) != (c).end())
#define mp make_pair
#define hell 1000000007
#define F first
#define S second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree<pp , null_type , less<pp> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t=1 ;
ll numdig( ll x )
{
    ll ans = 0 ;
    while( x > 0 )
    {
        ans++;
        x/=10;
    }
    return ans ;
}
string tostring( ll x )
{
    string ans = "" ;
    while(x>0)
    {
        char c = '0' ;
        rep( kk , 0 , x%10 )
            c++;
        ans+=c;
        x/=10;
    }
    reverse(all(ans));
    return ans;
}
void solve()
{
    ll n , m , x , y ;
    cin >> m >> n ;
    vector<pair<ll,ll> > vv ;
    map< ll,vector<pair<ll,ll> > > mapa ;
    rep( i , 0 , n )
    {
        cin >> x >> y ;
        mapa[x].pb( {y,i});
    }
    vector<string> ans( n ) ;
    rep( i , 1 , m+1 )
    {
        sort(all(mapa[i]));
        rep( j , 0 , sz(mapa[i]))
        {
            ll rank = j+1 , id = mapa[i][j].S ;
            string xx = "" ;
            rep( k , 0 , 6 - numdig(i) )
                xx+='0';
            xx+=tostring(i);
            rep( k , 0 , 6 - numdig(rank) )
                xx+='0';
            xx+=tostring(rank);
            ans[id]=xx;
            //cout << "id = " << id << " xx = " << xx << '\n' ;
        }
    }
    rep( i , 0 , n )
        cout << ans[i] << "\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


Measured memory_bytes: 17920
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
#define int ll
signed main(){
    int n; cin>>n;
    vector<int>v(n); rep(i,n)cin>>v[i];
    deque<int>deq;
    for(int i=1; i<=n;i++){
        if(n%2){
            if(i%2)deq.push_front(v[i-1]);
                else deq.push_back(v[i-1]);
        }else{
            if(i%2)deq.push_back(v[i-1]);
            else deq.push_front(v[i-1]);
        }
    }
    rep(i,n)if(i)cout<<" "<<deq[i]; else cout<<deq[i];
    cout<<endl;
}


Measured memory_bytes: 5376
import bisect


n = int(input())
A = list(map(int, input().split()))

edges = [[] for _ in range(n+1)]
for _ in range(n-1):
    from_, to = map(int, input().split())
    edges[from_].append(to)
    edges[to].append(from_)


DP = [10**9+7] * (n+1)
limit = 10**9 + 1
DP[0] = 0
olds = [None] * (n+1)
ans = [0] * n

todo = [1]
while todo:
    node = todo.pop()
    if node > 0:
        num = A[node-1]
        update_idx = bisect.bisect_left(DP, num)
        old = DP[update_idx]
        olds[node] = (old, update_idx)
        DP[update_idx] = num
        lis = bisect.bisect_left(DP, limit) - 1
        ans[node-1] = lis

        todo.append(-node)
        for to in edges[node]:
            if ans[to-1]:
                continue
            todo.append(to)

    else:
        node = -node
        old, update_idx = olds[node]
        DP[update_idx] = old

for res in ans:
    print(res)


Measured memory_bytes: 82012
// '
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef unsigned short sint;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
const ld TAU=2*acos(-1);
const ld eps=1e-8;
const int inf=1e9+99;
const ll linf=1e18+99;


const int P=1e9+7;
int powq(int x,int e) {
	if(!e) return 1;
	if(e&1) return int(1LL*powq(x,e-1)*x%P);
	x=powq(x,e>>1);
	return int(1LL*x*x%P);
}
int invq(int x) { return powq(x,P-2); }

int32_t main() {
	int n,X,Y; scanf("%d%d%d",&n,&X,&Y);
	vector<int> bycol[200<<10];
	for(int i=0;i<n;i++) {
		int c,w; scanf("%d%d",&c,&w);
		bycol[c-1].pb(w);
	}
	int lo=inf,lo2=inf;
	for(int i=0;i<n;i++) {
		if(!bycol[i].size()) continue;
		sort(bycol[i].begin(),bycol[i].end());
		int x=bycol[i][0];
		if(x<lo) lo2=lo, lo=x;
		else if(x<lo2) lo2=x;
	}
	if(lo>Y) return cout<<1<<endl,0;
	vector<int> V;
	for(int i=0;i<n;i++) {
		if(!bycol[i].size()) continue;
		bycol[i].pb(inf);
		int mi=bycol[i][0];
		int efflo = (mi==lo ? lo2 : lo);
		if(efflo+mi>Y) continue;
		int hi=max(X-mi,Y-efflo);
		int j=0;
		for(int w:bycol[i]) {
			if(w>hi) break;
			// cerr<<"wegood "<<i+1<<" at "<<w<<endl;
			++j;
		}
		V.pb(j);
	}

	static int F[200<<10],iF[200<<10];
	F[0]=1;
	for(int x=1;x<=n;x++) F[x]=int(1LL*F[x-1]*x%P);
	iF[n]=invq(F[n]);
	for(int x=n;x>=1;--x) iF[x-1]=int(1LL*iF[x]*x%P);
	int ss=accumulate(V.begin(),V.end(),0);
	ll Z=F[ss];
	for(int x:V) Z=Z*iF[x]%P;
	// for(int x:V) cerr<<x<<endl;
	cout<<Z<<endl;
}








Measured memory_bytes: 11512
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 'Yes'
    t0, x0, y0 = 0, 0, 0
    for _ in range(N):
        t, x, y = map(int, input().split())
        move = abs(x - x0) + abs(y - y0)
        time = t - t0
        if time >= move and (time - move) % 2 == 0:
            t0, x0, y0 = t, x, y
        else:
            ans = 'No'
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    N,m = i_map()
    l = [[0]*N for i in range(N)]

    for i in range(m):
        a,b = i_map()
        a -= 1
        b -= 1
        l[a][b] = 1
        l[b][a] = 1

    L = []

    def dfs(n,a):
        a = a + str(n)
        if len(a) == N:
            L.append(1)
            return

        for i in range(N):
            if l[n][i] == 1 and str(i) not in a:
                dfs(i,a)

    dfs(0,"")
    print(len(L))





if __name__=="__main__":
    main()


Measured memory_bytes: 73912
using System;
class Program {
    static void Main(string[] args) {
        var pass = Console.ReadLine();
        for(int i=0; i<3; i++) {
            if(pass[i] == pass[i + 1]) {
                Console.WriteLine("Bad");
                return;
            }
        }
        Console.WriteLine("Good");
    }
}

Measured memory_bytes: 13140
INF=float('inf')

N=int(input())
arr=list(map(int,input().split()))
A=[]
for i in range(N):
    A.append((arr[i],i))
A.sort(key=lambda x:x[0],reverse=True)
dp=[[-INF]*(N+1) for i in range(N+1)]
dp[0][0]=0

for i in range(N):
    a,w=A[i]
    for x in range(N+1):
        y=i-x+1
        if x>0:
            dp[i+1][x]=max(dp[i+1][x],dp[i][x-1]+a*abs(w-(x-1)))
        if y>=0:
            dp[i+1][x]=max(dp[i+1][x],dp[i][x]+a*abs(w-(N-y)))
print(max(dp[N]))

Measured memory_bytes: 201164
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <stdlib.h>
#define ll long long
#define MOD_P 1000000007
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<pair<int, int>>rep;
	ll int sum = 0LL;
	int size;
	int area;

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

	for (int i = 0; i < m; i++) {
		pair<int, int> tmp;
		cin >> tmp.second >> tmp.first;
		rep.emplace_back(tmp);
	}

	sort(rep.begin(), rep.end());
	sort(a.begin(), a.end());

	size = rep.back().second;
	area = rep.back().first;
	int i;

	for (i = 0; i < n; i++) {
		if (size > 0) {
			if (area > a[i]) {
				//printf("[%d](+%d)case:0\n", i + 1, area);
				sum += (ll int)area;
				size--;
			} else {
				//printf("[%d]case:1\n", i + 1);
				break;
			}
		} else {
			if (rep.size() == 1) {
				//printf("[%d]case:2\n", i + 1);
				break;
			} else {
				//printf("[%d]case:3", i + 1);
				rep.pop_back();
				size = rep.back().second;
				area = rep.back().first;
				i--;
				//printf("size = %d\n", rep.size());
			}

		}
	}

	for (; i < n; i++) {
		sum += (ll int) a[i];
	}

	printf("%lld", sum);

	return 0;
}

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

int main() {
  int n;
  cin>>n;
  int s=0;
  int x=n;
  while(n>0){
    s+=n%10;
    n/=10;
  }
  if(x%s==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		int[] readArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int S = fs.nextInt();
		long[] dp = new long[S + 1];

		dp[0] = 1;
		for (int i = 3; i <= S; i++) {
			for (int coins = 3; coins <= i; coins++) {
				dp[i] = (dp[i] + dp[i - coins]) % (long) (1e9 + 7);
			}
		}
		System.out.println(dp[S]);
	}
}


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

int main() {
  int num;
  int Max = 0;
  int tmp = 0;
  
  cin >> num;
  vector<int> vecOne(num);
  vector<int> vecTwo(num);
  
  for(int i = 0; i < num; i++) cin >> vecOne.at(i);
  for(int i = 0; i < num; i++) cin >> vecTwo.at(i);
  
  for(int i = 0; i < num; i++){
    tmp = 0;
    for(int j = 0; j <= i; j++){
      tmp += vecOne.at(j);
    }
    
    for(int j = i; j < num; j++){
      tmp += vecTwo.at(j);
    }
    
    Max = max(Max,tmp);
  }
  
  cout << Max;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String [] args){
    Scanner input = new Scanner(System.in);
    int num1 = input.nextInt();
    int num2= input.nextInt()/2;
    System.out.println(num1+num2);

    
    
  }
  
  
  
  
}
  
  
  

Measured memory_bytes: 23252