akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <set>
#include <cmath>

#include <type_traits>

#define EPS 1e-10
#define R 1

typedef std::pair<double,double> Vec;

Vec operator+(const Vec& lhs, const Vec& rhs){
	return std::make_pair(lhs.first+rhs.first, lhs.second+rhs.second);
}

Vec operator-(const Vec& lhs, const Vec& rhs){
	return std::make_pair(lhs.first-rhs.first, lhs.second-rhs.second);
}

Vec operator*(const double& lhs, const Vec& rhs){
	return std::make_pair(lhs*rhs.first, lhs*rhs.second);
}


double dist(const Vec& lhs, const Vec& rhs){
	return std::sqrt( std::pow(lhs.first-rhs.first,2)
			+ std::pow(lhs.second-rhs.second,2) );
}

bool inCircle(const Vec& pt){
	return ( std::pow(pt.first,2) + std::pow(pt.second,2) <= std::pow(R,2) + EPS);
}

bool inCircle(const Vec& circ, const Vec& pt){
	return inCircle(pt - circ);
}


std::pair<Vec,Vec> getCross(const Vec& lhs, const Vec& rhs){
	double d = dist(lhs, rhs);
	double alpha = std::acos(d/(2*R));
	double theta = std::atan2(lhs.second-rhs.second, lhs.first-rhs.first );


	return (std::make_pair(
				rhs+R*std::make_pair(
					std::cos(theta+alpha),
					std::sin(theta+alpha)
					),
				rhs+R*std::make_pair(
					std::cos(theta-alpha),
					std::sin(theta-alpha)
					)
			      )
	       );
}

bool inSquare(const Vec& pt){
	return ( (0<=pt.first && pt.first<=10) && (0<=pt.second && pt.second<=10) );
}

int main(void){
	using namespace std;

	unsigned int N;
	cin >> N;
	for(; N!=0; cin >> N){
		vector<pair<double,double>> v;
		v.reserve(N);
		for (int i=1; i<=N; i++){
			char sep;
			double x,y;
			cin >> x >> sep >> y;

			v.push_back(make_pair(x,y));
		}

		if(N==1){
			cout << 1 << endl;
			continue;
		}

		vector<bool> permTable(N);
		fill(permTable.begin()+2, permTable.end(), true);
		unsigned int count = 1;
		do {
			vector<unsigned int> tmp;
			tmp.reserve(2);
			for (unsigned int i = 0; i < N; ++i) {
				if (!permTable[i]) {
					tmp.push_back(i);
				}
			}

			if( dist(v[tmp[0]],v[tmp[1]]) <=2*R+EPS ){
				auto cross = getCross(v[tmp[0]],v[tmp[1]]);
				unsigned int first = 2;
				unsigned int second = 2;
				for(auto itr=v.begin(); itr!=v.end(); itr++){
					if(*itr==v[tmp[0]] || *itr==v[tmp[1]]){
						continue;
					}
					else if(inCircle(*itr, cross.first)){
						first++;
					}
					else if(inCircle(*itr, cross.second)){
						second++;
					}
				}
				if(!inSquare(cross.first)){
					first = 0;
				}
				if(!inSquare(cross.second)){
					second = 0;
				}
				count = std::max(count, std::max(first, second));
			}
		} while (std::next_permutation(permTable.begin(), permTable.end()));
		cout << count << endl;
	}
}

Measured memory_bytes: 1356
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int n;
int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}


void solve() {
   int n;
   cin >> n;
   int a[n],b[n],c[n-1];
   for(int i = 0;i < n;i++){
       cin >> a[i];
       a[i]--;
   }
   for(int i = 0;i < n;i++){
       cin >> b[i];
   }
   for(int i = 0;i< n-1;i++){
       cin >> c[i];
   }
    ll ans = 0;
   for(int i = 0;i < n;i++){
       if(a[i]-a[i+1] == -1 && i != n-1){
           ans+=b[a[i]]+c[a[i]];
       }else{
           ans+=b[a[i]];
       }
   }
   cout << ans << endl;
}


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}


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

int main()
{
    int N, d;
    bool heights[110] = {0};
    cin >> N;
    REP(i, N)
    {
        cin >> d;
        heights[d] = true;
    }
    cout << count(&heights[0], &heights[101], 1) << endl;

    return 0;
}


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

int main()
{
	int N = 0, K = 0, Q = 0;
	std::cin >> N >> K >> Q;

	std::vector<int> A(N, K-Q);
	if (K > Q)
	{
		std::vector<std::string>ans(N, "Yes");

		for (int i = 0; i < Q; i++)
		{
			int a = 0;
			std::cin >> a;
		}

		for (int i = 0; i < N; i++)
		{
			std::cout << ans[i] << std::endl;
		}
		return 0;
	}

	std::vector<std::string>ans(N, "No");

	for (int i = 0; i < Q; i++)
	{
		int a = 0;
		std::cin >> a;

		A[a - 1]++;
		if (A[a - 1] > 0)
		{
			ans[a - 1] = "Yes";
		}
	}

	for (int i = 0; i < N; i++)
	{
		std::cout << ans[i] << std::endl;
	}

	return 0;
}


Measured memory_bytes: 2432
#include "bits/stdc++.h"

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

using namespace std;
const int INF = 1 << 30;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        //for (int i = 0; i < n; i++)par[i] = i;
        for (int i = 0; i < n; i++)par[i] = -1;
    }

    int root(int x) {
        //if (par[x] == x) return x;
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false; // 同じ木に属するのでmergeしない（そのまま）
        if (par[x] > par[y]) swap(x, y); // merge technique（-nがその木の要素数)
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)]; // -nがノード数なのでマイナスかける
    }
};

int main() {
	int N, M; cin >> N >> M;
    UnionFind uf(N);
    rep(i, M) {
        int x, y, z; cin >> x >> y >> z;
        uf.merge(x - 1, y - 1);
    }
    map<int, int> mp;
    rep(i, N)mp[uf.root(i)] = 1;
    cout << mp.size();
}

Measured memory_bytes: 5376
from operator import itemgetter
N, M = map(int, input().split())
H = list(map(int, input().split()))
A = []
B = []

for i in range(M):
    A0, B0 = map(int, input().split())
    A.append(A0)
    B.append(B0)

C = [[i] for i in range(N)]
HC = [[H[i]] for i in range(N)]
for i in range(M):
    C[A[i]-1].append(B[i]-1)
    C[B[i]-1].append(A[i]-1)
    HC[A[i]-1].append(H[B[i]-1])
    HC[B[i]-1].append(H[A[i]-1])
   
cnt = 0    
for i in range(N):
    C0 = []
    HC0 = []
    for cc,hcc in sorted(zip(C[i],HC[i]),key=itemgetter(1)):
       C0.append(cc)
       HC0.append(hcc)
    C[i] = C0
    HC[i] = HC0
    if C[i][-1] == i:
        cnt += 1
   
print(cnt)

Measured memory_bytes: 65412
fun main() {
    abc140d()
}

fun abc140d() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val num = mutableListOf<Int>()
    var count = 0
    var p = ' '
    for (e in readLine()!!) {
        if (p != e) {
            p = e
            if (count > 0) num.add(count)
            count = 1
        } else {
            count++
        }
    }
    num.add(count)
    var precious = n - num.size
    if (num.size > k * 2) {
        precious += k * 2
    } else {
        precious = n - 1
    }
    println(precious)
}

Measured memory_bytes: 40184
s = input()
char = [0, 0, 0]
for i in range(len(s)):
    if s[i] == "a":
        char[0] += 1
    elif s[i] == "b":
        char[1] += 1
    else:
        char[2] += 1
char.sort()
char[2] -= char[0]
char[1] -= char[0]
char[0] = 0
if char[1]<=1 and char[2]<=1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 39536
/*
f[q[i]][j]=f[q[i-1]][j]+abs(q[i]-q[i-1])
f[q[i]][q[i-1]]=min{f[q[i-1]][j]+abs(q[i]-j)}
*/

#include<bits/stdc++.h>
using namespace std;
#define MAXN 200010
#define INF 1LL<<60
typedef long long ll;
template<typename T>
void read(T &x)
{
	char ch=getchar();
	for (x=0;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
}
int n,q,a,b;
int ope[MAXN];
ll seq[MAXN],tmp;
namespace Segtree
{
	struct Node{
		ll mn,add;
	};
	struct Tree{
		Node tree[MAXN<<2];
		void modify_add_Node(int node,ll val)
		{
			tree[node].mn+=val;
			tree[node].add+=val;
		}
		void pushup(int node)
		{
			tree[node].mn=min(tree[node<<1].mn,tree[node<<1|1].mn);
		}
		void pushdown(int node)
		{
			if (tree[node].add)
			{
				modify_add_Node(node<<1,tree[node].add);
				modify_add_Node(node<<1|1,tree[node].add);
				tree[node].add=0;
			}
		}
		void build(int l,int r,int node)
		{
			if (l==r)
			{
				tree[node].mn=seq[l];
				tree[node].add=0;
				return;
			}
			int mid=(l+r)>>1;
			build(l,mid,node<<1);
			build(mid+1,r,node<<1|1);
			pushup(node);
		}
		void modify_add(int L,int R,int l,int r,int node,int val)
		{
			if (r<L||R<l) return;
			if (L<=l&&r<=R)
			{
				modify_add_Node(node,val);
				return;
			}
			pushdown(node);
			int mid=(l+r)>>1;
			modify_add(L,R,l,mid,node<<1,val);
			modify_add(L,R,mid+1,r,node<<1|1,val);
			pushup(node);
		}
		void modify_min(int pos,int l,int r,int node,ll val)
		{
			if (l==r)
			{
				tree[node].mn=min(tree[node].mn,val);
				return;
			}
			pushdown(node);
			int mid=(l+r)>>1;
			if (pos<=mid) modify_min(pos,l,mid,node<<1,val);
			else modify_min(pos,mid+1,r,node<<1|1,val);
			pushup(node);
		}
		ll query_min(int L,int R,int l,int r,int node)
		{
			if (r<L||R<l) return INF;
			if (L<=l&&r<=R) return tree[node].mn;
			pushdown(node);
			int mid=(l+r)>>1;
			return min(query_min(L,R,l,mid,node<<1),query_min(L,R,mid+1,r,node<<1|1));			
		}
		ll dfs(int l,int r,int node)
		{
			if (l==r) return tree[node].mn+l;
			pushdown(node);
			int mid=(l+r)>>1;
			return min(dfs(l,mid,node<<1),dfs(mid+1,r,node<<1|1));
		}
	};
}
Segtree::Tree T1,T2;
int main()
{
	read(n),read(q),read(a),read(b);
	ope[0]=a;
	for (int i=1;i<=q;i++)
		read(ope[i]);
	for (int i=1;i<=n;i++)
		seq[i]=INF;
	seq[b]=-b;
	T1.build(1,n,1);
	seq[b]=b;
	T2.build(1,n,1);
	for (int i=1;i<=q;i++)
	{
		tmp=min(T1.query_min(1,ope[i],1,n,1)+ope[i],T2.query_min(ope[i],n,1,n,1)-ope[i]);
		T1.modify_add(1,n,1,n,1,abs(ope[i]-ope[i-1]));
		T2.modify_add(1,n,1,n,1,abs(ope[i]-ope[i-1]));
		T1.modify_min(ope[i-1],1,n,1,tmp-ope[i-1]);
		T2.modify_min(ope[i-1],1,n,1,tmp+ope[i-1]);
	}
	
	printf("%lld",T1.dfs(1,n,1));
	return 0;
}

Measured memory_bytes: 23552
x1,y1,x2,y2 = map(int,input().split())
x3 = x2 - y2 + y1
y3 = x2 - x1 + y2
x4 = x3 - y3 + y2
y4 = x3 - x2 + y3

print(x3,y3,x4,y4)

Measured memory_bytes: 2940
n = input()
n_list = []
for i in n:
    n_list.append(i)
if n_list[1]==n_list[2]==n_list[0]:
    print("Yes")
elif n_list[2]==n_list[3]==n_list[1]:
    print("Yes")
elif n_list[0]==n_list[1]==n_list[2]==n_list[3]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<i64>();
    let mut ans = 1;
    for i in 1..n + 1 {
        ans *= i;
        ans %= 1000_000_000 + 7;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
//****** @author mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define endl "\n"
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll fast_pow(ll x, ll y, ll p);


void solve() {
    ll n,m;cin>>n>>m;
    vector<ll> v[n+1];
    map<ll,ll> mp;
    for(ll i=0;i<m;i++){
        ll prob;cin>>prob;
        string s;cin>>s;
        if(s=="AC"){
            mp[prob]=1;
            v[prob].EB(1);
        } else{
            v[prob].EB(0);
        }
    }
    ll ac=0,pen=0;
    for(ll i=1;i<=n;i++){
        if(mp[i]==1){
            ac++;
            for(auto x:v[i]){
                if(x==1)break;
                pen++;
            }
        }
    }
    cout<<ac<<" "<<pen<<endl;
}

int main()
{
    IOS;
    ll test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}
ll fast_pow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

Measured memory_bytes: 12032
n=int(input())
import math
import collections
mod=10**9+7
fac=math.factorial(n)
ans=[0]*(n+1)
ans[0]=ans[1]=1
i=2
while i*i<=n:
    j=2
    while i*j<=n and ans[i]==0:
        ans[i*j]=1
        j+=1
    i+=1
v=[]
for i in range(n+1):
    if ans[i]==0:
        v.append(i)
v.sort()
num=[]
for k in v:
    while fac%k==0:
        fac//=k
        num.append(k)
data=collections.Counter(num)
cnt=1
for i,j in data.items():
    cnt*=j+1
print(cnt%mod)
    


Measured memory_bytes: 3316
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        s: chars,
        t: chars,
    }
    let mut u = s;
    u.sort();
    let mut v = t;
    v.sort_by(|a, b| b.cmp(a));

    let ans = if u < v {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
using System;
using System.Text;

class aizu_judge
{
    static void Main(string[] args)
    {
        int n = Convert.ToInt32(Console.ReadLine());
        StringBuilder sb = new StringBuilder();

        for(int i = 1; i <= n;i++)
        {
            if (i % 3 == 0 || i.ToString().Contains("3"))
                sb.Append(sb.Equals(string.Empty) ? i.ToString() : " " + i.ToString());
        }

        Console.WriteLine(sb.ToString());
    }
}

Measured memory_bytes: 9936
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
const str = input[0] + input[0];
let substring = input[1];
let regexp = new RegExp(substring);

if (regexp.test(str)) {
     console.log('Yes');
    } else {
     console.log('No');
    }



Measured memory_bytes: 19192
import sys
from io import StringIO
import unittest
from collections import deque

def resolve():
    n, k = map(int, input().split())

    a_s = list(map(int, input().split()))
    # 添え字は0始まり、町番号は1始まりなので、添え字0を足し込んで値を合わせる
    a_s.insert(0, 0)

    # 到達済みフラグ(添え字0は使わないので+1
    # arrived = [False for i in range[n+1]]

    # 町1からの距離(添え字0は使わないので+1
    distance = [-1 for i in range(n+1)]
    # 初期値：町1は町1との距離0
    distance[1] = 0

    # queを作成
    que = deque()
    que.append(1) # 初期値：町1

    # 答えを求めるために必要な情報を種痘
    while len(que) is not 0:

        now = que.pop()
        next = a_s[now]
        if distance[next] is not -1:
            # 循環が発生
            # 町1からループが発生する町までの距離
            # 例：1->6->2->5->3->2->5->2->5->3 ・・・というパターンの場合は「2」。2->5->3->2がループなので。
            no_loop = distance[next]
            # ループが発生する町(ループ始点)からループが発生する町(ループ終点)までの距離
            loop = distance[now] - distance[next]

        else:
            # 新しい街に到達した場合
            # 町1からの距離を設定
            distance[next] = distance[now] + 1
            # 次のとび先をキューに追加
            que.append(next)

    # 答えを出力(方程式の信頼性はトレース.xlsxを見ると良い。多分問題ない・・!
    if k <= no_loop:
        print(distance.index(k))
    else:
        print(distance.index((k - no_loop) % (loop + 1) + no_loop))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
#     def test_入力例_1(self):
#         input = """4 5
# 3 2 4 1"""
#         output = """4"""
#         self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 727202214173249351
6 5 2 5 3 2"""
        output = """2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

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

int main() {
	int n;
	cin >> n;
	int a[n];
	int flag = 0;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			if((a[i]%3!=0)&&(a[i]%5!=0)){
				cout << "DENIED" << endl;
				flag++;
				break;
			}
		}
	}
	if(flag==0) cout << "APPROVED" << endl;
	return 0;
}

Measured memory_bytes: 256
def main():
    x,n=map(int,input().split())
    p=list(map(int,input().split()))
    if n==0:
        print(x)
        return
    i=0
    while True:
        if x+i not in p:
            print(x+i)
            break
        if x-i not in p:
            print(x-i)
            break
        i-=1
if __name__ == "__main__":
    main()

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; int cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   int N; cin >> N;
   vec<int> a(N);
   REP(i, 0, N) {
      cin >> a[i];
   }

   bool flag = false;
   REP(i, 0, N) {
      if (a[i] % 2 == 1) {
         flag = true;
      }
   }

   if (flag) {
      cout << "first" << endl;
   } else {
      cout << "second" << endl;
   }

   return 0;
}


Measured memory_bytes: 1024
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
 
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(m),c(m);
  rep(j,m) cin >> b[j] >> c[j];
  
  priority_queue<pair<int,int> > q;
  
  rep(i,n) q.push(make_pair(a[i],1));
  rep(j,m) q.push(make_pair(c[j],b[j]));
  
  long long ans;
  
  rep(i,n){
    pair<int,int> p = q.top();
    q.pop();
    ans += p.first;
    if(p.second > 1){
      p.second--;
      q.push(p);
    }
  }
  
  cout << ans << endl;
}


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

public class Main{

	public static void main(String[] args) throws IOException {
		int N = readInt(), X = readInt();
		PriorityQueue<Integer> pq = new PriorityQueue<>();
		for(int i = 1; i<=N; i++) pq.add(readInt());
		int cnt = 0;
		while(pq.size() > 1) {
			if(pq.peek() > X) {println(cnt); exit();}
			X -= pq.poll();
			cnt++;
		}
		if(!pq.isEmpty() && pq.peek() == X) println(N);
		else println(N-1);
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e17;
int n;
ll a[55], ans, ma, mi;
bool check()
{
    for (int i = 0; i < n; i++) {
        if (a[i] >= n) return false;
    }
    return true;
}
int max_id()
{
    ll ma = 0;
    int maxi = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] > ma) {
            ma = a[i];
            maxi = i;
        }
    }
    return maxi;
}
int min_id()
{
    ll mi = INF;
    int mini = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] < mi) {
            mi = a[i];
            mini = i;
        }
    }
    return mini;
}
int main()
{
    scanf("%d", &n);
    ma = 0;
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        ma = max(ma, a[i]);
        mi = min(mi, a[i]);
    }
    if (ma < n * (n + 1)) {
        while (!check()) {
            int t = max_id();
            for (int i = 0; i < n; i++) {
                if (i != t) a[i]++;
                else a[i] -= n;
            }
            ans++;
        }
        printf("%lld\n", ans);
    }
    else {
        int t1 = max_id(), t2 = min_id();
        while (a[t1] - a[t2] > 100) {
            //printf("max: a[%d] = %lld, min: a[%d] = %lld\n", t1, a[t1], t2, a[t2]);
            ll x = (a[t1] - a[t2]) / (n + 1);
            a[t1] -= n * x;
            a[t2] += x;
            for (int i = 0; i < n; i++) {
                if (i != t1 && i != t2) a[i] += x;
            }
            t1 = max_id(), t2 = min_id();
            ans += x;
        }
        t2 = min_id();
        ll st = a[t2] - n;
        for (int i = 0; i < n; i++) {
            a[i] -= st;
        }
        ans += st * n;
        while (!check()) {
            int t = max_id();
            for (int i = 0; i < n; i++) {
                if (i != t) a[i]++;
                else a[i] -= n;
            }
            ans++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

#define NIL -1
#define A 101
#define N 2000



static const int MAX=500;
static const int INFTY=(1<<21);

int key[A], M[A][A], p[A], S[A], d[A], n, sum;

void MSTPrim(){
  int i, v, u;
  for(u=0;u<n;u++){
    key[u]=INFTY;
    p[u]=NIL;
    d[u]=INFTY;
  }
 
  key[0]=0;
  
  while(1){
    int minv=INFTY;
    u=NIL;
    for(i=0; i<n; i++){
      if(key[i]<minv && p[i]==NIL){
	u=i;
	minv=key[i];
      }
    }
    if(u==NIL) break;
    p[u]=1;
    d[u]=key[u];
    for(v=0;v<n;v++){
      if(p[v]!=1 && key[u]+M[u][v]<key[v]){
	key[v]=key[u]+M[u][v];
      }
    }
  }
}


int main(){
  int i, j, u, k, v, c;
  scanf("%d", &n);
  for (i=0; i<n; i++){
    for (j=0; j<n; j++){
      M[i][j]=INFTY;
    }
  }
  for (i=0; i<n; i++){
    scanf("%d %d", &u, &k);
    for (j=0; j<k; j++){
      scanf("%d %d", &v, &c);
      M[u][v]=c;
    }
  }
  sum = 0;
  MSTPrim();
  for (i=0; i<n; i++){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
ll n, cnt = 0;

void rec(ll x){
	if(x > n) return;
	ll y = x;
	int t3 = 0, t5 = 0, t7 = 0;
	while(y){
		if(y % 10 == 3) t3++;
		else if(y % 10 == 5) t5++;
		else if(y % 10 == 7) t7++;
		y /= 10;
	}
	if(t3 && t5 && t7) ++cnt;
	rec(x * 10 + 3);
	rec(x * 10 + 5);
	rec(x * 10 + 7);
}
void solve()
{
	cin >> n;
	rec(0);
	cout << cnt; 
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
package main

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

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}

func main() {
	s := nextString()

	win := 15 - len(strings.Replace(s, "o", "", -1))

	if win >= 8 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


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

int main() {
	int n; cin >> n;
	vector<int> d(n); for (auto&& x : d)cin >> x;

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)continue;
			ans += d[i] * d[j];
		}
	}
	cout << ans / 2 << endl;

	return 0;
}

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

typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


int main() {
    int D,G; cin >> D >> G;
    vector<pair<ll,ll>> score(D+1);
    REP(i,D){
        int p,c; cin >> p >> c;
        score[i] = {p,c};
    }
    
    int ans = INF;
    REP(bit, 1<<D){
        vector<int> S(D,0);
        int sum = 0;
        int cnt = 0;

        REP(i,D){
            if(bit & (1<<i)){
                S[i] = 1;
                sum += score[i].first*(i+1)*100 + score[i].second;
                cnt += score[i].first;
            }
        }

        if(G<=sum){
            ans = min(ans, cnt);
            continue;
        }

        REPR(i,D-1){
            if(S[i]==1) continue;
            REP(j,score[i].first){
                sum += 100*(i+1);
                cnt++;


                if(G<=sum){
                    ans = min(ans, cnt);
                    continue;
                }
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
use std::io::stdin;use std::collections::HashMap;fn main() {let mut st = String::new();stdin().read_line(&mut st).unwrap();let mut st = String::new();stdin().read_line(&mut st).unwrap();let a:Vec<usize> = st.split_whitespace().map(|x| x.parse().unwrap()).collect();let mut dic:HashMap<&usize, i64> = HashMap::new();for i in a.iter() {let count = dic.entry(&i).or_insert(0);*count += 1;};let mut result:i64 = 0;for (x, y) in dic.iter() {result += y*(y-1)/2;}for i in a.iter() {println!("{}", result-(dic[&i]-1));}}

Measured memory_bytes: 18380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
 
int main(void){
    int n;
    cin >> n;
 
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        if (i%2 == 1 && a%2 == 1) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int i = 1;
	int j = 1;
	string s = "No";

	for (i = 1; i <= 9; ++i) {
		for (j = 1; j <= 9; ++j) {
			if (N == i * j) {
				s = "Yes";
				break;
			}
		}
	}
	cout << s << endl;
}

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

int main(){
    int a;
    int b;
    cin >> a >> b;
    if((a * b) % 2 == 0){
        cout << "Even" << endl;
         }
    if((a * b) % 2 != 0){
        cout << "Odd" << endl;
    }
    return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int count=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N-2;i++){
    if(S[i]=='A'){
      if(S[i+1]=='B'){
        if(S[i+2]=='C'){
          count++;
        }
      }
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
function Main(input) {
  const numbers = input.split('').map(n => Number(n));
  if (numbers[0] === 9 || numbers[1] === 9) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.charAt(0) == '9' || s.charAt(1) == '9'){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35484
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    char b, enki1[2] = {'A', 'C'}, enki2[2] = {'T', 'G'};
    cin >> b;

    for(int i=0;i<2;i++){
        if(b == enki1[i])
            cout << enki2[i];
        if(b == enki2[i])
            cout << enki1[i];
    }

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int n = s.length(), ans=s.length();
  bool all=true;
  for(int i=0;i<n;i++) if(s[0]!=s[i]) all=false;
  if(all) ans = 0;
  
  for(int i=0;i<n;i++){
    string b(s);
    char c = s[i];
    for(int j=1;j<n;j++){
      for(int k=0;k<n-j;k++){
        if(s[k]==c) s[k]=c;
        else if(s[k+1]==c) s[k]=c;
        else s[k] = s[k];
      }
      bool flag = true;
      for(int k=0;k<n-j;k++){
        if(s[k]!=c){ flag = false; break;}
      }
      //cout << s << endl;
      if(flag){ ans = min(ans,j); break;}
    }
    for(int j=0;j<n;j++) s[j] = b[j]; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $n, $k);
$array = explode(' ', trim(fgets(STDIN)));
sort($array);
$survive = $n - $k;
$attnum = 0;
for($i = 0; $i < $survive; $i++){
    $attnum += $array[$i];
}
echo $attnum;
?>

Measured memory_bytes: 23200
#include <bits/stdc++.h>
using namespace std;
const long inf = 2e9;

int n;
int main() {
  cin >> n;
  long sum = 0;
  for (int i = 1; i <= n; ++i) {
    long k = n / i;
    sum += k * (k + 1) / 2 * i;
  }
  cout << sum << endl;
}

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

//ユークリッドの互除法
int GCD(int x, int y){
    if( x % y == 0 ){
        return y;
    }
    return GCD( y , x % y );
}

//O(A*logA + N)解
int main() {
    using namespace std;
    //要素数の入力
    int N;
    cin >> N;
    //集合 A と、数の出てくる回数を管理する配列の準備
    int MAX_A = 1000000;
    vector<int> A(N);
    vector<int> count(MAX_A + 1);
    int setwise_gcd = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        //pairwise判定の準備
        count[A[i]]++;
        //setwise判定(全てのgcdをここで計算する)
        setwise_gcd = GCD(setwise_gcd, A[i]);//定義から、i == 0 ではA[0]を返す
    }
    if(setwise_gcd != 1){
        cout << "not coprime" << endl;
        return 0;
    }
    //各数について倍数として出てくる数を確認する
    for(int i = 2; i < MAX_A + 1; i++){
        int divided_count = count[i];
        int now_number = 2 * i;
        while( now_number < MAX_A + 1 ){
            divided_count += count[now_number];
            now_number += i;
        }
        if(divided_count >= 2){
            //A[x] % i == A[y] % i == 0 となるx != yが存在するので、i | gcd(x, y)となる
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}


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

using namespace std;

int main() {
    string a;
    cin >> a;
    string v = "KIHBR";
    int i = 0;
    int ok = 1;
    for(int i = 0; i < (int)a.size()-1; i++){
    	if (a[i] == a[i+1] && a[i] == 'A') {
    		ok = 0;
    	}
    }
    string r = "";
    for(int i = 0; i < (int)a.size(); i++){
    	if(a[i] != 'A'){
    		r += a[i];
    	}
    }   
    if(r != v) ok = 0;
    int pk, pi, ph;
    for(int i = 0; i < (int)a.size(); i++){

     	if(a[i] == 'K'){
    		pk = i;
    	}
      	if(a[i] == 'I'){
    		pi = i;
    	}   
    	if(a[i] == 'H'){
    		ph = i;
    	}
    }
    if(!(pk+1 == pi && pi+1 == ph))ok = 0;

    if(ok)puts("YES");
    else puts("NO");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<int> v;
typedef vector<ll> vll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());


int main() {
  int n;
  cin >> n;
  ll a,b;
  vector<P> ab;
  REP(i,n) {
    cin >> a >> b;
    ab.emplace_back(b,a);
  }
  sort(ALL(ab));
  ll time=0;
  string ans="Yes";
  REP(i,n) {
    time+=ab[i].second;
    if(time>ab[i].first) ans="No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
import itertools
N, D = map(int, input().split())
count = 0
 
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

for i in list(itertools.combinations(X, 2)):
    f = 0
    for j in range(D):
        f += (i[0][j]-i[1][j])**2
    f **= 0.5
    if f.is_integer():
        count += 1
print(count)

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a=0;
    ll b=0;
    string s;
    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='0')a++;
        else b++;
    }
    cout<<min(a,b)*2<<endl;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define test(t) int t;cin>>t;while(t--)
#define debug(x) cerr<<"=>"<<#x<<" = "<<x<<endl

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference, debug statements can also cause TLE.
//priority_queue implements max heap by default

int main(){
    fastio;
    // think about edge cases like n=1(especially graph questions).
    int n;
    cin>>n;
    int ans = (1000-(n%1000))%1000;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3644
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, L] = string_to_int(inputs[0])
    apples = [x + L for x in range(0, N)]
    min_i = 0
    for i in range(1, len(apples)):
        if abs(apples[min_i]) > abs(apples[i]):
            min_i = i
    apples.pop(min_i)

    return sum(apples)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064