akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
using namespace std;
int main() {
	int n, m, ans = 0;
	cin >> n >> m;
	vector<int> k(m);
	vector<vector<int>> s(m, vector<int>(n));
	vector<int> p(m);
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for (int i = 0; i < m; i++)
		cin >> p[i];

	for (int i = 0; i < (1 << n); i++) {
		int countright = 0;
		for (int j = 0; j < m; j++) {
			int countswitch = 0;
			for (int l = 0; l < k[j]; l++) {
				if ((i >> (s[j][l])) & 1) {
					countswitch++;
				}
			}
				if (countswitch % 2 == p[j])
					countright++;
		}
		if (countright == m) {
			ans++;
		}
	}
	cout << ans;
}


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

typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define sz(v) ll(v.size)


void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    sort(A.begin(), A.end());
    vector<pair<ll, ll>> P;
    rep(i, M) {
        P.push_back(make_pair(C[i], B[i]));
    }
    sort(P.begin(), P.end());
    ll start = 0;
    rep(j, M) {
        ll i = M - j - 1;
        ll b = P[i].second;
        ll c = P[i].first;
        if (A[start] >= c) {
            break;
        } else {
            ll counter = 0;
            while(A[start] < c && counter < b) {
                A[start] = c;
                counter++;
                start++;
            }
        }
    }
    ll sum = 0;
    rep(i, N) {
        sum += A[i];
    }
    cout << sum << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, std::move(A), std::move(B), std::move(C));
    return 0;
}


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

struct node{
    int parent = -1;
    int left = -1;
    int right = -1;
};

vector<node> tree(100000);

int calcDepth(int id){
    int depth = 0;
    while(tree.at(id).parent != -1){
        id = tree.at(id).parent;
        depth++;
    }
    return depth;
}

int depth = 0;
void DFS(int id, vector<int> &node_depth){
    if(tree.at(id).left != -1){
        depth++;
        DFS(tree.at(id).left, node_depth);
        depth--;
    }
    if(tree.at(id).right != -1){
        DFS(tree.at(id).right, node_depth);
    }
    node_depth.at(id) = depth;
    return;

}

void printChild(int id){
    int child_left = tree.at(id).left;
    if(child_left == -1){
        cout << "[]";
        return;
    }
    cout << "[";
    while(tree.at(child_left).right != -1){
        cout << child_left << ", ";
        child_left = tree.at(child_left).right;
    }
    cout << child_left << "]";
}

void printMode(int id){
    if(tree.at(id).parent == -1){
        cout << "root";
    }else if(tree.at(id).left == -1){
        cout << "leaf";
    }else{
        cout << "internal node";
    }
}

int main(){
    int n; cin >> n;
    // vector<node> tree(n);
    vector<int> node_depth(n, -1);

    rep(i, n){
        int id, n_child; cin >> id >> n_child;
        int left_sib_id = -1;
        
        rep(j, n_child){
            int child_id; cin >> child_id;
            if(j == 0){
                tree.at(id).left = child_id;
            }
            if(left_sib_id != -1){
                tree.at(left_sib_id).right = child_id;
            }
            tree.at(child_id).parent = id;
            left_sib_id = child_id;
        }
    }
    int root_index;
    rep(i, n){
        if(tree.at(i).parent == -1){
            root_index = i;
            break;
        }
    }

    DFS(root_index, node_depth);
    rep(i, n){
        cout << "node " << i << ": parent = " << tree.at(i).parent << ", depth = " << node_depth.at(i) << ", ";
        printMode(i);
        cout << ", ";
        printChild(i);
        cout << endl;
    }

    return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(c-a) <= d) {
    cout << "Yes\n";
  } else if (abs(b-a) <= d && abs(c-b) <= d) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <queue>
#include <vector>
#include <sstream>

#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;
struct stt{
	int x,y,p;
	stt(int x, int y, int p) : x(x), y(y), p(p) {}
};

int main(void){

int px, py, n;
int sx[10], sy[10];
int pdx[]={-2,-2,-2,-1, 0, 1, 2, 2, 2,-1, 0, 1};
int pdy[]={-1, 0, 1,-2,-2,-2,-1, 0, 1, 2, 2, 2};
int sdx[]={-1,-1,-1, 1, 1, 1, 0, 0, 0};
int sdy[]={-1, 0, 1,-1, 0, 1,-1, 1, 0};
int cnt=0;

	while(cin >> px >> py){
		if(px==0 && py==0 || cin.eof()) break;
		cin >>n;
		rep(i,n){
			cin >> sx[i];
			cin >> sy[i];
		}
		bool use[10][10][10]={false};
		queue< stt > qq;
		qq.push(stt(px,py,0));
		bool lvf=false;
		while(!qq.empty()){
			stt cr = qq.front();
			qq.pop();
//			if( use[cr.x][cr.y][cr.p] ) continue;
			use[cr.x][cr.y][cr.p]=true;
			cnt++;
			rep(i,12){
				stt nx = cr;
				nx.x += pdx[i]; nx.y +=pdy[i]; nx.p++;
				if( nx.x < 0 || nx.x > 9 ) continue;
				if( nx.y < 0 || nx.y > 9 ) continue;
				rep(j,9){
					int wx = sx[cr.p] + sdx[j];
					int wy = sy[cr.p] + sdy[j];
					if(wx == nx.x && wy == nx.y){
						qq.push(nx);
						if(nx.p>=n){ lvf = true; break; } 
					}
				
				}
			}	
		}
		cout << (lvf? "OK": "NA") << endl;
//		printf("ct=%d\n",cnt);
	}
	
	
	return 0;
	
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC133D()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A)
		cin >> x;
	ll sum = accumulate(A.begin(), A.end(), 0LL);
	ll sum2 = 0;
	for (int i = 0; i < N / 2; ++i)
	{
		sum2 += A[2 * i];
	}
	vector<ll> ret(N);
	ret.back() = sum / 2 - sum2;
	for (int i = N - 2; i > -1; --i)
	{
		ret[i] = A[i] - ret[i + 1];
	}
	for (int i = 0; i < N; ++i)
	{
		cout << 2 * ret[i];
		if(i < N-1)
			cout << ' ';
	}
	cout << endl;

}

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

Measured memory_bytes: 2432
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
char s[1<<16];
int a[1<<16],b[1<<16];
int f[1<<16][2];
const int MOD=998244353;
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,int b)
{a-=b;return a<0?a+MOD:a;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline int ksm(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=mul(a,a))
        if(b&1)ans=mul(ans,a);
    return ans;
}
int fac[1<<16],ifac[1<<16];
#define C(x,y) mul(fac[x],mul(ifac[x-y],ifac[y]))
int Deal(int n,int m)
{
    f[0][0]=1;
    for(int j=1;j<=m;j++){
        f[0][j&1]=mul(fac[j],fac[j]);
        for(int i=1;i<=n;i++)
            f[i][j&1]=add(mul(f[i-1][j&1],i*j),mul(f[i][j&1^1],j*j));
            //fij=fi-1j*i*j+fij-1*j^2
    }
    int als=0;
    for(int i=0;i<=n;i++)
        als=add(als,mul(f[n-i][m&1],mul(mul(fac[i],fac[i]),mul(C(n,i),C(n+m,i)))));
    return als;
}
int main()
{
    scanf("%s",s+1);
    int s1=0,s2=0,n=strlen(s+1);
    for(int i=1;i<=n;i++)
        a[i]=s[i]-'0';
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
        b[i]=s[i]-'0';
    for(int i=1;i<=n;i++)
        if(a[i]+b[i]==2)++s1;
        else if(a[i])++s2;
    fac[0]=ifac[0]=1;
    for(int i=1;i<=10000;i++)
        fac[i]=mul(fac[i-1],i);
    ifac[n]=ksm(fac[n],MOD-2);
    for(int i=n-1;i;--i)
        ifac[i]=mul(ifac[i+1],i+1);
    printf("%d",Deal(s1,s2));
    return 0;
}

Measured memory_bytes: 512
// g++ -O3 -fmax-errors=1 -fsanitize=undefined -fsanitize=address -sanitize=leak 
#include <bits/stdc++.h>

using namespace std;

struct Tree {
  int n;
  vector<vector<int>> adj;
  Tree(int n) : n(n), adj(n) { }
  void addEdge(int u, int v) {
    adj[u].emplace_back(v);
    adj[v].emplace_back(u);
  }
  int sz() const { return adj.size(); }

  template <class F, class G>
  void dfs(int u, F f_visit, G f_leave, int p = -1) {
    f_visit(u);
    for (int v: adj[u]) {
      if (v == p) continue;
      dfs(v, f_visit, f_leave, u);
    }
    f_leave(u);
  }
  vector<int> size, depth, head, parent;
  void rootify(int r) {
    size = depth = parent = head = vector<int>(n, -1);
    function<int (int,int)> dfs = [&](int u, int p) {
      parent[u] = p;
      depth[u] = depth[p]+1;
      for (int v: adj[u]) 
        if (v != p) size[u] += dfs(v, u);
      return ++size[u];
    }; dfs(r, r);
    function<void (int,int)> dec = [&](int u, int s) {
      head[u] = s;
      int z = -1;
      for (int v: adj[u]) 
        if (head[v] < 0 && (z < 0 || size[z] < size[v])) z = v;
      for (int v: adj[u]) 
        if (head[v] < 0) dec(v, v == z ? s : v);
    }; dec(r, r);
  }
  int lca(int u, int v) {
    while (head[u] != head[v]) 
      if (depth[head[u]] < depth[head[v]]) v = parent[head[v]];
      else                                 u = parent[head[u]];
    return depth[u] < depth[v] ? u : v;
  }
};

struct Solution {
  Tree T;
  vector<pair<int,int>> constraint;
  Solution(Tree T, vector<pair<int,int>> constraint) :
    T(T), constraint(constraint) { }

  vector<int> delta;
  long long inclusion_exclusion(int k) {
    if (k == constraint.size()) {
      int r = 0, count = -1;
      vector<int> sum(T.n);
      T.dfs(r, 
          [&](int u) { 
            sum[u] = delta[u];
          }, 
          [&](int u) {
            if (T.parent[u] >= 0) sum[T.parent[u]] += sum[u];
            if (sum[u] == 0) ++count;
          }
      );
      return (1ll << count);
    }
    long long ans = 0;
    int u, v;
    tie(u, v) = constraint[k];
    if (T.depth[u] > T.depth[v]) swap(u, v);
    int w = T.lca(u, v);
    delta[u] += 1;
    delta[v] += 1;
    delta[w] -= 2;
    ans -= inclusion_exclusion(k+1);
    delta[u] -= 1;
    delta[v] -= 1;
    delta[w] += 2;
    ans += inclusion_exclusion(k+1);
    return ans;
  }
  void solve() {
    T.rootify(0);
    delta.resize(T.n);
    printf("%lld\n", inclusion_exclusion(0));
  }
};

int main() {
  int n; cin >> n;
  Tree T(n);
  for (int i = 0; i < n-1; ++i) {
    int u, v; cin >> u >> v;
    T.addEdge(u-1, v-1);
  }
  int m; cin >> m;
  vector<pair<int,int>> constraint;
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    constraint.emplace_back(u-1,v-1);
  }
  Solution solution(T, constraint);
  solution.solve();
}


Measured memory_bytes: 384
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;

int main() {
	while (cin >> n) {
		ll cont = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == n)cont++;
					}
				}
			}
		}
		cout << cont << endl;
	}
}

Measured memory_bytes: 2964
#include<bits/stdc++.h>
#define QS ios_base::sync_with_stdio(false);
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9+7;
using namespace std;

int main(){
//freopen("output.txt", "w", stdout);
    QS
    int n; cin >> n;
    long double x[n], y[n];
    for(int i = 0; i < n; ++i){
        cin >> x[i] >> y[i];
    }
    long double sum = 0.0;

    int fact[9] = {0};
    fact[0] = 1;
    for(int i = 1; i < 9; ++i){
        fact[i] = i*fact[i-1];
    }

    int arr[n+1];
    for(int i = 0; i < n; ++i){
        arr[i] = i;
    }

    do{
        for(int i = 0; i < n; ++i){
                int j;// = arr[i+1];
                if(i == n - 1) j = arr[0];
                else j = arr[i+1];
                long double ss = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
                ss = sqrt(ss);
                sum += ss;
        }
    }while(next_permutation(arr, arr+n));
    cout << fixed << setprecision(7) << sum/fact[n] << '\n';
}


Measured memory_bytes: 256
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
X = set([s for s in S])
if (len(S) == len(X)):
    print('yes')
else:
    print('no')


Measured memory_bytes: 27324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define vec vector<ll>
#define ms multiset<ll>
#define f(i,x,n) for(int i=x;i<n;i++)
#define int long long
#define mod 
#define endl "\n"
#define MAXN 300001 
const int INF = 1e9;
void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}  
int32_t main() 
{
	fastio();
	int fr[100002];
	memset(fr,0,sizeof(fr));
	int n,ww;
	cin>>n>>ww;
	int w[n],v[n];
	f(i,0,n)
	cin>>w[i]>>v[i];
	f(i,0,n)
	{
		int fr2[100001];
		memset(fr2,0,sizeof(fr2));
		f(j,1,100001)
		{
			if((j-v[i]>=1)&&fr[j-v[i]]!=0)
			{
				if(fr[j]==0)
				{
					fr2[j]=fr[j-v[i]]+w[i];
				}
				else
					fr2[j]=min(fr[j-v[i]]+w[i],fr[j]);
			}
			else 
				fr2[j]=fr[j];
		}
		if(fr[v[i]]==0)
			fr2[v[i]]=w[i];
		else
			fr2[v[i]]=min(w[i],fr[v[i]]);
		f(j,0,100001)
		fr[j]=fr2[j];
	}
	int ans=0;
	f(i,0,100001)
	{
		if(fr[i]<=ww&&fr[i]!=0)
		{	
			ans=max(ans,i);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        if (reader.nextInt()%500 > reader.nextInt()) System.out.println("No");
        else System.out.println("Yes");
    }

    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



Measured memory_bytes: 20564
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
double a,b,h,m;
void solve(){
//	if(m == 0) m = 60;
	double degm = (60 - m) / 60 * 360;
	double degh = (12-h)/12*360-(m/60)/12*360;
//	cout << degm << " " << degh << endl;
	double deg = abs(degh-degm)*pi/180;
	double c = sqrt(1.0*a*a+1.0*b*b-2*1.0*a*b*cos(deg));
	printf("%.12lf\n",c);
	return;
}
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	cout << cos(pi) << endl;
	cin >> a >> b >> h >> m;	
	solve();
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 4208
#include<stdio.h>
int main(void){
    int x,y,work;
    while(1){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0)break;
        if(x > y){
            work = x;
            x = y;
            y = work;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

struct UF
{
	VI parent, rank;
	UF(int n) : parent(n), rank(n, 1) {
		REP(i, 0, n) parent[i] = i;
	}

	int find(int u)
	{
		return parent[u] == u ? u : parent[u] = find(parent[u]);
	}

	void merge(int u, int v)
	{
		u = find(u); v = find(v);
		if(u == v) return;
		if(rank[u] > rank[v]) swap(u, v);
		parent[u] = v;
		rank[v] += rank[u] == rank[v];
	}
};

int n, k, l;
void solve()
{
	UF road(n), rail(n);

	int u, v;
	REP(i, 0, k) {
		cin >> u >> v;
		--u; --v;
		road.merge(u, v);
	}
	REP(i, 0, l) {
		cin >> u >> v;
		--u; --v;
		rail.merge(u, v);
	}

	map<PII, int> chk;
	for(int i = 0; i < n; ++i)
		++chk[{road.find(i), rail.find(i)}];
	for(int i = 0; i < n; ++i)
		cout << chk[{road.find(i), rail.find(i)}] << " ";
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n >> k >> l;
	
	solve();

	return 0;
}

Measured memory_bytes: 15104
#include<iostream>
using namespace std;
int M[15];
int ans[15];
int a[55][5];
int result=0;
int q;
void dfs(int start,int end,int n,int k)
{
	if (n==0)
	{
		int ansn=0;
		for (int j=1;j<=q;j++)
			if (ans[a[j][2]]-ans[a[j][1]]==a[j][3])
				ansn+=a[j][4];
		result=max(result,ansn);
		return ;
	}
	for (int i=start;i<=end;i++)
	{
		ans[k]=M[i];
		dfs(i,end,n-1,k+1);
	}
		
}

void solve()
{
	int n,m;
	cin>>n>>m>>q;
	for (int i=1;i<=q;i++)
		cin>>a[i][1]>>a[i][2]>>a[i][3]>>a[i][4];
	for (int i=1;i<=m;i++)
		M[i]=i;
	dfs(1,m,n,1);
	cout<<result;
}
int main()
{
	ios::sync_with_stdio(false);
	solve();
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in(),i=in();

	cout << N-i+1 << endl;
	return 0;
}


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

int main()
{
	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i])
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3848
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
using namespace std;

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

    vector<int> num;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == (char)('0'+now)) cnt++;
        else {
            num.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) num.push_back(cnt);
    if(num.size() % 2 == 0) num.push_back(0);

    int left = 0;
    int right = 0;
    int add = 2 * K + 1;
    int ans = 0;
    int tmp = 0;
    for(int i = 0; i < num.size(); i+=2) {
        int nextleft = i;
        int nextright = min(i+ add, (int)num.size());
        while(left < nextleft) {
            tmp -= num[left];
            left++;
        }

        while(right < nextright) {
            tmp += num[right];
            right++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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;

const int N = 100;

int main(void){
    for(int n, q, res; cin >> n >> q, n; cout << res << endl){
        res = 0;

        vector< vector<bool> > t = vector< vector<bool> >(n, vector<bool>(N, false));
        rep(i, n){
            int m; cin >> m;
            rep(j, m){
                int d; cin >> d;
                t[i][d] = true;
            }
        }

        range(i, 1, N){
            int cnt = 0;
            rep(j, n) if(t[j][i]) cnt++;

            if(q <= cnt){
                res = i;
                q = cnt + 1;
            }
        }
    }

	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<arr[k-1]<<"\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace paizaTest
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var readLine = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            var resultFlag = true;
            for (var i = 0; i < readLine.Count() - 1; i++)
            {
                if (readLine[i] >= readLine[i + 1])
                {
                    resultFlag = false;
                }
            }

            Console.WriteLine(resultFlag ? "Yes" : "No");
        }
    }
}

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

using namespace std;

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;

namespace std {
    bool operator < (const P& a, const P& b) {
        return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
}
double cross(const P& a, const P& b) {
    return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
    return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
}

vector<P> convex_hull(vector<P> ps) {
    int n = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    vector<P> ch(2*n);
    for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
        while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
    for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
        while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) <= 0) --k;
    ch.resize(k-1);
    return ch;
}

int main(){
    vector<P> v(4);
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &v[0].real(), &v[0].imag(), &v[1].real(), &v[1].imag(), &v[2].real(), &v[2].imag(), &v[3].real(), &v[3].imag()) != EOF){
        vector<P> q =  convex_hull(v);
        cout << (q.size()==4?"YES":"NO") << endl;
    }
}

Measured memory_bytes: 1232
h,w,a,b = map(int,input().split())
ans = [[0]*w for i in range(h)]

for i in range(h):
    if i >= h-b:
        for j in range(w-a,w):
            ans[i][j] = 1
    else:
        for j in range(w-a):
            ans[i][j] = 1
for i in ans:
    print(*i,sep="")

Measured memory_bytes: 17784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String a = sc.next();
		String b = sc.next();
		for (int i=0;i<a.length();i++) {
			boolean bo = false;
			for (int j=0;j<N-i;j++) {
				if (a.charAt(j+i)!=b.charAt(j)) {
					bo = true;
					break;
				}
			}
			if (bo==false) {
				System.out.println(N+i);
				return;
			}
		}
		System.out.println(N*2);
	}
}

Measured memory_bytes: 35528
/*
* author: pavveu
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int,int>;
using graph = vector<vi>;

#define FOR(name__, upper__) for (int name__ = 0; name__ < (upper__); ++name__)
#define all(x) begin(x), end(x)
#define mp make_pair
#define mt make_tuple

template<class T>
void initialize_matrix(vector<vector<T>>& matrix, int rows, int cols, T value) {
	assert(matrix.empty());
	FOR (row, rows) 
		matrix.emplace_back(cols, value);
}

ll fastpow(ll a, ll b, ll m) { 
	ll res = 1ll;
	while ( b ) {
		if ( b & 1 ) res = (res *  a) % m;
		a = (a * a) % m;
		b /= 2;
	}
	return res;
}

void go() {
	ll mod = 1e9 + 7;
	ll n; cin >> n;

	if ( n == 1 ) cout << 0 << endl;
	else {
		ll x = fastpow(10, n, mod);
		ll y = fastpow(9, n, mod);
		ll z = fastpow(8, n, mod);

		cout << ((x - 2 * y + z) % mod + mod) % mod << endl;

	}
}

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

	go();

	return 0;
}


Measured memory_bytes: 3648
using namespace std;
#include<iostream>
int main(){
  int A, B;
  cin >> A >> B;
  if (A+B > 16){
    cout << ":(" << endl;
    return(0);
  }
  if ( A <= 16 && A >= 1 && B <= 16 && B >= 1){
    if ( A <= 8 && B <= 8){
      cout << "Yay!" << endl;
    }
    else{
      cout << ":(" << endl;
    }
  }
  return(0);
}

Measured memory_bytes: 3644
#include<stdio.h>
char map[8][8]={0};
void bomb(int y,int x){
	if(x<0 || y<0 || x>7 ||y>7 ||map[y][x]==0)return ;
	if(map[y][x]=='1'){
		map[y][x]='0';
		bomb(y-3,x);bomb(y-2,x);bomb(y-1,x);
		bomb(y+1,x);bomb(y+2,x);bomb(y+3,x);
		bomb(y,x-3);bomb(y,x-2);bomb(y,x-1);
		bomb(y,x+1);bomb(y,x+2);bomb(y,x+3);
	}
}
int main(){
	int n,i,j,k,x,y;
	scanf("%d",&n);
	for(k=1;k<=n;k++){
		for(i=0;i<8;i++)scanf("%s",map[i]);
		scanf("%d",&x);
		scanf("%d",&y);
		bomb(y-1,x-1);
		printf("Data %d:\n",k);
		for(i=0;i<8;i++){
			for(j=0;j<8;j++)
			printf("%c",map[i][j]);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int reverse(char *a)
{
  int n, i;
  char rev[21] = "";
  n = strlen(a);
  for(i=0;i<n;i++)
    {
      rev[i] = a[n-i-1];
    }
  printf("%s\n", rev);
  return 0;
}

int main()
{
  char in[21] = "";
  gets(in);
  reverse(in);
  return 0;
}

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


class Dice:
    """
    0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
    """

    def __init__(self, surfaces):
        self.init_surface = surfaces
        self.surface = surfaces

    def init_dice(self):
        self.surface = self.init_surface

    def roll(self, direction: str):
        if direction == "E":
            self.surface = [self.surface[3], self.surface[1], self.surface[0],
                            self.surface[5], self.surface[4], self.surface[2]]

        elif direction == "N":
            self.surface = [self.surface[1], self.surface[5], self.surface[2],
                            self.surface[3], self.surface[0], self.surface[4]]

        elif direction == "S":
            self.surface = [self.surface[4], self.surface[0], self.surface[2],
                            self.surface[3], self.surface[5], self.surface[1]]

        elif direction == "W":
            self.surface = [self.surface[2], self.surface[1], self.surface[5],
                            self.surface[0], self.surface[4], self.surface[3]]

        return

    def spin(self):
        self.surface = [self.surface[0], self.surface[3], self.surface[1],
                        self.surface[4], self.surface[2], self.surface[5]]
        return

    def get_surface(self, num):
        if num in self.surface:
            indexes = [i for i, x in enumerate(self.surface) if x == num]
            return indexes
        else:
            return None

    def get_top(self):
        return self.surface[0]

    def get_south(self):
        return self.surface[1]

    def get_east(self):
        return self.surface[2]


def main():
    surface = [int(i) for i in input().strip().split()]
    dice1 = Dice(surface)
    surface = [int(i) for i in input().strip().split()]
    dice2 = Dice(surface)

    top1 = dice1.get_top()
    indexes = dice2.get_surface(top1)
    for cur in indexes:
        dice2.init_dice()
        if cur == 0:
            pass
        elif cur == 1:
            dice2.roll("N")
        elif cur == 2:
            dice2.roll("W")
        elif cur == 3:
            dice2.roll("E")
        elif cur == 4:
            dice2.roll("S")
        elif cur == 5:
            dice2.roll("S")
            dice2.roll("S")
        for _ in range(4):
            dice2.spin()
            if dice1.surface == dice2.surface:
                print("Yes")
                return
    print("No")


if __name__ == "__main__":
    main()



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

void fnInsertionSort(vector<int>&, int);
void fnTrace(vector<int>, int);

int main()
{
  vector<int> viSort;
  int iMaxSize;
  
  cin >> iMaxSize;
  viSort.resize( iMaxSize );
  for (int i = 0; i < iMaxSize; i++) cin >> viSort[i];

  fnTrace(viSort, iMaxSize);
  fnInsertionSort(viSort, iMaxSize);

  return 0;
}

void fnInsertionSort(vector<int> &argviSort, int argiSize)
{
  for (int i = 1; i < argiSize; i++)
  {
    int iTarget = argviSort[i];
    int j = i - 1;
    while (iTarget < argviSort[j] &&
           j       >= 0            )
    {
      argviSort[j + 1] = argviSort[j];
      j--;
    }
    argviSort[j + 1] = iTarget;
    fnTrace(argviSort, argiSize);
  }
}

void fnTrace(vector<int> argviSort, int argiSize)
{
  for (int i = 0; i < argiSize; i++)
  {
    if (i) cout << " ";
    cout << argviSort[i];
  }
  cout << endl;
}

Measured memory_bytes: 1216
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int cnt=0;
    rep(i,n){
        while(a[i]%2==0){
            a[i]/=2;
            cnt++;
        }
    }   
    cout<<cnt<<endl;
    
}

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

signed main() {
    string s;
    cin >> s;
    vector<int> res(2019, 0);
    int ex;
    int k = 0;
    res[k]++;
    int ten = 1;
    int n = s.size();
    rep(i, n) {
        ex = s[n - 1 - i] - '0';
        k = (k+ ex * ten) % 2019;
        ten = (ten*10)%2019;
        //cout << k << endl;
        res[k]++;
    }
    int ans = 0;
    for (auto i : res) {
        ans += i * (i - 1) / 2;
    }
    printf("%d",ans);
}


Measured memory_bytes: 3848
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<"a > b"<<endl;
    }else if(a<b){
        cout<<"a < b"<<endl;
    }else{
        cout<<"a == b"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int W = ni();
        int H = ni();
        int[] p = nia(W);
        int[] q = nia(H);

        ArrayList<Pair> list = new ArrayList<>();
        for (int i = 0; i < W; i++) {
            list.add(new Pair(p[i], 1));
        }
        for (int i = 0; i < H; i++) {
            list.add(new Pair(q[i], 0));
        }

        Collections.sort(list);

        long ans = 0;
        long a = W + 1;
        long b = H + 1;

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).y == 1) {
                ans += b * list.get(i).x;
                a--;
            } else {
                ans += a * list.get(i).x;
                b--;
            }
        }

        out.println(ans);
    }

    public class Pair implements Comparable<Pair> {
        int x, y;

        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        public int compareTo(Pair p) {
            return x - p.x;
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

using namespace std;

int a[100005];

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1);
    cout << a[n / 2 + 1] - a[n / 2] << '\n';
    return 0;
}



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

#define ctz __builtin_ctz
#define popc __builtin_popcount

typedef long long LL;
const int N = 15, mod = 1000000007;

int n, m, dp[1 << N], e[N], mask;

void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}
bool valid(int s) { return (s & 1) == (s >> 1 & 1); }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> m, mask = ~(-1 << n);
	for (int i = 0, x, y; i < m; ++i)
		std::cin >> x >> y, --x, --y, e[x] |= 1 << y;
	dp[0] = 1;
	for (int i = 0; i <= mask; ++i) if (dp[i]) {
		int c = mask ^ i;
		for (int j = c; j; j = j - 1 & c) if (valid(j)) {
			int prod = dp[i];
			for (int _k = i, k = ctz(_k); _k; k = ctz(_k &= _k - 1))
				prod = (LL) prod * ~(-1 << popc(e[k] & j)) % mod;
			for (int _k = j, k = ctz(_k); _k; k = ctz(_k &= _k - 1))
				prod = (LL) prod * (1 << popc(e[k] & i)) % mod;
			reduce(dp[i | j] += prod - mod);
		}
	}
	std::cout << (pow(2, m) - dp[mask] + mod) % mod << '\n';
	return 0;
}

Measured memory_bytes: 512
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7

n, m = map(int, input().split())
num_list = [-1]*n
flag = 1

for i in range(m):
    loc, num = map(int, input().split())
    if num_list[loc - 1] == -1 or num_list[loc - 1] == num:
        num_list[loc - 1] = num
    else:
        flag = 0
    
if num_list == [0] or num_list == [-1]:
    ans = 0
else:
    if num_list[0] == 0:
        flag = 0
    if num_list[0] == -1:
        num_list[0] = 1
    num_array = np.array([num_list])
    num_array[num_array < 0] = 0
    dig_array = 10 ** np.arange(n)
    ans = np.sum(num_array * dig_array[::-1])

if flag:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 27352
#include<bits/stdc++.h>
#define LL long long
#define uLL unsigned long long

using namespace std;
const int N=1e5+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,ff[N],sz[N],co[N],sq[N],ts,c[3];
bool v2[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
vector<int> e[N],fe[N];
void adde(int x,int y){e[x].push_back(y),fe[y].push_back(x);}
LL m;
queue<int> q,q2;

int main()
{
    n=rd(),m=rd();
    for(int i=1;i<=n;++i) ff[i]=i;
    for(int i=1;i<=m;++i)
    {
	int x=rd(),y=rd();
	adde(x,y);
	if(findf(x)!=findf(y)) sz[findf(x)]+=sz[findf(y)],ff[findf(y)]=findf(x);
	++sz[findf(x)];
    }
    for(int h=1;h<=n;++h)
	if(findf(h)&&(int)e[h].size()&&(int)fe[h].size())
	{
	    m-=sz[findf(h)];
	    ff[h]=0,ts=0,q.push(h);
	    while(!q.empty())
	    {
		int x=q.front();
		q.pop();
		sq[++ts]=x;
		int nn=e[x].size(),mm=fe[x].size(),sx=e[x][0],tx=fe[x][0];
		for(int i=0;i<nn;++i)
		{
		    int y=e[x][i];
		    if(!(int)e[y].size()) adde(y,tx);
		    if(ff[y]) co[y]=(co[x]+1)%3,ff[y]=0,q.push(y);
		}
		for(int i=0;i<mm;++i)
		{
		    int y=fe[x][i];
		    if(!(int)fe[y].size()) adde(sx,y);
		    if(!v2[y]) v2[y]=1,q2.push(y);
		}
		if(q.empty())
		{
		    while(!q2.empty()&&!ff[q2.front()]) q2.pop();
		    if(!q2.empty())
		    {
			int y=q2.front();
			q2.pop();
			mm=fe[y].size();
			for(int j=0;j<mm;++j)
			{
			    int z=fe[y][j];
			    if(!ff[z]){co[y]=(co[z]+1)%3,ff[y]=0,q.push(y);break;}
			}
			nn=e[y].size();
			for(int j=0;j<nn;++j)
			{
			    int z=e[y][j];
			    if(!ff[z]&&(int)e[z].size()){sx=e[z][0];break;}
			}
			assert(!ff[sx]);
			if(ff[y]) adde(sx,y),co[y]=(co[sx]+1)%3,ff[y]=0,q.push(y);
		    }
		}
	    }
	    bool ok=0;
	    for(int i=1;i<=ts;++i)
	    {
		int x=sq[i],nn=e[x].size();
		for(int j=0;j<nn;++j)
		{
		    int y=e[x][j];
		    ok|=(co[y]-co[x]+3)%3!=1;
		}
	    }
	    if(ok) m+=1ll*ts*ts;
	    else
	    {
		c[0]=c[1]=c[2]=0;
		for(int i=1;i<=ts;++i) ++c[co[sq[i]]];
		m+=1ll*c[0]*c[1]+1ll*c[1]*c[2]+1ll*c[2]*c[0];
	    }
	}
    printf("%lld\n",m);
    return 0;
}


Measured memory_bytes: 14200
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
	int an, bn, r, ans = 0, d, b0, b1, insides[41] = {0};
	vector< vector<int> > a(10000);
	scanf("%d %d %d", &an, &bn, &r);
	while (an || bn){
		d = r * r << 4;
		for(int i = 0; i <= r << 2; i++){
			for (int j = 0; j <= r << 2; j++){
				if (i*i + j*j <= d){
					insides[i]++;
				}
			}
		}
		for (int i = 0; i < an; i++){
			int tmp1, tmp2;
			scanf("%d %d", &tmp1, &tmp2);
			a[tmp1].push_back(tmp2);
		}
		for (int i = 0; i < 10000; i++){
			sort(a[i].begin(),a[i].end());
		}
		for (int i = 0; i < bn; i++){
			scanf("%d %d", &b0, &b1);
			for (int c0 = max(-(r << 2)-1, -b0); c0 < min((r << 2) + 1, 10000 - b0); c0++){
				for (int c1 = 0; c1 < a[b0 + c0].size(); c1++){
					if (abs(a[b0 + c0][c1] - b1) < insides[abs(c0)]){
						ans++;
					}
				}
			}
		}
		printf("%d\n", ans);
		ans = 0;
		for (int i = 0; i < 10000; i++){
			a[i].clear();
		}
		for (int i = 0; i < 41; i++){
			insides[i] = 0;
		}
		scanf("%d %d %d", &an, &bn, &r);
	}
	return 0;
}

Measured memory_bytes: 2712
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#define ll long long
#define P(a) cout << a << " ";
#define NCONS 200001
#define endl '\n'
using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) cin >> vec[i];
	sort(vec.begin(), vec.end());
	auto last = vec.back(); vec.pop_back();
	int sum = 0;
	for (int i = 0; i < vec.size(); i++) sum += vec[i];

	if (last < sum)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
	return 0;
}

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

pair<int, int> s[200];
int n;
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int main()
{
	while (cin >> n, n)
	{
		int left = 0;
		int right = 0;
		int top = 0;
		int bottom = 0;
		s[0] = pair<int, int>(0, 0);

		for (int i = 1; i < n; i++)
		{
			int t, d;
			cin >> t >> d;
			s[i] = pair<int, int>(s[t].first + dx[d], s[t].second + dy[d]);
			left = min(left, s[i].first);
			right = max(right, s[i].first);
			top = max(top, s[i].second);
			bottom = min(bottom, s[i].second);
		}

		cout << right - left + 1 << " " << top - bottom + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160