akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

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

vector<string> Ans;

rep(i, 0, S.size()- T.size() + 1){

    bool C = 1;

    rep(j, 0, T.size()){

        if(S[i + j] != '?' && S[i + j] != T[j]){C = 0;break;}

    }

    if(C){

        string N = S;

        rep(j, 0, T.size())N[i + j] = T[j];

        rep(j, 0, N.size()){

            if(N[j] == '?')N[j] = 'a';

        }

        Ans.push_back(N);

    }

}

sort(ALL(Ans));

if(Ans.empty())cout << "UNRESTORABLE";

else cout << Ans[0];
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

// k文字でいけるならtrue
bool C(int k, vector<int> A){
    stack<pair<int, int>> st;
    if(k == 1) {
        for (int i = 1; i < A.size(); ++i) {
            if(A[i-1] >= A[i]) return false;
        }
        return true;
    }
    
    for (int i = 1; i < A.size(); ++i) {
        if(A[i-1] >= A[i]){
            if(A[i-1] != A[i]){
                while (! st.empty() && st.top().first > A[i]) st.pop();
            }
            int cur = A[i]; // 1を足す桁
            while (1){
                if(st.empty() || st.top().first < cur) st.push({cur, 0});
                if(st.top().second < k-1) {
                    st.top().second++;
                    break;
                } else{
                    st.pop();
                    cur--;
                    if(cur <= 0) return false;
                }
            }
        }
    }
    return true;
}

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

    int lb = 0, ub = 1000000007;
    while( ub-lb > 1 ){
        int mid = (lb + ub)/2;
        if(C(mid, A)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    cout << ub;
    return 0;
}

Measured memory_bytes: 1808
#include <stdio.h>

int main(void){
    int n,i,j,k;
    char a[52];
    int b[52];
    scanf("%d\n",&n);
    for(i=0;i<n;i++){
        scanf("%c %d\n",&a[i],&b[i]);
    }
    for(j=0;j<13;j++){
        k=0;
        for(i=0;i<n;i++){
            if(a[i]=='S'&&b[i]==j+1){
                k=1;
                break;
            }
        }
        if(k==0) printf("S %d\n",j+1);
    }
    for(j=0;j<13;j++){
        k=0;
        for(i=0;i<n;i++){
            if(a[i]=='H'&&b[i]==j+1){
                k=1;
                break;
            }
        }
        if(k==0) printf("H %d\n",j+1);
    }
    for(j=0;j<13;j++){
        k=0;
        for(i=0;i<n;i++){
            if(a[i]=='C'&&b[i]==j+1){
                k=1;
                break;
            }
        }
        if(k==0) printf("C %d\n",j+1);
    }
    for(j=0;j<13;j++){
        k=0;
        for(i=0;i<n;i++){
            if(a[i]=='D'&&b[i]==j+1){
                k=1;
                break;
            }
        }
        if(k==0) printf("D %d\n",j+1);
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define N 850
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair <int , int> ii;
typedef pair <int , ii> i3;
int ir,ic,k,grid[N][N],d[N][N];
bool vis[N][N];

int dr[] = {-1 , 1 , 0 , 0};
int dc[] = {0 , 0 , -1 , 1};

bool inside(int r , int c) {
    return r >= 1 && r <= ir && c >= 1 && c <= ic;
}

int updiv(int a , int b) {
    int tmp = a / b;
    return tmp * b < a ? tmp + 1 : tmp;
}

int solve(ii s) {
    queue <i3> _q,q;
    _q.push(mp(0 , s));
    while (!_q.empty()) {
        i3 curr = _q.front(); _q.pop();
        int cd = curr.fi, cr = curr.se.fi, cc = curr.se.se;
        if (!inside(cr , cc)) continue;
        if (grid[cr][cc] == -1) { d[cr][cc] = 0; continue; }
        if (vis[cr][cc]) continue;
        vis[cr][cc] = true;
        d[cr][cc] = cd;
        if (d[cr][cc] <= k) q.push(mp(0 , mp(cr , cc)));
        for (int dir = 0 ; dir < 4 ; dir++)
            _q.push(mp(cd + 1 , mp(cr + dr[dir] , cc + dc[dir])));
    }
    memset (grid , 0 , sizeof grid);
    memset (vis , false , sizeof vis);
    int sol = 1;
    while (!q.empty()) {
        i3 curr = q.front(); q.pop();
        int cd = curr.fi, cr = curr.se.fi, cc = curr.se.se;
        if (!inside(cr , cc)) continue;
        if (cr == ir || cr == 1 || cc == ic || cc == 1) {
            sol += updiv(cd , k);
            return sol;
        }
        if (vis[cr][cc]) continue;
        vis[cr][cc] = true;
        for (int dir = 0 ; dir < 4 ; dir++)
            q.push(mp(cd + 1 , mp(cr + dr[dir] , cc + dc[dir])));
    }
    return sol;
}

int main() {
    scanf("%d%d%d" , &ir , &ic , &k);
    ii stCoor;
    for (int r = 1 ; r <= ir ; r++) {
        char inp[N]; scanf("%s" , inp);
        for (int c = 0 ; c < strlen(inp) ; c++) {
            int keep = 0;
            if (inp[c] == '#') keep = -1;
            else if (inp[c] == 'S') stCoor = mp(r , c + 1);
            grid[r][c + 1] = keep;
        }
    }
    printf("%d\n" , solve(stCoor));
}


Measured memory_bytes: 16144
#include<stdio.h>
long long int mod=1e9+7,h=0,w=0,gr[1005][1005];

int paths(int i,int j)
{
  if(gr[i][j]!=-1)
    return gr[i][j];

  if(i==h-1&&j==w-1)
    return 1;
  else if(i==h-1)
    return paths(i,j+1);
  else if(j==w-1)
    return paths(i+1,j);

    gr[i][j] = ((long long)paths(i,j+1) + paths(i+1,j))%mod;

  return gr[i][j];
}

int main()
{
  scanf("%lld %lld",&h,&w);
  char c[w+5];

  for(int i=0;i<h;i++)
  {
    scanf("%s",c);
  for(int j=0;j<w;j++)
  {
    if(c[j]=='#')
      gr[i][j]=0;
    else
      gr[i][j]=-1;
  }
  }

  printf("%d\n",paths(0,0));

  return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		
		if(x>=30) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35604
// aribon4-5_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;


pair<int, int> dfs(string& S, int& i, int last_idx){

    if (i > last_idx) return {0, 99};

    if ('0' <= S[i] && S[i] <= '9') {
        int n = S[i] - '0';
        i++;

        if (n == 0) return {0, 0};
        if (i > last_idx) return {n, 10*n+9};

        if ('0' <= S[i] && S[i] <= '9') {
            n = 10 * n + S[i] - '0';
            i++;
        }
        return {n, n};
    } else if (S[i] == '_' || S[i] == '^'){
        bool max_mode = S[i] == '^';

        i += 2;
        auto lhs = dfs(S, i, last_idx); //左辺
        i++;
        auto rhs = dfs(S, i, last_idx); //右辺
        i++;
        if (max_mode) {
            return {max(lhs.first, rhs.first), max(lhs.second, rhs.second)};
        } else {
            return {min(lhs.first, rhs.first), min(lhs.second, rhs.second)};
        };
    } else {
        print(i, S[i]);
        assert(false); //来ないはず
        return {-1, -1};
    }
}


int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int Q;
    cin >> Q;

    REP(_, Q){
        string S;
        cin >> S;

        REP(last_idx, S.size()){
            int idx = 0;
            auto res = dfs(S, idx, last_idx);
            if (res.first == res.second){
                print(res.first, last_idx+1);
                break;
            }
        }

    }

    return 0;
}


Measured memory_bytes: 256
import math

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    sum = 0
    for i in range(k):
        for j in range(k):
            for l in range(k):
                sum = sum + math.gcd(math.gcd(i+1 ,j+1), l+1)
    print(sum)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9132
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%s", $ABCD);
$k = array("+", "-");
$array = str_split($ABCD);
for ($i = 0; $i < 8; $i++) {
    $res = intval($array[0]);
    $ans = $array[0];
    if (($i & 4) == 4) {
        $res += $array[1];
        $ans .= "+" . $array[1];
    } else {
        $res -= $array[1];
        $ans .= "-" . $array[1];
    }
    if (($i & 2) == 2) {
        $res += $array[2];
        $ans .= "+" . $array[2];
    } else {
        $res -= $array[2];
        $ans .= "-" . $array[2];
    }
    if (($i & 1) == 1) {
        $res += $array[3];
        $ans .= "+" . $array[3];
    } else {
        $res -= $array[3];
        $ans .= "-" . $array[3];
    }
    if($res === 7) {
        echo "$ans=7\n";
        exit;
    }
}


Measured memory_bytes: 4856
def main():
    n = int(input())

    str_n = str(n)

    n_sum = 0

    for i in range(len(str_n)):
        n_sum += int(str_n[i])

    print('Yes' if n % n_sum == 0 else 'No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38484
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  char buf[128];
  scanf("%s", buf);
  std::string S = buf;

  std::vector<int> bal(N+1);
  for (size_t i = 0; i < N; ++i)
    bal[i+1] = bal[i] + ((S[i] == '(')? +1:-1);

  int min = *std::min_element(bal.begin(), bal.end());
  printf("%s%s%s\n",
         std::string(-min, '(').c_str(),
         S.c_str(), std::string(-min+bal[N], ')').c_str());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair

ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dat[ohara];
ll dat_cou;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    tmp=accumulate(a,a+n,0LL);
    tmpp=accumulate(b,b+n,0LL);
    if(tmp<tmpp)Cout(-1);
    else{
        ans=n;
        ll yoyuu;
        yoyuu=tmp-tmpp;
        rep(i,n){
            if(a[i]>=b[i]){
                dat[dat_cou++]=a[i]-b[i];
            }
        }
            sort(dat,dat+dat_cou);
            rep(i,dat_cou){
                if(yoyuu>=dat[i]){
                    yoyuu-=dat[i];
                    ans--;
                }
                else break;
            }
        Cout(ans);
    }
    return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  long long ans = 0, cnt = 0;
  int size = s.size();
  for (int i = 0; i < size; i++)
    if (s[i] == 'B')
    {
      ans += size - i;
      cnt++;
    }
  cout << ans - cnt * (cnt + 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 640
S = input()
N = len(S)
if S == "keyence" or S[1:] == "keyence" or S[:N-1] == "keyence":
    print("YES")
    exit(0)

for k in range(N):
    for l in range(k,N):
        if S[:k]+S[l+1:] == "keyence":
            print("YES")
            exit(0)
print("NO")

Measured memory_bytes: 39408
# coding: utf-8
# Your code here!
# TP1_2_D

# 5 4 2 2 1
# 22 - 33
# 3 < 5　かつ　3<4だからOK

# 5 4 2 4 1
# 24 - 35
# 5がアウトる

# x,yがマイナスの場合も考慮したい


N = input().split()
# print(N)

W=int(N[0])
H=int(N[1])
x=int(N[2])
y=int(N[3])
r=int(N[4])

if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
    print("Yes")
else:
    print("No")


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

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
		cout << vec.at(i);
		if (i != n - 1)cout << ' ';
	}
	cout << endl;
	for (int i = 1; i < n; i++) {
		int v = vec.at(i);
		int j = i - 1;
		while (j >= 0 && vec.at(j) > v) {
			vec.at(j + 1) = vec.at(j);
			j--;
		}
		vec.at(j + 1) = v;
		for (int k = 0; k < n; k++) {
			cout << vec.at(k);
			if (k != n - 1) cout << ' ';
		}
		cout << endl;
	}
}


Measured memory_bytes: 3100
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

void solve()
{
    int n, K;
    scanf("%d%d", &n, &K);
    vector<int> v0, v1, v2;
    int i;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (tmp == 0) v0.push_back(tmp);
        else if (tmp > 0) v1.push_back(tmp);
        else v2.push_back(tmp);
    }
    int n0 = (int)v0.size();
    int n1 = (int)v1.size();
    int n2 = (int)v2.size();
    int n2new = MIN(n2,K) / 2 * 2;
    if (n1 + n2 < K) {
        printf("0\n"); return;
    }
    if (n1 + n2new < K) {
        if (!v0.empty()) {
            printf("0\n"); return;
        }
        assert(n0 == 0);

        for (i = 0; i < (int)v2.size(); i++) {
            v1.push_back(abs(v2[i]));
        }
        sort(v1.begin(), v1.end());
        ll ss = 1;
        for (i = 0; i < K; i++) {
            ss = ss * v1[i]%MOD;
        }
        printf("%lld\n", (MOD-ss)%MOD);
        return;
    }
    sort(v1.rbegin(), v1.rend());
    sort(v2.begin(), v2.end());

    ll ss = 1;
    for (i = 0; i < n2new; i++) {
        ll tmp = (MOD - (-v2[i]) % MOD) % MOD;
        ss = ss * tmp%MOD;
    }
    int n1sel0=K-n2new;
    assert(n1sel0 <= n1);
    for (i = 0; i < n1sel0; i++) {
        ll tmp = v1[i] % MOD;
        ss = ss * tmp%MOD;
    }

    int n1sel = n1sel0;
    for (i = 0; i < n2new/2; i++) {
        if (n1sel + 2 > n1) break;
        ll tmp0=(ll)v2[n2new - 1 - i * 2];
        ll tmp1=(ll)v2[n2new - 1 - i * 2-1];
        ll tmp2=(ll)v1[n1sel];
        ll tmp3 = (ll)v1[n1sel + 1];
        n1sel += 2;
        if (tmp0*tmp1 >= tmp2 * tmp3) {
            break;
        }
        ll tmp = tmp2 * tmp3%MOD*minv(tmp0) % MOD*minv(tmp1) % MOD;
        ss = ss * tmp%MOD;
    }
    printf("%lld\n", ss);
    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


Measured memory_bytes: 4244
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
const int INF = 1 << 30;
using namespace std;
#define pp pair<int,int>
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int vv[100010] = {};
void ch(int n) {
	int b = 1;
	for (int i = 2; i <= sqrt(n);++i) {
		if (n%i == 0) { b = 0; break; }
	}
	if (b != 0) {
		int n2 = (n + 1) / 2;
		for (int i = 2; i <= sqrt(n2); ++i) {
			if (n2%i == 0) { b = 0; break; }
		}
	}
	if (n == 1) {vv[n] = 0; }
	else { vv[n] = vv[n - 2] + b; }
}
int main() {
	vv[0] = 0;
	for (int i = 1; i <= 100000; i+=2)ch(i);
	int n;
	int ans[100010];
	cin >> n;
	TFOR(i, n) {
		int a, b;
		cin >> a >> b;
		ans[i] = vv[b] - vv[max(1,a - 2)];
	}
	TFOR(i, n)cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(itr,data) for(__typeof((data).begin()) itr=(data).begin();itr!=(data).end();++itr)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

typedef pair<int ,int > P;

int n,r;

void solve() {
    int ary[60]={};
    rep(i,n+1) ary[i]=n-i+1;

    rep(i,r) {
        int p,c;
        cin>>p>>c;
        p--;
        int tmp[60]={};
        for(int j=1;j<=p;j++) tmp[j]=ary[j];
        for(int j=1;j<=c;j++) swap(ary[j],ary[j+p]);
        for(int j=c+1;j<=c+p;j++) ary[j]=tmp[j-c];
    }
    cout<<ary[1]<<endl;
}

int main() {
    while(cin>>n>>r) {
        if(!(n+r)) return 0;
        solve();
    }
    return 0;
}

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

using namespace std;

template<class T>
struct Graph {
    const int n, INF;
    bool is_neg_cycle;
    std::vector<std::vector<T>> d;

    Graph(int _n) : n(_n), INF(std::numeric_limits<T>::max()), is_neg_cycle(false),
                    d(n, std::vector<T>(n, INF)) { }

    void add_edge(int src, int dst, T w) { d[src][dst] = w; }
    T ShortestDistance(const int src, const int dst) const { return d[src][dst]; }
    bool CheckNegativeCycle() const { return is_neg_cycle; }

    void FloydWarshall() {
        for (int v = 0; v < n; ++v) d[v][v] = 0;
        for (int k = 0; k < n; ++k)
            for (int i = 0; i < n; ++i) {
                if (INF <= d[i][k]) continue;
                for (int j = 0; j < n; ++j) {
                    if (INF <= d[k][j]) continue;
                    d[i][j] = std::min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        for (int v = 0; v < n; ++v)
            if (d[v][v] < 0) is_neg_cycle = true;
    }
};

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

    int N, M, R;
    cin >> N >> M >> R;

    vector<int> r(R);
    for (int i = 0; i < R; ++i) { cin >> r[i]; --r[i]; }

    Graph<int> g(N);
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        g.add_edge(a - 1, b - 1, c);
        g.add_edge(b - 1, a - 1, c);
    }

    g.FloydWarshall();
    vector<int> idx(R);
    iota(idx.begin(), idx.end(), 0);

    int min_d = g.INF;
    do {
        int d = 0;
        for (int i = 1; i < R; ++i)
            d += g.ShortestDistance(r[idx[i - 1]], r[idx[i]]);
        min_d = min(min_d, d);
    } while (next_permutation(idx.begin(), idx.end()));

    cout << min_d << endl;

    return 0;
}


Measured memory_bytes: 384
N = int(input())
in0 = int(str(N)[0])
Nl = len(str(N))
if (N + 1) % 10 ** (Nl-1) == 0:
    print(9 * (Nl - 1) + in0)
else:
    print(in0 - 1 + (Nl - 1) * 9)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int m = min(X, Y), M = max(X, Y);
    cout << min(A * X + B * Y, min(A * (X - m) + B * (Y - m) + 2 * C * m, 2 * C * M)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string>
#include <algorithm>

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

typedef long long ll;

using namespace std;

const int INF = 1e9;
const double PI=3.14159265358979323846;

int main(){
  int N, field[10][10]={};
  cin >> N;
  for(int i=1; i<=N; i++){
    string s = to_string(i);
    int top = s[0] - '0';
    int end = s[s.size()-1] - '0';
    field[top][end]++;
  }
  ll ans = 0;
  for(int i=1; i<=N; i++){
    string s = to_string(i);
    int top = s[0] - '0';
    int end = s[s.size()-1] - '0';
    ans+=field[end][top];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 24;
int c[200][200];
int t[200][200];
int cost[200][200];
int tim[200][200];

int main(){
  int n, m, K;
  int p, q, r;
  while(cin >> n >> m && (n || m)){
    fill(&cost[0][0], &cost[199][199] + 1, INF);
    fill(&tim[0][0], &tim[199][199] + 1, INF);
    for(int i = 1; i <= m; i++){
      cost[i][i] = tim[i][i] = 0;
      c[i][i] = t[i][i] = 0;
    }

    for(int i = 0; i < n; i++){
      int a, b;
      int d, e;
      cin >> a >> b;
      cin >> d >> e;
      cost[b][a] = min(cost[b][a], d);
      cost[a][b] = min(cost[a][b], d);
      tim[b][a] = min(tim[b][a], e);
      tim[a][b] = min(tim[a][b], e);
    }

    for(int k = 1; k <= m; k++){
      for(int i = 1; i <= m; i++){
	for(int j = 1; j <= m; j++){
	  if(cost[i][j] > cost[i][k] + cost[k][j]){
	    cost[i][j] = cost[i][k] + cost[k][j];
	  }
	  if(tim[i][j] > tim[i][k] + tim[k][j]){
	    tim[i][j] = tim[i][k] + tim[k][j];
	  }
	}
      }
    }
    cin >> K;    
    for(int i = 0; i < K; i++){
      cin >> p >> q >> r;
      if(!r){
	cout << cost[p][q] << endl;
      }else{
	cout << tim[p][q] << endl;
      }
    }
    
  }
  return 0;
}
	
    

Measured memory_bytes: 1336
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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


int main(){
    int n, l;
    cin >> n >> l;
    string s[n];
    rep(i, n) cin >> s[i];
    sort(s, s + n);
    rep(i, n) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    string s; cin >> s;
    int cnt = 0, fore = 0;
    for (auto &c:s) {
        switch(c) {
            case 'a':
                if (cnt < a + b) {
                    cout << "Yes" << '\n';
                    cnt++;
                    break;
                }
            case 'b':
                if (fore < b && cnt < a + b) {
                    cout << "Yes" << '\n';
                    fore++;
                    cnt++;
                    break;
                }
            default:
                cout << "No" << '\n';
        }
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << (a[max_element(a, a + n) - a] - a[min_element(a, a + n) - a]) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll M = 1e9 + 7;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  ll a[m];
  ll sum = 0;
  for (int i = 0; i < m; ++i)
  {
    cin >> a[i];
    sum += a[i];
  }
  if (sum > n)
    cout << "-1";
  else
    cout << n - sum;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}


int dp[1010][1010];
signed main(){
    int h,w;cin>>h>>w;
    int si,sj;cin>>si>>sj;si--,sj--;
    int gi,gj;cin>>gi>>gj;gi--,gj--;

    vector<string>s(h);
    cin>>s;

    rep(i,h)rep(j,w)dp[i][j]=INF;

    using P=pair<int,int>;
    queue<P> que;
    dp[si][sj]=0;
    que.push(P(si,sj));
    int r=0;
    while(!que.empty()){
        // A
        vector<P> vn;
        while(!que.empty()){
            auto [i,j]=que.front();que.pop();
            vn.push_back(P(i,j));
            rep(k,4){
                int ni=i+dx[k],nj=j+dy[k];

                if(0<=ni and ni<h and 0<=nj and nj<w and s[ni][nj]=='.' and dp[ni][nj]==INF){
                    dp[ni][nj]=r;
                    que.push(P(ni,nj));
                }
            }
        }
        r++;
        // B
        for(auto [i,j]:vn){
            for(int ni=max(0,i-2);ni<min(h,i+3);ni++){
                for(int nj=max(0,j-2);nj<min(w,j+3);nj++){
                    if(s[ni][nj]=='.' and dp[ni][nj]==INF){
                        que.push(P(ni,nj));
                        dp[ni][nj]=r;
                    }
                }
            }
        }
    }
    if(dp[gi][gj]==INF) cout<<-1<<endl;
    else cout<<dp[gi][gj]<<endl;
    return 0;
}


Measured memory_bytes: 8836
#include <vector>
#include <algorithm>
#include <iostream>
#include <chrono>
#include<bitset>
#include<deque>
#include <map>
#include<string>
#define vint vector<int>
#define vint2 vector<vint>
#define vchar vector<char>
#define vchar2 vector<vchar> 
#define vchar3 vector<vchar2> 
#define pr pair<int,int>
#define vpr vector<pr>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
typedef  long long int ll;
using namespace std;
//CHAR_BIT	ビット フィールドではない最小変数のビット数。	8
//SCHAR_MIN	signed char 型変数の最小値。	–128
//SCHAR_MAX	signed char 型変数の最大値。	127
//UCHAR_MAX	unsigned char 型変数の最大値。	255 (0xff)
//CHAR_MIN	char 型変数の最小値。 - 128、 / J オプション使用時は 0
//CHAR_MAX	char 型変数の最大値。	127、 / J オプション使用時は 255
//MB_LEN_MAX	多文字定数の最大バイト数。	5
//SHRT_MIN	short 型変数の最小値。	–32768
//SHRT_MAX	short 型変数の最大値。	32767
//USHRT_MAX	unsigned short 型変数の最大値。	65535 (0xffff)
//INT_MIN	int 型変数の最小値。	–2147483647 – 1
//INT_MAX	int 型変数の最大値。	2147483647
//UINT_MAX	unsigned int 型変数の最大値。	4294967295 (0xffffffff)
//LONG_MIN	long 型変数の最小値。	–2147483647 – 1
//LONG_MAX	long 型変数の最大値。	2147483647
//ULONG_MAX	unsigned long 型変数の最大値。	4294967295 (0xffffffff)

int shurui(string str, int id){
	int memo[26] = {};
	string sb = str.substr(id, str.length() - id);
	cerr << "id:" << id << "\t" << sb << endl;
	REP(i, id ){
		char c = str[i];
		int cid = c - 'a';
		cerr << "\t" << c << "," << cid << endl;
		if (memo[cid] == 0){
			if (sb.find(c) != string::npos)memo[cid] = 1;
		}
	}
	int ret = 0;
	REP(i, 26){
		ret += memo[i];
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	//cerr << n << endl;
	string str;
	cin >> str;

	//cerr << str<< endl;
	int ret = 0;
	FOR(i, 1, str.length() - 1){
		ret = max(ret, shurui(str, i));
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long a[200010],b[200010];
bool cmp(long long x,long long y){
	return x>y;
}
int main(){
	int n,t1=0,t2=0,m=0,k;
	long long t,ans=1,temp;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>t;
		if(t>0){
			a[t1]=t;
			t1++;
		}
		else if(t<0){
			b[t2]=t;
			t2++;
		}
		else{
			m++;
		}
	}
	if(k>n-m){
		cout<<"0"<<endl;
		return 0;
	}
	sort(a,a+t1,cmp);
	sort(b,b+t2);
	if(k%2==0){
			if((t1/2+t2/2)*2>=k){
				ans=1;
				int kk=k/2,temp1=0,temp2=0,flag1=0,flag2=0;
				long long ma1,ma2;
				while(kk--){
					flag1=0;flag2=0;
					if(temp1+1<t1){
						ma1=a[temp1]*a[temp1+1];
					}
					else{
						ma1=0;
					}
					if(temp2+1<t2){
						ma2=b[temp2]*b[temp2+1];
					}
					else{
						ma2=0;
					}
					if(ma1>=ma2){
						ma1=ma1%1000000007;
						ans=(ans*ma1)%1000000007;
						temp1+=2;
					}
					else{
						ma2=ma2%1000000007;
						ans=(ans*ma2)%1000000007;
						temp2+=2;
					}
				}
				ans=(ans+1000000007)%1000000007;
				cout<<ans<<endl;
			}
			else{
				for(int i=0;i<t1;i++){
					ans=(ans*a[i])%1000000007;
				}
				for(int i=0;i<t2;i++){
					ans=(ans*b[i])%1000000007;
				}
				ans=(ans+1000000007)%1000000007;
				cout<<ans<<endl;
			}
	}
	else{
		if(t1==0){
			if(m==0){
				for(int i=t2-1;i>=t2-k;i--){
					ans=(ans*b[i])%1000000007;
				}
				ans=(ans+1000000007)%1000000007;
				cout<<ans<<endl;
			}
			else{
				cout<<"0"<<endl;
			}
		}
		else{
			if(((t1-1)/2+t2/2)*2>=k-1){
				ans=a[0];
				int kk=(k-1)/2,temp1=1,temp2=0;
				long long ma1,ma2;
				while(kk--){
					if(temp1+1<t1){
						ma1=a[temp1]*a[temp1+1];
					}
					else{
						ma1=0;
					}
					if(temp2+1<t2){
						ma2=b[temp2]*b[temp2+1];
					}
					else{
						ma2=0;
					}
					if(ma1>=ma2){
						ma1=ma1%1000000007;
						ans=(ans*ma1)%1000000007;
						temp1+=2;
					}
					else{
						ma2=ma2%1000000007;
						ans=(ans*ma2)%1000000007;
						temp2+=2;
					}
				}
				ans=(ans+1000000007)%1000000007;
				cout<<ans<<endl;
			}
			else{
				for(int i=0;i<t1;i++){
					ans=(ans*a[i])%1000000007;
				}
				for(int i=0;i<t2;i++){
					ans=(ans*b[i])%1000000007;
				}
				ans=(ans+1000000007)%1000000007;
				cout<<ans<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5132
#!/usr/bin/env python3
def main():
    import sys
    from itertools import combinations_with_replacement

    input = sys.stdin.readline

    N, M, Q = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(Q)]

    ans = 0
    for pattern in combinations_with_replacement(range(1, M + 1), N):
        res = 0
        pattern = list(pattern)
        for a, b, c, d in lst:
            if pattern[b - 1] - pattern[a - 1] == c:
                res += d
        ans = max(ans, res)

    print(ans)


main()


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N);
  for (int i = 0; i < N; i++) {
      vector<int> tmp(D);
      for (int j = 0; j < D; j++) {
          cin >> tmp[j];
      }
      X[i] = tmp;
  }

    int result = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {  
            int tmp = 0;
            for (int k = 0; k < D; k++) {
                tmp += pow(X[i][k] - X[j][k], 2);
            }
            if (floor(sqrt((double)tmp)) == ceil(sqrt((double)tmp))) {
                result++;
            }
        }
    }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if(N % 1110 < 10 || (N % 1000) % 111 == 0){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int x,y; cin >> x >> y;
    cout << x + y/2 << endl;
}

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

int n1,n2;

struct Kruskal{

  struct UnionFind{
    int n;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    int find(int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(int x,int y){
      return find(x)==find(y);
    }
    void unite(int x,int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  struct edge{
    int from,to,cost,used;
    edge(){}
    edge(int from,int to,int cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int sz):n(sz){}
  
  void add_edge(int u,int v,int c){
    edges.emplace_back(u,v,c);
  }

  void input(int m,int offset=0){
    int a,b,c;
    for(int i=0;i<m;i++){
      cin>>a>>b>>c;
      add_edge(a+offset,b+offset,c);
    }
  }
  
  int build(){
    sort(edges.begin(),edges.end());
    UnionFind uf(n+1);
    int res=0;
    for(auto &e:edges){
      if(!uf.same(e.from,e.to)){
        int f1=0,f2=0;
        rep(i,n1)if(uf.same(e.from,i))f1++;
        rep(i,n1)if(uf.same(e.to,i))f2++;
        if(!f1||!f2)res+=e.cost;
        uf.unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};
int main(){
  while(cin>>n1>>n2,n1){
    Kruskal K(n1+n2);
    rep(i,n1){
      rep(j,n2){
        int x;
        cin>>x;
        if(x)K.add_edge(i,j+n1,x);
      }
    }
    for(int i=0;i<n2;i++){
      for(int j=i+1;j<n2;j++){
        int x;
        cin>>x;
        if(x)K.add_edge(i+n1,j+n1,x);
      }
    }
    cout<<K.build()<<endl;
  }
}


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

struct UnionFind {
    vector<int> par; 
    vector<int> size;

    UnionFind(int N) : par(N + 1), size(N + 1, 1) {
        for(int i = 0; i <= N; i++) 
          par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    int siz(int x){
      return size[root(x)];
    }

    void unite(int x, int y) { 
        int rx = root(x);
        int ry = root(y); 
        if (rx == ry) return;
        if(size[rx] < size[ry]){
          size[ry] += size[rx];
          par[rx] = ry;
        } else{
          size[rx] += size[ry];
          par[ry] = rx;
        }
    }

    bool is_same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> P(n);
    rep(i, n){
        int p; cin >> p;
        P[i] = p-1;
    }
    UnionFind uf(n);
    rep(i, m){
        int x, y; cin >> x >> y; x--, y--;
        uf.unite(x,y);
    }

    int res = 0;
    rep(i, n){
        int num = P[i];
        if(uf.is_same(num, P[num])) res++;
    }
    cout << res << ln;
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

//abc103
//最小公倍数 -1のMODでよさそう
int main() {

    ll a,b,c,d;
    cin >> a >> b >> c >> d;


    if(abs(c-a) <= d)
    {
        cout << "Yes" << endl;
    }
    else if(abs(b-a) <= d && abs(c-b) <= d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

char a[60][60];

int h,w;
int dx[8]= {1,-1,0,0,-1,1,-1,1};
int dy[8]= {0,0,1,-1,1,1,-1,-1};
int main()
{

    scanf("%d%d",&h,&w);
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            cin >> a[i][j];
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
        {
            if(a[i][j]=='.')
            {
                int cnt=48;
                for(int ii=0; ii<8; ii++)
                {
                    if(a[i+dx[ii]][j+dy[ii]]=='#')
                        cnt++;
                }
                a[i][j]=cnt;
            }
        }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
            cout << a[i][j];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
# 制約
i = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            ans = a * 500 + b * 100 + c * 50
            if  ans == X:
                i += 1
print(i)


Measured memory_bytes: 3316
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
from decimal import *

H, W = MAP()
A = [input() for _ in range(H)]
check = [[-1]*W for _ in range(H)]
q = deque()

for y in range(H):
    for x in range(W):
        if A[y][x] == "#":
            check[y][x] = 0
            q.append((y, x, 0))

dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]

while q:
    y, x, cnt = q.popleft()
    for i in range(4):
        ny = y + dy[i]
        nx = x + dx[i]
        if 0 <= ny < H and 0 <= nx < W:
            if check[ny][nx] == -1 or cnt+1 < check[ny][nx]:
                check[ny][nx] = cnt + 1
                q.append((ny, nx, cnt+1))


print(max([max(c) for c in check]))

Measured memory_bytes: 186248
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.1415926535897932384626433832792884197169399375105820974944;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{


ll x;
cin>>x;
ll ref[1001];
for(int i=0;i<1001;i++)
ref[i]=pow(i,5);

ll i=0;
ll k;
bool neg=false;
while(true)
{ 

	ll b=x-ref[i];
	if(b>=0)
	neg=true;
	else
	neg=false;
	b=abs(b);
	bool f=false;
	for(ll j=0;j<=(ll)sqrt(b);j++)
	{
		ll p=ref[j];
		if(p>b)
		break;
		
		if(p==b)
		{
			k=j;
			f=true;
			break;
		}
	}
	
	if(f)
	break;
	i++;
}

if(neg==true)
k*=(-1);

cout<<i<<" "<<k;





}return 0;}


Measured memory_bytes: 4088
N,D=map(int, input().split())
d=D**2
ans=0
for maimelkm in range(N):
	x,y=map(int, input().split())
	if x**2+y**2<=d:
		ans+=1


print(ans)


# 2darray [[0] * 4 for i in range(3)]
# import itertools

Measured memory_bytes: 9180
N = int(input())
X = [int(x) for x in input().split()]
hp = []
dis = 0

for i in range(min(X), max(X) + 1):
  hp.append(dis)
  dis = 0
  for j in X:
    dis += (i - j) ** 2
if len(hp) == 1:
  print(0)
else:
  hp.remove(0)
  print(min(hp))

Measured memory_bytes: 3060
N = int(input())
As = list(map(int,input().split()))

#print(N,As)

tAs = []
for i,A in enumerate(As):
	tAs.append((A,i+1))
	
tAs = sorted(tAs, key=lambda x: x[0])

for tA in tAs:
	print(tA[1],end=" ")
print()

Measured memory_bytes: 63020
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 1
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	r := getNextInt(scanner)
	if n >= 10 {
		fmt.Fprintln(writer, r)
		return
	}
	fmt.Fprintln(writer, r+100*(10-n))
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))

int main()
{
ll i,j,k,l,m,n,q,p1,p2,q1,q2,x,ans,l1,l2,l3,l4,l5,l6,l7,l8;

cin >> n  >> m >> q;

ll s[n+10];
ll t[m+10];

for(i=0;i<n;i++)cin >> s[i];
for(i=0;i<m;i++)cin >> t[i];

while(q--)
{
    cin >> x ;

    q1 = upper_bound(s,s+n,x)-s;
    if(q1)q1--;
    q2 = upper_bound(s,s+n,x)-s;
    if(q2==n)q2--;

    p1 = upper_bound(t,t+m,x)-t;
    if(p1)p1--;
    p2 = upper_bound(t,t+m,x)-t;
    if(p2==m)p2--;

    q1 = s[q1] , q2 = s[q2] , p1 = t[p1] , p2 = t[p2];

    l1 = abs(x-q1) + abs(q1-p1);
    l2 = abs(x-q1) + abs(q1-p2);
    l3 = abs(x-q2) + abs(q2-p1);
    l4 = abs(x-q2) + abs(q2-p2);

    l5 = abs(x-p1) + abs(q1-p1);
    l6 = abs(x-p2) + abs(q1-p2);
    l7 = abs(x-p1) + abs(q2-p1);
    l8 = abs(x-p2) + abs(q2-p2);

    ans = min({l1,l2,l3,l4,l5,l6,l7,l8});

    cout << ans << endl;


}

}


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

int main(){
	int n,i,count=0,min=100000;
  	long long a;
  	cin>>n;
  	for(i=0;i<n;i++){
		cin>>a;
      	for(int j=0;a%2==0;j++){
          count++;
          a/=2;
        }
		if(count<min){
			min=count;
        }
      	count=0;
    }
	
  	cout<<min<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
int M;
int U[20], V[20];

int S[50];
int par[50];
LL dp[50];
VI G[50];


void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int a, b;
	scanf("%d%d", &a, &b);
	a--; b--;
	G[a].push_back(b);
	G[b].push_back(a);
    }
    scanf("%d", &M);
    REP (i, M) {
	int v, u;
	scanf("%d%d", &u, &v);
	u--; v--;
	S[u] ^= 1<<i;
	S[v] ^= 1<<i;
    }

    VI ord;
    ord.push_back(0);
    REP (i, N) {
	int v = ord[i];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    ord.push_back(*e);
	}
    }
    REP (i, N) {
	int v = ord[N-1-i];
	EACH (e, G[v]) if (*e != par[v]) {
	    S[v] ^= S[*e];
	}
    }

    LL ans = 0;
    REP (s, 1<<M) {
	REP (i, N) {
	    int v = ord[N-1-i];
	    dp[v] = 1;
	    EACH (e, G[v]) if (*e != par[v]) {
		if (s & S[*e]) {
		    dp[v] *= dp[*e];
		} else {
		    dp[v] *= 2 * dp[*e];
		}
	    }
	}

	if (__builtin_popcount(s) & 1) {
	    ans -= dp[0];
	} else {
	    ans += dp[0];
	}
    }

    printf("%lld\n", ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256