akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int N, M, K;
std::vector<int> f[100000];
std::vector<int> b[100000];
int group[100000];
int group_cnt[100000];

void check(int n, int g) {
    for (int vv : f[n]) {
        if (group[vv] == -1) {
            group[vv] = g;
            group_cnt[g] += 1;
            check(vv, g);
        }
    }
}

int main() {
    std::cin >> N >> M >> K;

    int A, B;
    for (int i = 0; i < M; ++i) {
        std::cin >> A >> B;
        --A;
        --B;
        f[A].push_back(B);
        f[B].push_back(A);
    }

    int C, D;
    for (int i = 0; i < K; ++i) {
        std::cin >> C >> D;
        --C;
        --D;
        b[C].push_back(D);
        b[D].push_back(C);
    }

    for (int i = 0; i < N; ++i) {
        group[i] = -1;
    }

    for (int i = 0; i < N; ++i) {
        if (group[i] != -1) {
            continue;
        }

        group_cnt[i] += 1;
        group[i] = i;
        check(i, i);
    }

        

    for (int i = 0; i < N; ++i) {
        const int g = group[i];
        int cnt = group_cnt[g] - 1;

        for (int vv : f[i]) {
            if (group[vv] == g) {
                --cnt;
            }
        }

        for (int vv : b[i]) {
            if (group[vv] == g) {
                --cnt;
            }
        }

        std::printf("%d", cnt);
        if (i != (N -1)) {
            std::printf(" ");
        }
    }

    std::printf("\n");

    return 0;
}


Measured memory_bytes: 13056
#include<iostream>
using namespace std;
const long long MOD = 1000000007;

long long mod_pow(long long a, long long n, long long mod) {
    if (n == 0)return 1;
    if (n % 2 == 0)
        return mod_pow(a, n / 2, mod) * mod_pow(a, n / 2, mod) % mod;
    else
        return mod_pow(a, n - 1, mod) * a % mod;
}

long long mod_inv(long long n, long long mod) {
    return mod_pow(n, mod - 2, mod);
}

long long combination(long long n, long long r, long long mod) {
    long long rtn = 1;
    for (long long i = 1; i <= r; i++, n--) {
        rtn = rtn * n % mod;
        rtn = rtn * mod_inv(i, mod) % mod;
    }
    return rtn;
}

long long mod_subtruction(long long a, long long b, long long mod) {
    if (a - b < 0)return a - b + mod;
    else return a - b;
}

int main() {
    long long n, a, b, ans = 0; cin >> n >> a >> b;
    ans = mod_subtruction(mod_pow(2, n, MOD), 1, MOD);
    ans = mod_subtruction(ans, combination(n, a, MOD), MOD);
    ans = mod_subtruction(ans, combination(n, b, MOD), MOD);
    cout << ans << endl;
}

Measured memory_bytes: 256
s = str(input())
f,l = int(s[0:2]),int(s[2:4])
k = 0
if 1 <= f <= 12:
  k += 1
if 1 <= l <= 12:
  k += 2
if k == 0:
  print("NA")
elif k == 1:
  print("MMYY")
elif k == 2:
  print("YYMM")
else:
  print("AMBIGUOUS")

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

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	T sub(int l, int r, int node, int lb, int ub) {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		T vl = sub(l, r, node * 2 + 0, lb, (lb + ub) / 2);
		T vr = sub(l, r, node * 2 + 1, (lb + ub) / 2, ub);
		return merge(vl, vr);
	}
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	SegmentTree(int n, T id, func_t merge) :
		n(size(n)), id(id), merge(merge), data(size(n) * 2, id) {}
	void update(int p, T val) {
		assert(0 <= p && p < n);
		p += n;
		data[p] += val;
		while (p /= 2) {
			int l = p * 2, r = p * 2 + 1;
			data[p] = merge(data[l], data[r]);
		}
	}
	T find(int l, int r) {
		return sub(l, r, 1, 0, n);
	}
};

int main() {
	int n, q, com, x, y;
	cin >> n >> q;
	SegmentTree<int> seg(n, 0, [](int a, int b) { return a + b; });
	while (q--) {
		cin >> com >> x >> y;
		if (com) cout << seg.find(x - 1, y) << endl;
		else seg.update(x - 1, y);
	}
	return 0;
}

Measured memory_bytes: 3888
import math


def divisorGenerator(n):

    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n // i)
    for divisor in reversed(large_divisors):
        yield divisor

if __name__ == '__main__':

    n = int(input())
    A = list(map(int, input().split()))

    gcd_ = math.gcd(A[0], A[1])
    for i in range(2, len(A)):
        gcd_ = math.gcd(gcd_, A[i])

    set_wise = False
    if gcd_ == 1:
        set_wise = True
    if not(set_wise):
        print("not coprime")
    else:
        pairwise = True
        divs = dict()
        for i in A:
            res = list(divisorGenerator(i))
            for el in res:
                if el != 1:
                    if not(el in divs):
                        divs[el] = 0
                    divs[el] += 1
                    if divs[el] > 1:
                        print("setwise coprime")
                        exit()
        print("pairwise coprime")
        # for value in divs.values():
        #     if value > 1:
        #         pairwise = False
        #         break
        # if pairwise:
        #     print("pairwise coprime")
        # else:
        #
        #



Measured memory_bytes: 181556
# ABC089
import sys
input = sys.stdin.readline

from itertools import combinations

n = int(input())
lst = [input().rstrip() for _ in range(n)]
cond = {"M": 0, "A": 0, "R": 0, "C": 0, "H": 0}
for i in lst:
    if i[0] in "MARCH":
        cond[i[0]] += 1
ans = 0
for x, y, z in combinations("MARCH", 3):
    ans += cond[x] * cond[y] * cond[z]
print(ans)

Measured memory_bytes: 9780
# coding: utf-8
import bisect
import math
#N, c, k = map(int,input().split())
N = int(input())
#T = []
A = list(map(int,input().split()))
A.sort()
A_ = sorted(A)
ans = 0
for i in range(N-1):
    A_[i+1] += A_[i]
#print(A)
#print(A_)
for i in range(N-1):
    #print(ans)
    if A_[i]*2 >= A[i+1]:
        ans += 1
    else:
        ans = 0
ans += 1
print(ans)

Measured memory_bytes: 86480
import qualified Data.Array as A
import Data.Array ((//), (!), listArray)
import Data.Functor
import Data.List
import Control.Monad
import System.IO

main :: IO ()
main = do
  eof <- isEOF
  if eof then return () else solve >> main

solve :: IO ()
solve = do
  xs <- getDegrees
  putStrLn $ if ok xs then "OK" else "NG"

getDegrees :: IO [Int]
getDegrees = rec $ listArray (0, 100) $ replicate 101 0
  where rec arr = do
          [x, y] <- map readInt . words <$> getLine
          if x == 0 && y == 0 then return $ A.elems arr
          else rec $ arr // [(x, (arr ! x) + 1), (y, (arr ! y) + 1)]

ok :: [Int] -> Bool
ok (_:x1:x2:xs) = odd x1 && odd x2 && all even xs

readInt :: String -> Int
readInt = read

Measured memory_bytes: 5056
import java.util.Scanner;

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

        String str = scanner.nextLine();
        int count = 0;

        for (int i = 0; i < str.length(); ++i) {
            count += (str.charAt(i) - '0');
        }
        if (count == 1) {
            count = 10;
        }
        System.out.println(count);
    }
}

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

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    ll n,m; cin >> n >> m;
    ll sum=0, a;
    rep(i,m){
        cin >> a;
        sum += a;
    }

    if(sum > n) cout << -1 << endl;
    else cout << n - sum << endl;
    return 0;
}

Measured memory_bytes: 3636
S=input()
a=[None]*(len(S)-2)
for i in range(len(S)-2):
    a[i]=int("{}{}{}".format(S[i],S[i+1],S[i+2]))
s=800
for i in range(len(a)):
    if s>abs(a[i]-753):
        s=abs(a[i]-753)
print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#include <math.h> 
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b;
	cin>>a>>b;
	string s,t;
	for(ll i=0;i<b;i++){
		char now=char('0'+a);
		s.push_back(now);
	}
	for(ll i=0;i<a;i++){
		char now=char('0'+b);
		t.push_back(now);
	}
	if(s<t){
		cout <<s;
	}
	else{
		cout << t;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 3628
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
dp=[[0,0,0] for i in range(n+1)]

for i in range(1,n+1):
    
    for j in range(3):
        for k in range(3):
            if k!=j:
                dp[i][j]=max(dp[i][j],dp[i-1][k]+l[i-1][j])
print(max(dp[-1]))

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

vector<int> edge[1010];
set<int> ans;

void bfs(int start, int goal) {
	bool used[1010];
	int prev[1010];
	for(int i = 0; i < 1010; ++i) {
		used[i] = false;
		prev[i] = -1;
	}
	queue<int> que;
	que.push(start);
	used[start] = true;
	prev[start] = goal;
	while(que.size()) {
		int from = que.front();
		que.pop();
		for(int to : edge[from]) {
			if(not used[to]) {
				used[to] = true;
				prev[to] = from;
				que.push(to);
			}
		}
	}
	set<int> tmp;
	int now = goal;
	while(now != start) {
		if(now == -1) return;
		tmp.insert(now);
		now = prev[now];
	}
	tmp.insert(start);
	if(tmp.size() < ans.size()) {
		ans = tmp;
	}
}

int main() {
	int n, m; cin >> n >> m;
	int s[m], t[m];
	for(int i = 0; i < m; ++i) {
		cin >> s[i] >> t[i];
		edge[--s[i]].push_back(--t[i]);
	}
	for(int i = 0; i <= n; ++i) {
		ans.insert(i);
	}
	for(int i = 0; i < m; ++i) {
		bfs(t[i], s[i]);
	}
	if(ans.size() == n + 1) {
		cout << -1 << '\n';
		return 0;
	}
	cout << ans.size() << '\n';
	for(int i : ans) {
		cout << i + 1 << '\n';
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int n;
    cin >> n;
    vector<string> vs;
    REP(i,n){
        string s;
        cin >> s;
        vs.pb(s);
    }
    sort(all(vs));
    int cnt=1;
    REP(i,n-1){
        if(vs[i]!=vs[i+1]) cnt++;
    }
    cout << cnt << endl;;
}


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

const int MAX=20000;
const int MAX_half=10000;
const long long inf=20001;

struct max_flow {
    struct edge { long long to, cap, rev; };
    long long V;
    vector<vector<edge>> G;
    vector<long long> itr, level;

    max_flow(long long V) : V(V) { G.assign(V,vector<edge>()); }

    void add_edge(long long from, long long to, long long cap) {
        G[from].push_back((edge) {to, cap, (long long) G[to].size()});
        G[to].push_back((edge) {from, 0, (long long) G[from].size()-1});
    }

    void bfs(long long s) {
        level.assign(V,-1);
        queue<long long> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            long long v = q.front(); q.pop();
            for(auto &e: G[v]){
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }

    long long dfs(long long v, long long t, long long f) {
        if (v == t) return f;
        for (long long& i = itr[v]; i < (long long) G[v].size(); ++i) {
            edge& e = G[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                long long d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    long long run(long long s, long long t) {
        long long ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V,0);
            while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main(){
    //input
    int H,W;
    cin >> H >> W;
    string a[H];
    int i,j,k;
    for(i=0; i<H; i++){
        cin >> a[i];
    }

    //calc
    max_flow mf(MAX);
    pair<int,int> S,T;
    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(a[i][j]=='S'){
                S=make_pair(i,j);
            }
            if(a[i][j]=='T'){
                T=make_pair(i,j);
            }
        }
    }
    if(S.first==T.first||S.second==T.second){
        cout << -1 << endl;
        system("pause");
        return 0;
    }
    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(a[i][j]!='.'){
                mf.add_edge(i*W+j,i*W+j+MAX_half,1);
            }
        }
    }
    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(a[i][j]!='.'){
                for(k=i+1; k<H; k++){
                    if(a[k][j]!='.'){
                        mf.add_edge(i*W+j+MAX_half,k*W+j,inf);
                        mf.add_edge(k*W+j+MAX_half,i*W+j,inf);
                    }
                }
                for(k=j+1; k<W; k++){
                    if(a[i][k]!='.'){
                        mf.add_edge(i*W+j+MAX_half,i*W+k,inf);
                        mf.add_edge(i*W+k+MAX_half,i*W+j,inf);
                    }
                }
            }
        }
    }

    //output    
    cout << mf.run(S.first*W+S.second+MAX_half,T.first*W+T.second) << endl;
    system("pause");
    return 0;
}

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

  
int main(){
  int a,b,c;
  cin >> a>> b>>c;
  int x,y,z;
  x=max(a,max(b,c));
 if(x==a) cout <<a*10+b+c<< endl;
  else if(x==b) cout << b*10+a+c <<endl;
  else if(x==c) cout << c*10+a+b <<endl;   
}
 

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

const int MAXN=110;

int main()
{
	int n,A[MAXN],cnt=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]); 
	for(int i=0;i<n;i++)
		for(int j=n-1;j>i;j--)
			if(A[j]<A[j-1])
			{
				std::swap(A[j],A[j-1]);
				cnt++;
			}
	for(int i=0;i<n;i++)
		printf("%d%c",A[i],i+1==n?'\n':' ');
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 3164
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int m,n,o;
  while(cin>>n&&n){
    o=0;
    for(i=0;i<n/4;i++){
      cin>>m;
      o+=m;
    }
    cout<<o<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    if(n == 1){
    printf("1\n");
    }
        else if(n == 2){
    printf("1\n");
    }
        else if(n == 3){
    printf("1\n");
    }
        else if(n == 4){
    printf("2\n");
    }
        else if(n == 5){
    printf("1\n");
    }
            else if(n == 6){
    printf("2\n");
    }
            else if(n == 7){
    printf("1\n");
    }
            else if(n == 8){
    printf("5\n");
    }
            else if(n == 9){
    printf("2\n");
    }
            else if(n == 10){
    printf("2\n");
    }
		else if(n == 11){
    printf("1\n");
    }
		else if(n == 12){
    printf("5\n");
    }
            else if(n == 13){
    printf("1\n");
    }
            else if(n == 14){
    printf("2\n");
    }
            else if(n == 15){
    printf("1\n");
    }
            else if(n == 16){
    printf("14\n");
    }
            else if(n == 17){
    printf("1\n");
    }
            else if(n == 18){
    printf("5\n");
    }
            else if(n == 19){
    printf("1\n");
    }
            else if(n == 20){
    printf("5\n");
    }
            else if(n == 21){
    printf("2\n");
    }
            else if(n == 22){
    printf("2\n");
    }
            else if(n == 23){
    printf("1\n");
    }
            else if(n == 24){
    printf("15\n");
    }
            else if(n == 25){
    printf("2\n");
    }
            else if(n == 26){
    printf("2\n");
    }
            else if(n == 27){
    printf("5\n");
    }
            else if(n == 28){
    printf("4\n");
    }
            else if(n == 29){
    printf("1\n");
    }
            else if(n == 30){
    printf("4\n");
    }
            else if(n == 31){
    printf("1\n");
    }
            else if(n == 32){
    printf("51\n");
    }
    }


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

class Dice{
private:
  int right,left,front,back,bottom,now;
  void role(int num[6],int num2[6],string str){
    for(int i=0;i<str.size();i++){
      if(num[0]==num2[0]&&num[1]==num2[1]&&num[2]==num2[2]&&num[3]==num2[3]&&num[4]==num2[4]&&num[5]==num2[5]){
	cout<<"Yes"<<endl;
	return;
      }
      switch(str[i]){
      case 'S':num[1]=now;num[0]=back;num[4]=bottom;num[5]=front;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      case 'W':num[3]=front;num[1]=right;num[2]=back;num[4]=left;front=num[1];left=num[3];back=num[4];right=num[2];break;
      case 'E':num[3]=bottom;num[0]=left;num[2]=now;num[5]=right;now=num[0];left=num[3];bottom=num[5];right=num[2];break;
      case 'N':num[4]=now;num[0]=front;num[1]=bottom;num[5]=back;now=num[0];back=num[4];bottom=num[5];front=num[1];break;
      }
      if(num[0]==num2[0]&&num[1]==num2[1]&&num[2]==num2[2]&&num[3]==num2[3]&&num[4]==num2[4]&&num[5]==num2[5]){
	cout<<"Yes"<<endl;
	return;
      }
    }
    cout<<"No"<<endl;
    return;
  }
public:
  void Scan(int num[6],int num2[6]){
    now=num[0];right=num[2];left=num[3];front=num[1];back=num[4];bottom=num[5];
    role(num,num2,"WWWNWWWWNWWWWNWWWNWWWWNNWWWNWWW");
  }
};

int main(){
  Dice dice;
  int a,b,n;
  int num[6],num2[6];
  for(int i=0;i<6;i++)
    cin>>num[i];
  for(int i=0;i<6;i++)
    cin>>num2[i];
  dice.Scan(num,num2);
  return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    int ans = 0;
    while (X >= Y * ans + Z * (ans + 1)) ans++;
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;
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;
}
vector<bool> seen;
void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
signed main() {
    long long INF = 1000000000000;
    int N;cin>>N; vector<int>H(100005);
    vector<int>DP(100005, INF);
    DP[0] = 0;
    for(int X=0;X<N;X++){
      cin>>H[X];
    }
    for (int X = 0; X < N; X++) {
        for (int Y = 1; Y <= 2; Y++) {
            chmin(DP[X + Y], DP[X] + abs(H[X] - H[X + Y]));
        }
    }
    cout<<DP[N-1]<<endl;
}


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

int main() {
  int n,a;
  cin >> n;
  long long int sum=0;
  int min=1000000;
  int max=-1000000;
  for(int i=0;i<n;i++){
    cin >>a;
    
    if(min>a){
      min=a;
    }
    
    if(max<a){
      max=a;
    }
    
    sum+=a;
    
  }
  
  cout << min << ' ' << max << ' ' << sum << endl;  
}



Measured memory_bytes: 3116
#include<stdio.h>

int main(void){
    register int i;
    long n;
    int m;
    scanf("%ld %d",&n,&m);
    int a[m];
    for(i = 0;i < m;i++)scanf("%d",&a[i]);
    long sumhw = 0;
    for(i = 0;i < m;i++)sumhw += a[i];
    if(sumhw > n){
        puts("-1");
        return 0;
    }else{
        printf("%ld",n - sumhw);
        return 0;
    }
}

Measured memory_bytes: 1724
import java.util.*;

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

        int n=sc.nextInt();
        int cnt_8;
        int cnt=0;

        for(int j=1;j<=n;j+=2){
            cnt_8=0;
            for(int k=1;k<=j;k++){
                if(j%k==0){
                    cnt_8++;
                }
            }
            if(cnt_8==8){
                //System.out.println("num="+j);
                cnt++;
            }
        }
    System.out.println(""+cnt);
    }
}

Measured memory_bytes: 21844
n = int(input())

ss = []
for i in range(n):
	ss.append(sorted(str(input())))

sm = sorted(ss)
c = 0
ans = 0
for i in range(n-1):
	if sm[i] == sm[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)


Measured memory_bytes: 25420
temp = input()
n = int(input())
for _ in range(n):
    order,a,b,*value = input().split()
    a = int(a)
    b = int(b)

    if order == "print":
        print(temp[a:b+1])
    elif order == "reverse":
        rev = temp[a:b+1]
        temp = temp[:a] + rev[::-1] + temp[b+1:]
    else:#replace
        temp = temp[:a] + value[0] + temp[b+1:]


Measured memory_bytes: 5616
import sys
import math
import copy
import queue
input = sys.stdin.readline
n,m = map(int,input().split())
ans = list('-' * n)
for _ in range(m):
    s,c = input().split()
    i = int(s) - 1
    if ans[i] == '-' or ans[i] == c:
        ans[i] = c
    else:
        print(-1)
        exit (0)
if ans[0] == '-' and n > 1:
    ans[0] = '1'
x = ''.join(ans).replace('-','0')
if x[0] == '0' and x != '0':
    print (-1)
else:
    print (x)

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

typedef long long ll;
typedef pair<int, int> p;


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b >= a * c) cout << c << endl;
  else cout << b / a << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;

  if (k > (n - 1) * (n - 2) / 2) {
    cout << -1 << endl;
    return 0;
  }

  vector<vector<int>> g(n, vector<int>(n, 1));
  int cnt = 0;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < n - 1; j ++) {
      if (i >= j) continue;
      if (cnt == k) break;
      g[i][j] = 0;
      cnt ++;
    }
    if (cnt == k) break;
  }

  cout << (n - 1) * n / 2 - k << endl;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < n; j ++) {
      if (i >= j) continue;
      if (g[i][j] == 0) continue;
      cout << i + 1 << " " << j + 1 << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S,T;cin >> S >> T;
    int t = T.size();
    if (t==S.size()+1 && T==(S+T[t-1])) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3632
k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(a[k - 1])


Measured memory_bytes: 8888
#include <iostream>
#include <vector>
#include <queue>
#include <map>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
 
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
 
int main(void)
{
  int h, w;
  cin >> h >> w;
  vec<vec<int> > a(h, vec<int>(w, - 1));
  queue<pair<int, int> > q;
  rep(i, h) rep(j, w) {
    char get;
    cin >> get;
    if (get == '#') {
      q.push(make_pair(i, j));
      a[i][j] = 0;
    }
  }
 
  while(!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    rep(i, 4) {
      int x = p.first + dx[i];
      if (x >= h || x < 0) continue;
      int y = p.second + dy[i];
      if (y >= w || y < 0) continue;
      if (a[x][y] >= 0) continue;
      a[x][y] = a[p.first][p.second] + 1;
      q.push(make_pair(x, y));
    }
  }
 
  int ans = 0;
  rep(i, h) rep(j, w) {
    if (ans < a[i][j]) ans = a[i][j];
  }
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12432
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 998244353;

int main()
{
    ll a, b, n;
    cin >> a >> b >> n;

    ll c = 0;
    if (n < b) c = n;
    else c = b - 1;

    ll ans = (a * c) / b;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
getcnt = gets.to_i

def Check( a, b, c )
  if a**2 == (b**2 + c**2)
    return true
  else
    return false
  end
end

getcnt.times {
  (a,b,c) = gets.split
  data = [a.to_i,b.to_i,c.to_i]

  if Check(data[0], data[1], data[2]) ||
     Check(data[2], data[0], data[1]) ||
     Check(data[1], data[2], data[0]) 
    puts("YES")
  else
    puts("NO")
  end
}

Measured memory_bytes: 6116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	stdin = null;
		char	d     = 'd';

		while ((stdin = parseStdin()) != null) {
			char	c = checkHori(stdin);

			if (c == d) {
				c = checkVert(stdin);
			}

			if (c == d) {
				c = checkDiag(stdin);
			}

			System.out.println(c);
		}
	}

	private static char checkHori(String board) {
		char	c = 'd';
		char	s = 's';

		if (board.charAt(0) == board.charAt(1) && board.charAt(1) == board.charAt(2) && board.charAt(0) != s) {
			c = board.charAt(0);
		}
		else if (board.charAt(3) == board.charAt(4) && board.charAt(4) == board.charAt(5) && board.charAt(3) != s) {
			c = board.charAt(3);
		}
		else if (board.charAt(6) == board.charAt(7) && board.charAt(7) == board.charAt(8) && board.charAt(6) != s) {
			c = board.charAt(6);
		}

		return c;
	}

	private static char checkVert(String board) {
		char	c = 'd';
		char	s = 's';

		if (board.charAt(0) == board.charAt(3) && board.charAt(3) == board.charAt(6) && board.charAt(0) != s) {
			c = board.charAt(0);
		}
		else if (board.charAt(1) == board.charAt(4) && board.charAt(4) == board.charAt(7) && board.charAt(1) != s) {
			c = board.charAt(1);
		}
		else if (board.charAt(2) == board.charAt(5) && board.charAt(5) == board.charAt(8) && board.charAt(2) != s) {
			c = board.charAt(2);
		}

		return c;
	}

	private static char checkDiag(String board) {
		char	c = 'd';
		char	s = 's';

		if (board.charAt(0) == board.charAt(4) && board.charAt(4) == board.charAt(8) && board.charAt(4) != s) {
			c = board.charAt(4);
		}
		else if (board.charAt(2) == board.charAt(4) && board.charAt(4) == board.charAt(6) && board.charAt(4) != s) {
			c = board.charAt(4);
		}

		return c;
	}

	private static String parseStdin() {
		String	stdin = null;

		try {
			stdin = br.readLine();
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 16860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;

ll pnum[4];
ll chartonum(char x){
	if(x=='+')return -1;
	if(x=='*')return -2;
	if(x=='^')return -3;
	else return pnum[x-'a'];
}

ll calc3(ll op,ll a,ll b){
	if(op==-1)return (a|b);//+
	if(op==-2)return (a&b);//*
	if(op==-3)return (a^b);//^
}

ll anscalc(string s){
	stack<ll> op;
	FOR(i,0,s.size()){
		if(s[i]=='[' || s[i]==']')continue;
		else op.push(chartonum(s[i]));
		while(op.size()>2){
			ll top1,top2,top3;
			top1 = op.top();op.pop();
			top2 = op.top();op.pop();
			top3 = op.top();op.pop();
			if(top3<0 && top2>=0 && top1>=0){
				op.push(calc3(top3,top1,top2));
			}else{
				op.push(top3);
				op.push(top2);
				op.push(top1);
				break;
			}
		}
	}
	return op.top();
}


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

	while(1){
		ll ans,num=0;
		string s,p;
		cin>>s;
		if(s[0]=='.')break;
		cin>>p;
		FOR(i,0,4)pnum[i] = p[i]-'0';
		ans = anscalc(s);
		FOR(i,0,10){
			FOR(j,0,10){
				FOR(k,0,10){
					FOR(l,0,10){
						pnum[0]=i;
						pnum[1]=j;
						pnum[2]=k;
						pnum[3]=l;
						if(anscalc(s)==ans)num++;
					}
				}
			}
		}
		cout<<ans<<" "<<num<<endl;
	}

}


Measured memory_bytes: 3104
c = [list(input()) for i in range(2)]
tmp = [[], []]
tmp[0] = c[0][:]
tmp[1] = c[1][:]
tmp[0][0], tmp[0][-1] = tmp[0][-1], tmp[0][0]
tmp[1][0], tmp[1][-1] = tmp[1][-1], tmp[1][0]
tmp[0], tmp[1] = tmp[1], tmp[0]
ans = 'YES'
for i in range(2):
    for j in range(3):
        if c[i][j] != tmp[i][j]:
            ans = 'NO'
print(ans)


Measured memory_bytes: 3064
import heapq
import sys
input = sys.stdin.readline

def main():
    num_sushi, chose_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num_sushi)]

    data.sort(key=lambda x: -x[1])
    delicious_heap = []
    count_d, count_n = 0, 0
    neta_data = [0 for i in range(num_sushi + 1)]

    for i in range(chose_num):
        neta, oishisa = data[i]

        if neta_data[neta]:
            heapq.heappush(delicious_heap, oishisa)
        else:
            neta_data[neta] = 1
            count_n += 1

        count_d += oishisa

    ans = count_d + count_n ** 2

    for i in range(chose_num, num_sushi):
        if len(delicious_heap) == 0:
            break
        neta, oishisa = data[i]

        if neta_data[neta]:
            continue
        neta_data[neta] = 1
        count_n += 1
        pop_oishisa = heapq.heappop(delicious_heap)
        count_d += oishisa - pop_oishisa

        ans = max(ans, count_d + count_n ** 2)

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 65884
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

const ll MOD=1e9+7;
void solve(){
  ll n; cin>>n;
  vector<vector<ll>> E(n);
  rep(_,n-1){
    ll x,y; cin>>x>>y;
    x--; y--;
    E[x].push_back(y);
    E[y].push_back(x);
  }
  auto dp=make_v(n,2,(ll)-1);
  function<void(ll,ll)> dfs=[&](ll v,ll p){
    if(dp[v][0]!=-1) return;
    ll white=1, black=1;
    for(ll &nv:E[v]){
      if(nv==p) continue;
      dfs(nv,v);
      white*=dp[nv][0]+dp[nv][1];
      white%=MOD;
      black*=dp[nv][0];
      black%=MOD;
    }
    dp[v][0]=white;
    dp[v][1]=black;
  };
  dfs(0,-1);
  cout<<(dp[0][0]+dp[0][1]+MOD)%MOD<<"\n";
}

Measured memory_bytes: 20992
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
const int nil = -2;
const int loop = -1;

int main() {
  int N;
  while (cin >> N) {
    vector<vector<int>> G(N);
    for (int i = 0; i < N; i++) {
      int p;
      cin >> p;
      --p;
      G[p].push_back(i);
    }
    vector<vector<int>> cand(N);
    vector<int> dp(N, nil);
    function<int(int)> dfs = [&](int v) {
      int &res = dp[v];
      if (res != nil) {
        return res;
      }
      res = loop;
      set<int> S;
      bool hasloop = false;
      for (int u : G[v]) {
        int g = dfs(u);
        if (g == loop) {
          hasloop = true;
        } else {
          S.insert(g);
        }
      }
      int g1 = 0;
      while (S.count(g1)) ++g1;
      int g2 = g1 + 1;
      while (S.count(g2)) ++g2;
      if (!hasloop) {
        return res = g1;
      }
      cand[v].push_back(g1);
      cand[v].push_back(g2);
      return res = loop;
    };
    int r = -1;
    for (int v = 0; v < N; v++) {
      dfs(v);
      if (!cand[v].empty()) {
        r = v;
      }
    }
    bool ans = true;
    if (r != -1) {
      ans = false;
      for (int x : cand[r]) {
        for (int u = 0; u < N; u++) {
          if (!cand[u].empty()) {
            dp[u] = nil;
          }
        }
        dp[r] = x;
        set<int> S;
        for (int u : G[r]) {
          S.insert(dfs(u));
        }
        int y = 0;
        while (S.count(y)) ++y;
        if (y == x) {
          ans = true;
          break;
        }
      }
    }
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
  }
  return 0;
}


Measured memory_bytes: 42112
#include <stdio.h>

int main()
{
    int n;
    int a[4];
    scanf("%d", &n);
    a[0] = n % 10;
    a[1] = ((n % 100) - a[0])/10;
    a[2] = ((n % 1000) - a[0] - a[1]*10)/100;
    a[3] = n/1000;

    if(((a[0]==a[1])&&(a[1]==a[2]))||((a[1]==a[2])&&(a[2]==a[3]))){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        int secand,h,m,s;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        secand = Integer.parseInt(br.readLine());
        h = secand/3600;
        secand = secand % 3600;
        m = secand/60;
        s = secand%60;
        System.out.println(h+":"+m+":"+s);
    }

}

Measured memory_bytes: 24384
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
81 58
)");
#define cin input
#endif

int main()
{
    int n, c;
    int a[400], b[400];

    cin >> n >> c;
    REP (i, n)
        cin >> a[i];
    REP (i, n)
        cin >> b[i];

    static ll p[404][404] = {};

    const ll mod = 1000000007;

    ll f[404];
    REP (i, 401)
        f[i] = 1;
    
    REP (i, 401)
    {
        REP (j, 401)
        {
            p[i][j + 1] = p[i][j] + f[j];
            p[i][j + 1] %= mod;
        }
        REP (j, 401)
            f[j] = f[j] * (j + 1) % mod;
    }
    
    static ll dp[404][404] = {};
    dp[0][0] = 1;

    REP (i, n)
    {
        REP (j, c + 1)
        {
            ll s = 0;
            REP (k, j + 1)
            {
                s += dp[i][k] * ((p[j - k][b[i]] + mod - p[j - k][a[i] - 1]) % mod);
                s %= mod;
            }
            dp[i + 1][j] = s;
        }
    }

    cout << dp[n][c] << endl;
}


Measured memory_bytes: 2816
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#include <cmath>
#include <limits.h>
#include <ios>
#include <iomanip>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b){return b? gcd(b, a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool greaterPair(const ipair& l, const ipair& r){return l.second > r.second;}

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  std::vector<ipair> sortY;
  cin >> N >> M;
  int count[N+1] = {0};
  int P[M], Y[M];
  int ans[M];
  for(int i = 0; i < M; i++){
    cin >> P[i] >> Y[i];
    sortY.push_back(ipair(i, Y[i]));
  }
  partial_sort(sortY.begin(), sortY.begin()+M, sortY.end(), lessPair);
  
  for(int i = 0; i < M; i++){
    int index = sortY[i].first;
    count[P[index]]++;
    ans[index] = count[P[index]];
  }
  for(int i = 0; i < M; i++){
    cout << setfill('0') << right << setw(6) << P[i] << setfill('0') << right << setw(6) << ans[i] << endl;
  }

  return 0;
}

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

struct Node{
	int key;
	Node *parent;
	Node *left;
	Node *right;
	
	Node(): left(NULL), right(NULL){}
	Node(int _k): key(_k), left(NULL), right(NULL){}
};

void Insert(Node *&T, int key)
{
	Node *z = new Node(key);
	
	Node *y = NULL;
	Node *x = T;

	while(x != NULL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	
	z->parent = y;
	 
	if (y == NULL)
	{
		T = z;
	}
	else if (z->key < y->key)
	{
		y->left = z;
	}
	else
	{
		y->right = z;
	}
}

void Find(Node *T, int key)
{
	Node *temp = T;
	while(temp != NULL)
	{
		if (temp->key < key)
		{
			temp = temp->right;
		}
		else if (temp->key > key)
		{
			temp = temp->left;
		}
		else
		{
			cout << "yes" << endl;
			return;
		}
	}
	cout << "no" << endl;
	return;
}

void Preorder(Node *T)
{
	if (T == NULL) return;
	
	cout << " " << T->key;
	Preorder(T->left);
	Preorder(T->right);
}

void Inorder(Node *T)
{
	if (T == NULL) return;
	
	Inorder(T->left);
	cout << " " << T->key;
	Inorder(T->right);
}

int main ()
{
	int n;
	cin >> n;
	string cmd;
	Node *Tree = NULL;
	while(n--)
	{
		cin >> cmd;
		if (cmd == "insert")
		{
			int k;
			cin >> k;
			Insert(Tree, k);
		}
		else if (cmd == "print")
		{
			Inorder(Tree);
			cout << endl;
			Preorder(Tree);
			cout << endl;
		}
		else if (cmd == "find")
		{
			int k;
			cin >> k;
			Find(Tree, k);
		}
	}
	
	return 0;
}


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

int main()
{
	int n, m;
	cin >> n >> m;

	int gyoretu[100][100];
	int vector[100];

	//行列読み込み
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int input;
			cin >> input;
			gyoretu[i][j] = input;
		}
	}

	//ベクトル読み込み
	for (int i = 0; i < m; i++)
	{
		int input;
		cin >> input;
		vector[i] = input;
	}
	
	//演算
	for (int i = 0; i < n; i++)
	{
		int ax = 0;

		for (int j = 0; j < m; j++)
		{
			ax += (gyoretu[i][j] * vector[j]);
		}
		cout << ax << endl;
	}
}


Measured memory_bytes: 3112
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	a := make([]int, N)
	b := make([]int, N)
	c := make([]int, M)
	d := make([]int, M)
	for i := 0; i < N; i++ {
		a[i], b[i] = ReadInt(), ReadInt()
	}
	for i := 0; i < M; i++ {
		c[i], d[i] = ReadInt(), ReadInt()
	}
	for i := 0; i < N; i++ {
		p, v := -1, 1<<62
		for j := 0; j < M; j++ {
			e := Abs(a[i]-c[j]) + Abs(b[i]-d[j])
			if e < v {
				p, v = j, e
			}
		}
		fmt.Println(p + 1)
	}
}

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1848
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main() {
	int a, b;
	cin >> a;
	b = a / 100;
	a = a - 100 * b;
	if (0 < b && b <= 12) {
		if (0 < a && a <= 12)
			cout << "AMBIGUOUS" << endl;
		else 
			cout << "MMYY" << endl;
	}
	else {
		if (0 < a && a <= 12)
			cout << "YYMM" << endl;
		else
			cout << "NA" << endl;
	}
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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;}

signed main(){
    string S;
    cin>>S;

    int cnt[26]={};
    int ans=1;
    rep(i,S.size()){
        rep(j,26){
            if(j!=S[i]-'a')ans+=cnt[j];
        }
        cnt[S[i]-'a']++;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 644
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
        
    ios_base::sync_with_stdio(0);
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    unsigned long long  q,h,s,d,n;
    cin>>q>>h>>s>>d;
    cin>>n;
    unsigned long long n1 = min(s,min(2*h,min(4*q,2*q+h)));
    unsigned long long n2 = min(d, 2*n1);
    if(n==1){
        cout<<n1<<endl;
    }
    else if(n==2){
        cout<<n2<<endl;
    }
    else{
        unsigned long long sum=(n/2)*n2 + (n%2)*n1;
        /*
        unsigned long long fi = n1, se=n2;
        for(unsigned long long i=3;i<=n;i++){
            if(i%2==0){
                sum = min(n2+fi, (i/2)*se);
            } 
            else{
                sum = n2 + fi;
                n2=sum;
            }
            //sum = n1 + n2;
           // cout<<i<<": Starting with "<<n1<<" "<<n2<<" => "<<sum<<endl; 
            //n1 = n2;
            //n2 = sum;
        }
        */
        cout<<sum<<endl;
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main () {
	int c[3][3];
	for (int yi = 0; yi < 3; ++yi)
	{
		for (int xi = 0; xi < 3; ++xi)
		{
			cin >> c[yi][xi];
		}
	}
	bool judge = true;
	for (int i = 0; i < 2; ++i)
	{
		if(c[0][i] - c[0][i+1] == c[1][i] - c[1][i+1] && c[1][i] - c[1][i+1] == c[2][i] - c[2][i+1]){

		}else{
			judge = false;
		}
	}
	if(judge){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;


int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	int temp = n;
	int sum = 0;
	while(temp > 0)
	{
		sum += (temp%10);
		temp = temp / 10;
	}

	if(n%sum == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

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

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	int imax, sum;
	sum = a + b + c;
	imax = max(a,max( b, c));

	cout << sum - imax << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  int ans = t.size();
  for(int start=0;start<=s.size()-t.size();start++){
    int diff=0;
    for(int i=0;i<t.size();i++){
    if(s[start+i]!=t[i]){
      diff++;
    }
    }
    ans = min(ans,diff);
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n,a[301000],S1,S2;
bool check(int lim){
	int now=0,lst=0;
	for(int i=1;i<=n;i++){
		if(i&1){
			if(now>=lim&&now+lst<=0) now=lst=0;
			now+=lst+a[i];
		}
		else lst=-a[i];
	}
	return now>=lim;
}
int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		if(i&1) S1+=a[i];
		else S2+=a[i];
	}
	if(~n&1){cout<<max(S1,S2)<<' '<<min(S1,S2)<<'\n';return 0;}
	int l=0,r=S1+1;
	while(l+1<r){
		int mid=l+r>>1;
		if(check(mid)) l=mid;
		else r=mid;
	}
	cout<<S2+l<<' '<<S1-l<<'\n';
	return 0;
}


Measured memory_bytes: 1408
/*
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<complex>
*/

#include<bits/stdc++.h>

#define X real()
#define Y imag()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
using ll = long long;
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vi::iterator vii;
typedef vector<ll> vl;
typedef vl::iterator vli;
typedef long double C;
typedef complex<C> P;
const int INF = 1e9 + 5;
const ll INFF = 1e18 + 5;
const int M = 1e9 + 7;
const double pi = acos(-1);

int main()
{
	//FastF;
	Fast;
	int n, a;
	cin >> n;
	double ans = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		ans += 1.00 / a;
	}
	ans = 1 / ans;
	printf("%.6lf", ans);
	return 0;
}

Measured memory_bytes: 256