akhauriyash/Code-Regression huggingface dataset:
// AOJ NTL_2_B Difference of Big Integers
// 2019.3.8 bal4u

#include <stdio.h>
#include <stdlib.h>

#define N       1000000000

int a[12000], b[12000], s[12000];
int a_minus, b_minus;
char buf[200100];

char *mpStr2Num(int *num, char *str)
{
	char *ss, *end;
	int  *nn;
	int  k, x;

//	while (*str == ' ' || *str == '\t') str++;
	while (*str == '0') str++;
	ss = str;
	while (*ss >= '0' && *ss <= '9') ss++;
	end = ss;

	if (ss == str) { *num = 0; return end; }

	x = 0, k = 1, nn = num;
	do {
		x += (*--ss - '0') * k;
		k *= 10;
		if (k == N || ss == str) *++nn = x, x = 0, k = 1;
	} while (ss != str);

	*num = nn - num;
	return end;
}

void mpNum2Str(char *str, int *num)
{
	int  i, j, x;
	char *ss;

	if (*num == 0 || (*num == 1 && *(num + 1) == 0)) {
		*str++ = '0', *str = '\0';
		return;
	}

	ss = str - 1;
	for (i = *num; i > 0; i--) {
		x = *++num;
		for (j = 1; j < N; j *= 10) {
			*++ss = x % 10 + '0';
			x /= 10;
		}
	}
	while (*ss == '0') ss--;

	*(ss + 1) = '\0';
	while (str < ss) {
		x = *str;
		*str++ = *ss;
		*ss-- = x;
	}
}

void mpAdd(int *ret, int *a, int *b)
{
	int  i, lr, la, lb, x;
	int  *rr;

	la = *a, lb = *b;
	lr = (la >= lb) ? la : lb;
	rr = ret, x = 0;
	for (i = 1; i <= lr; i++) {
		if (i <= la) x += *++a;
		if (i <= lb) x += *++b;
		if (x < N) *++rr = x, x = 0;
		else       *++rr = x - N, x = 1;
	}
	*++rr = x;
	*ret = lr + x;
}

void mpSub(int *ret, int *a, int *b)
{
	int  i, la, lb, x;
	int  *rr;

	la = *a, lb = *b;
	rr = ret, x = 0;
	for (i = 1; i <= la; i++) {
		x += *++a;
		if (i <= lb) x -= *++b;
		if (x >= 0) *++rr = x, x = 0;
		else 		*++rr = x + N, x = -1;
	}
	while (--i > 0) if (*rr-- != 0) break;
	*ret = i;
}

int mpCmp(int *a, int *b)
{
	int  *aa;

	if (*a != *b) return *a - *b;
	aa = a, a += *aa, b += *aa;
	while (a != aa) {
		if (*a != *b) return *a - *b;
		a--, b--;
	}
	return 0;
}

int mpAddSub(int *ret, int *a, int a_minus, int *b, int b_minus)
{
	int k, minus = 0;

	if (a_minus && b_minus) minus = 1, a_minus = 0, b_minus = 0;
	if (!a_minus && !b_minus) mpAdd(ret, a, b);
	else {
		k = mpCmp(a, b);
		if (k == 0) *ret = 0, minus = 0;
		else if (k > 0) mpSub(ret, a, b), minus = a_minus;
		else            mpSub(ret, b, a), minus = b_minus;
	}
	return minus;
}

int main()
{
	char *p;

	fgets(p = buf, 200100, stdin);
	if (*p == '-') a_minus = 1, p++;
	p = mpStr2Num(a, p);
	while (*p == ' ') p++;

	if (*p == '-') b_minus = 1, p++;
	mpStr2Num(b, p);

	b_minus = !b_minus;
	if (mpAddSub(s, a, a_minus, b, b_minus)) putchar('-');
	mpNum2Str(buf, s);
	puts(buf);
	return 0;
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

ll n, m, k, u, v, X, Y, t, a, b, ans=1;
ll F[MAXN], I[MAXN];
pii A[MAXN];
int comp[MAXN], sz[MAXN];
map<int, int> cnt[MAXN];
vector<int> G[MAXN], vec[MAXN];

ll powmod(ll a, ll b){
	if (!b) return 1;
	if (b&1) return a*powmod(a*a%mod, b>>1)%mod;
	return powmod(a*a%mod, b>>1);
}

bool ok(pii i, pii j){
	if (i.second==j.second) return i.first+j.first<=X;
	return i.first+j.first<=Y;
}

void join(int u, int v){
	G[u].pb(v);
	G[v].pb(u);
	//debug2(u, v)
}

void dfs(int node, int id){
	comp[node]=id;
	for (int v:G[node]) if (!comp[v]) dfs(v, id);
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
		
	cin>>n>>X>>Y;
	for (int i=1; i<=n; i++) cin>>A[i].second>>A[i].first;
	sort(A+1, A+n+1);
	
	for (int i=2; i<=n; i++) if (ok(A[1], A[i])) join(1, i);
	for (int i=1; i<=n; i++) vec[A[i].second].pb(i);
	for (int i=1; i<=n; i++) if (vec[i].size()>1){
		for (int j:vec[i]) if (ok(A[vec[i][0]], A[j])) join(vec[i][0], j);
	}
	
	set<int> shit;
	for (int i:vec[A[1].second]) shit.insert(i);
	for (int i=1; i<=n; i++) while (shit.size() && ok(A[(*shit.begin())], A[i])){
		join(i, (*shit.begin()));
		shit.erase(shit.begin());
	}	
	//for (int i:vec[A[1].second]) for (int j=1; j<=n; j++) if (ok(A[i], A[j])) join(i, j);
	
	for (int i=1; i<=n; i++) if (!comp[i]) dfs(i, i);
	
	for (int i=1; i<=n; i++) sz[comp[i]]++, cnt[comp[i]][A[i].second]++;
	for (int i=1; i<=n; i++){
		ans=ans*F[sz[i]]%mod;
		for (pii p:cnt[i]) ans=ans*I[p.second]%mod;
	}
	cout<<ans<<'\n';
	
	return 0;
}
/*
4 7 3
3 2
4 3
2 1
4 4



21 77 68
16 73
16 99
19 66
2 87
2 16
7 17
10 36
10 68
2 38
10 74
13 55
21 21
3 7
12 41
13 88
18 6
2 12
13 87
1 9
2 27
13 15

129729600

*/

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

int main() {
  int k;
  cin >> k;
  int digit = 0;
  int num[20]; rep(i, 20) num[i] = 0;
  rep(j, k) {
    int i=0;
    while (i < digit) {
      if ((num[i] < 9) && (num[i+1] > num[i]-1)) {
        num[i]++; break;
      } else {
        num[i] = 0;
      } i++;
    }
    if (i == digit) {
      if (num[digit] < 9) num[digit]++;
      else {num[digit] = 0; digit++; num[digit] = 1;}
    }
    while (i > 0) {
      if (num[i] == 0) break;
      else if (num[i]-1 > num[i-1]) {
        num[i-1] = num[i] - 1;
      } i--;
    }
  }
  ll ans = 0;
  for (int i=digit; i>-1; i--) {
    ans += num[i]; ans *= 10;
  }
  cout << ans / 10 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int h, w, n;
string s, t;

bool judge(int cur0, int lm, char ps, char ng) {
  int cur = cur0;
  for (int i = 0; i < n; i++) {
    if (s[i] == ng) cur--;
    if (cur < 0) {
      return false;
    }
    if (t[i] == ps && cur < lm - 1) cur++;
  }
  cur = cur0;
  for (int i = 0; i < n; i++) {
    if (s[i] == ps) cur++;
    if (cur >= lm) {
      return false;
    }
    if (t[i] == ng && cur > 0) cur--;
  }
  return true;
}

signed main() {
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;
  sr--;
  sc--;
  cin >> s >> t;

  if (judge(sr, h, 'D', 'U') && judge(sc, w, 'R', 'L'))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 776
k = 10000+1
def counting_sort(A, B, k):
    C = [0] * k
    n = len(A)-1
    for j in range(n):
        C[A[j+1]] += 1
    for i in range(1, k):
        C[i] += C[i-1]
    for j in range(n, 0, -1):
        # print('j = {0}'.format(j))
        # print('A[{0}] = {1}'.format(j, A[j]))
        # print('C[A[j]] = {0}'.format(C[A[j]]))
        B[C[A[j]]] = A[j]
        C[A[j]] -= 1


if __name__ == '__main__':
    # ??????????????\???
    # array_size = 7
    # A = [999, 2, 5, 1, 3, 2, 3, 0]
    array_size = int(input())
    A = [int(x) for x in input().split(' ')]
    A.insert(0, 9999999)
    B = A[:]

    # ????????????????????????
    counting_sort(A, B, k)

    # ???????????????
    # print('A = {0}'.format(' '.join(map(str, A[1:]))))
    print('{0}'.format(' '.join(map(str, B[1:]))))

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

int main()
{
	int n;
	cin>>n;
	long a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int ans = 0;
	for(int i=0;i<n-2;i++)
	{
		for(int j = i+1;j<n-1;j++)
		{
			for(int k = j+1;k<n;k++)
			{
				if(a[i] != a[j] && a[j] != a[k] && a[i] != a[k])
				{
					int maximum = max(a[i],max(a[j],a[k]));
					int minimum = min(a[i],min(a[j],a[k]));
					int third = a[i] + a[j] + a[k] - maximum - minimum;
					if(third + minimum > maximum)
					ans++;
				
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 1e18;

long long int N,M,A[200200]={},memo[100040]={},res=0,cou=0,num,fi=0,se=0;
string S;
int main()
{
    cout << fixed << setprecision(18);
	cin>>N;
	for(long long int i = 0; i < N; i++){
		cin>>A[i];
	}
	sort(A,A+N,greater<long long int>() );
	for(long long int i = 1; i < N; i++){
		if(fi==0&&A[i]==A[i-1]){fi=A[i];i++;}
		else if(A[i]==A[i-1]){cout<<fi*A[i]<<endl;return 0;}
	}
	cout<<0<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Maxn 1000007
using namespace std;
int n;
int a[Maxn],p[Maxn];
bool calc(int x,int y)
{
    return ((p[x]-p[y]-p[x-y])==0);
}
int main()
{
    scanf("%d",&n);
    bool flag=false;
    for (int i=1;i<=n;i++)
    {
        char ch=getchar();
        while (ch<'1'||ch>'3') ch=getchar();
        a[i]=ch-'0'-1;
        if (a[i]==1) flag=true;
    }
    for (int i=1;i<=n;i++)
        if (i%2==1) p[i]=0; else p[i]=p[i/2]+1;
    for (int i=1;i<=n;i++)
        p[i]+=p[i-1];
    if (flag)
    {
        int ans=0;
        for (int i=1;i<=n;i++)
            if (calc(n-1,i-1)) ans^=(a[i]%2);
        printf("%d\n",ans);
    } else
    {
        int ans=0;
        for (int i=1;i<=n;i++)
            if (calc(n-1,i-1)) ans^=(a[i]/2);
        printf("%d\n",2*ans);
    }
    return 0;
}

Measured memory_bytes: 11620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> l;
  vector<int> r;
  int count = 0;
  for(int i = 0; i < n && count < k;){
    if(s[i] == 'o'){
      l.push_back(i);
      i += c + 1;
      count++;
    }
    else {
      ++i;
    }
  }
  count = 0;
  for(int i = n - 1; n >= 0 && count < k;){
   if(s[i] == 'o'){
     r.push_back(i);
     i -= c + 1;
     count++;
   }
   else{
     --i;
   }
  }
  //for(int i = 0; i < k; ++i) cout << l[i] << endl;
  //cout << "----------------" << endl;
  //for(int i = 0; i < k; ++i) cout << r[i] << endl;
  for(int i = 0; i < k; ++i){
    if(l[i] == r[k - i - 1]) cout << l[i] + 1 << endl;
  }

}

Measured memory_bytes: 3448
fn main() {
    proconio::input! {
        n: usize,
        abs: [(usize, usize); n], // red
        cds: [(usize, usize); n], // blue
    }
    let mut abs_sorted_x = abs.clone();
    abs_sorted_x.sort_by_key(|x| x.0);

    let mut cds_sorted_y = cds.clone();
    cds_sorted_y.sort_by_key(|x| x.1);

    let mut count = 0usize;
    for i in (0..abs_sorted_x.len()).rev() {
        let (a, b) = abs_sorted_x[i];
        for j in 0..cds_sorted_y.len() {
            let (c, d) = cds_sorted_y[j];
            if a < c && b < d {
                count += 1;
                cds_sorted_y.remove(j);
                break;
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2196
def Floor_sum(N,M,A,B):
    ANS=0
    if A>=M:
        ANS+=N*(N-1)//2*(A//M)
        A%=M
    if B>=M:
        ANS+=B//M*N
        B%=M
    y_max=(A*N+B)//M
    x_max_divA=y_max*M-B
    if y_max==0:
        return ANS
    else:
        ANS+=Floor_sum(y_max,A,M,A*N-x_max_divA)
        return ANS
 
t=int(input())
for tests in range(t):
    n,m,a,b=map(int,input().split())
    print(Floor_sum(n,m,a,b))

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    int n, k;
    string s;
    cin >> n >> k >> s;
    if(s[k - 1] == 'A') s[k - 1] = 'a';
    if(s[k - 1] == 'B') s[k - 1] = 'b';
    if(s[k - 1] == 'C') s[k - 1] = 'c';
    cout << s;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <map>
#include <cstdint>

int main() {
  int N;
  std::cin >> N;
  std::map<std::int64_t, std::int64_t> counts;
  std::int64_t sum = 0;
  for (int i = 0; i < N; ++i) {
    std::int64_t A;
    std::cin >> A;
    ++counts[A];
    sum += A;
  }
  int Q;
  std::cin >> Q;
  for (int i = 0; i < Q; ++i) {
    std::int64_t B, C;
    std::cin >> B >> C;
    sum += (C - B) * counts[B];
    counts[C] += counts[B];
    counts.erase(B);
    std::cout << sum << std::endl;
  }
  return 0;
}


Measured memory_bytes: 7580
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.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println((a + b + 1) / 2);
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21588
import sys
from collections import Counter, deque, defaultdict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


a, b, x = MAP()
S = Fraction(x, a)
x = Fraction(S, a)

if 2*x >= b:
    print(math.degrees(math.atan(float(Fraction((2*b - 2*x), a)))))
else:
    print(math.degrees(math.atan(float(Fraction(b**2,2*S)))))



Measured memory_bytes: 66156
#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++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) { cin >> A[i]; A[i]--; }
		vector<ULL> S(N); rep(i, N) S[A[i]]++;
		ULL ans = 0; rep(i, N) ans += S[i] * (S[i] - 1) / 2;
		rep(i, N) {
			cout << (ans - (S[A[i]] - 1)) << endl;
		}
	}

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


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define ll long long
#define pp pair<int,int> 
const int INF = 1001001001;
//int 2×10の9乗

//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n){
    //rep(j,m) cin >> a[i][j]; 
  //}
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  rep(i,n) a[i]--;
  int ans=0;
  rep(i,n)  ans+=b[a[i]];
  rep(i,n-1) {
    if(a[i]+1==a[i+1]) ans+=c[a[i]];
  }  
  cout << ans << endl;
}    

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//定義 
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		ArrayList<Integer> al = new ArrayList<>();
		for (int i=0; i<n; i++){
			al.add(Integer.parseInt(sc.next()));
		}
		System.out.println(gcdarr(al));;
	}
	
	public static int gcd(int a, int b){
		if(b==0){
			return a;
		}
		else{
			return gcd(b,a%b);
		}
	}
	public static int gcdarr(ArrayList<Integer> a){
		int ans = a.get(0);
		for(int i:a){
			ans=gcd(ans,i);
		}
		return ans;
	}

}


Measured memory_bytes: 48808
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const ll Mod = 1e9 + 7;
ll n,k;
vector < ll > v[100100];

void Add_self(ll &x , ll y){
    x = (x + y)%Mod;
}

ll mul_self(ll x , ll y){
    return (x * y)%Mod;
}

ll Ans = 1;

ll DFS(ll x , ll p , ll depth){

    ll c = (depth == 0 ? k - 1 : k - 2);
    for(int i = 0;i<v[x].size() - (depth != 0);i++){
        Ans = mul_self(Ans , c);
        c--;
        c = max(c , (ll)0);
    }
    for(auto j : v[x])  if(j != p)  DFS(j , x , depth + 1);
}

int main()
{
    cin >> n >> k;
    Ans = k;
    for(ll i = 0;i<n - 1;i++){
        ll x,y;  cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    DFS(1 , -1 , 0);
    cout << Ans;
    return 0;
}


Measured memory_bytes: 9216
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>

#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<vector<vector<double> > > gp(n+1, vector<vector<double> >(n+1, vector<double>(n+1, 0)));
 
    long in[3]={0};
    long i, j, k;
    for(i=0; i<n; i++) {
        long tmp = 0;
        scanf("%ld", &tmp);
        in[tmp-1] ++;
    }

    for(i=0; i<=in[2]; i++) {
        for(j=0; j<=in[1]+in[2]-i; j++) {
            for(k=0; k<=in[0]+in[1]+in[2]-i-j; k++) {
                if(i>0)
                    gp[i][j][k] += (double)i/(i+j+k) * ((double)n/(i+j+k) + gp[i-1][j+1][k]);
                if(j>0)
                    gp[i][j][k] += (double)j/(i+j+k) * ((double)n/(i+j+k) + gp[i][j-1][k+1]);
                if(k>0)
                    gp[i][j][k] += (double)k/(i+j+k) * ((double)n/(i+j+k) + gp[i][j][k-1]);
            }
        }
    }

    printf("%.10f\n", gp[in[2]][in[1]][in[0]]);   

    return 0;
}


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



int main()
{
	int n;
	cin>>n;
	int id,val=-1;
	for(int i=0;i<n;i++)
	{
		int a,v;
		cin>>a>>v;
		if(val<v)
		{
			id=a;
			val=v;
		}
		else if(val==v)
		{
			id=min(id,a);
		}
		
	}
	cout<<id<<" "<<val<<endl;
}

Measured memory_bytes: 1164
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, k; cin >> n >> k;
    vector<ll> A(n); ll sum = 0;
    rep(i, n){
        cin >> A[i];
        if(A[i]>0)sum += A[i];
    }
    int index = 0;
    ll sei = 0, fu = 0, res = -LINF;
    for(index; index < k; index++){
        if(A[index]>0) sei += A[index];
        else fu += A[index];
        res = max(sum - sei, sum + fu);
    }
    for(index; index < n; index++){
        //cout << "sei:" << sei << " fu:" << fu << ln;
        if(A[index]>0) sei += A[index];
        else fu += A[index];
        if(A[index-k]>0) sei -= A[index-k];
        else fu -= A[index-k];
        chmax(res, sum - sei);
        chmax(res, sum + fu);
    }
    cout << res << ln;
}


Measured memory_bytes: 4056
#include <stdio.h>
 
int main()
{
  char a[4];
  scanf("%s",&a);
  int b[4] = {0,0,0};
  int i = 0;
  while (a[i])
  {
    if (a[i] == 'a')
      b[0] += 1;
    else if (a[i] == 'b')
      b[1] += 1;
    else
      b[2] += 1;
    i++;
  }
  if (b[0] == 1 && b[1] == 1 && b[2] == 1)
  	printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
char s[60][60];
int main()
{
    int dp[3],k; cin>>dp[0]>>dp[1]>>dp[2]>>k;
    if(abs(dp[2]-dp[0])<=k || (abs(dp[1]-dp[0])<=k && abs(dp[2]-dp[1]<=k))) return !printf("Yes");
    return !printf("No");
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<a*b-c*b-a*d+c*d;
    

}

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

int func(int n){
  if(n%2==0) return n/2;
  else return n*3 + 1;
}

int main(){
  int N; cin >> N;
  int l_max = 0;
  int l_sum = 0;
  for(int i=0;i<N;i++){
    int temp;
    cin >> temp;
    l_sum += temp;
    l_max = max(temp,l_max);
  }
  if(l_sum>l_max*2) cout <<"Yes"<<endl;
  else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    double a, b, x;
    cin >> a >> b >> x;
    if (x >= a * a * b / 2)
    {
        double tantheta = 2 * (a * a * b - x) / (a * a * a);
        double theta = atan(tantheta);
        theta = 360 * theta / (2 * pi);
        cout << setprecision(12) << theta << endl;
    }
    else
    {
        double tantheta = a * b * b / (2 * x);
        double theta = atan(tantheta);
        theta = 360 * theta / (2 * pi);
        cout << setprecision(12) << theta << endl;
    }

    return 0;
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
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(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int N;
	cin >> N;
	puts(N >= 1000 ? "ABD" : "ABC");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int M; cin >> M;
    cout << 48 - M << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextLong()

    var x = 1L
    var r = Long.MAX_VALUE
    while (true) {
        if (x == 1L) {
            r = n - 1
        } else if (n % x == 0L) {
            r = Math.min (r, n / x - 1 + x - 1)
        }
        x++
        if (x * x > n) {
            break
        }
    }
    println(r)
}


Measured memory_bytes: 31524
#include <bits/stdc++.h>
using namespace std;
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define forall(it, v) for(auto it = v.begin(); it != v.end(); ++it)
#define dforn(i, n) for(int i = ((int) n) - 1; i >= 0; i--)
#define db(v) cerr << #v << " = " << v << endl
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define ff first
#define ss second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int MAXN = -1;

int n, w;
string S, Ans;

int main(){
//	freopen("input.txt", "r", stdin);
	while(cin >> S){ n = S.size();
        Ans.clear();
        scanf("%d", &w);
        for(int p = 0; p < n; p+=w)Ans.pb(S[p]);
        cout << Ans << endl;
    }
	return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

MOD = 998244353

N,M = map(int,readline().split())
A,B,C,D = [np.array(list(readline().rstrip()))-48 for _ in range(4)]

def cumprod(arr,MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U,MOD):
    x = np.arange(U,dtype=np.int64); x[0] = 1
    fact = cumprod(x,MOD)
    x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
    fact_inv = cumprod(x,MOD)[::-1]
    return fact,fact_inv

U = 10**6
fact, fact_inv = make_fact(U,MOD)

def cnt_vertical(N,M,A,B,C,D):
    """
    ・ABが長さN、CDが長さM。
    ・初手に縦線を入れる場合。
    ・縦線の右端の位置に応じて場合分けして集計
    ・右端の位置を決めると、（左端の位置ごとの左側の入れ方の累積和） x （右側の入れ方の累積和）、適当に重みをつける必要あり
    """
    AB=A+B
    # ある場所を初めての縦線としたときに、左側にできる部分。上にある点の個数と下にある点の個数
    L=C.sum(); LU=A.cumsum()-A; LD=B.cumsum()-B
    NL=fact[LU+LD+L-1]*fact_inv[LU+LD]%MOD*fact_inv[L-1]% MOD

    R=D.sum(); RU=A[::-1].cumsum()-A[::-1]; RD=B[::-1].cumsum()-B[::-1]
    NR=fact[RU+RD+R-1]*fact_inv[RU+RD]%MOD*fact_inv[R-1]%MOD; NR=NR[::-1]

    x=np.ones(N,np.int64); x[AB==2]=2; coef=cumprod(x,MOD)
    x=np.ones(N,np.int64); x[AB==2]=(MOD+1)//2; coef_inv=cumprod(x,MOD)
    NL*=coef_inv; NR*=coef; NL%=MOD; NR%=MOD
    NL[AB==2]*=2
    NL[AB==0]=0;NR[AB==0]=0
    NL_cum=NL.cumsum()%MOD
    return (NL_cum*NR%MOD).sum()%MOD

def AB_only(N,A,B):
    x = np.ones(N,np.int64)
    x[A+B==2] = 2
    return cumprod(x,MOD)[-1]

def ABC_only(N,M,A,B,C):
    AB=A+B
    NA,NB,NC = [np.count_nonzero(x) for x in [A,B,C]]
    R=NC;RU=A[::-1].cumsum()-A[::-1];RD=B[::-1].cumsum()-B[::-1]
    NR=fact[RU+RD+R-1]*fact_inv[RU+RD]%MOD*fact_inv[R-1]%MOD; NR=NR[::-1]
    NR[AB==0]=0
    x=np.ones(N,np.int64); x[AB==2]=2; coef=cumprod(x,MOD)
    x=(coef*NR% MOD).sum()%MOD
    y=fact[NA+NB+NC-1]*fact_inv[NC-1]%MOD*fact_inv[NA+NB]%MOD
    return (x+y)%MOD

def F(N,M,A,B,C,D):
    # 問題の答えを出します。
    NA,NB,NC,ND = [np.count_nonzero(x) for x in [A,B,C,D]]
    if all(x != 0 for x in [NA,NB,NC,ND]):
        return (cnt_vertical(N,M,A,B,C,D) + cnt_vertical(M,N,C,D,A,B)) % MOD
    # A,Cに0列を寄せる
    if NA != 0:
        NA,NB = NB,NA; A,B = B,A; C = C[::-1]; D = D[::-1]
    if NC != 0:
        NC,ND = ND,NC; C,D = D,C; A = A[::-1]; B = B[::-1]
    if NB == 0:
        return AB_only(M,C,D)
    if ND == 0:
        return AB_only(N,A,B)
    # B,Dは0ではない
    if NA == 0 and NC == 0:
        # 2面B,Dのみ -> binom(B+D,B)
        return fact[NB+ND] * fact_inv[NB] % MOD * fact_inv[ND] % MOD
    if NA == 0:
        return ABC_only(M,N,C,D,B)
    if NC == 0:
        return ABC_only(N,M,A,B,D)

answer = F(N,M,A,B,C,D)
print(answer)

Measured memory_bytes: 58576
use proconio;
use std::collections::VecDeque;

#[proconio::fastout]
fn main() {
    proconio::input! {
        x: i64,
        n: usize,
        mut pp: [i64; n],
    }

    pp.sort_by(|l, r| {
        let ld = (x - l).abs();
        let rd = (x - r).abs();
        ld.cmp(&rd).then(l.cmp(r))
    });
    let mut pp: VecDeque<_> = pp.into();
    // println!("{:?}", pp);

    let mut v: Vec<i64> = vec![];
    v.push(x);
    for i in 1..=100 {
        v.push(x - i);
        v.push(x + i);
    }
    let mut v: VecDeque<_> = v.into();
    // println!("{:?}", v);

    let mut result = x;
    while v.len() > 0 {
        result = v[0];
        let in_pp = pp.iter().any(|p| p == &result);
        if in_pp {
            // println!("{} is in pp", result);
            v.pop_front();
            pp.pop_front();
            continue;
        }
        // println!("{} is NOT in pp", result);
        break;
    }
    println!("{}", result);
}


Measured memory_bytes: 2188
#include <stdio.h>

int main()
{
  int i, n, a, b, c;

  scanf("%d",&n);

  for(i=0;i<=n;i++){
    if(i==0){
      a=1;
      c=1;
    }
    if(i==1){
      b=1;
      c=1;
    }
    if(i>1){
      c=a+b;
      a=b;
      b=c;
    }
  }
  
  printf("%d\n",c);

  return 0;
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int X;
  int Y;
  int Z;
  cin >>X>>Y>>Z;
  int essentiallength=X-2*Z-Y;
  int count=1;    //一人入った状態。
  count +=essentiallength/(Y+Z);
  cout << count << endl;
}
  


Measured memory_bytes: 256
S = input()

if S.count('N') >= 1 and S.count('S') >= 1 and S.count('E') == 0 and S.count('W') == 0:
  print('Yes')
elif S.count('E') >= 1 and S.count('W') >= 1 and S.count('N') == 0 and S.count('S') == 0:
  print('Yes')
elif S.count('E') >= 1 and S.count('W') >= 1 and S.count('N') >= 1 and S.count('S') >= 1:
  print('Yes')
else: 
  print('No')

Measured memory_bytes: 9084
N,Q = (int(x) for x in input().split())
S = list(input())
count = [0 for i in range(N)]
c = 0
for i in range(N-1):
    if S[i] == 'A':
        if S[i+1] == 'C':
            count[i] = c
            c += 1
            i += 1
        elif S[i+1] != 'A':
            count[i] = c
            i += 1 
    count[i] = c
if count[-2] > count[-1]:
    count[-1] = count[-2]

for i in range(Q):
    l,r = (int(x) for x in input().split())
    print(count[r-1]-count[l-1])


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

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

   if(count(a.begin(),a.end(),1)==0){
      cout<<-1<<endl;
      return 0;
   }

   const int MAX=*max_element(a.begin(),a.end());
   vector<bool> dp(MAX+1);
   // dp[i]:=(今見ているところまでで)1,2,...iを部分列として含んでいるか
   dp[0]=true;
   for(int i=0;i<N;i++){
      if(dp[a[i]-1]) dp[a[i]]=true;
   }
   int ans=0;
   for(int i=1;i<=MAX;i++) if(dp[i]) ans=i;
   cout<<N-ans<<endl;
   return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

class Main
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        char[] c=sc.next().toCharArray();
        int ans=0;
        for(int i=0;i+2<n;++i){
            if(c[i]=='A'&&c[i+1]=='B'&&c[i+2]=='C')++ans;
        }
        System.out.println(ans);
    }
}

// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

int main()
{
    int N;
    cin >> N;
    int h[N];
    REP(i,0,N){
        cin >> h[i];
    }

    int dp[N];
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    if(N==2){
        cout << dp[1] << endl;
    }else{
        REP(i,2,N){
            dp[i] = min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
            
        }
        cout << dp[N - 1] << endl;
    }
}

Measured memory_bytes: 1024
module Main where

import Control.Applicative
import Control.Monad

main :: IO ()
main = do
    n <- readLn :: IO Int
    let a = 4
    let b = 7
    let cs = [ (x, y) | x <- [0 .. 25]
                      , y <- [0 .. 14]
                      , a * x + b * y == n
             ]
    if null cs
        then putStrLn "No"
        else putStrLn "Yes"

Measured memory_bytes: 508
#include<stdio.h>

int distance(int x,int y)
{
  if(x<0)
  {
    x=x*(-1);
  }
  if(y<0)
  {
    y=y*(-1);
  }
  
  return x+y;
}

int main()
{
  int n , a[51]={} , b[51]={};
  int m , c[51]={} , d[51]={};
  int i,j;
  int l[51]={},check[51]={};
  int min;
  
  scanf("%d%d",&n,&m);
  
  for(i=1;i<=n;i++)
  {
    scanf("%d %d",&a[i],&b[i]);
  }
  
  for(i=1;i<=m;i++)
  {
    scanf("%d %d",&c[i],&d[i]);
  }
  
  for(i=1;i<=n;i++)
  {
     min=distance(a[i]-c[1],b[i]-d[1]);
     check[i]=1;
    for(j=2;j<=m;j++)
    {
       l[i]=distance(a[i]-c[j],b[i]-d[j]);
      if(l[i]<min)
      {
        min=l[i];
        check[i]=j;
      }
    }
    printf("%d\n",check[i]);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
map<ll,ll> bag,keep;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,W;cin>>n>>W;
bag[0]=0;
vector<ll> w(n),v(n);
for(int i=0;i<n;i++)cin>>w[i]>>v[i];
for(int i=0;i<n;i++){
    for(auto p: bag){
    if(p.fi+w[i]>W)continue;
   keep[p.fi+w[i]]=max(bag[p.fi+w[i]],p.se+v[i]);
  }
 for(auto p: keep){
   bag[p.fi]=p.se;
 }
}
ll ans=0;
for(auto p: bag){
  //cout<<p.fi<<" "<<p.se<<endl;
  chmax(ans,p.se);
}
cout<<ans<<endl;
}


Measured memory_bytes: 896
X=int(input())
if X<=599:
    k=8
elif 600<=X<=799:
    k=7
elif 800<=X<=999:
    k=6
elif 1000<=X<=1199:
    k=5
elif 1200<=X<=1399:
    k=4
elif 1400<=X<=1599:
    k=3
elif 1600<=X<=1799:
    k=2
else:
    k=1
print(k)

Measured memory_bytes: 61772
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm;
struct Matrix {
    int n;
    vector<vm> mat;

    Matrix(int n) : n(n), mat(vector<vm>(n, vm(n))) {}
    Matrix(vector<vll>& a) : n(a.size()), mat(vector<vm>(n, vm(n))) {
        rep(i, n) rep(j, n) mat[i][j] = a[i][j];
    }

    Matrix matmul(const Matrix& a) const{
        Matrix res(n);
        rep(i, n) rep(j, n) rep(k, n) res.mat[i][j] += mat[i][k] * a.mat[k][j];
        return res;
    }

    Matrix pow(ll k) const{
        Matrix res(n);
        if(!k) {
            rep(i, n) res.mat[i][i] = 1;
            return res;
        }
        res = pow(k >> 1);
        res = res.matmul(res);
        if(k & 1) res = matmul(res);
        return res;
    }
};

int main() {
//	cout << fixed << setprecision(15);
    int n;
    ll k;
    cin >> n >> k;
    vector<vll> a(n, vll(n));
    rep(i, n) rep(j, n) cin >> a[i][j];
    Matrix m(a);
    m = m.pow(k);
    mint ans;
    rep(i, n) rep(j, n) ans += m.mat[i][j];
    cout << ans.x << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;
	cin>>N;
	vint V(N);rep(i,N)cin>>V[i];
	sort(all(V));
	double ans=V[0];
	for(int i=1;i<N;i++){
		ans=(ans+V[i])/2;
	}
	printf("%.20f\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int M=200005,N=1005;
int nxt[M],ed[M],ans[M];
vector<int> v[N];
int son[N],vis[N],ne,alb[M],lt[N][N];
void ae(int a,int b){
	nxt[++ne]=son[a]; son[a]=ne; ed[ne]=b;
}
void dfs(int p){
	vis[p]=1;
	for(auto i:v[p])if(!vis[i])dfs(i);
}
int main(){
	int n=read(),m=read();
	For(i,1,m){
		int s=read(),t=read(); 
		ae(s,t); v[s].pb(t);
	}
	For(i,1,n){
		memset(vis,0,sizeof(vis)); 
		vector<int> v; vis[i]=1;
		for(int j=son[i];j;j=nxt[j]){			
			if(vis[ed[j]]){
				alb[j]=1; 
			}else{
				dfs(ed[j]);
			}
			v.pb(j);
		}
		memset(vis,0,sizeof(vis));  vis[i]=1;
		Rep(o,v.size()-1,0){
			int j=v[o];
			if(vis[ed[j]]){
				alb[j]=1; 
			}else{
				dfs(ed[j]);
			}
		}
		For(j,1,n)lt[i][j]=vis[j];
	}
	For(i,1,n)for(int j=son[i];j;j=nxt[j])ans[j]=alb[j]==lt[ed[j]][i];
	//for(int i=son[3];i;i=nxt[i])if(ed[i]==4)cout<<alb[i]<<endl;
	For(i,1,m)puts(ans[i]?"same":"diff");
}

Measured memory_bytes: 9856
while True:
    try:
        a = [x for x in input().split()]
        b = [x for x in input().split()]
        hit_count = 0
        blow_count = 0
        for i in range(4):
            if a[i] == b[i]:
                hit_count += 1
            elif(b[i] in a):
                blow_count += 1
        print(hit_count, blow_count)
    except EOFError:
        break



Measured memory_bytes: 5564
a, b, h, m = map(int,input().split())
tanshin = h * 30 + m * 0.5
chousin = 6 * m
kakudo = tanshin - chousin
import math
print(math.sqrt(a**2 + b**2 -2*a*b*math.cos(math.radians(kakudo))))


Measured memory_bytes: 9552
package main

import (
  "fmt"
  "bufio"
  "os"
  "strconv"
)


var sc = bufio.NewScanner(os.Stdin)
func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
  // input
  sc.Split(bufio.ScanWords)
  n := nextInt()
  if n%2 == 0 {
    fmt.Println(n/2)
  } else {
    fmt.Println(n/2+1)
  }

}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

int main(){
    int N,M,C;
    cin>>N>>M>>C;
    vector<int> B(M);
    int ans=0;
    for(auto &b:B) cin>>b;
    for(int i=0;i<N;i++){
        vector<int> A(M);
        int sum=0;
        for(auto b:B){
            int a;
            cin>>a;
            sum+=a*b;
        }
        sum+=C;
        if(sum>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256