akhauriyash/Code-Regression huggingface dataset:
def cross(a, b):
    return (a.real*b.imag - a.imag*b.real)

EPS = 10**(-7)

while 1:
    n = int(raw_input())
    if n == 0: break
    l0 = []
    d0 = []
    for i in xrange(n+1):
        l = []
        d = []
        p = []
        m = int(raw_input())
        for j in xrange(m):
            x,y = map(int, raw_input().split())
            p.append(x+y*1j)
        for j in xrange(1, m):
            if i == 0:
                l0.append(abs(p[j]-p[j-1]))
                if j > 1:
                    tmp = cross(p[j-1]-p[j-2], p[j]-p[j-1])
                    if tmp > EPS: d0.append(1)
                    else: d0.append(-1)
            else:
                l.append(abs(p[j]-p[j-1]))
                if j > 1:
                    tmp = cross(p[j-1]-p[j-2], p[j]-p[j-1])
                    if tmp > EPS: d.append(1)
                    else: d.append(-1)
        if i > 0:
            flag = False
            #print l0
            #print l
            if len(l0) == len(l):
                #print d0
                #print d
                if len(l0) != len(l):
                    break
                else:
                    for j in xrange(len(l)):
                        if l0[j] != l[j]:
                            break
                    else:
                        for k in xrange(len(d)):
                            if d0[k] != d[k]:
                                break
                        else:
                            flag = True
                    if flag is False:
                        for j in xrange(len(l)):
                            if l0[j] != l[len(l)-(j+1)]:
                                break
                        else:
                            for k in xrange(len(d)):
                                if (-1)*d0[k] != d[len(d)-(k+1)]:
                                    break
                            else:
                                flag = True
            if flag is True: print i
    print '+++++'

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

void fnInput(vector<vector<int>> &rvvnAdjcy)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  rvvnAdjcy.resize(nMaxSiz + 1, vector<int>(nMaxSiz + 1, 0));
  for (int i = 0; i < nMaxSiz; i++)
  {
    int nx, nSecSiz;
    cin >> nx >> nSecSiz;
    for (int j = 0; j < nSecSiz; j++)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
}

void fnResult(const vector<vector<int>> &cnrvvnAdjcy)
{
  for (int i = 1; i < cnrvvnAdjcy.size(); i++)
  {
    for (int j = 1; j < cnrvvnAdjcy[i].size(); j++)
    {
      if (j != 1) cout << " ";
      cout << cnrvvnAdjcy[i][j];
    }
    cout << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;

  fnInput(vvnAdjcy);
  fnResult(vvnAdjcy);

  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

int main(){
	int a, b;
	int ans=-1;
	cin >> a >> b;
	for (int i = 0; i < 10000000; i++) {
		if ((i *8)/100 == a && i /10 == b) {
			ans = i; break;
		}
	}

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define For(x,a,b,c) for(x=a;x<b;x+=c)
#define mod 1000000007


int main(){
ll n,m;
cin>>n>>m;
char ar[n][m];
for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
		cin>>ar[i][j];
vector<vector<ll>>dp(n);
vector<ll>col(m,0);
for(int i=0;i<n;i++)dp[i]=col;	
for(int i=0;i<n;i++){
	if(ar[i][0]=='#')break;
	else dp[i][0]=1;
}
for(int i=0;i<m;i++){
	if(ar[0][i]=='#')break;
	else dp[0][i]=1;
}	

for(int i=1;i<n;i++){
	for(int j=1;j<m;j++){
		if(ar[i][j]!='#')
		dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
	    else dp[i][j]=0;
	}
}
cout<<dp[n-1][m-1];



  return 0;
}

Measured memory_bytes: 9088
#include<cstdio>
using namespace std;
int nn,xx,dd;
long double n,x,d,ans;
double p;
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%d%d%d",&nn,&xx,&dd);
	n=nn; x=xx; d=dd;
	do{
		ans+=0.5*((x*2)+(d*((2*n)-1)));
		x=0.5*((long double)((5*d)+(x*(2*(n+1))))/n);
		d=(long double)((d*(2+n))/n);
		n--;
	}while(n);
	double p=ans;
	printf("%.11lf\n",p);
	return 0;
}

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

int main()
{
	int N, t[110000], x[110000], y[110000];
	bool can = true;

	cin >> N;

	t[0] = x[0] = y[0] = 0;
	for (int i = 0; i < N; i++) { 
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1]; 
	}
		
	for (int i = 0; i < N; i++) {

		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);

		if (dt < dist) can = false;
		if (dt % 2 != dist % 2) can = false;		
	}
	
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;
int A[N];
int L[N], R[N];
int n;

void init(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
        scanf("%d", &A[i]);
    L[0] = A[0]; R[n-1] = A[n-1];
    for(int i = 1; i < n; i++){
        L[i] = __gcd(L[i-1], A[i]);
    }
    for(int i = n-2; i >= 0; i--)
        R[i] = __gcd(R[i+1], A[i]);

}

void solve(){
    init();
    if(n == 2){
        printf("%d\n", max(A[0], A[1]));
        return;
    }
    int ans = __gcd(L[0], R[2]);
    for(int i = 0; i < n-3; i++){
        ans = max(ans, __gcd(L[i], R[i+2]));
    }
    ans = max({ans, L[n-2], R[1]});
    printf("%d\n", ans);
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}


Measured memory_bytes: 1408
#include <iostream>
#include<string>
#include<iomanip>

using namespace std;

int main(void){
  int a, b, c;
	int x;
	int i, j, k;
	int t=0;

	cin >> a >> b >> c;
	cin >> x;

	for (i = 0; i <= a; i++) {
		for (j = 0; j <= b; j++) {
			for (k = 0; k <= c; k++) {
				if (x == 500 * i + 100 * j + 50 * k)
					t++;
			}
		}
	}
	cout << t;

	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, M  = i_l()
A = i_l()


if N >= sum(A):
    print(N-sum(A))
else:
    print(-1)

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

//Base class for Segment Trees
template <class T>
class segtree_base
{
protected:
	size_t width;
	vector<T> vec;
	T def;
	virtual T query_raw(int l_, int r_, int a_, int b_, int k_) = 0;
public:
	segtree_base(size_t size_, const T& def_ = T()) : def(def_)
	{
		width = 1;
		while (width < size_)width *= 2;
		vec.resize(width * 2 - 1, def);
	}
	T query(int left, int right)
	{
		return query_raw(left, right, 0, width, 0);
	}
	virtual ~segtree_base() {}
};


#include <algorithm>
//Range Sum + Range Add Tree
template <class T>
class rsaq_tree : public segtree_base<T>
{
protected:
	vector<T>lazy;
public:
	rsaq_tree(size_t size_, const T& def = 0) :segtree_base<T>(size_, def)
	{
		lazy.resize(this->vec.size());
	}
	void init(const vector<int>&base)
	{
		for (int i = 0; i < this->width; i++) this->vec[i + this->width - 1] = base[i];
		for (int i = this->width - 2; i >= 0; i--) this->vec[i] = this->vec[i * 2 + 1] + this->vec[i * 2 + 2];
	}
	void update(int left, int right, int val)
	{
		update_raw(left, right, val, 0, this->width, 0);
	}
private:
	void eval(int k_, int a_, int b_)
	{
		if (lazy[k_] != 0) {
			this->vec[k_] += lazy[k_];
			if (b_ - a_ > 1) {
				lazy[2 * k_ + 1] += lazy[k_] / 2;
				lazy[2 * k_ + 2] += lazy[k_] / 2;
			}
			lazy[k_] = 0;
		}
	}
	void update_raw(int l_, int r_, int x_, int a_, int b_, int k_)
	{
		eval(k_, a_, b_);
		if (r_ <= a_ || b_ <= l_) return;
		if (l_ <= a_ && b_ <= r_) {
			lazy[k_] += (b_ - a_) * x_;
			eval(k_, a_, b_);
		}
		else {
			update_raw(l_, r_, x_, a_, (a_ + b_) / 2, 2 * k_ + 1);
			update_raw(l_, r_, x_, (a_ + b_) / 2, b_, 2 * k_ + 2);
			this->vec[k_] = this->vec[2 * k_ + 1] + this->vec[2 * k_ + 2];
		}
	}
	T query_raw(int l_, int r_, int a_, int b_, int k_)override
	{
		eval(k_, a_, b_);
		if (r_ <= a_ || b_ <= l_) return this->def;
		if (l_ <= a_ && b_ <= r_) return this->vec[k_];
		T vl = query_raw(l_, r_, a_, (a_ + b_) / 2, 2 * k_ + 1);
		T vr = query_raw(l_, r_, (a_ + b_) / 2, b_, 2 * k_ + 2);
		return vl + vr;
	}
};

#include <iostream>

int main()
{
	int n, q;
	cin >> n >> q;
	rsaq_tree<long long>tree(n);
	for (int i = 0; i < q; ++i)
	{
		int com;
		cin >> com;
		if (com)
		{
			int s, t;
			cin >> s >> t;
			cout << tree.query(s - 1, t) << endl;
		}
		else
		{
			int s, t, x;
			cin >> s >> t >> x;
			tree.update(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 6944
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for(int i=0; i<s.size(); i++) {
    int n = i+1;
    if(n%2 != 0) {
      if(s.at(i) == 'L') {
        cout << "No" << endl;
        return 0;
      }
    } else {
      if(s.at(i) == 'R') {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3612
open Scanf
open Printf
open Array

let max_i64,(++),i64 = Int64.(max_int,add,of_int)

let () = scanf " %d" @@ fun l ->
  let a = init l (fun _ -> scanf " %d" @@ fun v -> v) in
  let dp = make_matrix (l+1) 5 max_i64 in
  let f typ v = i64 @@
    match typ with
    | 0 | 4 -> (* zero *)
      v
    | 1 | 3 -> (* even >= 2 *)
      if v=0 then 2
      else if v mod 2 = 0 then 0 else 1
    | 2 | _ -> (* odd *)
      if v mod 2 = 1 then 0 else 1
  in
  let update i j v =
    dp.(i).(j) <- min dp.(i).(j) v
  in
  for k=0 to 4 do
    dp.(0).(k) <- 0L;
  done;
  for i=1 to l do
    for k=0 to 4 do
      for j=k to 4 do
        if k=0 && j=4 || k=1 && j=3 then ()
        else update i j @@ dp.(i-1).(k) ++ f j a.(i-1)
      done
    done
  done;
  (* iter (fun b ->
    iter (printf "%2Ld ") b;
    print_newline ()
  ) dp; *)
  printf "%Ld" @@ fold_left min max_i64 dp.(l)

Measured memory_bytes: 41024
import java.util.ArrayList;
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		ArrayList<Integer> hoge=new ArrayList<>();
		ArrayList<Integer> ans=new ArrayList<>();

		int i;
		int std;
		int l;

		while(true) {
		int n=sc.nextInt();
		int r=sc.nextInt();

		if(n==0&&r==0)
			break;

		for(i=1;i<n+1;i++) {
			hoge.add(i);
		}

		for(i=0;i<r;i++) {
			int p=sc.nextInt();
			int c=sc.nextInt();

			for(l=0;l<c;l++) {
				std=hoge.remove(n-(p-1+c));
				hoge.add(std);
			}
		}
		ans.add(hoge.get(n-1));
		hoge.clear();
		}
	for(i=0;i<ans.size();i++)
		System.out.println(ans.get(i));
	sc.close();
	}

}


Measured memory_bytes: 36372
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
k=gi
putsend k if k<=9

runrun=(1..9).to_a
prev=(1..9).to_a
while runrun.size<k  
  cur=[]
  prev.each do |i|
    str=i.to_s
    if str[-1]=="0"
      cur<<i*10
      cur<<i*10+1
    elsif str[-1]=="9"
      cur<<i*10+8
      cur<<i*10+9
    else
      last = str[-1]
      cur<< i*10 + last.to_i - 1
      cur<< i*10 + last.to_i
      cur<< i*10 + last.to_i + 1
    end
  end
  prev = cur
  runrun = runrun+prev
end

puts runrun[k-1]

Measured memory_bytes: 5880
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <bitset>
#include <time.h>
#include <set>
#include <algorithm>
#define ll long long
#define Inf 123372036854775806ll
using namespace std;

bool B[111111];
bool ans[111111];

bool Poss(int pos, int N) {
    
    
    
    
    if (pos == N) {
        
        bool ok = true;
        if (ans[0]) {

            if (B[0]) {
                ok &= (ans[1]==ans[N-1]);
            } else {
                ok &= (ans[1]!=ans[N-1]);
            }
        } else {
            if (B[0]) {
                ok &= (ans[1]!=ans[N-1]);
            } else {
                ok &= (ans[1]==ans[N-1]);
            }
        }
        
        if (ans[N-1]) {
            
            if (B[N-1]) {
                ok &= (ans[0]==ans[N-2]);
            } else {
                ok &= (ans[0]!=ans[N-2]);
            }
        } else {
            if (B[N-1]) {
                ok &= (ans[0]!=ans[N-2]);
            } else {
                ok &= (ans[0]==ans[N-2]);
            }
        }
        
        return ok;
        
    }
    
    
    
    if (ans[pos-1]) {
        
        if (B[pos-1]) {
            ans[pos]=ans[pos-2];
        } else {
            ans[pos]=!ans[pos-2];
        }
        
    } else {
        if (B[pos-1]) {
            ans[pos]=!ans[pos-2];
        } else {
            ans[pos]=ans[pos-2];
        }
    }
    
    

    return Poss(pos+1,N);
    
    
}

int main() {
    int N;
    cin>>N;
    string S;
    cin>>S;
    
    
    for(int i=0;i<N;i++)
        B[i]=(S[i]=='o');
    
    string ans_str="";
    for(int b1=0;b1<=1 && ans_str.empty();b1++) {
        for(int b2=0;b2<=1 && ans_str.empty();b2++) {
            ans[0]=b1;
            ans[1]=b2;
            if (Poss(2,N)) {
                for(int i=0;i<N;i++)
                    ans_str.push_back(ans[i]?'S':'W');
            }
        }
    }
    
    if (ans_str.empty())
        cout << -1 << endl;
    else
        cout << ans_str << endl;
    //cout << Poss(0, N) << endl;
    
    
    
    
    
}

Measured memory_bytes: 896
#include <iostream>
#include <math.h>
using namespace std;


int main(void){

int x,y,d,r;
double f;
cin >> x >> y;

  d = x / y;
  r = x % y;
  f = (double) x /  (double) y;

 cout <<d<<" "<<r<<" "<< fixed<< f<< endl;

 
}


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

int main(){
  int64_t  n,k;
  cin >> n >> k;
  if(n%k<n){
  n = n%k;
  }
  if(n>k/2){
    n = k - n;
  }
  //  n = k%n;
  //}




  cout << n << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p;
  cin >> t;
  
  int ans = 0;
  for (int i = 0; i < k; ++i) {
  	int fr = 0, fs = 0, fp = 0;
    int curr = i;
    while (curr < n) {
      int nr, ns, np;
      switch(t[curr]) {
        case 'r':
          nr = max(fs, fp);
          ns = max(fr, fp);
          np = max(fr, fs) + p;
          break;
        case 's':
          nr = max(fs, fp) + r;
          ns = max(fr, fp);
          np = max(fr, fs);
          break;
        case 'p':
          nr = max(fs, fp);
          ns = max(fr, fp) + s;
          np = max(fr, fs);
          break;
      }
      fr = nr;
      fs = ns;
      fp = np;
      curr += k;
    }
    ans += max(fr, max(fs, fp));
  }
  
  cout << ans;
}

Measured memory_bytes: 512
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

struct node{int to,nxt;}sq[N<<1];
int all=0,head[N],d[N];
void addedge(int u,int v)
{
    all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;d[u]++;
}

int n,f[N],op[N],mx=0;
bool del[N];
queue<int> q;
char s[N];

void dfs(int u,int fu)
{
    f[u]=op[u];
    go(u,i)
    {
        if ((del[v]) || (v==fu)) continue;
        dfs(v,u);
        mx=max(mx,f[u]+f[v]);
        f[u]=max(f[u],f[v]+op[u]);
    }
}

int main()
{
    n=read();
    rep(i,1,n-1)
    {
        int u=read(),v=read();
        addedge(u,v);addedge(v,u);
    }
    scanf("%s",s+1);
    rep(i,1,n)
        if ((s[i]=='B') && (d[i]==1)) {del[i]=1;q.push(i);}
    while (!q.empty())
    {
        int u=q.front();q.pop();
        go(u,i)
        {
            if (del[v]) continue;
            d[v]--;
            if ((s[v]=='B') && (d[v]==1)) {del[v]=1;q.push(v);}
        }
    }
    //rep(i,1,n) cout << del[i] << " ";cout << endl;
    int ans=0;
    rep(u,1,n)
    {
        if (del[u]) continue;
        go(u,i)
        {
            if (del[v]) continue;
            ans++;
        }
        if (((d[u]&1) && (s[u]=='B')) || ((d[u]%2==0) && (s[u]=='W'))) {ans++;op[u]=1;}
    }
    rep(i,1,n)
        if (!del[i])
        {
            dfs(i,0);break;
        }
    ans-=mx*2;
    printf("%d",ans);
    return 0;
}

    


Measured memory_bytes: 7680
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll n;
vector<ll> a;
set<ll> s;

bool check(ll k) {
    if (k == 1) return false;
    ll N = n;
    while (1) {
        if (N % k) {
            return N % k == 1;
        }
        else {
            N /= k;
        }
    }
    return false;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,int(sqrt(n)))
        if (n % i == 0) {
            a.push_back(n / i);
            if (n / i != i) a.push_back(i);
        }
    FOR(i,1,int(sqrt(n-1)))
        if ((n-1) % i == 0) {
            s.insert((n-1) / i);
            s.insert(i);
        }
    s.erase(1);
    FOR(i,0,SZ(a)-1)
        if (check(a[i])) s.insert(a[i]);
    cout << SZ(s);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 1000000007;
#define ff(i,n) for(i=0;i<n;i++) 
int main()
{
    ll t;
    t = 1;
    while(t--)
    {
    	ll i,n,b,x=0,t;
		string a;
		cin>>a;
		ff(i,a.length())
			x += (a[i]-'0');
		if(x%9!=0)
			cout<<"No";
		else
			cout<<"Yes";			    
    }
    return 0;
} 

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
struct LCA {
  int N, logN; // logN-1 == floor(lg(N-1))
  vector<vector<int>> G;
  vector<int> depth;
  // vから根の方向に2^k回登ったときのノード parent[k][v]
  vector<vector<int>> parent;
 
  LCA(int size) : N(size), G(size), depth(size) {
    logN = 0;
    for(int x = 1; x < N; x *= 2) logN++;
    parent.assign(max(logN, 1), vector<int>(N));
  }
 
  // どちらが根であってもOK
  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }
 
  void dfs(int v, int par, int dep) {
    depth[v] = dep;
    parent[0][v] = par;
    for(int next : G[v]) {
      if(next != par) dfs(next, v, dep + 1);
    }
  }
 
  void init(int root) {
    dfs(root, -1, 0);
    for(int k = 1; k < logN; k++) {
      for(int v = 0; v < N; v++) {
        if(parent[k - 1][v] == -1) parent[k][v] = -1;
        else parent[k][v] = parent[k - 1][parent[k - 1][v]];
      }
    }
  }
 
  int lca(int u, int v) {
    if(depth[u] > depth[v]) swap(u, v); // vのほうが深くなる
    // uとvの深さが同じになるまでvを根の方向に移動する
    for(int k = 0; k < logN; k++) {
      if(((depth[v] - depth[u]) >> k) & 1) {
        v = parent[k][v];
      }
    }
    if(u == v) return u;
    for(int k = logN - 1; k >= 0; k--) {
      if(parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
 
int main() {
  cin.tie(nullptr);
  int N; cin >> N;
  LCA lca(N);
  for(int u = 0; u < N; u++) {
    int k; cin >> k;
    while(k--) {
      int v; cin >> v;
      lca.add_edge(u, v);
    }
  }
  lca.init(0);
  int Q; cin >> Q;
  while(Q--) {
    int u, v; cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}

Measured memory_bytes: 16080
a=[int(input())for i in[0]*int(input())]
b=max(a)
if a.count(b)>1:print('\n'.join([str(b)]*len(a)))
else:
  c=[b for i in a]
  c[a.index(b)]=max(a[:a.index(b)]+a[a.index(b)+1:])
  print('\n'.join([str(i)for i in c]))

Measured memory_bytes: 26460
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>


using namespace std;

int main(){
	int n,y;
	cin >> n >> y;
	int yukichi,higuchi,noguchi;
	yukichi=higuchi=noguchi=-1;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=n-i;++j){
			int k=n-i-j;
			int total = 10000*i+5000*j+1000*k;
			if(total==y){
				yukichi=i;
				higuchi=j;
				noguchi=k;
			}
		}
	}
	cout<<yukichi<<" "<<higuchi<<" "<<noguchi<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  string S; cin >> S;
  int N = S.size();
  
  rep(i, 7) {
    string T = S.substr(i, N-7);
    string R = S.substr(0, i) + S.substr(i+N-7);
    if(R == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  
  cout << "NO" << endl;
  
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int h[]=new int[n];
        for(int i=0;i<n;++i) {
            h[i]=sc.nextInt();
        }
        int min=0, min2=Math.abs(h[1]-h[0]);
        int min3=min2;
        for(int i=2;i<n;++i) {
            min3=Math.min(min+Math.abs(h[i]-h[i-2]),min2+Math.abs(h[i]-h[i-1]));
            min=min2;
            min2=min3;

        }
        System.out.println(min3);
    }
}

Measured memory_bytes: 59344
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

template <typename T>
void print_pairvec(const vector<T> &v, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  string S, T;
  cin >> S >> T;

  const ll INF = 1e9;
  ll ans  = INF;

  for(int i=0; i<(int)S.size(); i++){
    ll num = 0;
    if(i+(int)T.size() >S.size()) continue;
    for(int j=0; j<(int)T.size(); j++){
      
      if(S.at(i+j) != T[j]) num++;
    }
    ans = min(ans, num);
    
  }

  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 4010
#define ll long long
#define mod 924844033
using namespace std;
ll fac[N];
ll f[N][N],g[N][N];
int link[N];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	fac[0]=1;
	for(int i=1;i<=n<<1;i++) fac[i]=fac[i-1]*i%mod;
	int tot=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=i;j<=n;j+=m)
		{
			tot++;
			if(j!=i) link[tot]=1;
		}
		for(int j=i;j<=n;j+=m)
		{
			tot++;
			if(j!=i) link[tot]=1;
		}
	}
	f[0][0]=1;
	for(int i=0;i<n*2;i++)
		for(int j=0;j<=n;j++)
		{
			f[i+1][j]=(f[i][j]+g[i][j])%mod;
			if(link[i+1]) g[i+1][j+1]=f[i][j];
		}
	ll ans=0;
	for(int i=0;i<=n;i++)
	ans=(ans+(f[2*n][i]+g[2*n][i])*fac[n-i]*(i&1?-1:1)+mod)%mod;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 249984
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    long long int n,k,q;
    
    cin>>n>>k>>q;
    
   vector<int> cnt(n,0);
     int nq=q;
     while(nq--)
     {
         int x;
         cin>>x;
         x--;
         
         cnt[x]++;
     }
        
     for(int i=0;i<n;i++)
     {
        if((k-(q-cnt[i]))>0)
         cout<<"Yes"<<endl;
         else
         cout<<"No"<<endl;
     }
    
}


Measured memory_bytes: 1024
/******************
*  Author: BD747  *
******************/
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
using namespace std;

int n,sum;
int a[15];

int main(){

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-1;i++){
		sum+=a[i];
	}
	sum+=a[n-1]/2;
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    if n>999
        println("ABD")
    else
        println("ABC")
    end
end
main()

Measured memory_bytes: 163096
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define UNI(a)      a.resize(unique(all(a), a.begin()) - a.begin())
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1) {
            rem = (rem * a) % m;
        }
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 100 + 5;
const int LEN = 100000 + 5;
const ll MOD = 1000000007;

int n, W;
int w[MAX], v[MAX];

ll dp[MAX][LEN];

int main() {
    n = in(), W = in();
    for(int i = 1; i <= n; i++) {
        w[i] = in(), v[i] = in();
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= W; j++) {
            dp[i][j] = dp[i - 1][j];
            if(j >= w[i]) {
                dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
            }
        }
    }
    out(dp[n][W]), nl;
    return 0;
}

Measured memory_bytes: 79360
#include <stdio.h>

int main(void) {
	int x;
	int y;
	int i;
	while(1){
		scanf("%d%d",&x,&y);
		if (x == 0 && y == 0) break;
		if (x > y) {
			i = x;
			x = y;
			y = i;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int X;
    int Y;
    int flag = 0;
    cin >> X;
    cin >> Y;
    rep(i,X+1){
        int legs = i*2 + ((X-i)*4) ;
        if(legs == Y){
            cout << "Yes";
            flag = 1;
        }
    }
    if(flag == 0) cout << "No";
	return 0;
}



Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define LL(x) ll x; scanf("%lld",&x)
#define INPUT(x) cin >> x
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF_INT 2147483647
#define INF_LL 9223372036854775807

typedef long long ll;

vector<pair<int , pair<int, int> > > V;

vector<int> nige;

int abss(int a){
    return (a < 0)? -a: a;
}

void run(int N){
    int sum = 0;
    nige.push_back(sum);
    int x = 1;
    REP1(j,N){
        nige.push_back(sum);
        sum += abss(V[x].second.first - V[x+1].second.first) + abss(V[x].second.second - V[x+1].second.second);
        x++;
    }
}

int main(){
    INT(H);INT(W);INT(D);
    int N = H*W;
    V.push_back(make_pair(0, make_pair(-1, -1)));
    REP1(i,H){
        REP1(j,W){
            INT(a);
            V.push_back(make_pair(a, make_pair(i, j)));
        }
    }
    sort(V.begin(), V.end());
    
    run(N);
    
    INT(Q);
    if(D == 1){
        REP1(i,Q){
            INT(L);INT(R);
            printf("%d\n",nige[R]-nige[L]);
        }
    }else{
        REP1(i,Q){
            INT(L);INT(R);
            int x = L;
            int n = (R-L)/D;
            int sum = 0;
            int next = 0;
            REP1(j,n){
                next = x + D;
                sum += abss(V[x].second.first - V[next].second.first) + abss(V[x].second.second - V[next].second.second);
                x = next;
            }
            
            printf("%d\n",sum);
        }
    }
    return 0;
}

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

#define lli long long int
#define Sort(n) sort(n.begin(), n.end())
#define Reve(n) reverse(n.begin(), n.end())
#define YES puts("YES")
#define NO puts("NO")

//素数
bool IsPrime(lli num)
{
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)return false;
  }
  return true;
}
//各桁の和
lli Sum(lli n)
{
  lli sum=0;
  if (n<0) return 0;
  while (n>0)
  {
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  lli n, sum = 1;
  cin >> n;
  vector<lli> a(n);
  for(int i = 0;i < n;i++) {
    cin >> a.at(i);
  }
  Sort(a);
  Reve(a);
  for(int i = 1;i < n;i++) {
    if(a.at(i-1) != a.at(i))
    sum++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static final int maxN = 100000;

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int w = in.nextInt();

        int[] ws = new int[n];
        int[] vs = new int[n];

        for (int i = 0; i < n; i++) {
            ws[i] = in.nextInt();
            vs[i] = in.nextInt();
        }

        int[][] dp = new int[n + 1][maxN + 1];

        for (int i = 0; i <= n; i++) {
            for (int j = 1; j <= maxN; j++) {
                dp[i][j] = Integer.MAX_VALUE;
            }
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= maxN; j++) { //v
                if (j >= vs[i - 1]
                        && dp[i - 1][j - vs[i - 1]] != Integer.MAX_VALUE
                        && dp[i - 1][j - vs[i - 1]] + ws[i - 1] <= w) {
                    dp[i][j] = Math.min(dp[i - 1][j], dp[i - 1][j - vs[i - 1]] + ws[i - 1]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }

        for (int i = maxN; i >= 0; --i) {
            if (dp[n][i] != Integer.MAX_VALUE) {
                System.out.println(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 84180
#include <bits/stdc++.h>
#include <string> 
#include <iomanip>
#include <cmath> 
#include <bitset>
#include <string.h> 
#include <algorithm>  
using namespace std;
#define mod 1000000007
#define int long long int
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define PI 3.14159265358979323846
int32_t main()
{
    fast;
    int n,d;
    cin>>n>>d;
    int x[n];
    int y[n];
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        cin>>y[i];
    }
    int c=0;
    for(int i=0;i<n;i++)
    {
       if(d>=sqrt(x[i]*x[i]+y[i]*y[i]))
        {
            c++;
        }
    }
    cout<<c<<"\n";
   
    
}

Measured memory_bytes: 6816
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);ios::sync_with_stdio(0);
  string s;cin >> s;
  int n = s.size(),i = 0;
  reverse(s.begin(),s.end());
  while(i<n){
    if(s.substr(i,5)=="maerd") i+=5;
    else if(s.substr(i,7)=="remaerd") i+=7;
    else if(s.substr(i,5)=="esare") i+=5;
    else if(s.substr(i,6)=="resare") i+=6;
    else{
      printf("NO\n");return 0;
    }
  }
  printf("YES\n");return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
//author wjl

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int mp[305][305],k;
    int stx=1,sty=1,edx=1,edy=1;
    int ans[305][305];
int now=1;
void p()
{
    for(int i=stx;i<=edx;i++)
    {
        for(int j=sty;j<=edy;j++)
        {
            ans[i][j]=now;
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h,w;
    cin>>h>>w>>k;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            char x;
            cin>>x;
            if(x=='#')
                mp[i][j]=1;
            else mp[i][j]=0;
        }
    }
    int f;
    for(int i=1;i<=h;i++)
    {
        f=0;
        for(int j=1;j<=w;j++)
        {
            if(mp[i][j]==1)
            {
                edx=i;edy=j;
                p();
                now++;
                sty=edy+1;
                f=1;
            }
            if(j==w&&f==1)
            {
                edx=i;edy=j;
                if(now>1)now--;
                p();
                now++;
                stx=edx+1;
                sty=1;
            }
        }
    }
    if(f==0)
    {
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<=w;j++)
            {
                if(ans[i][j]==0)
                {
                    ans[i][j]=ans[i-1][j];
                }
            }
        }
    }
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cout<<ans[i][j]<<" ";
        }
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

vector<vl> s(2);

ll f(ll x, ll sm, ll t) {
  ll res;
  if(sm == 0) {
    auto it = lower_bound(all(s[t]), x);
    res = it == s[t].end() ? *(it - 1) : *it;
  } else {
    auto it = upper_bound(all(s[t]), x);
    res = it == s[t].begin() ? *it : *(it - 1);
  }
  return res;
}

int main() {
  ll a, b, q;
  cin >> a >> b >> q;
  s[0].resize(a), s[1].resize(b);
  rep(i, a) cin >> s[0][i];
  rep(i, b) cin >> s[1][i];
  sort(all(s[0]));
  sort(all(s[1]));
  rep(_, q) {
    ll x;
    cin >> x;
    ll ans = 1e18;
    rep(k, 2) {
      rep(i, 2) rep(j, 2) {
        ll s1 = f(x, i, 0);
        ll t1 = f(s1, j, 1);
        ll now = abs(x - s1) + abs(s1 - t1);
        ans = min(ans, now);
      }
      swap(s[0], s[1]);
    }
    cout << ans << '\n';
  }
}

Measured memory_bytes: 4788
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

const int INF = pow(10,9);

/*
n m
a1 b1 gakusei
...
an bn
c1 d1 cp
...
cm dm

n m 50
 */
int n,m,a[50],b[50],c[50],d[50];

int main(){
  cin>>n>>m;
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  REP(j,m){
    cin>>c[j]>>d[j];
  }

  REP(i,n){
    int min_j=-1;
    int lmin = INF;
    REP(j,m){
      int l = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(l < lmin){
        lmin = l;
        min_j = j;
      }
    }
    cout << min_j + 1 << endl;
  }

  return 0;
}


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

using ll = long long;

// Union-Find木
struct UnionFind {
  vector<int> par;
  
  // Constructor
  UnionFind(int n): par(n) {
    for(int i = 0; i < n; i++) par[i] = i;
  }
  
  // n要素で初期化
  void init(int n) {
    par.resize(n);
    for(int i = 0; i < n; i++) par[i] = i;
  }
  
  // 根の検索
  int find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  
  // xとyの属する集合を併合
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return false;
    par[x] = y;
    return true;
  }
  
  // xとyが同じ集合に属するか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  
  vector<pair<int, int>> a(m);
  for(int i = 0; i < m; i++) cin >> a.at(i).first >> a.at(i).second;
  
  UnionFind uf(n + 1);
  
  vector<ll> ans, num(n + 1, 1);
  ans.emplace_back(n * (n - 1) / 2);
  for(int i = m - 1; i >= 0; i--){
    if(uf.same(a.at(i).first, a.at(i).second)){
      ans.emplace_back(ans.back());
      continue;
    }
    else{
      ans.emplace_back(ans.back() - num.at(uf.find(a.at(i).first)) * num.at(uf.find(a.at(i).second)));
      ll keep = num.at(uf.find(a.at(i).first)) + num.at(uf.find(a.at(i).second));
      uf.unite(a.at(i).first, a.at(i).second);
      num.at(uf.find(a.at(i).first)) = keep;
    }
  }
  
  for(int i = m - 1; i >= 0; i--) cout << ans.at(i) << '\n';
}

Measured memory_bytes: 4212
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    bool three=true;
    for (int i = 0; i < N; i++)
    {
        char c;
        cin >> c;
        if(c == 'Y') three = false;
    }

    if(three) cout << "Three" << endl;
    else cout << "Four" << endl;
}

Measured memory_bytes: 256
N=int(raw_input())
A=[int(x) for x in raw_input().split()]
 
used=dict()
for a in A:
    if a in used:
        used[a] += 1
    else:
        used[a]=1

B=[]
for a in used:
    if used[a]>=4:
        B.append(a)
        B.append(a)
    elif used[a]>=2:
        B.append(a)

if len(B)<2:
    print 0
else:
    B.sort(reverse=True)
    print B[0]*B[1]

Measured memory_bytes: 16424
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if(string.Compare(S,"2019/04/30") == -1 || S.Equals("2019/04/30"))
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
        }
    }
}


Measured memory_bytes: 13404
package main

import (
    "fmt"
)

func main() {
    var (
        n     int
        count int
    )
    fmt.Scan(&n)
    nums := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&nums[i])
    }

    flag := true
    for flag {
        for i := 0; i < n; i++ {
            if nums[i]%2 == 0 {
                nums[i] /= 2
            } else {
                flag = false
            }
        }
        if flag {
            count++
        }
    }
    fmt.Println(count)
}

Measured memory_bytes: 1772
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 501000,mod = 1e9+7;
char s[N];
int a[N],n,m;
void solve1(){
	int f[N][2][2];memset(f,0,sizeof(f));
	f[1][1][1]=f[1][0][0]=1;
	auto upd=[](int&a,int b){a+=b;if(a>=mod)a-=mod;};
	for(int i=2;i<=n;i++){
		upd(f[i][1][1],f[i-1][1][0]);
		upd(f[i][1][1],f[i-1][1][1]);
		upd(f[i][1][0],f[i-1][1][1]);
		upd(f[i][0][1],f[i-1][0][0]);
		upd(f[i][0][1],f[i-1][0][1]);
		upd(f[i][0][0],f[i-1][0][1]);
	}
	cout<<(0ll+f[n][1][1]+f[n][1][0]+f[n][0][1])%mod<<'\n';
}
void solve2(){
	int _f[N],*f;memset(_f,0,sizeof(_f));
	f=_f+100;
	int len=n|1,now=0,pos=m;
	while(a[pos]) pos--;
	for(int i=pos;i;i--)
		if(!a[i]){
			if(now&1) len=min(len,now);
			now=0;
		}
		else now++;
	len=min(len,now|1);
	f[-1]=f[1]=1;
	for(int i=3;i<=n;i+=2){
		f[i]=2ll*f[i-2]%mod;
		if(i>len) f[i]=(f[i]-f[i-len-3]+mod)%mod;
	}
	ll ans=0;
	for(int i=1;i<=len;i+=2) ans=(1ll*(i+1)*f[n-i-2]+ans)%mod;
	cout<<ans<<'\n';
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>s+1;
	for(int i=1;i<=m;i++)
		a[i]=s[i]==s[1];
	int flag=1;
	for(int i=1;i<=m;i++)
		flag&=a[i];
	if(flag) solve1();
	else solve2();
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
int main()
{
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB") {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
/**Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
long long mp[1000006];
long long s[1000006],prime[1000006],mod;
vector<pair<long long,long long> >v[10004];
vector<long long>vc;
void sieveOfEratosthenes(long long N)
{
    for(long long i=2; i<=N; i+=2)
        s[i] = 2;
    for(long long i=3; i<=N; i+=2)
    {
        if (!prime[i])
        {
            s[i]=i;
            for(long long j=i; j*i<=N; j+=2)
            {
                //cout<<i*j<<' ';
                if (!prime[i*j])
                {
                    prime[i*j] = 1;
                    s[i*j] = i;
                }
            }
        }
    }
}
void generatePrimeFactors(long long N,long long p)
{
    long long curr = s[N];
    long long cnt = 1;
    while (N > 1)
    {
        N /= s[N];
        if (curr == s[N])
        {
            cnt++;
            continue;
        }
        v[p].push_back({curr, cnt});
        mp[curr]=max(mp[curr],cnt);
        curr = s[N];
        cnt = 1;
    }
}
long long bm(long long a,long long b,long long mod)
{
    long long x=1;
    while(b>0)
    {
        if(b%2)
            x=(x*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return x%mod;
}
int main()
{
    //fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    sieveOfEratosthenes(1000004);
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a;
        vc.push_back(a);
        generatePrimeFactors(a,i);
    }
    f=1;
    mod=1000000007;
    for(i=1;i<1000006;i++){
        f*=bm(i,mp[i],mod);
        f%=mod;
    }
    long long ans=0;
    for(i=0;i<n;i++){
        d=bm(vc[i],mod-2,mod);
        d*=f;
        d%=mod;
        ans+=d;
        ans%=mod;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 23680
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<b)return 0; a=b; return 1;}



signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n];
    ll cnt[n]={};
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
        cnt[a[i]]++;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        ans += cnt[i] * (cnt[i] - 1)/2;
    }
    for(int i=0;i<n;i++){
        ll ret = ans - cnt[a[i]]*(cnt[a[i]]-1)/2;
        ret += (cnt[a[i]]-1) * (cnt[a[i]]-2)/2;
        cout << ret << endl;
    }
    
    
}

Measured memory_bytes: 5760