akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string S;
  cin >> S;
  ll L = S.size();
  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  ll cntC = 0;
  RNG(i, 2, L-1) {
    if (S[i] == 'C') cntC += 1;
  }
  if (cntC != 1) {
    cout << "WA" << endl;
    return 0;
  }
  auto cntCap = 0;
  REP(i, L) {
    if (S[i] <= 'Z') cntCap += 1;
  }
  if (cntCap != 2) {
    cout << "WA" << endl;
    return 0;
  }
  cout << "AC" << endl;
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MAX = 10^^5 * 2;
immutable long MOD = 10^^9 + 7;
long[] F;
long[] G;

void main() {
    F = new long[](MAX);
    G = new long[](MAX);
    F[0] = F[1] = 1;
    foreach (i; 2..MAX) F[i] = F[i-1] * i % MOD;
    foreach (i; 0..MAX) G[i] = powmod(F[i], MOD-2, MOD);

    auto s = readln.split.map!(to!long);
    auto N = s[0].to!int;
    auto M = s[1];

    if (M == 1) {
        writeln(1);
        return;
    }

    long ans = 1;

    int[long] P;
    for (long i = 2; i * i <= M; ++i) {
        while (M % i == 0) P[i] += 1, M /= i;
    }
    if (M > 1) P[M] += 1;

    foreach (p; P.keys) {
        ans = ans * comb(N + P[p] - 1, P[p]) % MOD;
    }

    ans.writeln;
}


long powmod(long a, long x, long m) {
    a %= m;
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

long comb(long n, long k) {
    return F[n] * G[n-k] % MOD * G[k] % MOD;
}


Measured memory_bytes: 4220
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	static const ULL M = 1000000007;
	static ULL f(ULL a, ULL i) {
		if (i == 0) return 1;
		ULL b = f(a, i / 2), c = (i % 2) ? a : 1;
		return b * b % M * c % M;
	}
	vector<ULL> F, I, iF;
	ULL C(UL n, UL r) {
		return F[n] * iF[r] % M * iF[n - r] % M;
	}

	void Solve() {
		UL N, K; cin >> N >> K;
		UL Z = N * 2;
		F.resize(Z + 1), I.resize(Z + 1), iF.resize(Z + 1);
		F[0] = 1; I[1] = 1; iF[0] = 1;
		rep(i, Z) { F[i + 1] = F[i] * (i + 1) % M; }
		for (UL i = 2; i <= Z; i++) { I[i] = M - M / i * I[M % i] % M; }
		rep(i, Z) { iF[i + 1] = iF[i] * I[i + 1] % M; }

		ULL ans = C(N + N - 1, N - 1);
		for (UL i = 1; i + K < N; i++) {
			ULL buf = C(N, i);
			buf = buf * C(N - 1, i - 1) % M;
			ans += (M - buf);
		}
		ans %= M;
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 9600
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i=1; i<n+1; ++i){
    string s = to_string(i);
    int v = 0;
    for(int j=0; j<s.size(); ++j){
      v += (int) s[j] - (int) '0';
    }
    if(v>=a && v<=b) ans += i;
  }
  cout << ans << endl;

}

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

int main(void){
	int h,w;
	while(true){
		cin >> h >> w;
		if(h == 0 && w == 0){
			break;
		}
		for(int i = 0;i < h;i++){
			for(int j = 0;j < w;j++){
				if(i == 0 || i == h-1 || j == 0 || j == w-1){
					cout << "#";
				}else{
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;



int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n, k;
  scanf("%d%d", &n, &k);
  puts((k * 2 - 1 <= n) ? "YES" : "NO");

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
for _ in range(M):
    A, B = map(int, input().split())
    G[A].append(B)
    G[B].append(A)
visited = [False] * (N+1)
visited[1] = True
path = []
v = 1
while True:
    path.append(v)
    for c in G[v]:
        if not visited[c]:
            v = c
            visited[v] = True
            break
    else:
        break
path = path[::-1]
path.pop()
v = 1
while True:
    path.append(v)
    for c in G[v]:
        if not visited[c]:
            v = c
            visited[v] = True
            break
    else:
        break
print(len(path))
print(*path)

Measured memory_bytes: 60976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
  ll a,b; cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
  return 0;
}

Measured memory_bytes: 256
import collections

visited = set()


def is_goal(nums):
    A, B, C = nums
    return A == B == C


def bfs(nums):
    q = collections.deque()
    visited.add(nums)
    q.append(nums + (0,))

    if is_goal(nums):
        return 0

    while len(q) != 0:
        n = q.popleft()

        if is_goal(n[:3]):
            return n[3]

        for i in range(3):
            new_n = list(n[:])
            for j in range(3):
                if i != j:
                    new_n[j] += 1
            new_n[3] += 1
            new_n = tuple(new_n)
            if new_n[:3] not in visited:
                visited.add(new_n[:3])
                q.append(new_n)

        for i in range(3):
            new_n = list(n[:])
            new_n[i] += 2
            new_n[3] += 1
            new_n = tuple(new_n)
            if new_n[:3] not in visited:
                visited.add(new_n[:3])
                q.append(new_n)

    return -1


A, B, C = map(int, input().split())

print(bfs((A, B, C)))


Measured memory_bytes: 16108
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var n = ReadInt();

            long t = 1;
            long a = 1;
            for (int i = 0; i < n; i++)
            {
                var ta = ReadLongArray();
                var t2 = ta[0];
                var a2 = ta[1];
                //var c = (long)Math.Ceiling(Math.Max((double)t / t2, (double)a / a2));
                var c = Math.Max((t - 1) / t2, (a - 1) / a2) + 1;
                t = t2 * c;
                a = a2 * c;
            }
            Console.WriteLine($"{t + a}");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


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

int gox[4] = {1,-1,0,0};
int goy[4] = {0,0,1,-1};
typedef long long ll;

bool vis[410][410];
int n,m;
char a[410][410];

ll num1,num2;

void dfs(int x,int y,char f){
    vis[x][y] = 1;
    if(f=='#')
    num1++;
    else num2++;
    for(int i=0;i<4;i++){
        int nowx = x+gox[i];
        int nowy = y+goy[i];
        if(nowx<0||nowx>=n||nowy<0||nowy>=m||a[nowx][nowy]==f||vis[nowx][nowy])continue;
        dfs(nowx,nowy,a[nowx][nowy]);
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%s",a[i]);
    }
    ll res = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            num1 = num2 = 0;
            if(!vis[i][j]){
            dfs(i,j,a[i][j]);
            res+=num1*num2;
            }
        }
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 8064
//https://atcoder.jp/contests/abc125/tasks/abc125_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for(auto &x : V){
        cin >> x;
    }
    for(auto &x : C){
        cin >> x;
    }
    vector<int> dp(N + 1);
    dp[0] = 0;
    for( int i = 1; i < N + 1; ++i ){
        dp[ i ] = max( dp[i - 1], dp[ i - 1 ] + V[ i - 1 ] - C[ i - 1 ] );
    }
    cout << dp[N] << endl;
    return 0;
}

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

#ifdef DEBUG
#define watch(x) cout << "DEBUG: " << (#x) << " = " << (x) << endl
#else
#define watch(x) ;
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define endl "\n"
const int INF = 0x3f3f3f3f;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - (((begin) > (end)) << 1))

#define fi first
#define se second
#define pb push_back
#define all(X) begin(X),end(X)

#define rd1(x) scanf("%d", &x)
#define rd2(x, y) scanf("%d%d", &x, &y)
#define rd3(x, y, z) scanf("%d%d%d", &x, &y, &z)

#define rdl1(x) scanf("%lld", &x)
#define rdl2(x, y) scanf("%lld%lld", &x, &y)
#define rdl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)

#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2")

int main() {

#ifdef DEBUG
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	int a, p;
	cin >> a >> p;

	cout << (3*a+p)/2 << endl;

	return 0;
}


Measured memory_bytes: 256
N,W = map(int,input().split())
L = [list(map(int,input().split())) for i in range(N)]

supremum = 10**5

dp = [float("inf") for i in range(supremum+1)]
dp[0] = 0

for i in range(N) :
    weight_i,value_i = L[i]    
    for value in range(supremum,value_i-1,-1) :
        if dp[value-value_i] + weight_i <= W :
            dp[value] = min(dp[value], dp[value-value_i] + weight_i)

for i in range(supremum,-1,-1) :
    if dp[i] <= W :
        ans = i
        break

print(ans)

        

Measured memory_bytes: 54016
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        if(N <= 12) {
            System.out.println(N);
            return;
        }
        Queue<String> q = new LinkedList<>();
        int level = 0;
        for(int i = 1; i <= 9; i++) {
            q.offer(String.valueOf(i));
        }
        N-=9;
        while(true) {
            int size = q.size();
            while(size-- > 0) {
                String curr = q.poll();
                for (char i = (char)(curr.charAt(level)-1); i <= curr.charAt(level)+1;i++) {
                    if(i < '0' || i > '9') {
                        continue;
                    }
                    N--;
                    if(N == 0) {
                        System.out.println(curr + i);
                        return;
                    }
                    q.offer(curr+i);
                }
            }
            level++;
        }
    }
}

Measured memory_bytes: 45396
#include <bits/stdc++.h>
/*
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>

#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
*/
#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define up_b upper_bound
#define low_b lower_bound
#define lcm(a,b) (a * b) / __gcd(a, b)
#define REVERSE(a, n) reverse(a + 1, a + n + 1);
#define SORT(a, n) sort(a + 1, a + n + 1);
#define rsz resize

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
typedef vector <ll> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <ll, ll> pll;
typedef map <ll, ll> mll;
typedef set <ll> sl;
typedef set <char> sc;
typedef map <string, ll> msl;
typedef map <string, bool> msb;
typedef map <char, ll> mcl;
typedef map <string, string> mss;
typedef vector <vl> vvl;

const ll mxn = 1e6 + 1;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld eps = 1e-9;
const ld PI = acos(-1);
const ld E = 2.71828;

#define int int64_t
#define FLN "inverse"

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

inline void joji(bool ok = 0) {naj;if(ok){freopen(FLN".in","r",stdin);freopen(FLN".out","w",stdout);}}

map <int, int> cnt;
              
main () {

	joji();        	
	int h, a;
	cin >> h >> a;
	cout << h / a + (h % a ? 1 : 0);
	return 0;
}





        
                                                             


Measured memory_bytes: 256
#include <iostream>
#include <string>
int main()
{
	char c;
	std::cin >> c;

	char b[5] = { 'a', 'e', 'i', 'o', 'u' };

	for (int i = 0; i < 5; i++) {
		if (b[i] == c) {
			std::cout << "vowel" << std::endl;
			return 0;
		}
	}
	std::cout << "consonant" << std::endl;
    return 0;
}

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

using namespace std;

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

  long N,M,V,P; cin>>N>>M>>V>>P;
  vector<long> A(N); for (auto& a : A) cin>>a;
  sort(A.rbegin(), A.rend());
  vector<long> ds(N);
  for (long i = P; i < N; i++) {
    ds[i] = ds[i-1]+(A[P-1]-A[i]);
  }
  auto is_ok = [&](long i) {
    if (A[P-1] > M + A[i])
      return false;
    auto buf = ((P-1)+(N-i))*M + ds[i-1] + (i-P+1)*(A[i]+M-A[P-1]);
    return buf >= M*V;
  };
  long l = P, r = N-1;
  long ans = P;
  while (l <= r) {
    auto c = (l+r)/2;
    if (is_ok(c)) {
      ans = c+1;
      l = c+1;
    } else {
      r = c-1;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
n,m=map(int,input().split())
s,c=[],[]

for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    s.append(a)
    c.append(b)
        
for ans in range(10**n):
    st=str(ans)

    if len(st) != n:
        continue

    f=True    
    for i in range(m):
       if st[s[i]] != str(c[i]):
            f=False
          
    if f==True:
        print(ans)
        exit()

print(-1)

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

const int MAXN = 2e5 + 5;

int N, M, ans;
struct seg {
	int l, r;
} a[MAXN];
bool cmp(seg s1, seg s2) {
	return s1.l < s2.l;
}

#define ls (o << 1)
#define rs (o << 1 | 1)
#define mid ((l + r) >> 1)
int mx[MAXN << 2], tag[MAXN << 2];
void pushup(int o) { mx[o] = max(mx[ls], mx[rs]); }
void add(int o, int k) { mx[o] += k, tag[o] += k; }
void pushdown(int o) { if (tag[o]) add(ls, tag[o]), add(rs, tag[o]), tag[o] = 0;  }
void build(int o, int l, int r) {
	if (l == r) mx[o] = l;
	else build(ls, l, mid), build(rs, mid + 1, r), pushup(o);
}
void insert(int o, int l, int r, int L, int R, int K) {
	if (r < L || l > R) return;
	if (l >= L && r <= R) return add(o, K);
	pushdown(o), insert(ls, l, mid, L, R, K), insert(rs, mid + 1, r, L, R, K), pushup(o);
}
int query(int o, int l, int r, int L, int R) {
	if (r < L || l > R) return 0;
	if (l >= L && r <= R) return mx[o];
	else return max(query(o << 1, l, mid, L, R), query(o << 1 | 1, mid + 1, r, L, R));
}

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i) scanf("%d%d", &a[i].l, &a[i].r);
	ans = max(0, N - M);
	sort(a + 1, a + N + 1, cmp);
	build(1, 1, M + 1);
	for (int i = 1; i <= N; ++i) {
		insert(1, 1, M + 1, 1, a[i].r, 1);
		//printf("[%d, %d] : %d\n", a[i].l, a[i].r, -M - 1 - a[i].l + query(1, 1, M + 1, 1, a[i].r));
		ans = max(ans, -M - 1 - a[i].l + query(1, 1, M + 1, 1, a[i].r));
	}
	printf("%d\n", ans);
	return 0;
}

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

typedef long long i64;
string s; int N;
i64 calc(int l, int r) {
    i64 tmp =  stoll(s.substr(l, r - l + 1));
    return tmp;
}
i64 dfs(int l, int pos, i64 score) {
    if(pos == (N - 1)) return score + calc(l, pos);
    i64 res = 0;
    res += dfs(pos + 1, pos + 1, score + calc(l, pos));
    res += dfs(l, pos + 1, score);
    return res;
}
int main() {
    cin >> s;
    N = s.size();
    cout << dfs(0, 0, 0LL) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    vector<int> table;
    int cur = 1;
    int bound = 1e+6;
    for(;;){
        ll val = (ll)cur * (cur + 1) * (cur + 2) / 6;
        if(val > bound) break;
        table.emplace_back(val);
        ++cur;
    }
    vector<int> dp(bound, INF);
    dp[0] = 0;
    vector<int> dp2 = dp;
    for(int x : table){
        for(int i = 0; i < bound - x; ++i){
            chmin(dp[i + x], dp[i] + 1);
            if(x % 2)   chmin(dp2[i + x], dp2[i] + 1);
        }
    }
    
    for(;;){
        int n;
        cin >> n;
        if(n == 0)  return 0;
        cout << dp[n] << ' ' << dp2[n] << '\n';
    }
}


Measured memory_bytes: 10632
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

map<int, vector<int>> adList;
map<int, int> values;
map<int, int> counts;

void ComputeCounts(const int current, const int parent, const int countSum)
{
    int count = countSum + values[current];
    for (const int neighbor : adList[current])
    {
        if (neighbor != parent)
        {
            ComputeCounts(neighbor, current, count);
        }
    }
    counts[current] = count;
}

int main()
{
    int N, Q;
    cin >> N >> Q;
    for (int i = 0; i < N - 1; ++i)
    {
        int ai, bi;
        cin >> ai >> bi;
        adList[ai].push_back(bi);
        adList[bi].push_back(ai);
    }
    for (int i = 0; i < Q; ++i)
    {
        int pi, xi;
        cin >> pi >> xi;
        values[pi] += xi;
    }
    ComputeCounts(1, 0, 0);

    string output;
    for (const auto kvp : counts)
    {
        output += to_string(kvp.second) + ' ';
    }
    output.pop_back();
    cout << output << endl;
}


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

int main()
{
	int T;
	cin >> T;
	
	if( 400<=T && T<600)
		cout << 8 << endl;
	else if( 600<=T && T<800)
		cout << 7 << endl;
	else if( 800<=T && T<1000)
		cout << 6 << endl;
	else if( 1000<=T && T<1200)
		cout << 5 << endl;
	else if( 1200<=T && T<1400)
		cout << 4 << endl;
	else if( 1400<=T && T<1600)
		cout << 3 << endl;
	else if( 1600<=T && T<1800)
		cout << 2 << endl;
	else if( 1800<=T && T<2000)
		cout << 1 << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 998244353;

int main() {
  int N,M;cin >> N >> M;
  vector<vint> A(N,vint(M));
  repeat(i,N){
    repeat(j,M){
      cin >> A[i][j];A[i][j]--;
    }
  }
  int low = 0,high = N;
  while(high-low>1){
    int mid = (low+high)/2;
    vint idx(N,0);
    vector<bool> held(M,true);
    bool update = true;
    while(update){
      update = false;
      vint participants(M,0);
      repeat(i,N){
        while(idx[i]<M-1&&!held[A[i][idx[i]]]){
          idx[i]++;
        }
        participants[A[i][idx[i]]]++;
      }
      repeat(i,M){
        if(!held[i])continue;
        if(participants[i]>mid){
          held[i]=false;
          update=true;
        }
      }
    }
    bool isok = false;
    repeat(i,M){
      isok |= held[i];
    }
    if(isok) high = mid;
    else low = mid;
  }
  cout << high << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
    i64 N;
    cin >> N;

    i64 ans = 0;
    for(i64 k = 1; k*k <= N; k++){
        if((N-1) % k == 0){
            if(k*k == N-1 || k == 1) ans++;
            else ans += 2;
        }

        if(N % k == 0){
            i64 d = N / k;
            i64 M = N;
            while(M % d == 0) M /= d;
            if(M % d == 1) ans++;

            if(k*k == N || k == 1) continue;
            M = N;
            while(M % k == 0) M /= k;
            if(M % k == 1) ans++;
        }
    }
    if(N == 2) ans = 1;

    Cout(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
  string n;
  cin >> n;
  if(n[0] == n[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<utility>
using namespace std;
typedef pair<int, int> P;

int n, t;
P p[3000];

int dp[3001];

int main() {
    scanf("%d %d", &n, &t);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &p[i].first, &p[i].second);
    }
    sort(p, p + n);

    for (int i = 0; i < n; i++) {
        for (int j = t - 1; j >= 0 ; j--) {
            if (dp[j] < 0) continue;
            int k = (j + p[i].first < t) ? j + p[i].first : t;
            if (dp[k] < dp[j] + p[i].second) {
                dp[k] = dp[j] + p[i].second;
            }
        }
    }
    printf("%d\n", dp[t]);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 998244353
#define MAX 100009
#define endl '\n'
#define mp make_pair
#define INF 1000000000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define F first
#define S second
 
using namespace std;

bool isprime(ll n){			//to check whteher no is prime or not
	if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

ll power(ll a,ll n){
	ll ans=1;
	while(n){
		if(n%2!=0){
			ans=((ans%mod)*(a%mod))%mod;
			n--;
		}
		else{
			a=((a%mod)*(a%mod))%mod;
			n/=2;
		}
	}
	return ans;
}

int main(){
	fast
//	int t;
//	cin>>t;
//	while(t--){
		ll a,b,c,d,n,m;
		ld p,q,r;
		cin>>n;
		string s[n];
		forn(i,n)	cin>>s[i];
		set<string> se;
		forn(i,n)	se.insert(s[i]);
		cout<<se.size();
//	}
}



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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;

    rep(i, N + 1) {
        rep(j, N + 1 - i) {
            int k = N - i - j;
            int total = 10000*i + 5000*j + 1000*k;
            if (total == Y) {
                res10000 = i;
                res5000 = j;
                res1000 = k;
                break;
            }
        }
    }

    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            int N = int.Parse(read.Split(' ')[0]);
            int X = int.Parse(read.Split(' ')[1]);
            read = Console.ReadLine();
            int[] x = new int[N];
            List<int> X_list = new List<int>();
            string[] split = read.Split(' ');
            for (int i = 0; i < N; i++)
            {
                //x[i] = Math.Abs(int.Parse(split[i])- X);
                X_list.Add(Math.Abs(int.Parse(split[i]) - X));
            }
            int temp = 0;
            bool outputone = false;
            while (X_list.Count != 1)
            {
                int a = X_list[0];
                int b = X_list[1];
                X_list.RemoveAt(0);
                X_list.RemoveAt(0);
                int backgcd = gcd(a, b);
                if (backgcd == 1)
                {
                    outputone = true;
                    break;
                }
                else
                {
                    X_list.Add(backgcd);
                }
            }
            if (outputone == true)
            {
                Console.WriteLine(1);
            }
            else
            {
                Console.WriteLine(X_list[0]);
            }
        }
        static int gcd(int a, int b)
        {
            int bigger = Math.Max(a, b);
            int smaller = a + b - bigger;
            if (bigger % smaller == 0)
            {
                return smaller;
            }
            else
            {
                return gcd(smaller, bigger % smaller);
            }
        }

    }
}


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

#define pb push_back
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define beg begin()
#define en end()
#define rbeg rbegin()
#define ren rend()
#define mem(a,b) memset(a,b,sizeof a)
#define mem0(a) memset(a,0,sizeof a)
#define mem1(a) memset(a,1,sizeof a)
#define memm(a) memset(a,-1,sizeof a)


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
//~ const int tam=1000;
const int inf=(int)1e9;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==1){
		cout<<"Hello World";cout<<endl;
		return 0;
	}
	int a,b;
	cin>>a>>b;
	cout<<a+b;cout<<endl;
	
	
    return 0;
}


Measured memory_bytes: 256
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007  
#define endl '\n'
#define INF 1e18L+1
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
using namespace std;
template<class T> T max(T a, T b, T c) {
    return max(a, max(b, c));
}
template<class T> T min(T a, T b, T c) {
    return min(a, min(b, c));
}
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
            freopen("error.txt","w",stderr);
    #endif
}
bool prime[100005];
void SieveOfEratosthenes(ll n)//O(nloglogn) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
bool isPrime(ll n)//O(sqrt(n))
{
    if(n<2)
        return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;
    return true;
}
std::vector<ll> factors(ll n)//O(sqrt(n))
{
    std::vector<ll> f;
    for(ll i=2;i*i<=n;i++)
    {
        while(n%i==0)
        {
            f.push_back(i);
            n = n/i;
        }
    }
    if(n>1) f.push_back(n);
    return f;
}
ll gcd(ll a,ll b)//O(logn)
{
    if(!b) return a;
    return gcd(b,a%b);
}
ll modpow(ll x,ll n,ll m)//O(logn)// used for calculating (x^n)%m
{
    if(n==0) return 1%m;
    ll u = modpow(x,n/2,m);
    u = (u%m * u%m)%m;
    if(n%2==1)
        u = (u%m * x%m)%m;
    return u%m;
}
ll eulerstotientfunction(ll n)//O(sqrt(n))
{
    ll ans = n;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            while(n%i==0)
                n = n/i;
            ans -= ans/i;
        }
    }
    if(n>1)
        ans -= ans/n;
    return ans;
}
ll modinverse(ll x,ll m)//O(logn)
{
    ll temp = eulerstotientfunction(m);
    return modpow(x,temp-1,m);
}
ll ncr(ll n,ll k)
{
    ll res = 1;
    k = min(k,n-k);
    for(ll i=0;i<k;i++)
    {
        res *= (n-i);
        res /= (i+1);
    }
    return res;
}
int main()
{
    //fastio();
    ll n;
    cin >> n;
    std::vector<ll> arr(n);
    for(ll i=0;i<n;i++)
        cin >> arr[i];
    arr[0]--;
    for(ll i=0;i<n-1;i++)
    {
        if(arr[i+1]>arr[i])
            arr[i+1]--;
    }
    for(ll i=0;i<n-1;i++)
    {
        if(arr[i]>arr[i+1])
        {
            cout << "No" << endl;
            return 0;
        }
    }    
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
char s[2][15],ss[15];
int a[2];
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s%s",s[0]+1,s[1]+1);
    a[0]=read(),a[1]=read();
    scanf("%s",ss+1);int len=strlen(ss+1);
    for(int i=0;i<2;i++)
    {
    	int n=strlen(s[i]+1);
    	if(n==len)
    	{
    		bool bk=true;
    		for(int j=1;j<=n;j++)if(s[i][j]!=ss[j]){bk=false;break;}
    		if(bk==true)a[i]--;
    	}
    }pr1(a[0]);
    pr2(a[1]);
    return 0;
}

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

int main(void){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 0, i = 0;
  for(int i = 0; i < N-1; i++){
    if((S[i] == 'O' && S[i+1] == 'X')||(S[i] == 'X' && S[i+1] == 'O')){
      cnt++;
      i++;
    }
    else{
      continue;
    }
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3348
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANovember30 solver = new ANovember30();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANovember30 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();

            out.println(a == c ? 0 : 1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
int w[15];
int a[15][15];
int n, m, k;
int ans = 2147483647;
int ul[15];
void dfs(int x, int cur){
	if(x == n){
		for(int i = 0; i < m; i++) if(ul[i] < k) return;
		ans = min(ans, cur);
		return;
	}
	for(int i = 0; i < m; i++) ul[i] += a[x][i];
	cur += w[x];
	dfs(x + 1, cur);
	for(int i = 0; i < m; i++) ul[i] -= a[x][i];
	cur -= w[x];
	dfs(x + 1, cur);
	return;
}
int main(){
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++){
		cin >> w[i];
		for(int j = 0; j < m; j++) cin >> a[i][j];
	}
	dfs(0, 0);
	cout << (ans == 2147483647 ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int i;
  int a[31];
  int tmp;

  a[0] = 1;
  for(i=1;i<31;i++)a[i] = 0;
  for(i=0;i<28;i++){
    scanf("%d ",&tmp);
    a[tmp] = 1;
  }
  for(i=0;i<31;i++){
    if(!a[i])printf("%d\n",i);
  }
  return 0;
}

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



signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  ll n, m;
  
  cin >> n >> m;
  
  vector<ll> a(m);  
  
  rep(i, 0, n) {
    ll k;
    cin >> k;
    rep(j, 0, k) {
      ll A;
      cin >> A;
      a[A-1]++;
    }
  }
  
  ll ans = 0;
  rep(i, 0, m) {
    if(a[i] == n) ans++;
  }
  cout << ans << "\n";

}


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



int main(){
  int W,H,N;
  cin>>W>>H>>N;
  
  vector<vector<int>> vec(H, vector<int>(W));
  for(int i=0;i<N;i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      for(int i=0;i<H;i++){
        for(int j=0;j<x;j++){
          vec.at(i).at(j)=1;
        }
      }
    }
    if(a==2){
      for(int i=0;i<H;i++){
        for(int j=x;j<W;j++){
          vec.at(i).at(j)=1;
        }
      }
    }
    if(a==3){
      for(int i=0;i<y;i++){
        for(int j=0;j<W;j++){
          vec.at(i).at(j)=1;
        }
      }
    } 
    if(a==4){
      for(int i=y;i<H;i++){
        for(int j=0;j<W;j++){
          vec.at(i).at(j)=1;
        }
      }
    }
  }
  int sum=0;
  for(int i=0;i<H;i++){
     for(int j=0;j<W;j++){
       if(vec.at(i).at(j)==0) sum+=1;
     }
  }
  cout<<sum<<endl;
  
  
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
string pi(string x,string y)
{
    int mx=0,c=0;
    string s=y+"#"+x;
    vector<int>pi(s.length());
    for(int i=1,j=0;i<s.length();i++)
    {
        while(j&&s[i]!=s[j])j=pi[j-1];
        if(s[i]==s[j])j++;
        pi[i]=j;
        if(j==(int)y.size())return x;
    }
    return x.substr(0,x.size()-pi.back())+y;
}
int main()
{
    int n; string s,t;
    cin>>n>>s>>t;
    cout<<pi(s,t).size();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)

int main(void){
    ll N,M;
    cin >> N >> M;
    vector<ll> H(N+10);
    vector<ll> ma(N+10);
    FOR(i,1,N+1){
        cin >> H[i];
        ma[i] = 0;
    }
    ll ans = 0;
    REP(i,M){
        ll A,B;
        cin >> A >> B;
        ma[A] = max(ma[A],H[B]);
        ma[B] = max(ma[B],H[A]);
    }
    FOR(i,1,N+1) if(H[i] > ma[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4836
mod = 998244353
from bisect import bisect_left
from operator import itemgetter
N = int(input())
xd = [list(map(int,input().split())) for _ in range(N)]
xd.sort(key=itemgetter(0))
X = [xd[i][0] for i in range(N)]
D = [xd[i][1] for i in range(N)]

N0 = 2**(N-1).bit_length()
INF = 2**31-1
data = [INF]*(4*N0) #長さが足りないことがある. 3*N0にすればいい?

# k番目の要素をxに更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k >= 0:
        k = (k - 1) // 2
        data[k] = min(data[2*k+1], data[2*k+2])

# [l,r)の最小値
def query(l, r):
    L = l + N0; R = r + N0
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])

        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i in range(N-1,-1,-1):
    j = bisect_left(X,X[i]+D[i])
    update(i,-i)
    update(i,query(i,j))

dp = [0]*(N+1)
dp[-1] = 1
for i in range(N-1,-1,-1):
    dp[i] += dp[i+1]
    dp[i] += dp[-query(i,i+1)+1]
    dp[i] %= mod

print(dp[0])

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

int main() {
	int n, ans = 0;
	ll d;
	cin >> n >> d;
	vector<ll> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
		if (d*d >= x[i] * x[i] + y[i] * y[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6356
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

using Real = double;
using Point = complex< Real >;
const Real EPS = 1e-8, PI = acos(-1);

inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }

Point operator*(const Point &p, const Real &d) {
  return Point(real(p) * d, imag(p) * d);
}

istream &operator>>(istream &is, Point &p) {
  Real a, b;
  is >> a >> b;
  p = Point(a, b);
  return is;
}

ostream &operator<<(ostream &os, Point &p) {
  return os << fixed << setprecision(10) << p.real() << " " << p.imag();
}

Real distance(const Point &a, const Point &b) {
  return abs(real(a) - real(b)) + abs(imag(a) - imag(b));
}


void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<Point> Student(N);
  vector<Point> Checkpoint(M);
  for (int i = 0; i < N; i++)
  {
    int A,B;
    cin>>A>>B;
    Student[i] = Point(A,B);
  }

  for (int i = 0; i < M; i++)
  {
    int A,B;
    cin>>A>>B;
    Checkpoint[i] = Point(A,B);
  }
  vector<int> ANS(N,-1);

  for (int i = 0; i < N; i++)
  {
    double MIN = DBL_MAX;
    int index = -1;
    for (int j = 0; j < M; j++)
    {
      double dist = distance(Student[i],Checkpoint[j]);
      if(chmin(MIN,dist)) index = j;
    }
    ANS[i] = index +1;
  }

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

  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
def linear_search(A, n, key):
    A.append(key)
    i = 0
    while A[i] != key:
        i += 1
    A.pop()
    return i != n

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in T:
    if linear_search(S, n, i):
        count += 1


print(count)

Measured memory_bytes: 8564
#include<stdio.h>
#define MAX 100005
#define N -1

typedef struct{ 
  int parent;
  int right,left;
}Record;
Record u[MAX];
int n,D[MAX];

void print(int s){
  int i,c;
  printf("node %d: parent = %d, depth = %d, ",s,u[s].parent,D[s]);

  if(u[s].parent == N)printf("root, ");
  else if(u[s].left == N)printf("leaf, ");
  else printf("internal node, ");
  printf("[");
  for(i=0, c=u[s].left; c!=N; i++, c = u[c].right){
    if(i>=1)printf(", ");
    printf("%d",c);
  }
  printf("]\n");

}


void depth(int s, int p){
  D[s] = p;
  if(u[s].right != N){
    depth(u[s].right,p);
  }
  if(u[s].left != N){
    depth(u[s].left,p+1);
  }
}


int main(){
  int i,j,k,l,num,node,r;

  scanf("%d",&n);
  //Record[u]内の整数を初期化（必要なぶんだけ）
  for(i=0; i<n; i++) u[i].parent = u[i].right = u[i].left = N;
  //input
  for(i=0; i<n; i++){
    scanf("%d%d",&node,&num);
    for(j=0; j<num; j++){
      scanf("%d",&k);
      if(j == 0) u[node].left = k;
      else u[l].right = k;//よくわからん
      l = k;
      u[k].parent = node;
    }
  }
  for(i=0; i<n ; i++){
    if(u[i].parent == N)r = i;
  }
  
  depth(r,0);
  for(i=0; i<n; i++)print(i);
    
  return 0;
}



Measured memory_bytes: 6412
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
const ll MOD= 200003;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 2100000
#define offset 200
#define ptr nodo*
ll v[tam];
int main()
{
	int n;
	cin>>n;
	forr(i,0,n)
	{
		cin>>v[i];
	}
	sort(v,v+n);
	int c=0;
	forr(i,0,n)
	{
		forr(j,i+1,n)
		{
			forr(k,j+1,n)
			{
				if (v[i]+v[j]>v[k] && v[i]!=v[j] && v[j]!=v[k]){
					//cout<<i<<" "<<j<<" "<<k<<endl;
					//cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<endl;
					c++;
				}
			}
		}

	}
	cout<<c<<endl;
}				

Measured memory_bytes: 3632
#include <stdio.h>

int main (void)
{
    char N[3];
    scanf("%s", N);
    int N0 = N[0] - '0';
    int N1 = N[1] - '0';
    int N2 = N[2] - '0';
    //printf("%d,%d,%d\n", N0,N1,N2);
    if (N0==7 || N1==7 || N2==7) {
        printf("Yes");
    } else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>
#include<string>
using namespace std;

int main() {
  int A, B, K;
  scanf("%d%d%d", &A, &B, &K);
  
  //AからA+(K-1)を出力
  for (int i=A ; i<=A+K-1 ; i++) {
    if (i <= B) printf("%d\n", i);
  }
  
  //B-(K-1)からBを出力（A+(K-1)以下の数は出力しない）
  for (int i=B-(K-1) ; i<=B ; i++) {
    if (i > A+K-1) printf("%d\n", i);
  }  
}

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

using namespace std;

long long n;
long long l1[100010], l2[100010], r1[100010], r2[100010];
long long a[100010];

long long s[100010], top;

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

	s[++top] = 1;
	for(long long i = 2; i <= n; i++){
		while(top && a[s[top]] < a[i]){
			r1[s[top--]] = i;
		}
		s[++top] = i;
	}
	while(top){
		r1[s[top--]] = n+1;
	}
	

	s[++top] = n;
	for(long long i = n - 1; i >= 1; i--){
		while(top && a[s[top]] < a[i]){
			l1[s[top--]] = i;
		}
		s[++top] = i;
	}
	while(top){
		l1[s[top--]] = 0;
	}

	for(long long i = 1; i <= n; i++){
		for(long long j = r1[i] + 1; j <= r1[r1[i]]; j++){
			if(a[j] > a[i]) r2[i] = j;
		}
	}

	for(long long i = 1; i <= n; i++){
		r2[i] = n+1;
		for(long long j = r1[i] + 1; j <= r1[r1[i]]; j++){
			if(a[j] > a[i]){
				r2[i] = j;
				break;
			}
		}
	}

	for(long long i = n; i >= 1; i--){
		for(long long j = l1[i] - 1; j >= l1[l1[i]]; j--){
			if(a[j] > a[i]){
				l2[i] = j;
				break;
			}
		}
	}

	// for(long long i = 1; i <= n; i++) cout << l1[i] << " ";
	// cout << endl;
	// for(long long i = 1; i <= n; i++) cout << l2[i] << " ";
	// cout << endl;

	// for(long long i = 1; i <= n; i++) cout << r1[i] << " ";
	// cout << endl;
	// for(long long i = 1; i <= n; i++) cout << r2[i] << " ";
	// cout << endl;

	long long ans = 0;
	for(long long i = 1; i <= n; i++){
		ans += ((l1[i] - l2[i]) * (r1[i] - i) + (r2[i] - r1[i]) * (i - l1[i])) * a[i];
	}
	cout << ans;
	
}


Measured memory_bytes: 4864