akhauriyash/Code-Regression huggingface dataset:
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop

# 素因数分解
def primes(n):
    ps = []
    i = 2
    while i * i <= n:
        while n % i == 0:
            ps.append(i)
            n //= i
        i += 1
    if n > 1:
        ps.append(n)
    return ps


def main():
    n = int(input())
    pl = []
    for i in range(1,n+1):
        pl += primes(i)

    counter = Counter(pl)
    # print(counter)
    ans = 1
    for v in counter.values():
        ans *= (v + 1)
        ans %= 1000000007
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39600
fun main() = abc167b()

@OptIn(ExperimentalStdlibApi::class)
fun abc167b() {
    val (a, b, c, k) = readLine()!!.split(' ').map { it.toLong() }


    val answer = if (a >= k) {
        k
    } else if (a + b >= k) {
        a
    } else {
        a - (k - a - b)
    }

    println(answer)
}


Measured memory_bytes: 36416
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
void updateBIT(ll BITree[], ll n, ll index, ll val) 
{ 
    index = index + 1; 
    while (index <= n) 
    { 
        BITree[index] += val; 
        index += index & (-index); 
    } 
} 
ll *constructBITree(ll arr[], ll n) 
{ 
    ll *BITree = new ll[n+1]; 
    for (ll i=1; i<=n; i++) 
        BITree[i] = 0; 
    for (ll i=0; i<n; i++) 
        updateBIT(BITree, n, i, arr[i]); 
    return BITree; 
} 
ll getSum(ll BITree[], ll index)  
{
	ll sum =0;
    index = index + 1; 
    while (index>0) 
    { 
        sum += BITree[index]; 
        index -= index & (-index); 
    } 
    return sum; 
} 
void update(ll BITree[], ll l, ll r, ll n, ll val) 
{ 
    updateBIT(BITree, n, l, val); 
    updateBIT(BITree, n, r+1, -val); 
} 
ll gcd(ll n1, ll n2) {
    if (n2 != 0)
        return gcd(n2, n1 % n2);
    else
        return n1;
}
ll pp(string str) 
{ 
    ll l = 0; 
    ll h = str.length() - 1; 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
	return 1; 
}
int main()
{
    ll t;
    t=1;
    while(t--)
    {
    	ll i,j,n,q;
    	cin>>n;
    	ll arr[n];
		ff(i,n)  cin>>arr[i];
		ll dp[n]={0};
		ff(i,n)  dp[arr[i]-1]++;
		ll ans=0;
		ff(i,n)
		{
		    ans+=(dp[i]*(dp[i]-1))/2;	
		}
		ff(i,n)
		{
			ll sub = dp[arr[i]-1];
			ll pl = sub-1;
			ll check = ans - (sub*(sub-1))/2 + (pl*(pl-1))/2;
		    cout<<check<<endl; 	
		}    	      
    }
    return 0;
}

Measured memory_bytes: 5760
R=range
while True:
    n,x=map(int,input().split())
    if n==x==0:
        break
    r=0
    for a in R(1,x//3):
        for b in R(a+1,x//2):
            c=x-a-b
            if b<c<=n:
                r+=1
    print(r)

Measured memory_bytes: 7632
#include <iostream>

using namespace std;

int main(){
  int i,j,n,a,b,c,h,ret=0;
  cin >> a >> b >> c >> n;
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(h=0;h<=c;h++){
        if(500*i+100*j+50*h==n)ret++;
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int x,y; cin >>x >> y;
  rep(i, x+1){
    int turu = i;
    int kame = x-i;
    if(i*2+4*kame==y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();

        sc.close();

        long count = 0;
        if (m >= n * 2) {
            count = n;
            m = m - n * 2;
            count += m / 4;
        } else {
            count += m / 2;
        }

        System.out.println(count);
    }
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  ll n, d;
  cin >> n >> d;
  vl x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  ll cnt = 0;
  d = d * d;
  rep(i, n) {
    if (x[i] * x[i] + y[i] * y[i] <= d) cnt++;
  }
  cout << cnt << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> pli;

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

	int n;
	cin >> n;

	ll a[n];
	ll asum = 0;

	rep(i, n) {
		cin >> a[i];
		asum += a[i];
	}

	ll b[n];
	vector<ll> v;
	ll bsum = 0;
	rep(i, n) {
		cin >> b[i];
		if(a[i] > b[i]) v.push_back(a[i] - b[i]);
		bsum += b[i];
	}

	if(asum < bsum){
		cout << -1 << endl;
		return 0;
	}

	sort(v.begin(), v.end(), greater<ll>());
	v.insert(v.begin(), 0);

	ll ans = 0;
	rep(i, n){
		ll d = b[i] - a[i];
		if(d <= 0) continue;

		ans++;
		while(d > 0){
			if(v[0] > d){
				v[0] -= d;
				d = 0;
			}else{
				d -= v[0];
				v.erase(v.begin());
				ans++;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n,k;
  string s;
  cin >> n >> k >> s;
  s.at(k-1)=s.at(k-1)-'A'+'a';
  cout << s << endl;
}


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

void solve(string s, int currentMax, int N) {
  if (s.length() == N) {
    cout << s << endl;
  } else {
    for (int i = 0; i < currentMax; i++) {
      solve(s + (char)('a' + i), currentMax, N);
    }
    solve(s + (char)('a' + currentMax), currentMax + 1, N);
  }
}

int main(void) {
  int N;
  cin >> N;
  solve("", 0, N);
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
bool S[13]={},H[13]={},C[13]={},D[13]={};
int main(){
	int n,number;char symbol;
	cin>>n;
	for (int i=0;i<n;i++){
	cin>>symbol;
	if (symbol=='S'){
		cin>>number;
		S[number-1]=true;
	}
	else if (symbol=='H'){
		cin>>number;
		H[number-1]=true;
	}
	else if (symbol=='C'){
		cin>>number;
		C[number-1]=true;
	}
	else {
		cin>>number;
		D[number-1]=true;
	}
	}
	for (int j=0;j<13;j++){
		if (S[j]==false) cout<<'S'<<' '<<j+1<<endl;
	}
	for (int j=0;j<13;j++){
		if (H[j]==false) cout<<'H'<<' '<<j+1<<endl;
	}
	for (int j=0;j<13;j++){
		if (C[j]==false) cout<<'C'<<' '<<j+1<<endl;
	}
	for (int j=0;j<13;j++){
		if (D[j]==false) cout<<'D'<<' '<<j+1<<endl;
	}
}


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

int main(){
    long long int h, w;
    cin >> h >> w;

    if(h == 1 || w == 1){
        cout << 1 << endl;
        return 0;
    }

    long long int ans = 0;
    if(h % 2 != 0 && w % 2 != 0) ans = (h-1) * w / 2 + (w+1)/2;
    else ans = h * w / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3464
n, m = map(int, input().split())
ci = []
for i in range(n + 1):
    ci.append(0)
for i in range(m):
    li = list(map(int, input().split()))
    for i in range(n + 1):
        if i in li:
            ci[i] += 1
for i in range(1, n + 1):
    print(ci[i])


Measured memory_bytes: 3060
#pragma GCC optimize("O2") 
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;

int main(){
	//freopen("in.txt","r",stdin);    
	ios::sync_with_stdio(0); cin.tie(0);
	int n,k;
	cin >> n >> k;
	int up = (n-1)*(n-2)/2;
	if(k > up){
		cout << -1 << endl;
	} else {
		int rem = up-k;
		cout << n-1+rem << endl;
		for(int i = 2; i <= n; ++i) {
			cout << 1 << " " << i << endl;
		}
		for(int i = 2; i <= n && rem; ++i){
			for(int j = i+1; j <= n && rem; ++j){
				cout << i << " " << j << endl;
				--rem;
			}
		}
	}
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

    vector<vector<int>> dist(N, vector<int>(N));
    for (int i = 0; i + 1 < N; i++) {
        for (int j = i + 1; j < N; j++) {
            dist[i][j] = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
            dist[j][i] = dist[i][j];
        }
    }

    int factorial = 1;
    for (int i = 1; i <= N; i++) factorial *= i;
    vector<int> path;
    for (int i = 0; i < N; i++) path.push_back(i);

    double sum = 0;
    do {
        for (int i = 0; i + 1 < N; i++) {
            sum += sqrt(dist[path[i]][path[i + 1]]);
        }
    } while(next_permutation(path.begin(), path.end()));

    cout << fixed << setprecision(15) << sum / factorial << endl;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int dp[1<<16];

int main(void){
	int n;
	while(cin >> n){
		if(n==0)
			break;
		rep(i,1<<16) dp[i]=0;
		rep(i,n){
			int m,l,mask=0;
			cin >> m >> l;
			rep(j,m){
				int s,e;
				cin >> s >> e;
				s-=6,e-=6;
				for(int k=s;k<e;++k)
					mask|=(1<<k);
			}
			rep(j,1<<16) if((j&mask)==0)
				dp[j|mask]=max(dp[j|mask],dp[j]+l);
		}
		int ans=0;
		rep(i,1<<16) ans=max(ans,dp[i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1416
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=2e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,p[N];
#define ls (k<<1)
#define rs (k<<1|1)
#define mid ((l+r)>>1)
#define lson ls,l,mid
#define rson rs,mid+1,r
pa mn[N][2];
il void pu(int k){rep(i,0,1)mn[k][i]=min(mn[ls][i],mn[rs][i]);}
#define rt 1,0,n-1
void build(int k,int l,int r){
	if(l==r){
		rep(i,0,1)mn[k][i]=pa(INF,l);
		mn[k][l&1]=pa(p[l],l);
		return;
	}
	build(lson);build(rson);
	pu(k);
}
void del(int k,int l,int r,int x){
	if(l==r){rep(i,0,1)mn[k][i]=pa(INF,l);return;}
	if(x<=mid)del(lson,x);else del(rson,x);
	pu(k);
}
pa ask(int k,int l,int r,int x,int y,int typ){
	if(l==x&&r==y)return mn[k][typ];
	if(y<=mid)return ask(lson,x,y,typ);else
	if(x> mid)return ask(rson,x,y,typ);else
		return min(ask(lson,x,mid,typ),ask(rson,mid+1,y,typ));
}
struct data{int l,r;pa val;};
bool operator>(data a,data b){return a.val>b.val;}
priority_queue<data,vector<data>,greater<data> >pq;
void add(int l,int r){
	if(l>r)return;
	pq.push((data){l,r,ask(rt,l,r,l&1)});
}
int main(){
	read(n);
	re(i,0,n)read(p[i]);
	build(rt);
	pq.push((data){0,n-1,mn[1][0]});
	re(i,0,n/2){
		data cur=pq.top();pq.pop();
		int pl=cur.l,pr=cur.r,id=cur.val.w2;
		int id2=ask(rt,id+1,pr,1^(pl&1)).w2;
		printf("%d %d ",p[id],p[id2]);
		del(rt,id);del(rt,id2);
		add(pl,id-1);
		add(id+1,id2-1);
		add(id2+1,pr);
	}
}

Measured memory_bytes: 23028
import itertools
n,m = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]

c = [0,1]
ans = 0
for l,j,k in itertools.product(c,repeat=3):
    ans = max(ans,sum(sorted([a[i][0]*(-1)**l+a[i][1]*(-1)**j+a[i][2]*(-1)**k for i in range(n)])[n-m:]))

print(ans)

Measured memory_bytes: 3432
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  bool b = false;
  REP(i, 3) {
    if (S[i] == S[i + 1]) {
      b = true;
      break;
    }
  }
  if (b) {
    cout << "Bad";
  } else {
    cout << "Good";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <math.h>
#include <bitset>
#include <fstream>
#define int long long
using namespace std;
signed main()
{
    int n, p, ai;
    vector<int> data;
    cin >> n >> p;
    for (int i=0; i <n; i++){
        cin >> ai;
        data.push_back(ai);
    }
    int dp[n+1][2];
    for (int i=0; i <= n;i++){
        dp[i][0] = 0;
        dp[i][1] = 0;
    }
    dp[0][0] = 1;
    dp[0][1] = 0;
    for (int i=0; i < n; i++){
        if (data[i] % 2 == 0){
            dp[i+1][0] += 2 * dp[i][0];
            dp[i+1][1] += 2 * dp[i][1];
        }
        else{
            dp[i+1][0] += dp[i][0] + dp[i][1];
            dp[i+1][1] += dp[i][0] + dp[i][1];
        }
    }
    cout << dp[n][p] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long cnt =0;
      long cnt2 =0;
      int flg=0;
      long N = sc.nextLong();
      long[] a = new long[(int) N];
      long[] b = new long[(int) N];
      for (int i=0 ; i<N; i++) {
          a[i] = sc.nextLong();
          b[i] = sc.nextLong();
      }
      
      quick_sort(b,a);
      for(int i=0; i<N; i++) {
    	  cnt2 = cnt2 + a[i];

//    	  System.out.println("a=" + cnt2 + " b[i]=" + b[i] + " i=" + i );
    	  if (cnt2 > b[i]) {
    		  flg = 1;
    		  break;
    	  }
      }
      if(flg==1) {
    	  System.out.println("No");
      } else {
    	  System.out.println("Yes");
      }
  }
  
  static void quick_sort(long[] d, long[] d2) {
	  quick_sort(d,d2, 0, d.length-1);
  }

  // dのleftからrightまでの間のデータ列をクイックソートする
  static void quick_sort(long[] d, long[] d2, int left, int right) {
      if (left>=right) {
          return;
      }
      long p = d[(left+right)/2];
      int l = left, r = right;
      long tmp;
      while(l<=r) {
          while(d[l] < p) { l++; }
          while(d[r] > p) { r--; }
          if (l<=r) {
              tmp = d[l]; d[l] = d[r]; d[r] = tmp;
              tmp = d2[l]; d2[l] = d2[r]; d2[r] = tmp;
              l++; r--;
          }
      }
      quick_sort(d, d2, left, r);  // ピボットより左側をクイックソート
      quick_sort(d, d2, l, right); // ピボットより右側をクイックソート
  }
}

Measured memory_bytes: 98416
using System;
using System.Linq;
using System.Numerics;

namespace AtCoderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            if (input.Contains("0"))
            {
                Console.WriteLine(0);
                return;
            }
            BigInteger result = 0;
            BigInteger current = BigInteger.Parse(input[0]); ;
            BigInteger max = 1000000000000000000;
            // スペース区切りの整数の入力
            for (int i = 1; i < a; i++){
                BigInteger b = BigInteger.Parse(input[i]);
                if (b == 0)
                {
                    result = 0;
                    break;
                }
                if (b > max)
                {
                    result = -1;
                    break;
                }

                result = current * b;
                if (result > max)
                {
                    result = -1;
                    break;
                }
                else
                {
                    current = result;
                }
            }
            //出力
            Console.WriteLine(result);
        }
/*
 static void _Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int b = int.Parse(input[0]);
            int c = int.Parse(input[1]);
            // 文字列の入力
            string s = Console.ReadLine();
            //出力
            Console.WriteLine((a + b + c) + " " + s);
        }
*/
    }
}


Measured memory_bytes: 44472
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

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

void dfs(int sy,int sx,int d=0,int depth=0){
    if(field[sy][sx]=='0'){
        if(depth==3){
            return;
        }
        if(sy+dy[d]>=0 && sy+dy[d]<8 && sx+dx[d]>=0 && sx+dx[d]<8){
            dfs(sy+dy[d],sx+dx[d],d,depth+1);
        }
    }else{
        field[sy][sx]='0';
        for(int dir=0;dir<4;dir++){
            if(sy+dy[dir]>=0 && sy+dy[dir]<8 && sx+dx[dir]>=0 && sx+dx[dir]<8){
                dfs(sy+dy[dir],sx+dx[dir],dir,1);
            }
        }
    }
}

int main(){
    int ds;
    int num=1;

    cin>>ds;

    while(ds--){
        int sx,sy;

        cin.ignore(2);
        for(int i=0;i<8;i++){
            getline(cin,field[i]);
        }

        cin>>sx>>sy;

        dfs(sy-1,sx-1);

        cout<<"Data "<<num++<<":"<<endl;

        for(int i=0;i<8;i++){
            cout<<field[i]<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1212
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int length = s.length();
    long count = 0;
    for (int i = 0; i < length; i++) {
      count += (int) s.charAt(i) - 48;
    }
    if (count % 9 == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 40440
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;

int main(void){
  ll n,k,y,x;
  cin>>n>>k>>x>>y;
  if(n<=k) cout<<n*x<<endl;
  else cout<<(n-k)*y+k*x<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    char s[100];
    
    scanf("%d",&n);
    scanf("%s",s);
    
    if(n % 2 == 1){
        printf("No\n");
        return 0;
    }
    
    for(int i = 0; i < n/2; i++){
        if(s[i] != s[(n/2)+i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


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

const int maxn = 1e5 + 10;

int n,m;
ll a[maxn],b[maxn];

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

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

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i] / 2;
	}
	ll t = 1;
	for(int i = 0; i < n; i++) t = lcm(t,b[i]);
	//cout << t << endl;
	int flag = 1, ans = 0;
	for(int i = 0; i < n; i++){
		if(t / b[i] % 2 == 0) flag = 0;
	}
	if(flag) ans = (m / t + 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).tally.sort_by{ |k, v| -v}
sum = 0
ans = 0
a.each_with_index do |x|
  if sum >= k
    ans += x[1]
  elsif sum + 1 >= k
    sum += 1
  else
    sum += 1
  end
end
puts ans


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

int n;
vector<double> p;

int main() {
    cin >> n;
    p.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    // dp[i][j]:[0,i)まで投げて表がj枚出る確率
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        }
    }
    double ans = 0.0;
    for (int i = (n + 1) / 2; i <= n; i++) {
        ans += dp[n][i];
    }
    cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	ll N;
	cin >> N;

	ll ans = LLONG_MAX;
	for (ll i = 1; i <= sqrt(N); i++) {
		if (N % i == 0) {
			ans = min(ans, i + (N / i) - 2);
		}
	}
	
	cout << ans;

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 256
import numpy as np
import math

a, b, h, m = map(int, input().split())
pi = np.pi

a_angle = (60*h+m)/720*2*pi
b_angle = (m/60)*2*pi

angle = a_angle - b_angle

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


Measured memory_bytes: 27184
#include <iostream>
#include <bitset>
#include <array>
#include <vector>
#include <limits>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<bitset<10>> F(N);
  vector<array<int, 11>> P(N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 10; j++) {
      int a;
      cin >> a;
      F[i][j] = (a == 1);
    }
    cerr << F[i] << endl;
}

  for (int i = 0; i < N; i++){
    for (int j = 0; j < 11; j++){
      cin >> P[i][j];
      cerr << P[i][j] << ' ';
    }
    cerr << endl;
}

  int ans = numeric_limits<int>::min();
      int temp;
  for (uint16_t a = 1; a <= 1023; a++) {
      bitset<10> p(a);
      /*
      for(int i = 0; i < 5; i++){
          if((p[2*i] || p[2*i+1]) == false) goto next;
      }
      */
      temp = 0;
      cerr << p << endl;
      for(int i = 0; i < N; i++){
          temp += P[i][(p & F[i]).count()];
      }
      ans = max(ans, temp);
      next:;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec v(n);
    rep(i,n){
        cin>>v[i];
    }
    sort(ALL(v));
    ll a = v.size();
    Uniq(v);
    ll b = v.size();
    YES(a==b);
    return  0;
}


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

int main() {
	int n;
	cin>>n;
	std::vector<int>v(n),p(n);
	for(int i=0;i<n;i++)
	cin>>v[i];
	p[0]=0;
	p[1]=abs(v[1]-v[0]);
	for(int i=2;i<n;i++)
	{
	p[i]=min(p[i-1]+abs(v[i]-v[i-1]),p[i-2]+abs(v[i]-v[i-2]));
	}
	cout<<p[n-1];
	return 0;
}


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

int main() {
    ll x, k, d;
    cin >> x >> k >> d;
    ll a = abs(x)/d;
    if(a==0) {
        if(k%2==0) cout << abs(x) << endl;
        else {
            ll ans = min(abs(x+d), abs(x-d));
            cout << ans << endl;
        }
        return 0;
    }
    else{
        ll left = k-a;
        if(left<=0){
            ll ans = abs(abs(x)-d*k);
            cout << ans << endl;
            return 0;
        }
        else{
            if(abs(x)%d==0) {
                if(left%2==0) cout << 0 << endl;
                else cout << d << endl;
            }
            else {
                ll now = abs(x)%d;
                if(left%2==0) cout << now << endl;
                else {
                    ll ans = min(abs(now+d), abs(now-d));
                    cout << ans << endl;
                }
                return 0;
            }
        }
       
    }
    return 0;
}
/*  ll x, k, d;
    cin >> x >> k >> d;
    vector<ll> a, b;
    ll i = 1;
    while(1) {
        if(x >= 0) x-=d;
        if(x < 0) x+=d;
        if(i%2) a.push_back(x);
        else b.push_back(x);
    }
    */

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::vector<std::vector<long long>> A, long long N, std::vector<long long> b){
  REP(N){
    For(x,3){
      For(y,3){
        if(b[i]==A[x][y]){
          A[x][y]=-1;
        }
      }
    }
  }
  REP(3){
    bool f=true;
    For(j,3){
      if(A[i][j]!=-1){
        f=false;
        break;
      }
    }
    if(f){
      cout<<YES<<endl;
      return;
    }
    f=true;
    For(j,3){
      if(A[j][i]!=-1){
        f=false;
        break;
      }
    }
    if(f){
      cout<<YES<<endl;
      return;
    }
  }
  bool f=true;
  REP(3){
    if(A[i][i]!=-1){
      f=false;
      break;
    }
  }
  if(f){
    cout<<YES<<endl;
    return;
  }
  f=true;
  REP(3){
    if(A[i][2-i]!=-1){
      f=false;
      break;
    }
  }
  if(f){
    cout<<YES<<endl;
    return;
  }
  cout<<NO<<endl;
}

int main(){
  cout<<setprecision(1000);
    std::vector<std::vector<long long>> A(3, std::vector<long long>(3));
    for(int i = 0 ; i < 3 ; i++){
        for(int j = 0 ; j < 3 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    long long N;
    scanf("%lld",&N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
    solve(std::move(A), N, std::move(b));
    return 0;
}


Measured memory_bytes: 256
n, sum = map(int, input().split())

for x in range(n+1):
    for y in range(n+1):  
        if 10000 * x + 5000 * y + 1000 * (n - x - y)  == sum and (n - x - y) >= 0:
                print(x, y, n - x - y)
                exit()

print(-1, -1, -1)

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

using namespace std;

using int64 = long long;

constexpr int64 P = 998244353;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int r = 0;
  int g = 0;
  int b = 0;
  int rg = 0;
  int gb = 0;
  int br = 0;
  FiniteField ans = 1;
  for (char c : s) {
    if (c == 'R') {
      if (gb > 0) {
        ans *= gb;
        gb--;
      } else if (g > 0) {
        ans *= g;
        g--;
        rg++;
      } else if (b > 0) {
        ans *= b;
        b--;
        br++;
      } else {
        r++;
      }
    } else if (c == 'G') {
      if (br > 0) {
        ans *= br;
        br--;
      } else if (b > 0) {
        ans *= b;
        b--;
        gb++;
      } else if (r > 0) {
        ans *= r;
        r--;
        rg++;
      } else {
        g++;
      }
    } else if (c == 'B') {
      if (rg > 0) {
        ans *= rg;
        rg--;
      } else if (r > 0) {
        ans *= r;
        r--;
        br++;
      } else if (g > 0) {
        ans *= g;
        g--;
        gb++;
      } else {
        b++;
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    ans *= i;
  }

  cout << ans.Value() << endl;
}

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

int n, t, num,z, T, x, y, r, c;
int g(int p) {return p > 0 ? p : -p;}
int main()
{
	cin >> n;
	r = c = t = 0;
	while (n--) {
		scanf ("%d %d %d", &T, &x, &y);
		num = g(x - r) + g(y - c);
		z = T - t;
		if (z < num || (z - num) % 2 == 1) {
			cout << "No";
			return 0;
		}
		r = x;
		c = y;
		t = T;
	}
	cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
K,X=map(int,input().split())
A=[]
if X-K+1 < -1000000:
  B= range(-1000000, X+K)
  for i in B:
    A.append(i)
elif 1000000 < X-K+1:
  C= range(X-K+1,1000001)
  for i in C:
    A.append(i)
else:
  D=range(X-K+1,X+K)
  for i in D:
    A.append(i)
print(*A)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <typename T>
struct Graph {
    ll V, E;
    struct Edge {
        int from, to;
        T cost;
    };
    vector<vector<Edge>> edge;
    vector<vector<T>> dist;
    vector<Edge> es;

    Graph(ll V, ll E) : V(V), E(E) {
        edge.assign(V, vector<Edge>(0));
        dist.assign(V, vector<T>(0));
        ans.assign(V, V * (V + 1) / 2);
        color.resize(V);
        cnt.assign(V, V);
        size.assign(V, 1);
    }

    void input(bool is_direct, bool inputc, bool index0 = false) {
        int a, b;
        T c = 0;
        for (int i = 0; i < E; i++) {
            cin >> a >> b;
            if (inputc) cin >> c;
            if (!index0) a--, b--;
            edge[a].push_back((Edge){a, b, c});
            es.push_back((Edge){a, b, c});
            if (!is_direct) {
                edge[b].push_back((Edge){b, a, c});
                es.push_back((Edge){b, a, c});
            }
        }
        if (!is_direct) E *= 2;
    }

    void add_edge(int from, int to, T cost, bool is_direct) {
        edge[from].push_back({from, to, cost});
        es.push_back({from, to, cost});
        if (!is_direct) {
            edge[to].push_back({to, from, cost});
            es.push_back({to, from, cost});
            E++;
        }
        E++;
    }

    vector<ll> ans;
    vector<ll> size;
    vector<int> color;
    vector<ll> cnt;

    void calc_size(int v, int par = -1) {
        for (const auto& [from, to, cost] : edge[v]) {
            if (par == to) continue;
            calc_size(to, v);
            size[v] += size[to];
        }
    }

    void dfs(int v, int par = -1) {
        ll tmp = cnt[color[v]];
        for (const auto& [from, to, cost] : edge[v]) {
            if (par == to) continue;
            cnt[color[v]] = size[to];
            dfs(to, v);
            ans[color[v]] -= cnt[color[v]] * (cnt[color[v]] + 1) / 2;
        }
        cnt[color[v]] = tmp - size[v];
    }
};

int main() {
    int N;
    cin >> N;
    Graph<int> g(N, N - 1);
    for (int i = 0; i < N; i++) cin >> g.color[i], g.color[i]--;
    g.input(false, false);
    g.calc_size(0);
    g.dfs(0);
    for (int i = 0; i < N; i++) cout << g.ans[i] - g.cnt[i] * (g.cnt[i] + 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 44648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;cin>>a>>b;
  if(a>0&&a<10&&b>0&&b<10){
    cout<<a*b<<endl;
  }
  else {
    cout<<-1<<endl;
  }

  return 0;

}


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

int main() {

  int N, M;
  cin >> N;

  vector<string> vec1(N);
  for(int i = 0; i < N; i++) {
    string str1;
    cin >> str1;
    vec1.at(i) = str1;
  }
  cin >> M;
  vector<string> vec2(M);
  for(int i = 0; i < M; i++) {
    string str2;
    cin >> str2;
    vec2.at(i) = str2;
  }
  
  int max = 0;
  for(int i = 0; i < N; i++) {
    int blNum = 0;
    string blStr = vec1.at(i);
    for(int j = 0; j < N; j++) {
      if (blStr == vec1.at(j)) {
        blNum += 1;
      }
    }
    int rdNum = 0;
    for(int k = 0; k < M; k++) {
      if (blStr == vec2.at(k)) {
        rdNum += 1;
      }
    }
    int tmpNum = 0;
    tmpNum = blNum - rdNum;
    if (tmpNum >= 0 && tmpNum > max) {
      max = tmpNum;
    }
  }

  cout << max << endl;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long ;

unll func(unll h,unll num ){
  if( h == 1 ) return 1*num;
  return num + func(h/2,num*2);
}
  

int main() {
  unll h;
  cin >> h;
  unll num=1; //敵の数
  unll ans=0;
  cout << func(h,num) << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int64_t> lucas(87);
    lucas[0] = 2ll;
    lucas[1] = 1ll;
    for (int i = 2; i <= n; i++) {
        lucas[i] = lucas[i-1] + lucas[i-2];
    }
    cout << lucas[n] << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split())) + [float("inf")] * (K-1)

dp = [0] * N + [float("inf")] * K
for i in range(N-1)[::-1]:
    temp = float("inf")
    for k in range(1, K+1):
        temp = min(temp, abs(h[i+k] - h[i]) + dp[i+k])
    dp[i] = temp

print(dp[0])

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

typedef long long ll ; 
typedef unsigned long long ull ; 
typedef vector<int> vi ; 
typedef vector<vi> vii ;
typedef vector<ll> vl ;
typedef vector<vl> vll ;
typedef set<int> si ; 
typedef map<int,int> mii ; 
typedef map<ll,ll>  mll ; 
typedef map<string,int> msi ;
typedef set<ll> sl ; 
typedef set<char> sc ; 
typedef pair<int,int> pii ;


#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
const int INF = 1 << 29 ; 
#define MOD (ll)(1e9+7)
#define eps 1e-6
#define pb push_back 
#define mp make_pair 
#define DEBUG(x)		cout << '>' << #x << ':' << x << endl;
#define F first 
#define S second 

int main() 
{
	ios::sync_with_stdio(0) ;
	
	string s , t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	long long dp[n+1][m+1];
	REP(i,n+1) REP(j,m+1) dp[i][j] = 0;

	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(s[i-1] == t[j-1]) {
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else {
				dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
			}
		}
	}
	string lcs = "";
	int i = n , j = m;
	while(i > 0 && j > 0) {
		if(s[i-1] == t[j-1]) {
			lcs += s[i-1];
			--i;
			--j;
		}
		else if(dp[i][j] == dp[i-1][j]) --i;
		else --j;

	}
	reverse(lcs.begin() , lcs.end());
	cout << lcs << endl;

	return 0 ; 
}


Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define    endl        '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  10000
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";



void solve(){
	ll n,k;
	cin>>n>>k;
	mii m;
	rep(i,0,k){
		ll d;
		cin>>d;
		rep(j,0,d){
			ll x;
			cin>>x;
			m[x]++;
		}
	}
	cout<<n-sz(m);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll TESTS=1,an=1,f;
    // cin>>TESTS;
    while(TESTS--){
        // cout<<"Case #"<<an<<": ";
        an++;
        solve();

    }
    return 0;
}

Measured memory_bytes: 3648