akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int W,H,N;
    cin >> W >> H >> N;
     vector<vector<int>> area(H, vector<int>(W));  // 初期値は0
     for (int i =0; i<N; i++){
         int x,y,a;
         cin >> x >> y >> a;
         
         if(a==1){
             for(int i=0;i<x;i++){
                 for(int j=0;j<H;j++){
                     area.at(j).at(i) = 1;
                 }
                }
            }
         if(a==2){
             for(int i=x;i<W;i++){
                 for(int j=0;j<H;j++){
                     area.at(j).at(i) = 1;
                 }
             }
         }
         if(a==3){
             for(int i=0;i<W;i++){
                 for(int j=0;j<y;j++){
                     area.at(j).at(i) = 1;
                 }
             }
         }
         if(a==4){
             for(int i=0;i<W;i++){
                 for(int j=y;j<H;j++){
                     area.at(j).at(i) = 1;
                 }
             }
         }
     }
     int count =0;
     for(int i=0;i<H;i++){
         for(int j=0;j<W;j++){
             if(area.at(i).at(j) == 0){
                 count++;
             }
         }
     }
     cout << count << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	ll N;
	cin >> N;

	ll D = N % 10;
	N /= 10;
	ll C = N % 10;
	N /= 10;
	ll B = N % 10;
	ll A = N / 10;

	if (A + B + C + D == 7) { cout << A << "+" << B << "+" << C << "+" << D << "=" << 7; }
	else if (A + B + C - D == 7) { cout << A << "+" << B << "+" << C << "-" << D << "=" << 7; }
	else if (A + B - C + D == 7) { cout << A << "+" << B << "-" << C << "+" << D << "=" << 7; }
	else if (A + B - C - D == 7) { cout << A << "+" << B << "-" << C << "-" << D << "=" << 7; }
	else if (A - B + C + D == 7) { cout << A << "-" << B << "+" << C << "+" << D << "=" << 7; }
	else if (A - B + C - D == 7) { cout << A << "-" << B << "+" << C << "-" << D << "=" << 7; }
	else if (A - B - C + D == 7) { cout << A << "-" << B << "-" << C << "+" << D << "=" << 7; }
	else if (A - B - C - D == 7) { cout << A << "-" << B << "-" << C << "-" << D << "=" << 7; }

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	// step #1. input
	int N;
	cin >> N;
	vector<int> w(N);
	for(int i = 0; i < N; ++i) {
		cin >> w[i];
	}
	// step #2. make functional graph
	vector<int> p(N);
	for(int i = 0; i < N; ++i) {
		p[i] = i;
	}
	sort(p.begin(), p.end(), [&](int i, int j) { return w[i] < w[j]; });
	// step #3. calculate minimum cost
	int lightest = w[p[0]];
	vector<bool> vis(N, false);
	int ans = 0;
	for(int i = 0; i < N; ++i) {
		if(vis[i]) continue;
		int pos = i, sum = 0, sz = 0, sublight = w[pos];
		while(!vis[pos]) {
			sublight = min(sublight, w[pos]);
			sum += w[pos];
			++sz;
			vis[pos] = true;
			pos = p[pos];
		}
		int costA = sum + sublight * (sz - 2);
		int costB = sum + sublight + lightest * (sz + 1);
		ans += min(costA, costB);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3176
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
K = l.shift() * 1
l = inp.shift().split(' ')
R = l.shift() * 1
S = l.shift() * 1
P = l.shift() * 1
T = inp.shift()
a = ''
c = 0
for (i=0;i<N;i++) {
    s = T[i]
    if (i>=K) {
        b = a[i-K]
    } else {
        b = ''
    }
    if (s == 'r') {
        if (b != 'p') {
            c += P
            a += 'p'
        } else {
            a += '?'
        }
    } else if (s == 's') {
        if (b != 'r') {
            c += R
            a += 'r'
        } else {
            a += '?'
        }
    } else if (s == 'p') {
        if (b != 's') {
            c += S
            a += 's'
        } else {
            a += '?'
        }
    }
}
console.log(c)


Measured memory_bytes: 40652
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def get_blacks(n, m, N, M):
    return (n * m) + (N - n) * (M - m)

def main():
    N, M, K = get_ln_int_inputs()

    found = False
    for n in range(N + 1):
        for m in range(M + 1):
            if (get_blacks(n, m, N, M) == K):
                print("Yes")
                return
    print("No")
    return


main()

Measured memory_bytes: 3060
mod = int(1e9 + 7)

N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    cnt1 = len([x for x in A[i + 1:] if x < A[i]])
    mul1 = K * (K + 1) // 2 % mod
    cnt2 = len([x for x in A[:i] if x < A[i]])
    mul2 = (K - 1) * K // 2 % mod
    ans = (ans + cnt1 * mul1 % mod) % mod
    ans = (ans + cnt2 * mul2 % mod) % mod
print(ans)

Measured memory_bytes: 3188
#AIsing2020 c

import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
ans = [0]*N

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x**2+y**2+z**2+x*y+y*z+z*x
            if n <= N:
                ans[n-1] +=1
                

for i in range(N):
    print(ans[i])
        


Measured memory_bytes: 74668
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int numofbits5(long bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
}

int n, k;
int a[19];

int main(void)
{
	cin >> n >> k;
	for (int i = 0; i < n; ++i)cin >> a[i];
	long long ans = LLONG_MAX;
	for (int bit = 0; bit < (1 << n); ++bit)
	{
		if (numofbits5(bit) == k)
		{
			int kid = -1;
			long long score = 0;
			for (int i = 0; i < n; ++i)
			{
				
				if (bit & (1 << i))
				{
					if (kid <= a[i])
					{
						kid = a[i] + 1;
					}
					else
					{
						score += kid - a[i];
						kid++;
					}
				}
				else if (kid <= a[i])
				{
					kid = a[i] + 1;
				}
			}
			ans = min(ans, score);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
class UnionFind {
public:
    vector<int> par, rank;
    int cnt;

    UnionFind(int n) : cnt(n) {
        par = vector<int>(n);
        iota(par.begin(), par.end(), 0);
        rank = vector<int>(n, 0);
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        cnt--;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

struct edge {
    int u;
    int v;
    int cost;
};

bool comp_edge(const edge &e1, const edge &e2) {
    return e1.cost < e2.cost;
}

int kruskal(int V, vector<edge> &es) {
    sort(es.begin(), es.end(), comp_edge);
    UnionFind uf(V);
    int ret = 0;

    for (edge e : es) {
        if (uf.same(e.u, e.v)) continue;
        uf.unite(e.u, e.v);
        ret += e.cost;
    }

    return ret;
}

signed main() {
    int V, E;
    cin >> V >> E;
    vector<edge> es(E);
    for (int i = 0; i < E; i++) {
        cin >> es[i].u >> es[i].v >> es[i].cost;
    }
    cout << kruskal(V, es) << endl;
    return 0;
}


Measured memory_bytes: 5440
#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N, i;

int main()
{
  scanf( "%d%d", &N, &i );

  printf( "%d\n", N-i+1 );

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
using ll = long long;
using pii = pair<int, int>;
const long long INF = 2e18;

template <class A, class B> ostream& operator<<(ostream &os, const pair<A, B> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;} 
template <class A> ostream& operator<<(ostream &os, const vector<A> &v) {os << "{"; for(int i = 0; i < (int)v.size(); i++) if(i == 0) os << v[i]; else os << ", " << v[i]; os << "}"; return os;}

void dprint(string s) {cout << endl;}
template <class T, class... U> void dprint(string s, T t, U... u) 
{int w = s.find(','); cout << "[" << s.substr(0, w) << ": " << t << "] "; dprint(s.substr(w+2, (int)s.size()-w-1), u...);} 

#define DEBUG 
#ifdef DEBUG
#define dbg(X...) dprint(#X, X)
#else
#define dbg(X...) "KEEP CALM" 
#endif

const int N=1e6+5; // CHANGE this value ACC. TO Q.

int32_t main()
{
    IOS;
    string n; cin>>n;
    int sum=0;
    for(char c: n)
    {
        sum+=c-'0';
        sum%=9;
    }
    if(sum==0)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<ll> B(N-1);
    vector<ll> A(N, 1e9);
    rep(i, N-1) cin >> B[i];

    rep(i, N-1) {
        A[i] = min(A[i], B[i]);
        A[i+1] = min(A[i+1], B[i]);
    }

    ll sum = 0;
    rep(i, N) sum += A[i];
    cout << sum << endl;

}


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

int main() {
  int n, a, o = 0, q = 0;
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a;
    if(a & 1)
      o++;
    else if(a % 4 == 0)
      q++;
  }
  if(o <= q || n / 2 == q)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=50000;
    rep(y,1,P){
        ll x=mod(y*k);
        
        if(abs(x)<=P||x+P>=i_7){
            if(x+P>=i_7){
                x-=i_7;
            }
            cout<<x<<"/"<<y<<endl;
            //cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
typedef vector<ll> vl;
//////////////////////////



int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    bool b[n],c[n];memset(b,0,sizeof(b));
    memset(c,0,sizeof(c));
    rep(i,0,n-1){
        if((i==0||a[i-1]>=a[i])&&(i==n-1||a[i]<=a[i+1]))b[i]=true;
        if((i==0||a[i-1]<=a[i])&&(i==n-1||a[i]>=a[i+1]))c[i]=true;
    }
    ll m=1000,k=0;
    rep(i,0,n-1){
        if(b[i]){
            ll t=m/a[i];
            m-=t*a[i];
            k+=t;
        }
        if(c[i]||i==n-1){
            m+=k*a[i];
            k=0;
        }
    }
    cout<<m<<endl;
    
    return 0;
}



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

int main(void) {
  ll x,y;
  cin >> x >> y;

  int ans=0;
  while(x<=y){
    ans++;
    x *= 2;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
/* ----------------------------
 * ABC 81 C
 * ---------------------------- */
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	map<int, int> a;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		a[tmp] += 1;
	}
	vector<int> v;
	for(auto x: a){
		v.push_back(x.second);
	}
	sort(v.rbegin(), v.rend());
	int ans = 0;
//	int min = 1 << 30;
//	int min_key = -1;
//	// a に k　種類以上の数字が入っている場合
//	while(a.size() > k){
//		for (auto itr = a.begin(); itr != a.end(); ++itr) {
//			if(itr->second < min) min_key = itr->first;
//		}
//		ans += a[min_key];
//		a.erase(min_key);
//		min = 1 << 30;
//	}
	for(int i = k; i <= v.size(); i++){
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10748
N, K, Q = map(int,input().split(' '))
a = [0  for i in range(N)]
A = int(Q -K) + 1

for i in range(Q):
  a[int(input()) - 1] += 1
  
for i in a:
  if i >= A:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 4680
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 0x3fffffff;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, M;
	int nx[100005]={}, X[100005], mX[100005];
	int cx[100005]={}, ax[100005]={};

	cin >> N >> M;
	rep(i,N){
		cin >> X[i];
		nx[X[i]]++;
		mX[i] = X[i] % M;
	}
	rep(i,100005){
		cx[i%M] += nx[i]%2;
		ax[i%M] += nx[i]/2;
	}
//	rep(i,M+1){
		//cout << i << " : " << cx[i] << " " << ax[i] << endl;
//	}

	ll ans = 0;
	rep(i,M){
		int j = (M-i)%M;
		//cout << "j" <<  j << endl;
		if( j<i ){
			continue;
		}else if( i==j ){
			//cout << "i=j " << i << endl;
			ans += ax[i];
			ans += cx[i] / 2;
		}else{
			//cout << "i=" << i << " j=" << j << endl;
			int oi = i;
			if( cx[i] < cx[j] ) swap(i,j);
			ans += ax[i];
			int d = cx[i] - cx[j];
			ans += cx[j];
			if( ax[j]*2 >= d ){
				ans += ax[j] + d/2;
			}else{
				ans += ax[j]*2;
			}
			i = oi;
		}
		//cout << ans << endl;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
double pi=acos(-1.0);
int main()
{
    double p=(double)180/pi;
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);
    double y=x/a;
    if (y>a*b/2)
    {
        double z=a*a*a/((a*a*b-x)*2);
        double theta=(double)90-atan(z)*p;
        printf("%lf\n",theta);
    } else
    {
        y=y*2;
        y/=b;
        double theta=(double)90-atan(y/b)*p;
        printf("%lf\n",theta);
    }
    return(0);
}


Measured memory_bytes: 256
#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "abc173_f.cpp"

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

  int n;
  cin >> n;
  vector<vi> g(n);

  REP(i, n - 1) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  REP(i, n) { sort(g[i].begin(), g[i].end()); }
  vl dp(n, 0);
  dp[0] = 1;
  FOR(i, 1, n) {
    dp[i] += dp[i - 1] + i + 1;
    for (auto el : g[i]) {
      if (el < i)
        dp[i] -= el + 1;
    }
  }

  ll ans = 0;
  REP(i, n) { ans += dp[i]; }
  cout << ans << endl;
}


Measured memory_bytes: 16588
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

// #define LOCAL

#ifdef LOCAL
constexpr long N = 999999999;
#endif

string toStr(long v)
{
    ostringstream oss;
    oss << v;
    return oss.str();
}

long fromStr(const string& s)
{
    istringstream iss(s);
    long v;
    iss >> v;
    return v;
}


bool ask(long n)
{
#ifdef LOCAL
    string sn = toStr(n);
    string sN = toStr(N);
    bool ans = (n <= N && sn <= sN) || (n > N && sn > sN);
    cout << "? " << n << " => " << ans << '\n';
    return ans;
#else
    cout << "? " << n << '\n';
    cout.flush();

    string ans;
    cin >> ans;
    return ans == "Y";
#endif
}

void answer(long n)
{
#ifdef LOCAL
    cout << "! " << n << '\n';
    cout << (n == N ? "CORRECT\n" : "WRONG\n");
#else
    cout << "! " << n << '\n';
    cout.flush();
#endif
}

void detHead(char* sn, int d)
{
    sn[d] = '4';
    bool ans = ask(fromStr(sn));
    if (ans) {
        sn[d] = '2';
        ans = ask(fromStr(sn));
        if (ans) {
            sn[d] = '1';
            ans = ask(fromStr(sn));
            if (ans && d != 0) {
                sn[d] = '0';
                ans = ask(fromStr(sn));
                if (!ans)
                    sn[d] = '1';
            } else if (!ans) {
                sn[d] = '2';
            }
        } else {
            sn[d] = '3';
            ans = ask(fromStr(sn));
            if (!ans)
                sn[d] = '4';
        }
    } else {
        sn[d] = '7';
        ans = ask(fromStr(sn));
        if (ans) {
            sn[d] = '6';
            ans = ask(fromStr(sn));
            if (ans) {
                sn[d] = '5';
                ans = ask(fromStr(sn));
                if (!ans)
                    sn[d] = '6';
            } else {
                sn[d] = '7';
            }
        } else {
            sn[d] = '8';
            ans = ask(fromStr(sn));
            if (!ans)
                sn[d] = '9';
        }
    }
}

bool detTail(char* sn, int lastnz, int last)
{
    if (sn[lastnz] != '9') {
        ++sn[lastnz];
        sn[last] = '\0';
        bool ans = ask(fromStr(sn));
        --sn[lastnz];
        if (ans)
            return true;
        sn[last] = '0';
        return false;
    }

    --sn[lastnz];
    bool ans = ask(fromStr(sn));
    ++sn[lastnz];
    if (ans)
        return false;
    sn[last] = '\0';
    return true;
}

int main()
{
    char sn[12];
    for (int i = 0; i < 11; ++i)
        sn[i] = '9';
    sn[11] = '\0';

    for (int i = 0; i < 10; ++i)
        detHead(sn, i);

    sn[10] = '\0';
    int last = 9;
    int lastnz = 9;
    while (sn[lastnz] == '0')
        --lastnz;

    while (lastnz < last) {
        if (!detTail(sn, lastnz, last)) {
            break;
        }
        --last;
    }

    answer(fromStr(sn));

    return 0;
}


Measured memory_bytes: 596
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    int n,k;
    scanf("%d",&n);
    scanf("%d",&k);
    int hoge = 1;
    int i;
    for(i=0;i<n;i++){
        hoge = hoge*2 < hoge+k ? hoge*2 : hoge+k;
    }
    printf("%d",hoge);
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
	int n,k;
	int ans;
	bool isNA;

	while(scanf("%d",&n) && n){
		ans = 1;
		isNA = true;

		for(int i = 0; i < n ;i++){
			scanf("%d",&k);
			if(k > 0){
				ans++;
			}
			if(k > 1){
				isNA = false;
			}
		}

		if(isNA)
			printf("NA\n");
		else
			printf("%d\n",ans);
	}

	return 0;
}

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

public class Main {
    static int MAX_INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        String line;
        while ((line = in.readLine()) != null) {
            st = new StringTokenizer(line, " ");
            int n = Integer.parseInt(st.nextToken());
            int s = Integer.parseInt(st.nextToken());
            if (n == 0 && s == 0) {
                break;
            }
            System.out.println(dfs(n, s, 0));
        }
    }
    
    static int dfs(int n, int s, int cur) {
        if (n == 0 && s == 0) {
            return 1;
        } 
        if (n == 0 || s < 0 || cur > 9) {
            return 0;
        }
        int ans = 0;
        for (int i = cur; i <= 9; i++) {
            ans += dfs(n - 1, s - i, i + 1);
        }
        return ans;
    }
}


Measured memory_bytes: 24352
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
using namespace std;
int n,k,a[100005];
ll l[100005],r[100005],s[100005],ans;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",a+i),s[i]=s[i-1]+a[i];
    for(int i=1;i<=n;++i)l[i]=l[i-1]+max(a[i],0);
    for(int i=n;i;--i)r[i]=r[i+1]+max(a[i],0);
    for(int i=k;i<=n;++i)ans=max(ans,max(s[i]-s[i-k],0ll)+l[i-k]+r[i+1]);
    printf("%lld\n",ans);
   // system("pause");
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int ans, n, m, a[20], is_zz[20], y[20][20], x[20][20];

void check()
{
	int sum = 0;
	for (int i = 1; i <= n; i+=1)
	{
		if (!is_zz[i]) continue;
		++sum;
		bool fl = true;
		for (int j = 1; j <= a[i]; j+=1)
		{
			if (y[i][j] == 1)
			{
				if (!is_zz[x[i][j]]) {fl = false; break;}
			}
			else
			{
				if (is_zz[x[i][j]]) {fl = false; break;}
			}
		}
		if (!fl) return;
	}
	ans = max(ans, sum);
}

void dfs(int x)
{
	if (x > n) {check(); return;}
	is_zz[x] = 1;
	dfs(x + 1);
	is_zz[x] = 0;
	dfs(x + 1);
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	for (int i = 1; i <= n; i+=1)
	{
		a[i] = gi();
		for (int j = 1; j <= a[i]; j+=1)
		{
			x[i][j] = gi(), y[i][j] = gi();
		}
	}
	dfs(1);
	printf("%d\n", ans);
	return 0;
}


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

typedef pair<string, int> ps;

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

	queue<ps> Q;
	int n, q, st = 0;
	cin >> n >> q;

	ps p;
	while (n--) {
		cin >> p.first >> p.second;
		Q.push(p);
	}

	while (!Q.empty()) {
		p = Q.front();
		Q.pop();
		if (p.second <= q) {
			st += p.second;
			cout << p.first << " " << st << endl;
		} else {
			st += q;
			p.second -= q;
			Q.push(p);
		}
	}
}


Measured memory_bytes: 6368
s=input()
k=int(input())
def gets(n,s):
  l=[''.join(s[i:i+n]) for i in range(len(s)-n+1)]
  return l
x=[]
for i in range(1,k+1):
  x+=gets(i,s)
x=sorted(list(set(x)))
print(x[k-1])

Measured memory_bytes: 5060
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

ll N;

int main() {
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
}


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

using namespace std;

const int MAX=1e9;
int l[100],r[100],x[100],y[100],d[100];

int direct(int a,int b,int c,int d)
{
    return abs(c-a)+abs(d-b);
}

int main()
{
    int n,m,i,t,s,j;
    cin >> n >> m;
    for(i=0;i<n;i++)
    {
        cin >> l[i] >> r[i];
    }
    for(i=0;i<m;i++)
    {
        cin >> x[i] >> y[i];
    }
    for(i=0;i<n;i++)
    {
        t=MAX;
        for(j=0;j<m;j++)
        {
            s=direct(l[i],r[i],x[j],y[j]);
            if(s<t) t=s,d[i]=j+1;
        }
    }
    for(i=0;i<n;i++)
    {
        cout << d[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
ab=n.times.map{gsmi}.sort
if n.odd?
  aft=ab[n/2..-1]
  st=aft[0][0]
  b_sort = ab.sort{|x,y|x[1]<=>y[1]}
  en=b_sort[n/2][1]
  puts en-st+1
else
  aft=ab[(n/2-1)..-1]
  st=(aft[0][0]+aft[1][0])
  b_sort = ab.sort{|x,y|x[1]<=>y[1]}
  en=(b_sort[n/2-1][1]+b_sort[n/2][1])
  puts en-st+1
end


Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> num;
  for(int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if(num.count(s)) num[s] += 1;
    else num[s] = 1;
  }
  int max = 0;
  for (auto p : num) {
    auto v = p.second;
    if(v > max) max = v;
  }
  for (auto p : num) {
    auto k = p.first;
    auto v = p.second;
    if(v == max) cout << k << endl;
  }
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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

const ll MRINF = 5000000000000000;

int main() {

    int L, R, d;
    cin >> L >> R >> d;
    cout << R / d -  (L-1) / d << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3560
input_list = list(map(str, input().split()))
stack_list = []

for i in input_list:
    if i not in ['+', '-', '*']:
        stack_list.append(i)
    else:
        a = stack_list.pop()
        b = stack_list.pop()
        stack_list.append(str(eval(b + i + a)))

print(stack_list[0])



Measured memory_bytes: 5572
#include<stdio.h>

#define MAX 10000
#define NIL -1

void setDepth(int u,int d);
int setHeight(int u);
int getSibling(int u);
void print(int u);


typedef struct
{
  int parent;
  int left,right;
} Node;

Node T[MAX];
int n;
int D[MAX],H[MAX];

int main(void){

  int l,r,v;
  int root=0;
  int i;
  
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      T[i].parent=NIL;
    }
  
  for(i=0;i<n;i++)
    {
      scanf("%d %d %d",&v,&l,&r);
    
      T[v].left=l;
      T[v].right=r;
      
      if(l!=NIL)
	{
	  T[l].parent=v;
	}
    
      if(r!=NIL)
	{
	  T[r].parent=v;
	}
    
    }
  
  for(i=0;i<n;i++)
    {
      if(T[i].parent==NIL)
	{
	  root=i;

	}
    }

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++)
    {
      print(i);
    }

  return 0;
}

void setDepth(int u,int d)
{
  if(u==NIL)
    return;
  
  D[u]=d;

  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u)
{
  int h1=0;
  int h2=0;

  if(T[u].left!=NIL)
    {
      h1=setHeight(T[u].left)+1;
    }
  
  if(T[u].right!=NIL)
    {
      h2=setHeight(T[u].right)+1;
    }

  return H[u]=h1>h2?h1:h2;

}

int getSibling(int u)
{
  if(T[u].parent==NIL)
    {
    return NIL;
    }
  
  if(T[T[u].parent].left!=NIL&&T[T[u].parent].left!=u)
    {
      return T[T[u].parent].left;
    }
  
  if(T[T[u].parent].right!=NIL&&T[T[u].parent].right!=u)
    {
      return T[T[u].parent].right;
    }
  
  return NIL;
}

void print(int u)
{
  int deg=0;
  
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));

  if(T[u].left!=NIL)
    {
      deg++;
    }
  
  if(T[u].right != NIL)
    {
      deg++;
    }
  
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent==NIL)
    {
      puts("root");
    }
  
  else if(T[u].right==NIL&&T[u].left==NIL)
    {
      puts("leaf");
    }
  
  else
    {
      puts("internal node");
    }
  
}



Measured memory_bytes: 2052
n, k = gets.split.map &:to_i
h = gets.split.map &:to_i

cost = Array.new(n, 0)
cost[0] = 0

1.upto(n-1).each{|i|
    c = 1e9.to_i
    1.upto(k).each{|j|
        if i - j >= 0
            c_ = (h[i] - h[i-j]).abs + cost[i-j]
            c = c_ if c_ < c
        end
    }
    cost[i] = c
}

puts cost.last


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

int main(){
	int n,m;
	cin>>n>>m;
	if(n>m){
		cout<<n+n-1;
	}else if(n==m){
		cout<<n+n;
	}else cout<<m+m-1;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 1e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, X, Y, Z;
void add(int &a, int b)
{
    a += b;
    if(a >= mod)
        a -= mod;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> n >> X >> Y >> Z;
    int m = (1 << (X + Y + Z + 1)) - 1;
    vector<vector<int> >dp(m + 1, vector<int>(2, 0));
    dp[1][0] = 1;
    for(int i = 0; i < n; i++)
    {
        vector<vector<int> >new_dp(m + 1, vector<int>(2, 0));
        for(int msk = 1; msk <= m; msk++)
        {
            for(int f = 0; f < 2; f++)
            {
                if(!dp[msk][f])
                    continue;
                for(int a = 1; a <= 10; a++)
                {
                    int nf = f;
                    int new_msk = (msk << a) | 1;
                    new_msk &= m;
                    if(new_msk >> 0 & 1)
                    {
                        if(new_msk >> Z & 1)
                        {
                            if(new_msk >> (Y + Z) & 1)
                            {
                                if(new_msk >> (X + Y + Z) & 1)
                                    nf = 1;
                            }
                        }
                    }
                    add(new_dp[new_msk][nf], dp[msk][f]);
                }
            }
        }
        dp = new_dp;
    }

    int ans = 0;
    for(int msk = 1; msk <= m; msk++)
        add(ans, dp[msk][1]);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 28928
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let m: usize = iterator.next().unwrap().parse().unwrap();

    let mut uf = union_find::UnionFind::new(n);
    for _ in 0..m {
        let ai: usize = iterator.next().unwrap().parse().unwrap();
        let bi: usize = iterator.next().unwrap().parse().unwrap();
        uf.unite(ai - 1, bi - 1);
    }

    let ans = (0..n)
        .map(|i| uf.size(i))
        .max()
        .unwrap();
    ans.to_string()
}

#[allow(dead_code)]
mod union_find {
    pub struct UnionFind {
        parent: Vec<usize>,
        sizes: Vec<usize>,
        len: usize,
    }

    impl UnionFind {
        pub fn new(n: usize) -> UnionFind {
            UnionFind {
                parent: (0..n).map(|i| i).collect(),
                sizes: vec![1; n],
                len: n,
            }
        }

        pub fn find(&mut self, x: usize) -> usize {
            if self.parent[x] == x {
                x
            } else {
                let px = self.parent[x];
                self.parent[x] = self.find(px);
                self.parent[x]
            }
        }

        pub fn unite(&mut self, x: usize, y: usize) {
            let px = self.find(x);
            let py = self.find(y);

            if px == py {
                return;
            }

            let (large, small) = if self.sizes[px] < self.sizes[py] {
                (py, px)
            } else {
                (px, py)
            };

            self.parent[small] = large;
            self.sizes[large] += self.sizes[small];
            self.sizes[small] = 0;
            self.len -= 1;
        }

        pub fn same(&mut self, x: usize, y: usize) -> bool {
            self.find(x) == self.find(y)
        }

        pub fn size(&mut self, x: usize) -> usize {
            let px = self.find(x);
            self.sizes[px]
        }

        pub fn len(&self) -> usize {
            self.len
        }
    }
}


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

int cl[10101];
int clnum[2];
bool f = 0;

void dfs(vector<vector<int>> &G, int n, int col){
    if(cl[n] != -1){
        if(cl[n] == col){
            f = 1;
        }
        return;
    }
    cl[n] = (col+1)%2;
    clnum[cl[n]]++;
    for(auto &x: G[n]){
        dfs(G, x, cl[n]);
    }
}


int main(){
    int n, m;
    cin >> n >> m;
    while(n > 0){
        memset(cl, -1, sizeof(cl));
        memset(clnum, 0, sizeof(clnum));
        f = 0;
        vector<vector<int>> G(n);
        for(int i=0; i<m; i++){
            int x, y;
            cin >> x >> y;
            x--; y--;
            G[x].push_back(y);
            G[y].push_back(x);
        }
        dfs(G, 0, 0);
        int k = 0;
        if(f) cout << 0 << endl;
        else{
            set<int> ans;
            if(clnum[0] % 2 == 0){
                ans.insert(clnum[0]/2);
            }
            if(clnum[1] % 2 == 0){
                ans.insert(clnum[1]/2);
            }
            cout << ans.size() << endl;
            for(auto &x: ans){
                cout << x << endl;
            }
        }
        // cout << endl;
        cin >> n >> m;
    }
}


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

typedef long long ll;

ll o[65],z[65];

bool checkbit(ll N,int pos)
{
    return (bool)(N & (1LL<<pos));
}

ll mulMod(ll a,ll b,ll M)
{
    return ((a%M)*(b%M))%M;
}

ll addMod(ll a,ll b,ll M)
{
    return ((a%M)+(b%M))%M;
}

int main()
{
    //freopen("in.txt","r", stdin);
    //freopen("out.txt","w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);

    ll n,x,m = 1e9+7;

    cin>>n;

    for(int i=0; i<n; i++)
    {
        cin>>x;
        for(int j=0; j<=61; j++)
        {
            if(checkbit(x,j))   o[j]++;
            else                z[j]++;
        }
    }

    ll ans = 0;

    for(ll i=0; i<=61; i++)
        ans = (ans+mulMod(o[i]*z[i],(1LL<<i),m))%m;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
n, m = [int(i) for i in input().split()]
e = [[int(i) for i in input().split()] for i in range(m)]
v = [-(10 ** 9 * 2000)] * n

# Bellman-Ford
v[0] = 0
for i in range(n):
    tmp = v[-1]
    for a, b, cost in e:
        if v[a-1] + cost > v[b-1]:
            v[b-1] = v[a-1] + cost
    if tmp != v[-1] and i == n-1: break        
else:
    print(v[n-1])
    exit()

print("inf")


Measured memory_bytes: 9280
//20190707
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(void){

    int n,d;
    cin >> n >> d;

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

    int count=0;

    for(int i=0; i<n-1;i++){
        for(int j=i+1;j<n;j++){
            double dis = 0;
            for(int k=0; k<d; k++){
                dis += (x[i][k]-x[j][k]) * (x[i][k]-x[j][k]);
            }
            dis = sqrt(dis);
            int test = dis;
            if(dis == test) count++;
        }
    }

    cout << count << endl;

    return 0;
}




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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  
  sort(a.begin(), a.end());
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 1024
INF=1000000000
# A Dynamic Programming based Python Program for 0-1 Knapsack problem 
# Returns the maximum value that can be put in a knapsack of capacity W 
def knapSack(W,l, n):
    
    
    
    min_cost = [[0 for i in range(W+1)] for j in range(n+1)] 
    # fill 0th row with infinity 
    for i in range(W+1): 
        min_cost[0][i] = INF 
  
    # fill 0th column with 0 
    for i in range(1, n+1): 
        min_cost[i][0] = 0
    # now check for each weight one by one and fill the 
    # matrix according to the condition 
    for i in range(1, n+1): 
        for j in range(1, W+1): 
            # wt[i-1]>j means capacity of bag is 
            # less than weight of item 
            if (l[i-1][0] > j): 
                min_cost[i][j] = min(min_cost[i-1][j] ,l[i-1][1])
            # here we check we get minimum cost either 
            # by including it or excluding it 
            else: 
                min_cost[i][j] = min(min_cost[i-1][j], 
                    min_cost[i][j-l[i-1][0]] + l[i-1][1]) 
    
  
    # exactly weight W can not be made by given weights 
    if(min_cost[n][W] == INF): 
        return -1
    else: 
        return min_cost[n][W]

h,n=map(int,input().split())
l=list()
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
print( knapSack(h , l , n) ) 


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

void solve(long long S){
  ll ans = 0;
  string s = to_string(S);
  for(ll i=0; i<(1<<(s.size()-1)); i++) {
    string t = "";
    for(ll j=0; j<s.size()*2; j++) {
      if(j%2==0)
	t.push_back(s[j/2]);
      else if(i & 1<<(j/2))
	t.push_back('+');
      }
    string u = "";
    for(auto x : t) {
      if(x=='+') {
	ans+=stoll(u);
	u = "";
      } else
	u.push_back(x);
    }
    ans+=stoll(u);
  }
  std::cout << ans << std::endl;
}

int main(){
  long long S;
  scanf("%lld",&S);
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  	int a,b,c=0,k=0;
  	cin>>a>>b;
  	k=(b-1)/(a-1);
    c=(b-1)%(a-1);
    if(c!=0)
      cout<<k+1;
   else
     cout<<k;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)
#include <queue>

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  priority_queue<pair<ll, int>,
		 vector<pair<ll, int> >,
		 less<pair<ll, int> > > P; // candidates
  priority_queue<pair<ll, int>,
		 vector<pair<ll, int> >,
		 greater<pair<ll, int> > > Q; // selected
  for(int i=0; i<N; i++) {
    int t;
    ll d;
    cin >> t >> d;
    t--;
    P.push(make_pair(d, t));
  }
  ll value = 0LL;
  vector<int> selected(N, 0);
  ll nType = 0;
  for(int i=0; i<K; i++) {
    pair<ll, int> p = P.top();
    P.pop();
    value += p.first;
    if(selected[p.second] == 0)
      nType++;
    selected[p.second]++;
    Q.push(p);
  }
  ll ans = value + nType * nType;

  while(!P.empty()) {
    pair<ll, int> p = P.top();
    P.pop();
    if(selected[p.second] == 0) {
      pair<ll, int> q;
      while(!Q.empty()) {
	pair<ll, int> tmpQ = Q.top();
	Q.pop();
	if(selected[tmpQ.second] > 1) {
	  q = tmpQ;
	  break;
	}
      }
      if(q.first == 0) continue;
      value += p.first - q.first;
      nType++;
      selected[p.second]++;
      selected[q.second]--;
      Q.push(p);
      ans = max(ans, value + nType * nType);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5232
#include<iostream>
#include<queue>
using namespace std;
int main(){
  
  queue<string> name;
  queue<int>time;
  string name_in;
  int n,q,time_in,time_tmp,currenttime=0;
  
  cin >>n>>q;
  
  for(int i=0 ; i < n ; i++){
    cin >>name_in>>time_in;
    name.push(name_in);  
    time.push(time_in);
  }
  
  while(!(time.empty())){
    time_tmp=time.front();
    if(time_tmp - q <= 0){
      currenttime+=time_tmp;
      cout <<name.front()<<" "<<currenttime<<endl;
      time.pop();
      name.pop();
    }else{
      currenttime+=q;
      time.push(time_tmp - q);
      name.push(name.front());
      time.pop();
      name.pop();
    }
  }
  
  return 0;
}

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

struct Edge {
	int s, t, d;
};

const int INF = 1 << 30;

int main() {
  int V, E, r;
	cin >> V >> E >> r;
	vector<Edge> g(E);
	rep(i, E) {
		cin >> g[i].s >> g[i].t >> g[i].d;
	}
	vector<int> ans(V, INF);
	ans[r] = 0;
	for (int i = 0; i < V; i++) {
		for (int j = 0; j < E; j++) {
			if (ans[g[j].s] == INF) continue;
			if (ans[g[j].s] + g[j].d < ans[g[j].t]) {
				ans[g[j].t] = ans[g[j].s] + g[j].d;
				if (i == V - 1) {
					cout << "NEGATIVE CYCLE" << endl;
					return 0;
				}
			}
		}
	}
	rep(i, V) {
		if (ans[i] != INF) cout << ans[i] << endl;
		else cout << "INF" << endl;
	}
	return 0;
}



Measured memory_bytes: 3108