akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

 int binary(int n,int S[],int T){
          int i,mid,left,right;
          left=0;right=n;
          while(left<right){
                mid=(left+right)/2;
                if(S[mid]==T)return mid;
                else if(T<S[mid]){
                         right=mid;
                         }
                else {left=mid+1;}
                }
          return 0;
          }



 int main(){
       int i,n,q,S[100001],T,cnt=0;
       scanf("%d",&n);
       for(i=0;i<n;i++){
                 scanf("%d",&S[i]);
                 }
       scanf("%d",&q);
       for(i=0;i<q;i++){
                 scanf("%d",&T);
                 if(binary(n,S,T))cnt++;
                 }
       printf("%d\n",cnt);
       return 0;
       }



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

int main() {
  int H, W; cin >> H >> W;
  vector<vector<int>> a(H, vector<int>(W));
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) cin >> a[i][j];
  }
  auto f = [&](int i, int j) { return (i % 2) ? W - 1 - j : j; };
  vector<vector<int>> x;
  int tgl = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (a[i][f(i, j)] % 2 || tgl) {
        x.push_back(vector<int>(2));
        x.back()[0] = i + 1;
        x.back()[1] = f(i, j) + 1;
        if (a[i][f(i, j)] % 2 && tgl) {
          tgl = 0;
          continue;
        }
        if (tgl) {
          x.push_back(vector<int>(2));
          x.back()[0] = i + 1;
          x.back()[1] = f(i, j) + 1;
        }
        tgl = 1;
      }
    }
  }
  cout << x.size() / 2 << endl;
  for (int i = 0; i < x.size() / 2 * 2; ++i) {
    if (i % 2) cout << ' ';
    cout << x[i][0] << ' ' << x[i][1];
    if (i % 2) cout << endl;
  }
  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 A,B;
    cin >> A >> B;

    if(B%A==0) cout << A+B << endl;
    else cout << B-A << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication5
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int a =int.Parse(Console.ReadLine());
            var b = Console.ReadLine();
            var d =b.Split();
            int [] number = new int[a];
            for (int i = 0; i < a; i++)
            {
                number[i] = int.Parse(d[i]);
            }
Array.Sort(number);

    Console.WriteLine(number[a/2]-number[a/2-1]);

    
        }
    }
}

Measured memory_bytes: 18784
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;

#define ll long long
#define pal pair<ll,ll>
#define pad pair<double,double>
#define PB push_back
#define MP make_pair
#define F first
#define S second

const ll MOD = 1e9+7;
const ll INF = 1e18;
const double EPS = 1e-8;

long long MODPOW(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return ret;
}

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


int main(){
	ll n;
    cin >> n;
    cout << (1000-n%1000)%1000 << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
    int a,b;
    a=0,b=0;

    scanf("%d %d",&a,&b);

    if(a>=13){
        printf("%d",b);
    }
    else if(a<=5){
        printf("0");
    }else{
        printf("%d",b/2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(void){
    int x,y; cin>>x>>y;
    int a=abs(abs(x)-abs(y));
    if (x<=y and ((x>=0 and y >= 0) or (x<=0 and y<=0)))cout<<a<<endl;
    else if (x>y and ((x>0 and y>0) or (x<0 and y<0)))cout<<a+2<<endl;
    else cout<<a+1<<endl;
}


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

int main(void){
    long long int n = 0, a = 0, b = 0; 
    long long int cnt = 0, ans = 0, num = 0;

    scanf("%lld%lld%lld", &n, &a, &b);

    cnt = n / (a + b);
    num = (a + b) * cnt;
    ans = a * cnt;
//    printf("cnt:%lld num:%lld ans:%lld\n", cnt, num, ans);

    long long int tmp = 1;
    if((n - num) < a){
        ans += n -num;
    }else{
        ans += a;
    }

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


    return 0;

} 


Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
 
position_diff = abs(a-b)
pace_diff = v-w
 
if pace_diff <= 0:
    print('NO')
elif pace_diff > 0:
    if pace_diff * t >= position_diff:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9084
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp
class Stack:
    def __init__(self):
        self.elements = []
    
    def push(self, element):
        self.elements.append(element)
    
    def pop(self):
        item = self.elements[-1]
        del self.elements[-1]
        return item

def putsarray(array):
    if len(array) == 0:
        return
    for i in range(len(array) - 1):
        print(array[i], end=' ')
    print(array[-1])

def get_operands(st):
    # オペランドの順番は逆に格納されている
    op2 = st.pop()
    op1 = st.pop()
    return op1, op2

if __name__ == "__main__":
    st = Stack()
    array = input().split()
    for symbol in array:
        if symbol == "*":
            op1, op2 = get_operands(st)
            st.push(op1 * op2)
        elif symbol == "+":
            op1, op2 = get_operands(st)
            st.push(op1 + op2)
        elif symbol == "-":
            op1, op2 = get_operands(st)
            st.push(op1 - op2)
        else:
            st.push(int(symbol))
    print(st.pop())


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

int main () {
  string S;
  cin >> S;
  int n = S.length();
  long long res = 0;
  for(int i = 0; i<(1<<(n-1)); i++) {
    long long tmp = 0;
    for(int j = 0; j<n; j++) {
      tmp = tmp * 10 + S[j] - '0';
      if(i & (1<<j)) {
        res += tmp;
        tmp = 0;
      }
    }
    res += tmp;
  }
  printf("%ld", res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int hp;
  int attack;
  
  cin >> hp >> attack;
  
  for(int i = 1;; i++) {

    hp -= attack;

    if (hp <= 0) {
      cout << i << endl;
      break;
    }
  
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pl;
const ll N = 1e3 + 50;
const ll MOD = 1000000000;

double x;

int main() {
	cin>>x;
  cout<<2 * x * 3.1415926<<endl;
	return 0;
}


Measured memory_bytes: 3788
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][int(input())-1])


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

int main() {
  int64_t N,A,B,ans=0;
  cin>>N>>A>>B;
  vector<int64_t> S(N);
  rep(i,N) cin>>S.at(i);
  for(int i=1;i<N;i++){
    ans+=min(A*(S.at(i)-S.at(i-1)),B);
  }
  cout<<ans;
}

Measured memory_bytes: 3972
#include<iostream>
using namespace std;
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
int main(){
    int k;
    cin>>k;
    int b[k],ans[k];
    rep(i,0,k)cin>>b[i];
    rep(i,0,k){
        int next=0,est=0,buf=-1;
        rep(j,0,k){
            if(b[j]==0)continue;
            next++;
            if(b[j]==next&&est<b[j]){
                est=b[j];
                buf=j;
            }
        }
        if(!est){
            cout<<"-1"<<endl;
            return 0;
        }
        else {
            b[buf]=0;
            ans[i]=est;
        }
    }
    for(int i=k-1;i>=0;i--)cout<<ans[i]<<endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    ll N, K;
    cin >> N >> K;

    int count = 1;
    ll now = K;
    while(now < N+1){
        now = now * K;
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
A=[list(map(int,input().split())) for i in range(3)]
N=int(input())
B=[int(input()) for i in range(N)]
for i in B:
  for j in range(3):
    for k in range(3):
      if A[j][k]==i:
        A[j][k]=0
D=list(zip(*A))
for i in range(3):
  if A[i]==[0,0,0]:
    print('Yes')
    exit()
  if D[i]==(0,0,0):
    print('Yes')
    exit()
if A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
  print('Yes')
  exit()
if A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
  print('Yes')
  exit()  
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,m,a,b,i,j,l,lg,lgmaxi,sp[100010];
char sir[100010];
int main()
{
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>sir[i];
        sp[i]=sp[i-1];
        if(sir[i]=='C' && sir[i-1]=='A')
            sp[i]++;
    }
    for(int k=1;k<=m;k++)
    {
        cin>>a>>b;
        cout<<sp[b]-sp[a]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
 
int main(){
  int a, b;
  cin >> a >> b;

  int c;
  for(int i=1; i<=3; i++){
    if(a!=i && b!=i){
      c = i;
    }
  }
  
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
int main(void){
    long long n;
    cin>>n;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    vector<long long> sum(n);
    long long p=0;
    for(int i=0;i<n;i++){
        p+=a[i];
        sum[i]=p;
    }
    long long ans=1;
    for(int i=n-2;i>=0;i--){
        if(sum[i]*2>=a[i+1])ans++;
        else break;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

const int MAXN = 300;

int N;
double dp[MAXN + 1][MAXN + 1][MAXN + 1];

double p(int i, int j, int k) {
    if (i + j + k > N)
        return 0;
    if (dp[i][j][k] == -1) {
        dp[i][j][k] = 0;
        if (i + j + k < N)
            dp[i][j][k] += p(i + 1, j, k) * (i + 1) / (i + j + k + 1);
        if (i > 0)
            dp[i][j][k] += p(i - 1, j + 1, k) * (j + 1) / (i + j + k);
        if (j > 0)
            dp[i][j][k] += p(i, j - 1, k + 1) * (k + 1) / (i + j + k);
    }
    return dp[i][j][k];
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);
    cin >> N;
    int i0 = 0, j0 = 0, k0 = 0, pieces = 0;
    forn(i, N) {
        int a; cin >> a;
        if (a == 1)
            i0++;
        else if (a == 2)
            j0++;
        else
            k0++;
        pieces += a;
    }
    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= N; j++)
            for (int k = 0; k <= N; k++)
                dp[i][j][k] = -1;
    dp[i0][j0][k0] = 1;
    double useless = 0;
    for (int i = 0; i <= N; i++)
        for (int j = 0; j <= N; j++)
            for (int k = 0; k <= N; k++)
                if (i + j + k > 0)
                    useless += p(i, j, k) * (N - i - j - k) / (i + j + k);
    cout << pieces + useless << endl;
}


Measured memory_bytes: 213376
#include <bits/stdc++.h>
#define LL long long
const LL MOD = 1e9 + 7;
const int SZ = 1e5 + 5;
using namespace std;

int arr[1000];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        arr[i] = x;
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] ==  arr[i+1]) {
            arr[i+1] = -1;
            cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}


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


int main() {
	int n;
	cin >> n;
	int count=0;
	vector<int> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		mp[to_string(x[i])]=0;
	}
	for (int i = 0; i < n; i++) {
		mp[to_string(x[i])]++;
	}
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr->second % 2 == 1) {
			count++;
		}
	}
	cout << count;
}

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

const int maxn=2e5+10;
int n,p[maxn],sum[maxn];
char ans[maxn];

inline void init(){
	for(int i=1,top=0;i<=n;++i)
		if(p[i]>top)
			sum[i]=sum[i-1]+1,top=p[i];
		else
			sum[i]=sum[i-1];
}
namespace segt{
	const int size=maxn*20;
	int cnt,root[maxn];
	int odd[size],even[size],lson[size],rson[size];
	inline void init(){
		odd[cnt]=-1e9;
		even[cnt]=0;
	}
	inline int newnode(int rt){
		++cnt;
		odd[cnt]=odd[rt];
		even[cnt]=even[rt];
		lson[cnt]=lson[rt];
		rson[cnt]=rson[rt];
		return cnt;
	}
	void query(int rt,int l,int r,int x,int&reso,int&rese){
		if(l==x){
			if(reso<odd[rt])
				reso=odd[rt];
			if(rese<even[rt])
				rese=even[rt];
			return;
		}
		int mid=l+r>>1;
		if(x<=mid)
			query(lson[rt],l,mid,x,reso,rese),query(rson[rt],mid+1,r,mid+1,reso,rese);
		else
			query(rson[rt],mid+1,r,x,reso,rese);
	}
	int modify(int rt,int l,int r,int x,int valo,int vale){
		rt=newnode(rt);
		if(odd[rt]<valo)
			odd[rt]=valo;
		if(even[rt]<vale)
			even[rt]=vale;
		if(l==r)
			return rt;
		int mid=l+r>>1;
		if(x<=mid)
			lson[rt]=modify(lson[rt],l,mid,x,valo,vale);
		else
			rson[rt]=modify(rson[rt],mid+1,r,x,valo,vale);
		return rt;
	}
	inline void run(){
		init();
		for(int i=n,o,e;i;--i){
			o=-1e9;e=0;
			query(root[i+1],1,n,p[i],o,e);
			if(sum[i]==sum[i-1])
				root[i]=modify(root[i+1],1,n,p[i],e+1,o+1);
			else
				root[i]=modify(root[i+1],1,n,p[i],o+2,e+2);
		}
	}
}
inline bool check(int pos,int numx,int numy,int maxx,int maxy){
	int odd,even,res;
	odd=-1e9;even=0;
	if(maxy<n)segt::query(segt::root[pos],1,n,maxy+1,odd,even);
	if((numx-numy+sum[n]-sum[pos-1]&1?odd:even)>=numx-numy+sum[n]-sum[pos-1]&&numx-numy+sum[n]-sum[pos-1]>=0)
		return true;
	odd=-1e9;even=0;
	if(maxx<n)segt::query(segt::root[pos],1,n,maxx+1,odd,even);
	if((numy-numx+sum[n]-sum[pos-1]&1?odd:even)>=numy-numx+sum[n]-sum[pos-1]&&numy-numx+sum[n]-sum[pos-1]>=0)
		return true;
	return false;
}
void dfs(int pos,int numx,int numy,int maxx,int maxy){
	if(!check(pos,numx,numy,maxx,maxy))
		return;
	if(pos>n){
		puts(ans+1);
		exit(0);
	}
	ans[pos]='0';
	if(p[pos]>maxx)
		dfs(pos+1,numx+1,numy,p[pos],maxy);
	else
		dfs(pos+1,numx,numy,maxx,maxy);
	ans[pos]='1';
	if(p[pos]>maxy)
		dfs(pos+1,numx,numy+1,maxx,p[pos]);
	else
		dfs(pos+1,numx,numy,maxx,maxy);
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>p[i];
	init();
	segt::run();
	dfs(1,0,0,0,0);
	puts("-1");
	return 0;
}

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

using namespace std;

int main(){
    int k;
    vector<int> a(5);
    for(int i=0; i<5; ++i) cin>>a[i];
    cin>>k;
    int r  = 4;
    while(r >=0){
        if (a[r] - a[0] > k){
            cout<<":("; return 0;
        }
        --r;
    }
    cout<<"Yay!";
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn

int main()
{
	IO;
	int a{},b{},res{};
	cin>>a>>b;
	int ans=1;
	while(ans<b)
	{	
		ans+=a-1;
		res++;
	}
	cout<<res<<'\n';
	//system("pause");
	return 0;
}

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

int fizzBuzz (int num) {
  return (num % 3 == 0 || num % 5 == 0);
}

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  
  bool Approval = true;
  for (int i=0; i<N; i++){
    if (A.at(i) % 2 == 0){
      Approval = fizzBuzz(A.at(i));
    }
    if (!Approval) {
      Approval == false;
      break;
    }
  }
  if (Approval) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

char P[55][55];

const int dir[4][2] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };

int main() {
    int H, W;
    scanf ("%d %d", &H, &W);
    for (int i = 0; i < H; ++i) {
        scanf ("%s", P[i]);
    }

    bool ok = true;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (P[i][j] == '.') continue;
            bool exist = false;
            for (int k = 0; k < 4; ++k) {
                int x = i + dir[k][0];
                int y = j + dir[k][1];

                if (x >= 0 && x < H && y >= 0 && y < W && P[x][y] == '#') {
                    exist = true;
                }
            }

            if (!exist) {
                ok = false;
                goto done;
            }
        }
    }

    done:
    printf ("%s\n", ok ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   1000000000
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    int a, b;
    cin>>a>>b;
    double sm = a/.08, fm = b/.1;
    int i = ceil(max(sm, fm));
    if(floor(i*.08) == a && floor(i*.1) == b)
        cout<<i;
    else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 3656
s = input()
K = int(input())

slist = []
for i in range(len(s)):
    slist += [s[i:i+j] for j in range(1, min(len(s) - i + 1, K + 1))]

slist = list(set(slist))
slist.sort()

print(slist[K-1])

Measured memory_bytes: 4980
import itertools
import math

def main():
    N = int(input())
    X = []
    Y = []
    ans = 0

    for i in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y) 

    for i in itertools.permutations(range(N)):
        for j in range(len(i)-1):

            ans += math.sqrt((X[i[j+1]]-X[i[j]])**2 + (Y[i[j+1]]-Y[i[j]])**2)

    print(ans/math.factorial(N))

if __name__ == '__main__':
    main()

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

int main() {
	int n; cin >> n;
	int p[200010], a[200010];
	for(int i=0; i<n; ++i){
	    cin >> a[i];
	    if(n>2*i) p[i]=n-i*2-1;
	    else p[i]=i*2-n;
	}
	for(int i=0; i<n; ++i){
	    cout << a[p[i]];
	    if(i+1<n) cout << ' ';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3712
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <random>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using ull = __uint128_t;

using sc = signed char;
using si = signed int;
using sl = signed long long int;
using sll = __int128_t;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

namespace std {
  template <>
  struct is_integral<__int128_t> {
    constexpr static bool value = true;
  };
};

static sl N;
static vector<sl> Ai;

void solve(void) {
  FOR0(i, N) {
    if ((Ai[i] % 2) == 0) {
      if ((Ai[i] % 3 != 0) && (Ai[i] % 5 != 0)) {
        cout << "DENIED" << endl;
        return;
      }
    }
  }
  cout << "APPROVED" << endl;
}

int main(void) {
  cin >> N;
  Ai.resize(N);
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int r, g, b; cin >> r >> g >> b;
    int num = 100 * r + 10 * g + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N,K;
    string S;
    cin >> N >> K;
    cin >> S;

    int cnt=2; //両端のカウント
    char memory=S[0];
    REP(i,0,N){
        if(memory!=S[i]){
            cnt++;
            memory=S[i];
        }
    }

    int ans;
    ans=S.size()-max(1,(cnt-1)-2*K); //cnt-1が不幸な人の数
    P(ans);
}

Measured memory_bytes: 512
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()), reverse=True)

AB = []
for a in A:
  for b in B:
    AB.append(a+b)
AB.sort(reverse = True)

ans = []
for ab in AB[:K]:
  for c in C:
    ans.append(ab+c)

ans.sort(reverse=True)
print(*ans[:K], sep="\n")

Measured memory_bytes: 217744
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    ll n,a,b;cin>>n>>a>>b;
    ll t = abs(a-b)-1;
    ll ans = 0;
   
    if(t == -1) cout << 0;
    else {
        if (t % 2 == 1) {
            ans = 1 + (t - 1) / 2;
        } else {
            ll l, r;
            if (a > b) {
                l = b;
                r = a;
            } else {
                l = a;
                r = b;
            }
            if(t == 0) {

                if (r - 1 > n - l) ans = n - l;
                else ans = r - 1;
            }else{
                if (l - 1 < n - r) {
                    ans = (r-l-1)/2+1+l-1;
                }else{
                    ans = (r-l-1)/2+1+n-r;
                }
            }
        }
        cout << ans;
    }

    return 0;
}











Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll r,c,k;
ll v[3001][3001];
ll dp[3001][3001][4];

int main(){
    cin >> r >> c >> k;
    ll r1,c1,v1;
    for(int i=0; i<k; i++){
        cin>>r1>>c1>>v1;
        v[r1][c1]=v1;
    }
    dp[r][c][1]=v[r][c];
    dp[r][c][2]=v[r][c];
    dp[r][c][3]=v[r][c];
    for(int i=c-1; i>=1; i--){
        for(int j=1; j<4; j++){
            dp[r][i][j]=max(dp[r][i+1][j-1]+v[r][i],dp[r][i+1][j]);
        }
    }
    for(int i=r-1; i>=1; i--){
        for(int j=1; j<4; j++){
            dp[i][c][j]=dp[i+1][c][3]+v[i][c];
        }
    }
    for(int i=r-1; i>=1; i--){
        for(int j=c-1; j>=1; j--){
            for(int l=1; l<4; l++){
                dp[i][j][l]=max(dp[i][j+1][l-1]+v[i][j],dp[i][j+1][l]);
                dp[i][j][l]=max(dp[i][j][l],dp[i+1][j][3]+v[i][j]);
            }
        }
    }
    cout << dp[1][1][3] << endl;
}


Measured memory_bytes: 354708
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

struct MyStruct {
	int idx, pts;
	string name;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.name != t.name)
		return s.name < t.name; 
	return s.pts > t.pts;
}
int main() {
	int n;
	cin >> n;
	vector<MyStruct> v(n);
	REP(i, n) {
		cin >> v[i].name >> v[i].pts;
		v[i].idx = i + 1;
	}
	sort(v.begin(), v.end(), comp);

	REP(i, n) {
		ANS(v[i].idx);
	}

	return 0;

}


Measured memory_bytes: 256
N = int(input())
act = []
for _ in range(N):
    act.append(tuple(map(int, input().split())))

dp = [[0]*3 for _ in range(N)]

for i in range(3):
    dp[0][i] = act[0][i]

for i in range(1, N):
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1) % 3], dp[i-1][(j+2) % 3]) + act[i][j]


print(max(dp[N-1]))


Measured memory_bytes: 75096
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e6 + 6, mod = (int) 0;
int res[N];
int main() {
	long long n;
	cin >> n;
	++n;
	int cur = 0;
	int flag = 0;
	int lft = 0;
	for (int j = 60; j >= 0; --j) {
		if (n >> j & 1) {
			lft = j;
			break;
		}
	}
	int len = __builtin_popcountll(n) + lft - 1;
	for (int j = 0; j < len; ++j) {
		res[j] = j;
	}
	n -= 1ll << lft;
	int pt = len;
	for (int j = 0; j <= lft; ++j) {
		if (n >> j & 1) {
			res[pt++] = --len;
		}
		if (j != lft) res[pt++] = j;
	}
	cout << pt << endl;
	for (int j = 0; j < pt; ++j)
		cout << 1 + res[j] << ' ';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, m, i, x, y;
vector<int> list[maxN];
bool us[maxN];
vector<int> ans;

void dfs(int node) {
    us[node] = true;
    ans.pb(node);

    for (auto to : list[node]) {
        if (us[to]) continue;
        dfs(to);
        return;
    }
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d%d", &n, &m);
    for (i = 1; i <= m; i++) {
        scanf("%d%d", &x, &y);
        list[x].pb(y);
        list[y].pb(x);
    }

    dfs(1);
    reverse(ans.begin(), ans.end());
    for (auto to : list[1]) {
        if (us[to]) continue;
        dfs(to);
        break;
    }

    printf("%d\n", ans.size());
    for (auto e : ans) printf("%d ", e);


    return 0;
}


Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

using pchar = pair<char, char>;
int simulate(string str, vector<pchar> td, int pos)
{

    for (auto &&i : td)
    {
        if (str[pos] != i.first)
            continue;
        if (i.second == 'L')
            --pos;
        else
            ++pos;
        if (pos < 0)
            return -1;
        if (pos >= (int)str.size())
            return 1;
    }
    return 0;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::string s;
    std::cin >> s;
    vector<pchar> td(Q);

    for (int i = 0; i < Q; i++)
    {
        cin >> td[i].first >> td[i].second;
    }

    int low = -1, high = N;
    while (high - low > 1)
    {
        int mid = (high + low) / 2;
        if (simulate(s, td, mid) == -1)
            low = mid;
        else
            high = mid;
    }
    int left_fall = high;

    low = -1, high = N;
    while (high - low > 1)
    {
        int mid = (high + low) / 2;
        if (simulate(s, td, mid) == 1)
            high = mid;
        else
            low = mid;
    }
    int right_fall = N - 1 - low;

    cout << N - (left_fall + right_fall) << endl;
    return 0;
}


Measured memory_bytes: 1536
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n; ll ara[n+9];
    for(i=1; i<=n; i++)
        cin>>ara[i];

    ll ans = LONG_LONG_MAX;

    for(x=0; x<=101; x++)
    {
        ll ret = 0;

        for(j=1; j<=n; j++)
        {
            ret+=(ara[j]-x)*(ara[j]-x);
        }

        ans = min(ans, ret);
    }

    cout<<ans<<endl;

   // main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
x=[0]*(10**3+1)
y=[]
for i in range(n):
    x[l[i]]+=1
for i in range(10**3+1):
    if i==0:
        y.append(0)
    else:
        y.append(y[i-1]+x[i])
y.append(y[len(y)-1])
ans=0
for i in range(n):
    for j in range(n):
        if i!=j:
            a=min(l[i],l[j])
            b=max(l[i],l[j])
            m=b-a
            M=min(a+b,10**3+1)
            g=y[M-1]-y[m]
            ans+=g
            if m<a<M:
                ans-=1
            if m<b<M:
                ans-=1
print(ans//6)

Measured memory_bytes: 68964
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    signed main(){
        goku
    int a,b;
    cin>>a>>b;
    if(a<b)
    {
        for(int i=0;i<b;i++)
            cout<<a;
    }
    else
    {
        for(int i=0;i<a;i++)
            cout<<b;
    }
    }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    while(scanf("%lld%lld",&a,&b)!=EOF)
    {
        if(b>a)  printf("%lld\n",(b-2*a)/4+a);
        else
        {
            printf("%lld\n",b/2);
        }
    }

    return 0;
}


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

using namespace std;


struct myNode {
    int x, y, id;
};

bool sortX(const myNode &left, const myNode &right) {
    return left.x < right.x;
}

bool sortY(const myNode &left, const myNode &right) {
    return left.y < right.y;
}


//クラスカル法
//spaghetti-source(github)から
struct edge {
    int src, dst;
    int weight;
};

struct graph {
    int n;
    vector<edge> edges;

    explicit graph(int n = 0) : n(n) {
    }

    void add_edge(int src, int dst, int weight) {
        n = max(n, max(src, dst) + 1);
        edges.push_back({src, dst, weight});
    }

    vector<int> p;

    int root(int i) {
        return p[i] < 0 ? i : p[i] = root(p[i]);
    }

    bool unite(int i, int j) {
        if ((i = root(i)) == (j = root(j))) return false;
        if (p[i] > p[j]) swap(i, j);
        p[i] += p[j];
        p[j] = i;
        return true;
    }

    int kruskal() {
        p.assign(n, -1);
        sort(edges.begin(), edges.end(), [](edge x, edge y) {
            return x.weight < y.weight;
        });

        int result = 0;
        for (auto e: edges)
            if (unite(e.src, e.dst))
                result += e.weight;
        return result;
    }
};


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

    vector<myNode> vt;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        vt.push_back({x, y, i});
    }

    auto g = graph(n);

    sort(vt.begin(), vt.end(), sortX);
    for (int i = 0; i < n - 1; ++i) {
        g.add_edge(vt[i].id, vt[i + 1].id, vt[i + 1].x - vt[i].x);
    }

    sort(vt.begin(), vt.end(), sortY);
    for (int i = 0; i < n - 1; ++i) {
        g.add_edge(vt[i].id, vt[i + 1].id, vt[i + 1].y - vt[i].y);
    }

    cout << g.kruskal() << endl;
    return 0;
}

Measured memory_bytes: 6132
(defn create-data [s]
  (map #(Long/parseLong %) (.split s " ")))

(defn noYes [p]
  (if p "NO" "YES")
)
(defn chooseIntegers [[a b c]]  
  (->> (for [i (range 0 a)
             :when (zero? (mod (+ (* i b) c) a))]
         "YES")
       (empty?)
       (noYes)
       )
  )

(println (chooseIntegers (create-data (read-line))))

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int a, b;
	cin >> a >> b;

	vi h(1000);
	for(int i = 1; i < 1000; i++)
		h[i] = i + h[i-1];
	int dif = b - a;
	int ans = 0;
	rep(i, 1000)
	{
		if(h[i+1] - h[i] == dif)
			ans = h[i] - a;
	}
	cout << ans << endl;
	return 0;
}

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

int main(void)
{
	char a[11], b[11], c[11];
	int m, n;
	
	scanf("%s %s %s", a, b, c);
	
	m = strlen(a);
	n = strlen(b);
	
	if(a[m - 1] == b[0] && b[n - 1] == c[0]) {
		printf("YES");
	}
	else {
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int W = sc.nextInt();
    long[][] memo = new long[N+1][W+1];
    for(int i = 0; i <= N; i++){
      Arrays.fill(memo[i], -1);
    }
    memo[0][0] = 0;
    int[] w = new int[N];
    long[] v = new long[N];
    for(int i = 0; i < N; i++){
      w[i] = sc.nextInt();
      v[i] = sc.nextLong();
    }
    System.out.println(solve(memo, w, v, W, N));
  }
  
  public static long solve(long[][] memo, int[] w, long[] v, int W, int N){
    for(int i = 0; i < N; i++){
      for(int j = 0; j <= W; j++){
        if(memo[i][j] != -1){
          if(w[i] + j <= W){
            long tmp = memo[i][j] + v[i];
            memo[i+1][w[i]+j] = memo[i+1][w[i]+j] > tmp ? memo[i+1][w[i]+j] : tmp;
          }
          memo[i+1][j] = memo[i+1][j] > memo[i][j] ? memo[i+1][j] : memo[i][j];
        }
      }
    }
    Arrays.sort(memo[N]);
    return memo[N][W];
  }
}

Measured memory_bytes: 130192
use std::cmp::{max, min};

fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let a: usize = read(&mut stdin_lock, &mut buf, b' ');
    let b: usize = read(&mut stdin_lock, &mut buf, b' ');
    let c: usize = read(&mut stdin_lock, &mut buf, b' ');
    let x: usize = read(&mut stdin_lock, &mut buf, b' ');
    let y: usize = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = c * max(x * 2, y * 2);
    for cx in 0..max(x * 2, y * 2) {
        let ax = if x > cx / 2 { x - cx / 2 } else { 0 };
        let bx = if y > cx / 2 { y - cx / 2 } else { 0 };
        ans = min(ans, a * ax + b * bx + c * cx);
    }
    println!("{}", ans);
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		for(int i=1;i<=5;i++)
			if(sc.nextInt()==0)
				System.out.println(i);
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

		int[] nxtArr(int n) throws IOException {
			int[] ans = new int[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextInt();
			return ans;
		}

	}

	static void sort(int[] a) {
		shuffle(a);
		Arrays.sort(a);
	}

	static void shuffle(int[] a) {
		int n = a.length;
		Random rand = new Random();
		for (int i = 0; i < n; i++) {
			int tmpIdx = rand.nextInt(n);
			int tmp = a[i];
			a[i] = a[tmpIdx];
			a[tmpIdx] = tmp;
		}
	}

}

Measured memory_bytes: 32648
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());

        if (x < a) System.out.println(0);
        else System.out.println(10);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main(void){
int a,b,m;cin>>a>>b;
m = max(a,b);
if(abs(a-b)%2==0)
    cout<<m-(abs(a-b)/2)<<endl;
else
    cout<<"IMPOSSIBLE"<<endl;
return 0;}


Measured memory_bytes: 3576
N=int(input())
a=list(map(int,input().split()))
d=[[0]*21 for _ in[0]*~-N]
d[0][a[0]]=1
for i in range(1,N-1):
 for j in range(21):
  d[i][j]=(21>j+a[i]and d[i-1][j+a[i]])+(0<=j-a[i]and d[i-1][j-a[i]])
print(d[N-2][a[N-1]])


Measured memory_bytes: 5608