akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  ll n, m;
  cin >> n >> m;

  ll mi = m;
  for(ll i = 1; i * i <= m; i++){
    if(m % i == 0){
      ll x = i, y = m / i;
      if(x >= n) mi = min(mi, x);
      if(y >= n) mi = min(mi, y);
    }
  }

  ll ans = m / mi;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))

not_important = 0
for a in A:
    not_important ^= a

for i in range(n):
    A[i] &= ~not_important

A.sort()
rank = 0
for digit in range(60, -1, -1):
    check_bit = 1 << digit

    for i in range(rank, n):
        if A[i] & check_bit:
            A[rank], A[i] = A[i], A[rank]
            break
    else:
        continue

    for i in range(n):
        if i == rank: continue
        if A[i] & check_bit:
            A[i] ^= A[rank]

    rank += 1

ans = 0
for i in range(rank):
    ans ^= A[i]

print(ans*2 + not_important)

Measured memory_bytes: 16116
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

// https://math.nakaken88.com/textbook/cp-binary-exponentiation-and-recursive-function/
ll modPow(ll a, ll n, int P) {
  if (n == 1) return a % P;
  if (n % 2 == 1) return (a * modPow(a, n - 1, P)) % P;
  ll t = modPow(a, n / 2, P);
  return (t * t) % P;
}

int main() {
    // input, ready
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    // resolve
    bool yes = true;
    while(1) {
        C-=B;
        if (C<=0) break;        
        A-=D;
        if (A<=0) {
            yes = false;
            break;
        }       
    }

    // output
    if (yes) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int N;
	cin >> N;
	vector<Int> T(N), A(N);
	for (int i = 0; i < N; ++i) {
		cin >> T[i] >> A[i];
	}

	Int nowT = T[0], nowA = A[0];
	for (int i = 1; i < N; ++i) {
		Int x = max((nowT + T[i] - 1) / T[i], (nowA + A[i] - 1) / A[i]);
		nowT = T[i] * x;
		nowA = A[i] * x;
	}
	cout << nowT + nowA << endl;

	return 0;
}


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

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n + 1);
    for (int i = 0; i < n + 1; i++) {
        cin >> a[i];
    }

    if (n == 0) {
        if (a[0] == 1) {
            cout << 1 << '\n';
        } else {
            cout << -1 << '\n';
        }
        return 0;
    } else {
        if (a[0] == 1) {
            cout << -1 << '\n';
            return 0;
        }
    }

    V< P<ll, ll> > nminmax(n + 1, make_pair(1, 1));
    for (int i = 1; i < n; i++) {
        ll nmin = 1, nmax = nminmax[i - 1].second * 2LL - a[i];
        if (nmin > nmax) {
            cout << -1 << '\n';
            return 0;
        }
        nminmax[i] = make_pair(nmin, min(nmax, 1000000000000000LL));
    }

    if (nminmax[n - 1].second * 2LL < a.back()) {
        cout << -1 << '\n';
        return 0;
    }

    nminmax[n] = make_pair(0, 0);

    ll ans = a.back();
    for (int i = n - 1; i >= 0; i--) {
        chmin(nminmax[i].second, nminmax[i + 1].second + a[i + 1]);
        ans += nminmax[i].second + a[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5512
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n,m;
	rl2(n,m);
	VL arr(100005,0);
	fr(i,0,m)
	{
		ll l,r;
		rl2(l,r);
		// l--;
		// fr(j,l,r)
		// {
		// 	arr[j]+=1;
		// }
		arr[l]+=1;
		arr[r+1]--;
	}
	ll ct=0;
	fr(i,1,100005)
	{
		arr[i]+=arr[i-1];
		if(arr[i]==m)
			ct++;

	}
	wl(ct);
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,(n) - 1)
#define rep1(i,n) repU(i,1,(n))
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 ^ b & 1 ^ 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;

const pii dir[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;

ll N,M,Q,K;
string S;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> S;
	N = S.size();
	ll ans = N * (N - 1) / 2;
	vct<ll> alp(26);
	rep(i,N) ++alp[S[i] - 'a'];
	rep(i,26) ans -= alp[i] * (alp[i] - 1) / 2;
	esc(++ans);
}






Measured memory_bytes: 720
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.8
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.8
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

Measured memory_bytes: 131832
def a_sorted_arrays(N, A):
    ans = 0  # 条件を満たすように数列に区切り線を入れるとき、その本数を解とする
    change = 0  # 数列の変化の仕方。1なら増加、0なら横ばい、-1なら減少
    for k in range(1, N):
        if change == 0:
            # 数列が横ばい状態でなくなるまで数列を見る
            if A[k] > A[k - 1]:
                change = 1
            elif A[k] < A[k - 1]:
                change = -1
        elif change == 1:
            if A[k] < A[k - 1]:
                # 数列が非減少状態から変化した。ここで数列を区切る
                change = 0
                ans += 1
        elif change == -1:
            if A[k] > A[k - 1]:
                # 数列が非増加状態から変化した。ここで数列を区切る
                change = 0
                ans += 1
    ans += 1  # 数列の末尾で区切る分、1足す
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(a_sorted_arrays(N, A))

Measured memory_bytes: 14252
import sys
from sys import stdin
input = stdin.readline

inf = float("inf")
cnt = 0
def MS(NL, l, r):
    if l+1 <r:
        m = (l+r)//2
        MS(NL, l, m)
        MS(NL, m, r)
        M(NL, l, m, r)

def M(NL, l, m, r):
    global cnt
    L = NL[l:m]+[inf]
    R = NL[m:r]+[inf]
    i, j = 0, 0
    for k in range(l, r):
        if L[i] >= R[j]:
            NL[k] = R[j]
            j += 1
        else:
            NL[k] = L[i]
            i += 1
    cnt += (r-l)
    
n = int(input())
NL = list(map(int, input().split()))
MS(NL, 0, n)

print(" ".join(list(map(str, NL))))
print(cnt)


Measured memory_bytes: 66884
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, K = map(int, input().split())
mx = (N - 1) * (N - 2) // 2
if K > mx:
    print(-1)
    exit()

es = []
for i in range(2, N + 1):
    es.append((1, i)) 

now = (N - 1) * (N - 2) // 2

for i in range(2, N + 1):
    if now == K:
        break
    for j in range(i + 1, N + 1):
        if now == K:
            break
        es.append((i, j))
        now -= 1

print(len(es))
for a, b in es:
    print(a, b)

    

Measured memory_bytes: 9852
#最大要素の相手は一意?

from collections import Counter
n = int(input())
a = list(map(int, input().split( )))
a_c = Counter(a)

a.sort(reverse = True)
ans = 0
for i in range(n):
    if not a_c[a[i]]:
        continue
    a_c[a[i]] -= 1
    t = (1<<a[i].bit_length()) - a[i]
    if t in a_c:#1つしか残っていないときに誤ってペアができていた
        if a_c[t]:
            a_c[t] -= 1
            #a_c[a[i]] -= 1#こっちも減らす
            ans += 1

print(ans)
            

Measured memory_bytes: 112084
//Problem D
#include<bits/stdc++.h>
using namespace std;
const int N=100005,p=1000000007;
int n,dp[4][N];
char str[N];
int add(int a,int b){a+=b;if(p<=a)a-=p;return a;}
int mul(int a,int b){return (long long)a*b%p;}
#define dbg cerr<<i<<endl
void addch(int a,int op){
    /*switch(op){
        case 'A':
            dp[1][a]+=dp[0][a];
            break;
        case 'B':
            dp[2][a]+=dp[1][a];
            break;
    }*/
    dp[op+1][a]=add(dp[op+1][a],dp[op][a-1]);
}
int main(){
    scanf("%s",str+1),n=strlen(str+1),dp[0][0]=1;
	//printf("%s\n",str+1);
	//for(int i=1;i<=n;i++)printf("%d%c\n",str[i],str[i]);
    for(int i=1;i<=n;i++){//dbg;
        for(int j=0;j<4;j++)dp[j][i]=dp[j][i-1];//dbg;printf("%d\n",str[i]);
        if(str[i]=='?'){//dbg;
            for(int j=0;j<4;j++)dp[j][i]=mul(dp[j][i],3);//,printf("mul %d %d\n",j,i);dbg;
            for(int j=0;j<3;j++)addch(i,j);//dbg;
        }else{
            addch(i,str[i]-'A');
        }
    }
    //for(int i=0;i<4)
    printf("%d",dp[3][n]);
    return 0;
}

Measured memory_bytes: 1920
from bisect import bisect_left
from itertools import accumulate

n = int(input())
a = tuple(map(int, input().split()))

cumsum = (0,) + tuple(accumulate(a))
# print(cumsum)

# PQ := [0, cut)
# RS = [cut, n)

ans = cumsum[-1]
for cut in range(2, n - 1):
    # cumsum[cut] : PQ区間和
    # cumsum[lc], cumsum[lc_1] : P区間和の候補
    # cumsum[n] - cumsum[cut] : RS区間和
    # cumsum[rc], cumsum[rc_1] : R区間和 + sPQの候補

    sPQ = cumsum[cut]
    sRS = cumsum[n] - cumsum[cut]

    lc = bisect_left(cumsum, sPQ // 2)
    # x以上で最小, 累積和のindexは、aの1-indexedに対応
    lc_1 = lc - 1
    # x未満で最大

    if abs((sPQ - cumsum[lc]) - cumsum[lc]) < abs((sPQ - cumsum[lc_1]) - cumsum[lc_1]):
        sP = cumsum[lc]
        # print('sP', sP, lc, cumsum)
    else:
        sP = cumsum[lc_1]
        # print('sP', sP, lc_1, cumsum)
    sQ = sPQ - sP
    # print('sQ', sQ)

    rc = bisect_left(cumsum, sPQ + (sRS // 2))
    # x以上で最小, 累積和のindexは、aの1-indexedに対応
    rc_1 = rc - 1
    # x未満で最大

    if abs((sRS - (cumsum[rc] - sPQ)) - (cumsum[rc] - sPQ)) < abs((sRS - (cumsum[rc_1] - sPQ)) - (cumsum[rc_1] - sPQ)):
        sR = cumsum[rc] - sPQ
        # print('sR', sR, rc, cumsum)
    else:
        sR = cumsum[rc_1] - sPQ
        # print('sR', sR, rc_1, cumsum)
    sS = sRS - sR
    # print('sS', sS)

    t = (sP, sQ, sR, sS)

    ans = min(ans, max(t) - min(t))
    # print(t)
print(ans)


Measured memory_bytes: 25932
h,w,d,f;main(i){for(;scanf(f="%d %d\n",&h,&w)*h;printf(f,h,w)){for(d=i=h*h+w*w;;d++)for(h=d!=i?:h+1;h<(w=sqrt(d-h*h));h++)if(w*w==d-h*h)goto c;c:;}}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul a, b;
  cin >> a >> b;
  if (a==b) cout << 0 << endl;
  else if ((a+b)%2==0) cout << (a+b)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
    long N;
    scanf("%ld",&N);
    int ans ;
    if(N%2==1){
        ans = N/2;
    }else{
        ans = N/2 -1;
    }
    printf("%d\n",ans);
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
ll X,A[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>X;
	FOR(i,N) cin>>A[i];
	sort(A,A+N);
	int ret=0;
	FOR(i,N) {
		if(X>=A[i]) {
			ret++;
			X-=A[i];
		}
	}
	if(ret==N && X) ret--;
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

int main() {
	int s, w;
	cin >> s >> w;
	string ans = (s > w) ? "safe" : "unsafe";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
  int n,a[3],min,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  min=a[0];
  for(i=1;i<n;i++){
    if(min>a[i])
      min=a[i];
  }
  for(i=1;i<=min;i++){
    if(n==2){
      if(a[0]%i==0&&a[1]%i==0)
	printf("%d\n",i);
    }else if(n==3){
      if(a[0]%i==0&&a[1]%i==0&&a[2]%i==0)
	printf("%d\n",i);
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(){
    int i, j, h, w;
    char c[110][110];
    scanf("%d %d", &h, &w);
    for(i = 0; i < h; i++){
        scanf("%s", c[i]);
        // getchar();
        // for(j = 0; j < w; j++){
        //     scanf("%c", &c[i][j]);
        // }
    }
    for(i = -1; i <= h; i++){
        for(j = -1; j <= w; j++){
            if(i == -1 || i == h || j == -1 || j == w){
                printf("#");
            }else{
                printf("%c", c[i][j]);
            }
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
	int n,k;
	scanf("%d",&n);
	scanf("%d",&k);
	int x=1;
	for(int i=0;i<n;i++){
		if(x*2<x+k){
			x*=2;
		}
		else if(x*2>x+k){
			x+=k;
		}
		else{
			x*=2;
		}
	}
	printf("%d",x);
	puts("");
	return 0;
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;

  a = N/1000;
  b = N/100 - a*10;
  c = N/10 - a*100 - b*10;
  d = N - a*1000 - b*100 - c*10;
  if ((a==b && b==c) || (b==c && c==d)) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> T(N + 1);
    rep(i, N) {
        cin >> S[i] >> T[i + 1];
        T[i + 1] += T[i];
    }

    string X;
    cin >> X;
    rep(i, N) {
        if (S[i] == X) {
            write(T[N] - T[i + 1]);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn];
struct node {
	int x, y, c;
};
node m[maxn];
int main(void)
{
	int A, B, M;
	scanf("%d %d %d", &A, &B, &M);
	for (int i = 0; i < A; i++)
		scanf("%d", &a[i]);
	for (int i = 0; i < B; i++)
		scanf("%d", &b[i]);
	for (int i = 0; i < M; i++)
		scanf("%d %d %d", &m[i].x, &m[i].y, &m[i].c);
	int Min = 1e9;
	for (int i = 0; i < M; i++) {
		Min = min(Min, a[m[i].x-1] + b[m[i].y-1] - m[i].c);
	}
	sort(a, a + A);
	sort(b, b + B);
	Min = min(Min, a[0] + b[0]);
	printf("%d\n", Min);
	return 0;
}

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

int main()
{
    int n;
    int x;
    cin>>n>>x;
    
    
    if(x==2*n-1||x==1)
    {
        
        if(n==1){cout<<"Yes\n";cout<<1<<endl;}
        else cout<<"No\n";
        return 0;
    }
    n=2*n-1;
    int arr[n+1];
    int i;
    arr[n/2]=x;
    int tx1=x,tx2=x;
    int flg=0,j;
    for(j=n/2-1,i=n/2+1;i<=n,j>=0;i++,j--)
    {
        if(flg==0)
        {
        if(tx2-1>=1)
        {arr[j]=tx2-1;tx2--;}
        else{
            arr[j]=tx1+1;tx1++;
        }
        
        if(tx1+1<=n)
        {arr[i]=tx1+1;tx1++;}
        else {
            arr[i]=tx2-1;tx2--;
        }
        flg=1;
        }
        else if(flg==1)
        {
        if(tx1+1<=n)
        {arr[j]=tx1+1;tx1++;}
        else{
            arr[j]=tx2-1;tx2--;
        }
        
        if(tx2-1>=1)
        {arr[i]=tx2-1;tx2--;}
        else{
            arr[i]=tx1+1;tx1++;
        }
        flg=0;
        }
    }
        cout<<"Yes\n";
        for(i=0;i<n;i++)cout<<arr[i]<<endl;
    
    return 0;
}


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

/*-----------------END TEMPLATE-----------------*/

int main() {
  FASTIO;
  ll n;
  cin >> n;

  cout << (n * (n - 1)) / 2 << endl;
}


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

int main(){
  string o,e;
  cin >> o >> e;
  if(o.length()==e.length()){
    r(i,o.length()){
      cout << o.at(i)<<e.at(i);
    }
    cout << endl;
  }
     else{
       r(i,o.length()-1){
         cout << o.at(i)<<e.at(i);
       }
       cout << o.at(o.length()-1)<<endl;;
     }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,a[maxn];
ll cnt[1000005];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		ll x = a[i];
		for(ll i = 2;i * i <= x;i++){
			if(x % i == 0){
				ll tmp = 0;
				while(x % i == 0){
					x /= i;
					tmp++;
				}
				cnt[i] = max(cnt[i],tmp);
			}
		}
		if(x > 1) cnt[x] = max(cnt[x],1LL);
	}
	ll k = 1;
	for(int i = 0;i < 1000005;i++){
		if(cnt[i]){
			k = k * poww(i,cnt[i],mod) % mod;
		}
	}
	ll ans = 0;
	for(int i = 0;i < n;i++){
		ll tmp = (k % mod) * poww(a[i],mod-2,mod) % mod; 
		ans = (ans + tmp) % mod;
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 8192
#include<cstdio>
using namespace std;
const int MAXN=3e5+5;
int N;
int A[MAXN];

bool Check(int Key){
	for(int i=0;i<N-1;i++){
		if( (A[N+i]>Key && A[N+i+1]>Key) || (A[N-i]>Key && A[N-i-1]>Key) ){
			return 0;
		}
		if( (A[N+i]<=Key && A[N+i+1]<=Key) || (A[N-i]<=Key && A[N-i-1]<=Key) ){
			return 1;
		}
	}
	return A[1]<=Key;
}

int BS(int L,int R){
	int Ans=0;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(Check(Mid)){
			Ans=Mid;
			R=Mid-1;
		}else{
			L=Mid+1;
		}
	}
	return Ans;
}

int main(){
	
	scanf("%d",&N);
	
	for(int i=1;i<=2*N-1;i++){
		scanf("%d",&A[i]);
	}
	
	printf("%d\n",BS(1,2*N-1));
	
	return 0;
	
} 

Measured memory_bytes: 896
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())

    ans = set(range(1, M+1))
    for _ in range(N):
        ans &= set(map(int, input().split()[1:]))
    print(len(ans))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int[] P = new int[N];
		for(int i = 0; i < N; i++) {
			P[i] = sc.nextInt();
		}
		sc.close();
		int c1 = 0;
		int c2 = 0;
		int c3 = 0;
		for(int i = 0; i < N; i++) {
			if(P[i] <= A) {
				c1++;
			}else if(P[i] <= B) {
				c2++;
			}else {
				c3++;
			}
		}
		int min = Math.min(c1, Math.min(c2, c3));
		System.out.println(min);
	}
}

Measured memory_bytes: 22740
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let n = get!(i64);
    let a = if n == 1 { 0 } else { get!(i64) };
    let b = if n == 1 { 0 } else { get!(i64) };

    println!("{}", if n == 1 { "Hello World".to_string() } else { (a + b).to_string() });
}

Measured memory_bytes: 4352
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [n, m] = next().split(" ").map(el => BigInt(el))
    let ans = 0n
    if (n == 1n && m == 1n) {
        ans = 1n
    } else if (n == 1n && m !== 1n) {
        ans = m - 2n
    } else if (n !== 1n && m == 1n) {
        ans = n - 2n
    } else if (n == 2n || m == 2n) {
        ans = 0n
    } else {
        ans = (n - 2n) * (m - 2n)
    }
    console.log(ans.toString())
}
Main()


Measured memory_bytes: 29528
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 105;

int N, D[MAX_N], mx, vis[MAX_N], mn = MAX_N;

int main() {

  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &D[i]), vis[D[i]]++;
    mx = max(mx, D[i]), mn = min(mn, D[i]);
  }

  bool flag = 1;
  if (mn < (mx + 1) / 2) flag = 0;
  
  if ((mx & 1) == 0) {
    for (int i = mx; i >= mn; --i)
      if (i != mx / 2) {
	if (vis[i] < 2) flag = 0;
      } else {
	if (vis[i] != 1) flag = 0;
      }
  } else {
    for (int i = mx; i >= mn; --i)
      if (i != (mx + 1) / 2) {
	if (vis[i] < 2) flag = 0;
      } else {
	if (vis[i] != 2) flag = 0;
      }
  }

  if (flag) puts("Possible");
  else puts("Impossible");
  
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
#define MAX 2000000
#define INF 1000000000

int H, A[MAX+1];

void maxHeapify(int i){
	int largest;
	int l = i*2;
	int r = i*2+1;
	int tmp;

	if(l <=H && A[l] > A[i]){ 
		largest = l; 
	}else{
		largest = i;
	}
	
	if(r <=H && A[r] > A[largest]){
		largest = r;
	}

	if(largest != i){
		tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(largest);
	}
}


int extract(){
	int maxv;
	if(H < 1){
		return -INF;
	}
	maxv = A[1];
	A[1] = A[H];
	H--;
	maxHeapify(1);
	return maxv;
}

void increaseKey(int i,int key){
	if(key < A[i]){
		return;
	}
	A[i] = key;
	while(i>1 && A[i/2] < A[i]){
		swap(A[i],A[i/2]);
		i /= 2;
	}
}


void insert(int key){
	H++;
	A[H] = -INF;
	increaseKey(H,key);
}

int main(void){
	int key;
	char input[10];

	while(1){
		scanf("%s",input);
		if(input[0] == 'e' && input[1] == 'n'){
			break;
		}
		if(input[0] == 'i'){
			scanf("%d",&key);
			insert(key);
		}else{
			printf("%d\n",extract());
		}
	}
	return 0;
}


















Measured memory_bytes: 6548
#pragma GCC optimize("trapv")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 3555;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a, b, c;
	cin >> a >> b;
	c = a*(b/__gcd(a, b));
	cout << c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int f(int x) {
	if (x == 0) return 0;
	return f(x % __builtin_popcount(x)) + 1;
}
int main() {
	int N;
	string X;
	cin >> N >> X;
	int popcount0 = 0;
	for (int i = 0; i < N; ++ i) if (X[i] == '1') ++ popcount0;
	vector<int> a0, a1;
	ll s0 = -1, s1 = -1;
	for (int i = 0; i < N; ++ i) {
		if (X[i] == '0') {
			int popcount = popcount0 + 1;
			if (s0 < 0) {
				s0 = 0;
				a0 = vector<int>(N);
				for (int i = 0; i < N; ++ i) {
					a0[i] = i == 0 ? 1 : (a0[i-1] * 2 % popcount);
					if (X[N-1-i] == '1') (s0 += a0[i]) %= popcount;
				}
			}
			cout << 1 + f((s0 + a0[N-1-i]) % popcount) << endl;
		} else {
			int popcount = popcount0 - 1;
			if (popcount == 0) {
				cout << 0 << endl;
			} else {
				if (s1 < 0) {
					s1 = 0;
					a1 = vector<int>(N);
					for (int i = 0; i < N; ++ i) {
						a1[i] = i == 0 ? 1 : (a1[i-1] * 2 % popcount);
						if (X[N-1-i] == '1') (s1 += a1[i]) %= popcount;
					}
				}
				cout << 1 + f((s1 + popcount - a1[N-1-i]) % popcount) << endl;
			}
		}
	}
}


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

int main() {
    string A, B; cin >> A >> B;
    if (A.length() > B.length() || (A.length() == B.length() && A > B)) {
        cout << "GREATER" << endl;
    } else if (A.length() < B.length() || (A.length() == B.length() && A < B)) {
        cout << "LESS" << endl;
    } else {
        cout << "EQUAL" << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)














int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> used(h, vector<ll>(w, -1));
    queue<pair<pair<ll, ll>, ll>> que;
    REP(i, h){
        string s;
        cin >> s;
        REP(j, w){
            if(s[j] == '#'){
                que.push({{i, j}, 0});
            }
        }
    }
    const ll dy[4] = {-1, 0, 1, 0};
    const ll dx[4] = {0, 1, 0, -1};
    while(!que.empty()){
        auto tmp = que.front(); que.pop();
        ll y = tmp.first.first, x = tmp.first.second, d = tmp.second;
        if(y < 0 || y >= h || x < 0 || x >= w || used[y][x] != -1) continue;
        used[y][x] = d;
        REP(i, 4){
            que.push({{y + dy[i], x + dx[i]}, d + 1});
        }
    }
    
    ll ans = 0;
    REP(i, h){
        REP(j, w){
            ans = max(ans, used[i][j]);
        }
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  string S;
  cin>>S;
  N=S.size();
  
  int count_a=0,count_b=0,count_c=0;
  for(int i=1; i<=(N-1)/2/2; i++){
    if(S.at(i-1)==S.at((N-1)/2+1-i-1)){
      count_a++;
    }
  }
  for(int i=1; i<=(N-(N+3)/2+1)/2; i++){
    if(S.at((N+3)/2+i-2)==S.at(N-i)){
      count_b++;
    }
  }
  for(int i=1; i<=N/2; i++){
    if(S.at(i-1)==S.at(N-i)){
      count_c++;
    }
  }
  if(count_a==(N-1)/2/2&&count_b==(N+1-(N+3)/2)/2&&count_c==N/2){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3632
A = input()
B = input()
C = input()

cards = {'a':A, 'b':B, 'c':C}

def play(cards):
    p = 'a'
    while True:
        cs = cards[p]
        if len(cs) == 0:
            return p.upper()
        next = cs[0]
        cards[p] = cs[1:]
        p = next

print(play(cards))


Measured memory_bytes: 3060
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()
def factorization(n):
  res = []
  if n%2==0:
    res.append(2)
  for i in range(3,math.floor(n//2)+1,2):
    if n%i==0:
      c = 0
      for j in res:
        if i%j==0:
          c=1
      if c==0:
        res.append(i)
  if len(res)==0:
    res = [n]
  return res
def fact2(n):
  p = factorization(n)
  res = []
  for i in p:
    c=0
    z=n
    while 1:
      if z%i==0:
        c+=1
        z/=i
      else:
        break
    res.append([i,c])
  return res
def fact(n):#階乗
  ans = 1
  m=n
  for _i in range(n-1):
    ans*=m
    m-=1
  return ans
def comb(n,r):#コンビネーション
  if n<r:
    return 0
  l = min(r,n-r)
  m=n
  u=1
  for _i in range(l):
    u*=m
    m-=1
  return u//fact(l)
def combmod(n,r,mod):
  return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
  r=copyQueue(q)
  ans=[0]*r.qsize()
  for i in range(r.qsize()-1,-1,-1):
    ans[i] = r.get()
  print(ans)
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.parents = [-1]*n

  def find(self, x): # root
    if self.parents[x]<0:
      return x
    else:
      self.parents[x] = self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x = self.find(x)
    y = self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y = y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self,x):
    return -1*self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x): # much time
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
  x = 1
  zero = "0"*n
  ans = []
  ans.append([0]*n)
  for i in range(2**n-1):
    ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
    x+=1
  return ans;
def arrsSum(a1,a2):
  for i in range(len(a1)):
    a1[i]+=a2[i]
  return a1
def maxValue(a,b,v):
  v2 = v
  for i in range(v2,-1,-1):
    for j in range(v2//a+1): #j:aの個数
      k = i-a*j
      if k%b==0:
        return i
  return -1
def copyQueue(q):
  nq = queue.Queue()
  n = q.qsize()
  for i in range(n):
    x = q.get()
    q.put(x)
    nq.put(x)
  return nq
def get_sieve_of_eratosthenes(n):
  data = [2]
  #data = [0,0,0]
  for i in range(3,n+1,2):
    data.append(i)
    data.append(0)
  for i in range(len(data)):
    interval = data[i]
    if interval!=0:
      for j in range(i+interval,n-1,interval):
        data[j] = 0
  ans = [x for x in data if x!=0]
  #ans = data[:]
  return ans


a,b = readInts()

#print(a+b)
print(a*b)

Measured memory_bytes: 9564
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
c = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    dist_min = float('inf')
    dist_min_pos = 0
    for j in range(m):
        dist = abs(a[i][0] - c[j][0]) + abs(a[i][1] - c[j][1])
        if dist < dist_min:
            dist_min = dist
            dist_min_pos = j + 1
    print(dist_min_pos)


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


int main() {
	int N;
	cin >> N;
	int ans = 0;
	for(int i = 0; i < N; i++){
		int a;
		cin >> a;
		int cnt = 0;
		while(a % 2 == 0){
			a /= 2;
			cnt++;
		}
		ans += cnt;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
ll mod = 1000000007;
ll inf = 1e18;
int main(){

    int n;
    cin >> n;
    vector<vector<ll>> num(10,vector<ll>(10));
    int k=1;
    rep(i,n+1){
        if(i==10*k) k*=10;
        num[i/k][i%10]++;
    }

    ll sum=0;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++) sum+=num[i][j]*num[j][i];
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 800010
using namespace std;
ll n,q,bin[N],sum[N],pre[N],val[N],sz;
vector<ll> vt[N];
void update(ll l,ll r,ll v)
{
	ll i;
	l+=sz;
	r+=sz;
	while(l<=r)
	{
		val[l]=min(val[l],v);
		val[r]=min(val[r],v);
		l=(l+1)/2;
		r=(r-1)/2;
	}
	return;
}
ll getans(ll v)
{
	v+=sz;
	ll ret=LINF;
	while(v>0)
	{
		ret=min(ret,val[v]);
		v/=2;
	}
	return ret;
}
int main(){
	ll i,j,x,y;
	cin>>n;
	sum[0]=0;
	memset(val,127,sizeof(val));
	for(i=0;i<n;i++)
	{
		cin>>bin[i];
		sum[i+1]=sum[i]+(1-bin[i]);
	}
	cin>>q;
	for(i=0;i<q;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vt[y].push_back(x);
	}
	for(sz=1;sz<=n;sz*=2);
	for(i=0;i<n;i++)
	{
		update(i,i,pre[i]-sum[i]);
		for(j=0;j<vt[i].size();j++)
		{
			update(vt[i][j]+1,i+1,getans(vt[i][j]));
		}
		pre[i+1]=min(pre[i]+bin[i],getans(i+1)+sum[i+1]);
	}
	cout<<pre[n]<<endl;
	return 0;
}

Measured memory_bytes: 39936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,pair<int,int>>iii;
int N;
set<iii>vis;
unordered_map<int,int> mp;
void bf(int x, int y, int z){
	if(vis.count({x,{y,z}}))
		return;
	vis.insert({x,{y,z}});
	int ret= (x*x) + (y*y) + (z*z) + (x*y) + (y*z) + (x*z);
	if(ret > N)
		return;
	mp[ret]++;
	bf(x+1,y,z);
	bf(x,y+1,z);
	bf(x,y,z+1);
	return;
}
int main(){
	scanf("%d", &N);
	bf(1,1,1);
	for(int i=1;i<=N;i++){
		printf("%d\n", mp[i]);
	}
	return 0;
}

Measured memory_bytes: 20272
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**6)
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    
    #'Yes', 'No', 'YES', 'NO', ':(', 'Yay!'
    #res = 0
    a, b, c = map(int, r.split())
    if a+b < c:
        print('No')
    else:
        print('Yes')
    #print()

if __name__ == '__main__':
    main()



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

int main(){
    string s;
    int k, n;
    char c;
    cin >> n >> s >> k;
    c = s[k-1];
    for(int i = 0; i < s.length(); i++){
        if(s[i] != c){
            putchar('*');
        }
        else{
            putchar(c);
        }
    }
    putchar('\n');
}

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

typedef long long ll;

const int MN = 100002;

int N, E, T;
vector<ll> X;
vector<ll> dp;

struct BIT {
    vector<ll> tree;
    void init() {
        tree = vector<ll>(4*MN, 1e18);
    }
    void upd(int idx, ll val, int l, int r, int n) {
        if(idx < l || r < idx) return;
        if(l == r) {
            tree[n] = val;
            return;
        }
        int m = (l + r)>>1;
        upd(idx, val, l, m, 2*n);
        upd(idx, val, m + 1, r, 2*n + 1);
        tree[n] = min(tree[2*n], tree[2*n + 1]);
    }
    ll quer(int a, int b, int l, int r, int n) {
        if(b < l || r < a) return 1e18;
        if(a <= l && r <= b) return tree[n];
        int m = (l + r)>>1;
        ll L = quer(a, b, l, m, 2*n);
        ll R = quer(a, b, m + 1, r, 2*n + 1);
        return min(L, R);
    }
} bit1, bit2;

int main() {
    scanf("%d %d %d", &N, &E, &T);

    X.push_back(0);
    for(int i = 0; i < N; i++) {
        int t; scanf("%d", &t);
        X.push_back(t);
    }

    dp.resize(X.size());
    dp[X.size() - 1] = E - X.back();

    bit1.init();
    bit2.init();
    bit1.upd(X.size() - 1, X.back() + dp[X.size() - 1], 0, MN - 1, 1);
    bit2.upd(X.size() - 1, 3*X.back() + dp[X.size() - 1], 0, MN - 1, 1);

    for(int i = (int)X.size() - 2; i >= 0; i--) {
        int s = i + 1, e = (int)X.size() - 1;
        int x = i;
        while(s <= e) {
            int m = (s + e)>>1;

            if(X[m] - X[i + 1] <= T/2) {
                x = m;
                s = m + 1;
            }
            else e = m - 1;
        }

        dp[i] = min(-X[i] + bit1.quer(i + 1, x, 0, MN - 1, 1) + T, -X[i] - 2*X[i + 1] + bit2.quer(x + 1, MN - 1, 0, MN - 1, 1));
        bit1.upd(i, X[i] + dp[i], 0, MN - 1, 1);
        bit2.upd(i, 3*X[i] + dp[i], 0, MN - 1, 1);
    }

    cout << dp[0];
}


Measured memory_bytes: 8308
N=int(input())
A=list(map(int,input().split()))
count=0
cnt=0
for i in range(N):
    if A[i]%2==0:
        count+=1
        if A[i]%3==0 or A[i]%5==0:
            cnt+=1
if cnt==count:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
x,n=map(int,input().split())
if n>0:
  p=list(map(int,input().split()))
else:
  p=[]
minx=0
absx=101
for i in range(102):
  if i in p:
    continue
  else:
    cabs=abs(x-i)
    if cabs < absx:
      absx=cabs
      minx=i
if absx==101:
  if x>51:
    minx=101
print(minx)

Measured memory_bytes: 9192
package main

import "fmt"


func main() {
	var n int
	fmt.Scan(&n)

	res := make([]int, n)
	for i := 0; i < n - 1; i++ {
		var a int
		fmt.Scan(&a)
		res[a - 1]++;
	}

	for _, n := range res {
		fmt.Println(n)
	}
}

Measured memory_bytes: 6484
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int n=read();
	int m=read();
	int s=0;
	for(int i=1;i<=m;++i){
        int k=read();
        s+=k;
	}
	if((n-s)<0) cout<<-1<<endl;
	else cout<<n-s<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
	int res;
	if(m==0)return 1;
	if(i>=n)return 0;
	res=solve(i+1,m)||solve(i+1,m-A[i]);
	return res;
}
int main(){
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}

Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
int main () {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long long x[1000];
  long long y[1000];
  vector<long long> z(Z);
  for (int i = 0; i < X; i ++) cin >> x[i];
  for (int i = 0; i < Y; i ++) cin >> y[i];
  for (int i = 0; i < Z; i ++) cin >> z[i];
  vector<long long> XY(X * Y);
  for (int i = 0; i < X * Y; i ++) {
    int i_ = i;
    int j = i_ % Y;
    i_ /= Y;
    XY[i] = x[i_] + y[j];
  }
  //for (int i = 0; i < X * Y; i ++) cout << XY[i] << ' ';
  //cout << endl;
  sort(XY.begin(), XY.end());
  int mxy = min(X * Y, K);
  vector<long long> an(mxy, 0);
  for (int i = 0; i < mxy; i ++) {
    an[i] = XY[X * Y - i - 1];
    //cout << an[i] << ' ';
  }
  //cout << endl;
  sort(z.begin(), z.end());
  int mz = min(Z, K);
  vector<long long> as(mz, 0);
  for (int i = 0; i < mz; i ++) {
    as[i] = z[Z - i - 1];
    //cout << as[i] << ' ';
  }
  //cout << endl;
  vector<long long> ans(mxy * mz, 0);
  for (int i = 0; i < mxy * mz; i ++) {
    int i_ = i;
    int j = i_ % mz;
    i_ /= mz;
    ans[i] = an[i_] + as[j];
  }
  sort(ans.begin(), ans.end());
  for (int i = 1; i <= K; i ++) {
    cout << ans[mxy * mz - i] << endl;
  }
}

  



Measured memory_bytes: 31616