akhauriyash/Code-Regression huggingface dataset:
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}
const int maxN = 5005;
int fact[maxN];
int invfact[maxN];
int inv[maxN];
void init() {
    fact[0] = invfact[0] = inv[1] = fact[1] = invfact[1] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(mod - mod / i, inv[mod % i]);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
}
int cnk(int n, int k) {
    if (n < k || k < 0) return 0;
    return mult(fact[n], mult(invfact[k], invfact[n - k]));
}
vector < int > g[maxN];
int n;
int sz[maxN];
int sb[maxN];
void dfs(int v, int p) {
    sz[v] = 1;
    sb[v] = 0;
    for (int to : g[v]) {
        if (to == p) continue;
        dfs(to, v);
        sz[v] += sz[to];
        sb[v] = max(sb[v], sz[to]);
    }
}
int dp[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    init();
    cin >> n;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    dfs(1, -1);
    int c = -1;
    for (int i = 1; i <= n; i++) {
        if (sb[i] <= n / 2 && n - sz[i] <= n / 2) {
            c = i;
            break;
        }
    }
    assert(c != -1);
    dfs(c, -1);
    vector < int > sizes;
    for (int to : g[c]) {
        sizes.emplace_back(sz[to]);
    }
    dp[0][0] = 1;
    int p = 0;
    for (int i = 0; i < sizes.size(); i++) {
        vector < int > f(sizes[i] + 1);
        for (int j = 0; j <= sizes[i]; j++) {
            f[j] = mult(fact[j], mult(cnk(sizes[i], j), cnk(sizes[i], j)));
            if (j & 1) f[j] = (mod - f[j]) % mod;
        }
        for (int at = 0; at <= p; at++) {
            for (int j = 0; j <= sizes[i]; j++) {
                dp[i + 1][at + j] = sum(dp[i + 1][at + j], mult(dp[i][at], f[j]));
            }
        }
        p += sizes[i];
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        ans = sum(ans, mult(dp[sizes.size()][i], fact[n - i]));
    }
    cout << ans;
    return 0;
}

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

//////////////////
// Union-Find木¨ //
//////////////////

// 0-indexed
class UnionFind {
private:
	std::vector<int> parent_, size_;
public:
	UnionFind(const int size)
		:parent_(size), size_(size, 1)
	{
		for (int i{}; i < size; i++) parent_[i] = i;
	}
	int calcRoot(const int index)
	{
		if (parent_[index] == index) return index;
		const int p{calcRoot(parent_[index])};
		parent_[index] = p;
		return p;
	}
	bool areConnected(const int index1, const int index2)
	{
		return calcRoot(index1) == calcRoot(index2);
	}
	void unite(const int index1, const int index2)
	{
		const int root1{calcRoot(index1)}, root2{calcRoot(index2)};
		if (root1 == root2) return;
		if (size_[root1] <= size_[root2])
		{
			size_[root2] += size_[root1];
			parent_[root1] = root2;
		}
		else
		{
			size_[root1] += size_[root2];
			parent_[root2] = root1;
		}
		return;
	}
	int calcSize(const int index)
	{
		return size_[calcRoot(index)];
	}
};


int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	UnionFind uf(N);
	for (int i{}; i < M; i++)
	{
		int X, Y, Z;
		scanf("%d%d%d", &X, &Y, &Z);
		X--; Y--;
		uf.unite(X, Y);
	}
	int count{};
	for (int i{}; i < N; i++)
		if (uf.calcRoot(i) == i)
			count++;
	
	printf("%d\n", count);

	return 0;
}

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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

#define MAX 100000

bool is_prime(int x){
    for(int i=2;i*i<=x;++i){
        if(x%i==0)return false;
    }
    return true;
}

int main(void){
    int x;cin>>x;
    int p=x;
    while(!is_prime(p))++p;
    co(p);
}

Measured memory_bytes: 256
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static ArrayList<Integer> list = new ArrayList<>();
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		long[] x = new long[n];
		long sum = 0;
		for (i = 0; i < x.length; i++) {
			x[i] = parseLong(sc.next());
			sum+=x[i];
		}
		sc.close();
		double ave = (double)sum/n;
		long p1 = (long)floor(ave);
		long p2 = (long)ceil(ave);
		long tot1=0,tot2=0;
		for (i = 0; i < n; i++) {
			tot1+=(x[i]-p1)*(x[i]-p1);
			tot2+=(x[i]-p2)*(x[i]-p2);
		}
		out.println(Math.min(tot1,tot2));
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

Int N;
vector<Int> ord;
vector<Int> R, A, W, T;

_int used[2010][5010][2], mem[2010][5010][2];
Int dfs(Int i, Int t, Int flag){
  if(t <= 0) return -(Int)INF;
  if(i == N) return 0;
  if(used[i][t][flag]++) return mem[i][t][flag];

  Int I = ord[i];
  Int a = -INF, b = -INF;
  {//次の曲にいく
    a = dfs(i+1, t, 0);
  }

  {//演奏する
    b = dfs(i, min(T[I], t - R[I]), 1) + (flag == 0? A[I]:W[I]);
  }
  Int res = max(a, b);
  return mem[i][t][flag] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>N;
  R.resize(N), A.resize(N), W.resize(N), T.resize(N);
  for(Int i=0;i<N;i++) cin>>R[i]>>A[i]>>W[i]>>T[i];

  ord.resize(N); iota(ord.begin(), ord.end(),0);
  sort(ord.begin(), ord.end(), [&](Int i, Int j){
      return P(R[i] + T[i], -R[i]) > P(R[j] + T[j], -R[j]);
    });


  Int ans = dfs(0, 5000, 0);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 80920
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int n,d;
    cin >> n >> d;
    d = (d*2)+1;
    int cnt = 0;
    while(1){
        n -=d;
        cnt++;
        if(n<=0)break;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 256
N, D, A = map(int, input().split())

data = []
for _ in range(N):
	data.append(tuple(map(int, input().split())))

data.sort()

queue = []
i = 0
j = 0
total = 0
height = 0
while i < N:
	if j >= len(queue) or data[i][0] <= queue[j][0]:
		x, h = data[i]
		i += 1
		if height < h:
			count = (h - height + A - 1) // A
			total += count
			height += count * A
			queue.append((x + D * 2, count * A))
	else:
		height -= queue[j][1]
		j += 1

print(total)


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

using namespace std;

typedef vector <int> vi;

int n, m;
vector <vi> graph;
vi in_degree;
vi visited;
vi dist;

void dfs(int u)
{
    if (visited[u])
        return;

    visited[u] = true;

    for (int v: graph[u])
    {
        dist[v] = max(dist[v], 1 + dist[u]);
        in_degree[v]--;

        if (!in_degree[v])
            dfs(v);
    }
}

int main()
{
    int u, v;

    cin >> n >> m;

    graph.assign(n+1, vi());
    in_degree.assign(n+1, 0);

    for (int i = 1; i <= m; i++)
    {
        cin >> u >> v;

        graph[u].push_back(v);
        in_degree[v]++;
    }

    for (int i = 1; i <= n; i++)
    {
        if (!in_degree[i])
        {
            graph[0].push_back(i);
            in_degree[i]++;
        }
    }

    visited.assign(n+1, 0);
    dist.assign(n+1, 0);

    dfs(0);

    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        // cout << i << " " << dist[i] << "\n";
        ans = max(ans, dist[i]);
    }

    cout << ans - 1 << "\n";
    
    return 0;
}

Measured memory_bytes: 9984
import sys

def dupchk(seq):
  return len(seq) != len(set(seq))
arrw = []

N = int(input())
for i in range(0,N):
  W = str(input())
  arrw.append(W)

if dupchk(arrw) == False:
  for i in range(0,N-1):
    if arrw[i][-1] != arrw[i+1][0]:
      print("No")
      sys.exit()
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var n, t int
	fmt.Scan(&n, &t)
	var prev int
	fmt.Scan(&prev)
	sum := t
	for i := 0; i < n - 1; i++ {
		var tmp int
		fmt.Scan(&tmp)
		if tmp - prev < t {
			sum += tmp - prev
		} else {
			sum += t
		}
		prev = tmp
	}
	fmt.Println(sum)
}

Measured memory_bytes: 5504
n = int(input())
a = list(map(int, input().split()))

a.sort(reverse = True)
alice_score = 0
bob_score = 0
for i in range(n):
	if i % 2 == 0:
		alice_score += a[i]
	else:
		bob_score += a[i]
print(alice_score - bob_score)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <stdlib.h> //rand() 0~RAND_MAX2147483647
#include <math.h>
#include <time.h>   //srand((unsigned int)time(NULL));
#include <unistd.h> //sleep
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <unordered_map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int MOD=1e9+7;
const int MOD2=998244353;

const int INF=2000000001;
const ll INFll=2e18;
//const int MAX_V=10000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INFll || MOD2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}
#define elif else if

#define issame(a,b,c,d) ((a)==(b) and (b)==(c) and (c)==(d))
#define isdiff3(a,b,c) ((a)!=(b) and (b)!=(c) and (c)!=(a))
#define isdiff4(a,b,c,d) ((a)!=(b) and (b)!=(c) and (c)!=(a) and (d)!=(a) and (d)!=(b) and (d)!=(c))
#define Func3(f,a,b,c) (f)((f)((a),(b)),(c))
#define Func4(f,a,b,c,d) (f)((f)((f)((a),(b)),(c)),(d))

inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
inline ll  gcd(ll a,ll b){ if(b==0)return a;else return gcd(b,a%b);}//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
inline ll  lcm(ll a,ll b){return a*b/gcd(a,b);}//MODやオーバーフローには注意！
//inline ll  ceil(double a){return (ll)a+1;}


//Eと名のつくのはデバッグ用！
int EintN(ll array[],const ll num){
    for(int i=0;i<num;i++){cerr<<array[i]<<" ";}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {cerr<<array[i][k]<<" ";}
        }
        br;
    }
    br;
    return 0;
}
int Eint(string str,const ll num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}













int prob(){
    ll ans;ans=0;
    ll N;cin>>N;
    ll A[N];
    inarray(A, 0, N);
    
    ans = std::accumulate(A, A+N, 0, [](int a, int b) {
        return gcd(a,b);
    });
    
    OutputAndReturn0(ans);
    return 0;
}


signed main(){
    prob();
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int n = s.length();
	int cun = 0;
	for (int i = 0; i < n; i++) {
		if(s[i] == t[i])
			cun++;
	}
	if (cun == n && n + 1 == t.length())
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main(int argc, char* argv[]) {
  int q;
  cin >> q;
  int rets[q];
  for (int i = 0; i < q; ++i) {
    string s, t;
    cin >> s >> t;

    int dp[s.size() + 1][t.size() + 1];
    memset(dp, 0, sizeof(int) * (s.size() + 1) * (t.size() + 1));

    for (int j = 0; j < s.size(); ++j) {
      for (int k = 0; k < t.size(); ++k) {
        if (s[j] == t[k])
          dp[j + 1][k + 1] = dp[j][k] + 1;
        else
          dp[j + 1][k + 1] = max(dp[j + 1][k], dp[j][k + 1]);
      }
    }

    rets[i] = dp[s.size()][t.size()];

  }

  for (int i = 0; i < q; ++i)
    cout << rets[i] << endl;

  return 0;
}


Measured memory_bytes: 6996
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a,b;
	cin>>a>>b;
	if(a<10 && b<10)
		cout<<a*b;
	else
		cout<<-1;
	

}

Measured memory_bytes: 3632
#import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np
from collections import defaultdict

def main():
	n=II()
	A=LI()
	q=II()

	d=defaultdict(int)

	for i in A:
		d[i]+=1

	ans=sum(A)

	for _ in range(q):
		b,c=MI()
		ans+=(c-b)*d[b]
		d[c]+=d[b]
		d[b]=0
		#print(d)
		print(ans)



















if __name__ == "__main__":
	main()


Measured memory_bytes: 24088
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];

        long[] a = new long[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++)
        {
            long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();
            a[i] = tmp[0];
            b[i] = tmp[1];
        }

        Array.Sort(a, b);
        long ans = 0;
        long count = 0;
        for (int i = 0; i < n; i++)
        {
            count += b[i];
            if (count >= k)
            {
                ans = a[i];
                break;
            }   
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 16952
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  string s;
  getline(cin,s);
  char *p;
  char str[s.length()+1];
  strcpy(str,s.c_str());
  p = strtok(str," .,");
  int f=0;
  while(p!=NULL) {
    if (strlen(p)>=3&&strlen(p)<=6) {
      if (f) cout << " ";
      else f++;
      cout << p;
    }
    p = strtok(NULL, " .,");
  }
  cout << endl;
}

Measured memory_bytes: 0
//
//  main.c
//  ITP1_5_B
//
//  Created by ??±??°?????? on 2015/10/10.
//  Copyright ?? 2015??´ HamadaShogo. All rights reserved.
//

#include <stdio.h>

void printSquareF(unsigned int High, unsigned int Wide);

int main(int argc, const char * argv[]) {
    // insert code here...
    unsigned int w = 1, h = 1;
    
    while (!(h == 0 && w == 0)) {
        scanf("%d %d", &h, &w);
        if(!(h == 0 && w == 0)){
            printSquareF(h, w);
        }
    }
    
    return 0;
}

void printSquareF(unsigned int High, unsigned int Wide){
    int i, j;
    
    for (i=0; i<High; i++) {
        for (j=0; j<Wide; j++) {
            if (i == 0 || i + 1 == High || j == 0 || j + 1 == Wide) {
                printf("#");
            }
            else{
                printf(".");
            }
        }
        puts("");
    }
    puts("");
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
int n,m,i,j,l,f,max,min,k;
int mp[101][101];
int a[5001],b[5001],c[5001],d[5001],e[5001],h[101],p[5001];
int main(void)
{
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0&&m==0) break;
		for(i=1;i<=n;i++) for(j=1;j<=n;j++) mp[i][j]=-1;
		j=0; l=0;
		for(i=0;i<m;i++) a[i]=0,b[i]=0,c[i]=0,d[i]=0,e[i]=0;
		for(i=0;i<m;i++){
			scanf("%d",&f);
			if(f==0) scanf("%d %d",&a[i],&b[i]);
			else scanf("%d %d %d",&c[i],&d[i],&e[i]);
		}
		for(i=0;i<m;i++){
			for(j=1;j<=n;j++) h[j]=M; //初期化
			if(a[i]!=0){
				p[0]=a[i];
				l=0;
				k=1;
				h[a[i]]=0;
				for(j=1;j<=n;j++){
					if(mp[p[l]][j]!=-1&&h[j]>h[p[l]]+mp[p[l]][j]) {
						h[j]=h[p[l]]+mp[p[l]][j];
						p[k]=j;
						k++;
					}
					//printf("%d p=%d mp=%d hp=%d h=%d\n",j,p[l],mp[p[l]][j],h[p[l]],h[j]);
					if(j==n){
						j=0;
						l++;
					}
					if(l==k) break;
				}
				if(h[b[i]]!=M)printf("%d\n",h[b[i]]);
				else printf("-1\n");
			}
			else if(c[i]!=0){
				if(mp[c[i]][d[i]]==-1||mp[c[i]][d[i]]>e[i]){
					mp[c[i]][d[i]]=e[i];
					mp[d[i]][c[i]]=e[i];
				}
			}
		}
		/*for(i=1;i<=n;i++) {
			for(j=1;j<=n;j++) printf("%d %d mp=%d ",i,j,mp[i][j]);
			printf("\n");
		}*/
	}
	return 0;
}


Measured memory_bytes: 3288
N, M, C = [int(x) for x in input().split(" ")]
B = [int(x) for x in input().split(" ")]
A = [[int(x) for x in input().split(" ")] for _ in range(N)]


print(len([sum(ab) + C for ab in [[a * b for (a, b) in zip(AA, B)]
                                  for AA in A] if sum(ab) + C > 0]))


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b, c) = (v[0], v[1], v[2]);
    let a = a - b;
    if a > c {
        println!("{}", 0);
    } else {
        println!("{}", c - a);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2144
#include<iostream>
using namespace std;
int arr1[100005];
int arr2[50500];
int n,q,ans;

bool Linear_Serch(int x)
{
    for(int j=0;j<n;j++)
        {
            if(x==arr1[j])
                return true;
        }
    return false;
}
bool Binary_Serch(int x)
{
    int l=0,r=n,mid;
    //下面的这个判断点在右边的情况“a[mid]>=x”
    while(l<r)
    {
        mid=l+r>>1;
        if(x<=arr1[mid])r=mid;
        else l=mid+1;
    }
    //下面的这个判断点在左边的情况“a[mid]<=x”
    
    while(l<r)
    {
        mid=l+r+1>>1;
        if(x>=arr1[mid])l=mid;
        else r=mid-1;
    }
    
    return x==arr1[l];

}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>arr1[i];
    cin>>q;
    for(int i=0;i<q;i++)cin>>arr2[i];
    for(int i=0;i<q;i++)
    {
        if(Binary_Serch(arr2[i]))
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define Md 1000000007
#define MN 3005
#define inv2 500000004
int nex[MN][MN],lst[MN];
lg dp[MN][MN];
int a[MN];
int k1,k2;
lg P2[MN];
int n,q;
int main(){
	read(n);read(q);
	for(int i=1;i<=n;++i){
		read(a[i]);
	}
	P2[0]=1;
	for(int i=1;i<MN;++i)P2[i]=P2[i-1]*2%Md;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j)if(a[i]<a[j])++dp[i][j];
	}
	for(int i=1,now=1,lst=0;i<=q;++i,swap(now,lst)){
		read(k1);read(k2);
		for(int j=1;j<=n;++j)if(j!=k1&&j!=k2){
			{lg aa=(dp[j][k1]+dp[j][k2])*inv2%Md;
			dp[j][k1]=dp[j][k2]=aa;}
			{lg aa=(dp[k1][j]+dp[k2][j])*inv2%Md;
			dp[k1][j]=dp[k2][j]=aa;}
		}
		dp[k1][k2]=dp[k2][k1]=(dp[k1][k2]+dp[k2][k1])*inv2%Md;
	}
	lg res=0;
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			res+=dp[j][i];
			res%=Md;
		}
	}
	cout<<res*P2[q]%Md;
	return 0;
}


Measured memory_bytes: 71936
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
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();}
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 EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int n, m;

	while(cin >> n >> m, n) {
		vvi ans(m, vi(2));
		REP(i, m) {
			ans[i][1] = i+1;
		}

		int tmp;
		int M = 0;
		REP(i, n) {
			REP(j, m) {
				cin >> tmp;
				if(tmp) {
					ans[j][0]++;
				}
				M = max(M, ans[j][0]);
			}
		}

		bool flag = false;
		for(int i = M; M >= 0; M--) {
			REP(j, m) {
				if(ans[j][0] == M) {
					if(flag) 
						cout << " ";
					cout << ans[j][1];
					flag = true;
				}
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string num;
  int res = 0;
  cin >> num;
  
  if (num[0] == '1') res++;
  if (num[1] == '1') res++;
  if (num[2] == '1') res++;
  
  cout << res << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AProduct {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b;
	    in >> a >> b;
	    if(a*b % 2 == 1) out << "Odd" << endl;
	    else out << "Even" << endl;
	}
};


int main() {
	AProduct solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
////////////////////////////////////////////////
//                                            //
//  Author: Muhammad Faishol Amirul Mukminin  //
//                                            //
////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef pair<ll,ll> pl;
typedef pair<pl,ll> pll;
typedef pair<double,double> pd;
typedef pair<pd,double> pdd;

#define fi first
#define se second
#define PUB push_back
#define POB pop_back
#define PUF push_front
#define POF pop_front
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"

const double EPS = 1e-9;
const double PI = acos(-1);

const ll MOD = 1e9+7;

const int dCol[] = {0,+1,0,-1,+1,+1,-1,-1};
const int dRow[] = {-1,0,+1,0,-1,+1,+1,-1};

ll A, B,C,D;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> A >> B >> C >> D;
	if(A+B>C+D) cout << "Left" << endl;
	else if(A+B<C+D) cout << "Right" << endl;
	else cout << "Balanced" << endl;

	return 0;
}

Measured memory_bytes: 764
package main

import "fmt"

func main() {
	var H, W int
	for {
		fmt.Scan(&H, &W)
		if H == 0 && W == 0 {
			break
		}
		for i := 0; i < H; i++ {
			for j := 0; j < W; j++ {
				if (i+j)%2 == 0 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println("")
		}
		fmt.Println("")
	}
	return
}




Measured memory_bytes: 1124
k, x = gets().chomp.split("\s").map{|x| x.to_i}

min = x - k + 1
max = x + k - 1

min = -1000000 if min < -1000000
max = 1000000 if max > 1000000

list = []
(min..max).each do |x|
  list.push(x)
end

puts list.join("\s")

Measured memory_bytes: 14308
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    long M = 1_000_000_007;
    int N = scanner.nextInt();
    int[] A = new int[N + 1];
    Set<Integer> set = new HashSet<>();
    int t = 0;
    for (int i = 0; i < N + 1; i++) {
      A[i] = scanner.nextInt();
      if (set.contains(A[i])) t = A[i];
      set.add(A[i]);
    }
    int l = 0;
    while (A[l] != t) l++;
    int r = 0;
    while (A[N - r] != t) r++;
    int lr = l + r;

    long[] nck = chooseForN(N + 1, M);
    long[] lrck = chooseForN(lr, M);
    StringBuilder sb = new StringBuilder();
    for (int k = 1; k <= N + 1; k++) {
      long c = nck[k];
      if (lr >= k - 1) {
        c -= lrck[k - 1];
        if (c < 0) c += M;
      }
      sb.append(c).append('\n');
    }
    System.out.print(sb.toString());
  }

  public static long[] chooseForN(int n, long mod) {
    long[] C = new long[n + 1];
    long[] fact = new long[n + 1];
    long[] factinv = new long[n + 1];

    fact[0] = 1;
    for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (n - i) % mod;
    factinv[0] = 1;
    for (int i = 1; i <= n; i++) factinv[i] = factinv[i - 1] * inverse(i, mod) % mod;

    for (int i = 0; i <= n; i++) C[i] = fact[i] * factinv[i] % mod;

    return C;
  }

  private static long inverse(long a, long mod) {
    return modpow(a, mod - 2, mod);
  }

  private static long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
      if (n % 2 == 1) res = (res * a) % mod;
      a = (a * a) % mod;
      n >>= 1;
    }
    return res % mod;
  }
}


Measured memory_bytes: 70148
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(int i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<int,int>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((int)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
    // FILE;
    SPEED;
    int l,r,d;
    cin>>l>>r>>d;

    int a1 = (l-1)/d;
    int a2 = r/d;

    cout<<a2-a1<<endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end());
    int max = l[n-1];
    int plus = 0;
    for(int i = 0; i < n-1; i++) {
        plus += l[i];
    }
    if(max < plus) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
N = int(input())
S = input()

lefts = [(0, 0)]  # W, E
for i in range(N):
    t = lefts[-1]
    if S[i] == "W":
        lefts.append((t[0] + 1, t[1]))
    else:
        lefts.append((t[0], t[1] + 1))

ans = 1e100
for i in range(1, N + 1):
    lt = lefts[i]
    rt = lefts[-1]

    lw = lt[0]
    le = lt[1]
    rw = rt[0] - lw
    re = rt[1] - le
    if S[i - 1] == "W":
        lw -= 1
    else:
        le -= 1
    ans = min(ans, lw + re)
print(ans)


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

int main() {
  int A,B;
  cin >> A >> B;
  int c=-1;
    for(int i =10*B;i<10*B+10;i++){
      for(int j=(25*A+1)/2;j<(25*(A+1)+1)/2;j++){
        if(i==j){
          c=i;
          break;
        }
      }
     if(c!=-1)
      break;
    }
   cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>

using lint = long long int;
using Graph = std::vector<std::vector<lint>>;

template<class T>
struct edge
{
	T dist;
	lint to;
	edge(){}
	edge(const T &a_dist,const lint &a_to) : dist(a_dist), to(a_to) {}
	~edge(){}
};

int main(int argc,char *argv[])
{
	int a,b;
	std::cin >> a >> b;

	int ans = 0;
	int len = 1;
	while(len < b)
	{
		--len;
		len += a;
		++ans;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
 
/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 
 
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
 
/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;
 
/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
/* func */
 
/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;
 
/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
 
//#define int ll
//#define int long long
 
int main(){
   string n; cin>>n;
   int ans=0;
   int i=0;

  for(i=1;n[i]=='0' || n[i]=='\0' && n[0]=='1';i++){
    if(n[i]=='\0'){
      cout<<10;
      return 0;
    }
  }
  
   for(i=0;i<n.size();i++){
     ans+=(n[i]-'0');
   }
   cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int a, b, c=0, d, n, i;

  scanf("%d %d", &a, &b);
  n = b - a;

  for(i=1;i<n;i++){
    c += i;
  }
  d = c - a;

  printf("%d\n", d);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}//最大公約数
int lcm(int a,int b){return a/gcd(a,b)*b;}//最小公倍数

/****************************** START ******************************/

signed main(){
  int N,X,T;
  cin >> N >> X >> T;
  
  if (N % X > 0){
    cout << (N / X + 1) * T;
  } else {
    cout << (N / X) * T;
  }
}

Measured memory_bytes: 3620
#include <atcoder/all>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

int main(){
    int n,q;
    cin>>n>>q;
    auto uf = atcoder::dsu(n);
    REP(i,q){
        int m,u,v;
        cin>>m>>u>>v;
        if(m==0){
            uf.merge(u, v);
        }else{
            if(uf.same(u,v)){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    
}

Measured memory_bytes: 4036
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
aa = [a, b, c, d, e]
low = min(aa)
high = max(aa)
if high - low > k:
    print(':(')
else:
    print('Yay!')


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>


using namespace std;

int main()
{
	string S;
	string T;
	cin >> S;
	long long count=1;

	for (int i = 0; i < S.size()-1; ++i) {
		if (S[i] != S[i + 1]) {
			count++;
		}

	}
	cout << count-1 << endl; 
	return 0;
}


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

Int P;

Int modpow(Int a, Int n) {
    Int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % P;
        a = a * a % P;
        n >>= 1;
    }
    return res;
}

int main(){ 
    Int N;
    cin >> N >> P;
    string S;
    cin >> S;

    vector<int> s(N);

    rep(i,N) {
        s[i] = S.at(i) - '0';
    }

    //rep(i,S.size()) cout << s.at(i) << endl;

    Int cnt = 0;

    if (P == 2) {
        rep(i,N) {
            if (s[i] % 2 == 0) cnt += i+1;
        }
    }
    else if (P == 5) {
        rep(i,N) {
            if (s[i] % 5 == 0) cnt += i+1;
        }
    }
    else {
        Int U = 0;
        vector<Int> m(P,0);
        m[0] = 1;
        rep(i,N) {
            U = (U + s[N-1-i] * modpow(10,i)) % P;
            cnt += m[U];
            m[U]++;
        }
        
    }
    cout << cnt << endl;

}

Measured memory_bytes: 1412
k = gets.to_i
a = "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".split(",").map(&:to_i)
p a[k-1]

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, s, g) for(int i = s; i < g; i++)
#define FORR(i, s, g) for(int i = s - 1; i >= g; i--)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define DMP(a) std::cerr << "[Debug] : " << #a << " = " << a << "\n"
#define DMP(a) std::cerr << "[Debug] : " << #a << " = " << a << "\n"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<std::string> vs;
struct aaa{
    aaa(){
        std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout<<std::fixed<<std::setprecision(20);
    };
}aaaaaaa;

class UnionFind {
private:
    vi _par;
    vi _rank;
public:
    UnionFind(const int n);
    int find(const int n);
    void unite(int x, int y);
    bool same(const int x, const int y);
};

UnionFind::UnionFind(const int n) {
    REP(i,n) {
        _par.push_back(i);
        _rank.push_back(0);
    }
}

int UnionFind::find(const int x) {
    if(_par[x] == x) return x;
    else return _par[x] = find(_par[x]);
}

void UnionFind::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(_rank[x] < _rank[y]) _par[x] = y;
    else {
        _par[y] = x;
        if(_rank[x] == _rank[y]) _rank[x]++;
    }
}

bool UnionFind::same(const int x, const int y) {
    return find(x) == find(y);
}

int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind ufr(n), ufl(n);
    REP(i, k) {
        int p, q;
        cin >> p >> q;
        ufr.unite(p - 1, q - 1);
    }
    vi a(n,1);
    REP(i, l) {
        int r, s;
        cin >> r >> s;
        ufl.unite(r - 1, s - 1);
    }

    map<pair<int, int>, int> ans;
    vector<pair<int, int>> p(n);
    REP(i, n) {
        p[i].first = ufr.find(i);
        p[i].second = ufl.find(i);
        ans[p[i]]++;
    }
    REP(i, n) {
        if(i != n - 1) cout << ans[p[i]] << " ";
        else cout << ans[p[i]] << "\n";
    }

    return 0;
}


Measured memory_bytes: 17428
#include <stdio.h>
#include <iostream>
#define MAX_N 100000
#define MAX_Q 100000
#define M 0
using namespace std;

long long par[MAX_N+1];//parents
long long Rank[MAX_N+1];//depth of tree

//initialize
void init(long long n){
	for(long long i = 0;i < n;i++){
		par[i] = i;
		Rank[i] = 0;
	}
}

//find root
long long find(long long x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = find(par[x]);
	}
}

//unite group of x and group of y
void unite(long long x,long long y){
	x = find(x);
	y = find(y);
	if(x == y)return;

	if(Rank[x] < Rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(Rank[x] == Rank[y])Rank[x]++;
		//in other cases we don't have to change rank[x] cos 
		//rank of x is needed only if x is root of tree
	}
}

//check if x and y belong to the same group
bool same(long long x, long long y){
	return find(x) == find(y);
}

long long N,Q;
long long sum = 0;
long long tree[MAX_N+1];

long long nearestAncstr(long long num){
	if(same(num,M))return num;
	nearestAncstr(tree[num]);
}

void operate(char symbol,long long num){
	if(symbol == 'Q'){
		sum += nearestAncstr(num);sum++;//1-indexed
	}else unite(num,M);
}

long long num;char symbol;


void solve(){
	init(N);sum = 0;
	tree[0] = 0;
	for(long long i = 1;i < N;i++){cin >>tree[i];tree[i]--;}//0-indexed
	for(int i = 0;i < Q;i++){
		cin >>symbol >>num;num--;
		operate(symbol,num);
	}
	printf("%lld\n",sum);
}

int main(){
	while(true){
		cin >>N >>Q;
		if(N == 0 && Q == 0)break;
		solve();
	}

	return 0;
}

Measured memory_bytes: 3492
#include<stdio.h>
int main()
{
    int A,B,C,D,i;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    if(A>=1&&A<=100&&B>=1&&B<=100&&C>=1&&C<=100&&D>=1&&D<=100)
    {
        for(i=0;i<100;i++)
        {
            C=C-B;
            A=A-D;
            if(C==0||C<0)
            {
                printf("Yes");
                break;
            }
            else if(A==0||A<0)
            {
                printf("No");
                break;
            }

        }
    }
}


Measured memory_bytes: 2144
import bisect
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
S = [0]*(n+1)
for i in range(n):
    S[i+1] = S[i] + A[i]

def cnt(x,A,S):
    res = 0
    for i,a in enumerate(A):
        res += bisect.bisect_left(A,x - a)
    return res

def ans(x,A,S):
    res = 0
    for i,a in enumerate(A):
        res += a*bisect.bisect_left(A,x-a) + S[bisect.bisect_left(A,x-a)]
    return res

top = A[-1]*2+1
bottom = 0
# mid以上が何個あるか
while top - bottom > 1:
    mid = (top + bottom)//2
    if n*n - cnt(mid,A,S) > m:
        bottom = mid
    else:
        top = mid

print(S[-1]*2*n - ans(top,A,S) + bottom*(m - (n*n - cnt(top,A,S))))


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

using namespace std;

int main() {
  
    int N;
    int counter=0;
  cin >> N;
  
  for (int i=0; i < N; i++){
    
    string S;
    cin >> S;
    
    if (S == "Y"){
      counter++;
    }
    
    else{
      counter += 0;
    }
  }
  
  if (counter > 0){
    cout << "Four" << endl;
  }
  else {
    cout << "Three" << endl;
  }
      
}


Measured memory_bytes: 256
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        exit ()
    
    if m == -1 or f == -1:
        print ("F")
    elif 80 <= m+f:
        print ("A")
    elif 65 <= m+f and m+f < 80:
        print ("B")
    elif 50 <= m+f and m+f < 65:
        print ("C")
    elif 30 <= m+f and m+f < 50:
        if 50 <= r:
            print ("C")
        else:
            print ("D")
    else:
        print ("F")



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vvi vector<vector<int>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define pii pair<int, int>
#define vpli vector<pair<long long, int>>
#define deb(x) cout << "deb " << #x << " " << x << endl
#define all(x) x.begin(), x.end()
#define endl "\n"
const int N = 2e5 + 3,MOD = 1e9+7;

int n;
vll a(N),b(N);

ll bpow(ll base,ll pow)
{
    if(pow == 0) return 1;
    ll ans = bpow(base,pow/2);
    ans = (ans*ans)%MOD;
    if(pow%2)
    {
        ans = (ans * base)%MOD;
    }
    return ans;
}

void solve()
{
    cin>>n;
    ll zeroc = 0;
    map<pair<ll,ll>,ll> mp;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        if((a[i]>0 && b[i]<0) || (a[i]<0 && b[i]<0))
        {
            a[i]*=-1;
            b[i]*=-1;
        }
        else if(a[i] == 0 && b[i] != 0) b[i] = 1;
        else if (a[i] != 0 && b[i] == 0) a[i] = 1;
        else if(a[i] == 0 && b[i] == 0)
        {
            zeroc++;
            continue;
        }
        ll g = __gcd(abs(a[i]),abs(b[i]));
        a[i] /= g;
        b[i] /= g;
        mp[{a[i],b[i]}]++;
    }
    /*
    for(auto x : mp)
    {
        cout<<x.first.first<<" "<<x.first.second<<" "<<x.second<<endl;
    }
    */
    ll res = 1;
    for(auto x : mp)
    {
        ll a1 = x.first.first;
        ll b1 = x.first.second;
        ll cnt1 = x.second;
        ll a2,b2=abs(a1);
        if(a1>0)
        {
            a2 = -b1;
        }
        else
        {
            a2 = b1;
        }
        ll cnt2 = mp[{a2,b2}];
        if(mp.find({a2,b2}) != mp.end())
        {
            mp.erase({a2,b2});
        }
        res = (res*((bpow(2,cnt1)+bpow(2,cnt2)-1+MOD)%MOD)+MOD)%MOD;
        /*
        vll deb = {a1,b1,a2,b2,cnt1,cnt2,res};
        cout<<"DEBUGGING\n";
        for(ll x : deb) cout<<x<<" ";
        */
    }
    cout<<(res-1+zeroc+MOD)%MOD<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //pre();
    int t = 1;
    //cin >> t;
    //cout<<__gcd(-5,0)<<endl;
    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 18668
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<28)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    deque<int> b;
    rep(i, 0, n) {
        int a; cin >> a;
        if (i%2 == n%2) b.pb(a);
        else b.push_front(a);
    }
    rep(i, 0, n) {
        printf("%d", b[i]);
        if (i != n-1) printf(" ");
        else printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3072
import java.util.*;
import java.util.stream.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() {
		for (int i=1, x=0; (x = in.nextInt()) != 0; i++) {
			out.println("Case "+i+": "+x);
		}
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}


Measured memory_bytes: 43208