akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

#define A

#ifdef A
int main(void)
{
	vector<char> arr;

	int m, f, r;
	while (true)
	{
			cin >> m >> f >> r;
			int sum = m + f;
			if (m <0 && f<0 && r <0)
			{
				break;
			}
			if (m < 0 || f < 0 || sum < 30) {
				arr.push_back('F');
				continue;
			}
			if (sum > 79) {
				arr.push_back('A');
				continue;
			}
			if (sum > 64) {
				arr.push_back('B');
				continue;
			}
			if (sum > 49 || r >49)
			{
				arr.push_back('C');
				continue;
			}
			arr.push_back('D');


	}

	for (auto a : arr) {
		cout << a << endl;
	}


	return 0;
}
#endif // A

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n;
char s[N];
long long ans=0;

int main() {
	scanf("%s",s+1),n=strlen(s+1);
	int lst=0;
	for(int i=1;i<n;i++) {
		if(lst>=i) lst=0;
		if(s[i]=='B'&&s[i+1]=='C'&&lst) {
			ans+=i-lst,lst+=2;s[i-1]='A';s[i]='A';s[i+1]='A';i-=2;
			s[lst-2]='B',s[lst-1]='C';
		}
		else if(s[i]=='A') lst?0:lst=i;
		else lst=0;
		//cerr<<i<<' '<<lst<<' '<<ans<<endl;
	}
	cout<<ans;
	return 0;
}


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

#define REP(i, n) for(int i=0; i<n;i++)
#define REPR(i, n) for(int i=n-1 ; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    string s;
    cin>>s;
    int size = s.length();
    int i, j;
    int mae, ushiro;

    for(i=0; i<size; i++){
        if(s[i]=='A'){
            mae = i;
            break;
        }
    }
    for(i=size-1; i>=0; i--){
        if(s[i]=='Z'){
            ushiro = i;
            break;
        }
    }

    cout<<ushiro-mae+1<<endl;
    return 0;
}

Measured memory_bytes: 640
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: i64 = read();

    for i in 0..120 {
        for j in -120..120 {
            if i*i*i*i*i - j*j*j*j*j == x {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2076
//Nipah!~☆
#include<bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 10;

int n;
int ans;
int a[maxn];
int b[maxn];
int P[maxn];
int HOLD;
int CMP;
int par[maxn];
vector<int> cmp;
vector<int> bois;
set<int> badbois;
vector<int> inds[2][maxn];
map<int, int> comp;

void in();
void solve();
void dsu(int, int);
int root(int);
void out();

int main(){
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	in();
	solve();
	out();
}

void in(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cmp.push_back(a[i]);
		HOLD ^= a[i];
	}
	cmp.push_back(HOLD);
	for(int i = 0; i < n; i++){
		cin >> b[i];
		cmp.push_back(b[i]);
	}
	sort(cmp.begin(), cmp.end());
	cmp.resize(unique(cmp.begin(), cmp.end()) - cmp.begin());
	for(int i = 0; i < cmp.size(); i++)
		comp[cmp[i]] = i;
	HOLD = comp[HOLD];
	for(int i = 0; i < n; i++){
		a[i] = comp[a[i]];
		b[i] = comp[b[i]];
	}
}

void solve(){
	int hold = HOLD;
	for(int i = 0; i < n; i++){
		if(a[i] != b[i]){
			inds[0][a[i]].push_back(i);
			inds[1][b[i]].push_back(i);
			bois.push_back(b[i]);
		}
	}
	memset(par, -1, sizeof par);
	int pfft = 0;
	inds[0][hold].push_back(n);
	sort(bois.begin(), bois.end());
	bois.resize(unique(bois.begin(), bois.end()) - bois.begin());
	CMP = bois.size();
	for(auto i: bois){
		if(inds[1][i].size() > inds[0][i].size()){
			ans = -1;
			return;
		}
		if(inds[1][i].size() < inds[0][i].size())
			pfft = 1;
		for(int j = 0; j < inds[1][i].size(); j++){
			dsu(i, a[inds[1][i][j]]);
			ans++;
		}
	}
	int now = n;
	ans += CMP - pfft;
}

void dsu(int u, int v){
	u = root(u);
	v = root(v);
	if(u == v)
		return;
	if(par[u] < par[v])
		swap(u, v);
	par[u] += par[v];
	par[v] = u;
	CMP--;
}

int root(int u){
	return par[u] < 0 ? u : par[u] = root(par[u]);
}

void out(){
	cout << ans;
}

Measured memory_bytes: 34248
if __name__ == "__main__":
    ND=input().split(" ")
    N,D=int(ND[0]),int(ND[1])
    cnt=0
    for i in range(N):
        xy=input().split(" ")
        x,y=int(xy[0]),int(xy[1])
        if x*x+y*y<=D*D:
            cnt+=1
    print(cnt)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    string s; cin >> s;
    int n = s.size();
    string zen, kou;
    rep(i, n/2) zen.push_back(s[i]);
    rep(i, n/2) kou.push_back(s[i+(n+1)/2]);
    string ans;
    if (zen == kou) ans = "Yes";
    else ans = "No";
    cout << ans;
}


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

const static ll MOD = (1e+9)+7;

int main(){
    ll n,k;cin>>n>>k;
    ll ans = 0;
    ll before_min;
    for(ll i = 1;i<=n+1;i++){
        if(i == 1){
            if(i >= k){
                ans += n+1 % MOD;
            }
            before_min = 1;
        }else{
            ll min_ = i*(i+1)/2;
            ll max_ = i*(2*n-i+1)/2;
            if(i >= k){
                ans += (max_-min_+1) % MOD;
                ans += max((ll)0,min_-before_min) % MOD;
            }
            before_min = min_;
        }
    }
    cout<<ans%MOD<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define fup(i,a,b) for(int i=a;i<=b;++i)
#define fdw(i,a,b) for(int i=a;i>=b;--i)
#define sync ios::sync_with_stdio(false);cin.tie(0)
#define cl(a) memset(a,0,sizeof(a))
#define gcd __gcd
#define fi first
#define se second
#define pb push_back
#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
//ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;for(;b;b>>=1){if(b&1) ans=ans*a%mod;a=a*a%mod;}return ans;}
//ll oula(ll n){ ll res=n;for(ll i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) res=res-res/n;return res;}
//bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;}
//void shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数"
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e-7;
const int N = 2e5 + 10;
ll fac[N] , inv[N] ;
ll C(ll n , ll m)
{
    return fac[n] * inv[n - m] % mod* inv[m] % mod ;
}
ll work(ll n , ll m)
{
    return C(n + m - 1 , m - 1) ;
}
int main()
{
    sync;
    ll n , k ;
    ll ans = 1 ;
    fac[0] = fac[1] = inv[0] = inv[1] = 1 ;
    fup(i , 2 , N - 1)
    {
        fac[i] = fac[i - 1] * i % mod ;
        inv[i] = -inv[mod % i] * (mod / i) % mod ;
        while(inv[i] < 0) inv[i] += mod ;
    }
    fup(i , 2 , N - 1)
    inv[i] = inv[i] * inv[i - 1] % mod ;
    cin >> n >> k;
    k = min(k , n) ;
    fup(i , 1 , n - 1)
    {
        if(i > k)  break ;
        ans += C(n , i) * work(i , n - i) ;
        ans %= mod ;
    }
    cout << ans << endl;
    return 0 ;
}

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

int main()
{
  int n;
  cin >> n;
  n %= 10;

  if (n == 3) {
    cout << "bon" << endl;
  } else if (n == 0 || n == 1 || n == 6 || n == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }

  return 0;
}


Measured memory_bytes: 3672
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var h = new int[4].Select(_ => int.Parse(Console.ReadLine())).ToArray();
		var q =
			from i in Enumerable.Range(0, h[0] + 1)
			from j in Enumerable.Range(0, h[1] + 1)
			select (h[3] - 500 * i - 100 * j) / 50;
		Console.WriteLine(q.Count(k => 0 <= k && k <= h[2]));
	}
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

const long long INF = 1LL << 50;

int main(void) {
    int N, M;
    cin >> N >> M;

    const int NMAX = 1000;
    const int MMAX = 2000;
    int a[MMAX], b[MMAX];
    long long c[MMAX];
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    long long dist[NMAX];

    for (int i = 0; i < N; ++i) {
        dist[i] = INF;
    }

    dist[0] = 0;

    for (int loop = 0; loop < N - 1; ++loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;

            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
            }
        }
    }

    long long ans = dist[N - 1];

    bool negative[NMAX];

    for (int i = 0; i < N; ++i) {
        negative[i] = false;
    }

    for (int loop = 0; loop < N; ++loop) {
        for (int i = 0; i < M; ++i) {
            if (dist[a[i] - 1] == INF) continue;

            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
                negative[b[i] - 1] = true;
            }

            if (negative[a[i] - 1] == true) {
                negative[b[i] - 1] = true;
            }
        }
    }

    if (negative[N - 1]) {
        cout << "inf" << endl;
    } else {
        cout << -ans << endl;
    }
    return 0;
}

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

class Stack{
private:
  int sp;
  int S[100];
public:
  Stack(){
    sp=0;
  }
  bool isFull(){
    return sp==100;
  }
  bool isEmpty(){
    return sp==0;
  }
  void push(int d){
    if(isFull())return;
    S[sp++]=d;
  }
  int top(){
    if(isEmpty())return -1;
    return S[sp-1];
  }
  void pop(){
    if(isEmpty())return;
    sp--;
  }
};

int main(){
  Stack s;

  string expr;
  getline(cin,expr);

  istringstream is(expr);

  while(!is.eof()){
    string op;
    is >> op;

    int tmp1,tmp2;

    switch(op[0]){
      case '+':
        tmp1=s.top();
        s.pop();
        tmp2=s.top();
        s.pop();
        s.push(tmp2+tmp1);
        break;
      case '-':
        tmp1=s.top();
        s.pop();
        tmp2=s.top();
        s.pop();
        s.push(tmp2-tmp1);
        break;
      case '*':
        tmp1=s.top();
        s.pop();
        tmp2=s.top();
        s.pop();
        s.push(tmp2*tmp1);
        break;
      default:
        istringstream is2(op);
        is2 >> tmp1;
        s.push(tmp1);
        break;
    }
  }

  cout << s.top() << endl;

  return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

ll dp[3003][3003];

string s,t; 

ll f(ll x,ll y){
	ll &r=dp[x][y];
	if(r>=0)return r;
	if(x==SZ(s)||y==SZ(t)){
		r=0; return r;
	}
	r=max(f(x,y+1),f(x+1,y));
	if(s[x]==t[y])r=max(r,f(x+1,y+1)+1);
	return r;
}

int main(){FIN;
	cin>>s>>t;
	mset(dp,-1);
	ll res=f(0,0);
	ll l=0,r=0,va=res;
	while(va){
		if(f(l,r+1)==va)r++;
		else if(f(l+1,r)==va)l++;
		else if(f(l+1,r+1)==va-1){
			cout<<s[l]; va--; l++; r++;
		}
	}
	
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main(){
  	int S ,W;
    cin >> S>>W;
    if(S<=W) cout <<"unsafe" << endl;
    else cout <<"safe"<< endl;
}

Measured memory_bytes: 3600
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>

#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;
using namespace __gnu_pbds;

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

const int N = 2e5 + 10 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7;

void solve() {
    ll x , k , d;
    cin >> x >> k >> d;
    x = abs(x);
    if(k <= x/d) {
        cout << x-d*k;
    }
    else {
        ll movs = k - (x/d);
        if(movs % 2 == 0) {
            cout << x%d;
        }
        else {
            cout << abs(x%d - d);
        }
    }
}

/*
1 1 5 5
1 2 13
*/
main() {
    ios;
    int tt = 1;
   // cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	long long int a[100];
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=a[i-2]+a[i-1];
	}
	cout << a[n] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 800 + 10;
int n, m, k, dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, mark[N][N], dis[N][N], ans = N + 1;
string s[N];
pair<int, int> st;
bool isval(int x, int y) {
	if (x < n && x >= 0 && y < m && y >= 0 && s[x][y] == '.')
		return true;
	return false;
}
void bfs(int sx, int sy) {
	mark[sx][sy] = 1;
	queue<pair<int, int> > q;
	q.push({sx, sy});
	dis[sx][sy] = 0;
	while (!q.empty()) {
		auto p = q.front();
		q.pop();
		int x = p.first, y = p.second;
		for (int i = 0; i < 4; i++) {
			int xx = x + dx[i], yy = y + dy[i];
			if (isval(xx, yy) && !mark[xx][yy]) {
				mark[xx][yy] = 1;
				dis[xx][yy] = dis[x][y] + 1;
				q.push({xx, yy});
			}
		}
	}
}
int main() {
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < m; j++)
			if (s[i][j] == 'S')
				st = {i, j};
	}
	memset(dis, 127, sizeof(dis));
	bfs(st.first, st.second);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (dis[i][j] <= k) {
				ans = min({ans, (i + k - 1) / k, (j + k - 1) / k, (n - i - 1 + k - 1) / k, (m - j - 1 + k - 1) / k});
			}	
		}
	}
	cout << ans + 1;
	return 0;
}


Measured memory_bytes: 6144
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 if r<H:
  if A[i]<A[l]:
   if A[l]<A[r]:A[i],A[r]=A[r],A[i];h(r)
   else:A[i],A[l]=A[l],A[i];h(l)
  elif A[i]<A[r]:A[i],A[r]=A[r],A[i];h(r)
 elif l<H and A[i]<A[l]:A[i],A[l]=A[l],A[i];h(l)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 65352
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


ll dp[1000005];
ll dpOdd[1000005];

int main()
{
	REP(i, 1000001)
	{
		dp[i] = dpOdd[i] = i;
	}

	for (ll n = 2;; n++) {
		ll bNumber = n * (n + 1) * (n + 2) / 6;
		if (bNumber > 1000001) break;

		for (ll i = 0; i <= 1000001; i++) {
			if (i - bNumber < 0) continue;
			dp[i] = min(dp[i], dp[i - bNumber] + 1);
			if (bNumber % 2 == 1) dpOdd[i] = min(dpOdd[i], dpOdd[i - bNumber] + 1);
		}
	}

	for (;;) {
		ll Value;
		cin >> Value;
		if (!Value) break;
		cout << dp[Value] << " " << dpOdd[Value] << endl;
	}

	return 0;
}

Measured memory_bytes: 18708
#include <stdio.h>
#define REP(i, n) for ((i)=0; (i)<(n); (i)++)

int linearSearch(int key, int *a, int n) {
    int i = 0;
    a[n] = key;
    while (a[i] != key) i++;
    return i != n;
}

int main(void) {
    int n, q, i, T;
    int ans = 0;
    scanf("%d", &n);
    int A[n+1];

    REP(i, n) scanf("%d", &A[i]);

    scanf("%d", &q);

    REP(i, q) {
        scanf("%d", &T);
        ans += linearSearch(T, A, n);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 2112
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
  string s;
  cin >> s;

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for(int i=0;i<s.size();){
    bool can2 = false;
    for(int j=0;j<4;j++){
      string d = divide[j];
      if(s.substr(i,d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }
  
  if(can) cout<< "YES"<<endl;
  else cout << "NO"<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
inline ll read()
{
	ll x=0;
	bool pos=1;
	char ch=getchar();
	for(;!isdigit(ch);ch=getchar())
		if(ch=='-')
			pos=0;
	for(;isdigit(ch);ch=getchar())
		x=x*10+ch-'0';
	return pos?x:-x;
}
const int MAXN=1e5+10;
int n,m;
ll a[2][MAXN];
#define ninf -1e18
#define inf 1e18
#define siz (k?m:n)
ll Findleft(int k,ll x)
{
	if(x<a[k][1])
		return ninf;
	int p=upper_bound(a[k]+1,a[k]+1+siz,x)-a[k];
	return a[k][p-1];
}
ll Findright(int k,ll x)
{
	if(x>a[k][siz])
		return inf;
	int p=lower_bound(a[k]+1,a[k]+1+siz,x)-a[k];
	return a[k][p];
}
int main()
{
	int Q;
	n=read(),m=read();Q=read();
	for(int i=1;i<=n;++i)
		a[0][i]=read();
	for(int i=1;i<=m;++i)
		a[1][i]=read();
	sort(a[0]+1,a[0]+1+n);
	sort(a[1]+1,a[1]+1+m);
	while(Q--)
		{
			ll x=read();
			ll ans=inf;
			ll s,pos,qos;
			if((pos=Findleft(0,x))!=ninf)
				{
					s=x-pos;
					if((qos=Findleft(1,pos))!=ninf)
						ans=min(ans,s+pos-qos);
					if((qos=Findright(1,pos))!=inf)
						ans=min(ans,s+qos-pos);
				}
			if((pos=Findright(0,x))!=inf)
				{
					s=pos-x;
					if((qos=Findleft(1,pos))!=ninf)
						ans=min(ans,s+pos-qos);
					if((qos=Findright(1,pos))!=inf)
						ans=min(ans,s+qos-pos);
				}
				
			if((pos=Findleft(1,x))!=ninf)
				{
					s=x-pos;
					if((qos=Findleft(0,pos))!=ninf)
						ans=min(ans,s+pos-qos);
					if((qos=Findright(0,pos))!=inf)
						ans=min(ans,s+qos-pos);
				}
			if((pos=Findright(1,x))!=inf)
				{
					s=pos-x;
					if((qos=Findleft(0,pos))!=ninf)
						ans=min(ans,s+pos-qos);
					if((qos=Findright(0,pos))!=inf)
						ans=min(ans,s+qos-pos);
				}
			cout<<ans<<endl;
		}
	return 0;
}


Measured memory_bytes: 2816
N, M = map(int, input().split())
A_list = sorted(list(map(int, input().split())), reverse=True)
c = 0

for i, a in enumerate(A_list):
    if a >= sum(A_list)*(1/(4 * M)):
        c += 1
    else:
        break

if c >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=6005;
int all,dp[N][N],g[N],mx,f[N][N],gg[N],mm;
int n,a[N];
void update(int i,int j,int v)
{
    dp[i][j]=dp[j][i]=max(dp[i][j],v);
    g[i]=max(g[i],v);
    g[j]=max(g[j],v);
    mx=max(mx,v);
}
void init(int x,int y,int z)
{
    f[x][x]=dp[x][x];
    f[y][y]=dp[y][y];
    f[z][z]=dp[z][z];
    mm=mx;
    for(int i=1;i<=n;i++)
    {
        gg[i]=g[i];
        f[x][i]=f[i][x]=dp[x][i];
        f[y][i]=f[i][y]=dp[y][i];
        f[z][i]=f[i][z]=dp[z][i];
    }
}
void update1(int x,int y,int z)
{
    update(y,z,f[x][x]+1);
}
void update2(int x,int y,int z)
{
    if(x!=y) return;
    for(int i=1;i<=n;i++)
        update(i,z,f[i][x]+1);
}
void update3(int x,int y,int z)
{
    update(x,y,mm);update(y,z,mm);update(x,z,mm);
}
void update4(int x,int y,int z)
{
    update(x,x,gg[x]),update(y,y,gg[y]),update(z,z,gg[z]);
}
void update5(int x,int y,int z)
{
    for(int i=1;i<=n;i++)
        update(i,x,gg[i]),update(i,y,gg[i]),update(i,z,gg[i]);
}
int main()
{
    memset(dp,-inf,sizeof(dp));
    memset(g,-inf,sizeof(g));
    scanf("%d",&n);
    for(int i=1;i<=3*n;i++)
        scanf("%d",&a[i]);
    update(a[1],a[2],0);
    for(int i=3;i<=3*n;i+=3)
    {
        if(i==3*n)
            update(a[i],a[i],dp[a[i]][a[i]]+1);
        else if(a[i]==a[i+1]&&a[i+1]==a[i+2])
           all++;
        else
        {
            init(a[i],a[i+1],a[i+2]);
            update1(a[i],a[i+1],a[i+2]);
            update1(a[i+1],a[i],a[i+2]);
            update1(a[i+2],a[i],a[i+1]);
            update2(a[i],a[i+1],a[i+2]);
            update2(a[i],a[i+2],a[i+1]);
            update2(a[i+1],a[i+2],a[i]);
            update3(a[i],a[i+1],a[i+2]);
            update4(a[i],a[i+1],a[i+2]);
            update5(a[i],a[i+1],a[i+2]);
        }
    }
    printf("%d\n",mx+all);
}


Measured memory_bytes: 168308
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int main()
{
    ll n;
    cin>>n;
    ll arr[n],i,j,t,sum[n],ans=0;
    for(i=0;i<n;i++)
        cin>>arr[i];

    t=0;
    for(i=n-1;i>=0;i--)
    {
        t=t+arr[i];
        sum[i]=t%mod;
    }

    for(i=0;i<(n-1);i++)
    {
        t=(arr[i]*sum[i+1])%mod;
        ans=(ans+t)%mod;
    }

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


Measured memory_bytes: 6700
n=int(input())
a=list(map(int, input().strip().split()))
b=[0]*(10**5)
for i in range(n):
  b[a[i]]+=1
ma=0
for i in range(1,10**5-1):
    ma=max(b[i-1]+b[i]+b[i+1],ma)
print(ma)

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

int main() {
    string s;
    cin >> s;

    if(s.at(0) == 'R' && s.at(1) == 'R' && s.at(2) == 'R') {
        cout << 3 << endl;
    }
    else if((s.at(0) == 'R' && s.at(1) == 'R') || (s.at(1) == 'R' && s.at(2) == 'R')) {
        cout << 2 << endl;
    }
    else if(s.at(0) == 'R' || s.at(1) == 'R' || s.at(2) == 'R') {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, 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;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e17;
#define int long long


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	VE a(n), f(n); rep(i, n)cin >> a[i];
	rep(i, n)cin >> f[i];
	sort(ALL(a)); sort(ALLR(f));
	int l = -1, r = 1e12;
	while (l + 1 < r) {
		int mid = (l + r) / 2;
		bool ok = [&]{
			int s = 0;
			rep(i, n) {
				s += max(0ll, a[i]-mid / f[i]);
			}
			return s <= k;
		}();
		if (ok)r = mid;
		else l = mid;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)



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

  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<bool> good(n,true);

  rep(i,m){
    int u,v;
    cin >> u >> v;
    --u;--v;
    if(h[u] <= h[v]){
      good[u] = false;
    }
    if(h[v] <= h[u]){
      good[v] = false;
    }

  }
  ll ans =0;
  rep(i,n) {
    if(good[i]) ans++;
  }
cout << ans << endl;
return 0;
    

}


Measured memory_bytes: 3696
#include<iostream>
#include<string>
#include<algorithm>
#include<map>

using namespace std;
int main(void){
  int N, cnt = 0;
  int num_sum = 0;
  cin >> N;
  //あるj（奇数）を固定
  for(int j = 1; j <= N; j = j + 2){
    num_sum = 0;
    //その中でj以下の約数を探す
    for(int i = 1; i <= j; i++){
      if(j%i == 0){num_sum++;}
    }
    if(num_sum == 8) cnt++;
  }
  cout << cnt << endl;
return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int,input().split()))
d1 = {}
d2 = {}

for i in range(0,n//2):
  a1 = v[2*i]
  a2 = v[2*i+1]
  
  if a1 not in d1:
    d1[a1] = 1
  else:
    d1[a1] += 1
    
  if a2 not in d2:
    d2[a2] = 1
  else:
    d2[a2] += 1


l1 = list(sorted(d1.items(), key=lambda x:x[1]))
l2 = list(sorted(d2.items(), key=lambda x:x[1]))


if len(set(v)) == 1:
  print(n//2)
  exit()
if l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) >= 2:
  print(min(n - l1[-1][1] - l2[-2][1],n - l1[-2][1] - l2[-1][1]))
elif l1[-1][0] == l2[-1][0] and len(l1) == 1 and len(l2) >= 2:
  print(n - l1[-1][1] - l2[-2][1])
elif l1[-1][0] == l2[-1][0] and len(l1) >= 2 and len(l2) == 1:
  print(n - l1[-2][1] - l2[-1][1])
else:
  print(n - l1[-1][1] - l2[-1][1])

Measured memory_bytes: 32252
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int A, B;
	cin >> A >> B;
	static char masu[100][100];
	REP(i, 100) {
		REP(j, 100){
			masu[i][j] = (i < 50) ? '#' : '.';
		}
	}

	A--;
	B--;
	REP(i, 50) {
		REP(j, 100){
			if (0 < A) {
				bool isMuru = false;
				if (IsOdd(i)) {
					if (IsOdd(j)) {
						isMuru = true;
					}
				}
				if (isMuru) {
					A--;
					masu[i][j] = '.';
				}
			}
		}
	}
	
	REPN(i, 51, 100) {
		REP(j, 100){
			if (0 < B) {
				bool isMuru = false;
				if (IsOdd(i)) {
					if (IsOdd(j)) {
						isMuru = true;
					}
				}
				if (isMuru) {
					B--;
					masu[i][j] = '#';
				}
			}
		}
	}

 	cout << "100 100" << endl;
	REP(i, 100) {
		REP(j, 100){
			cout << masu[i][j];
		}
	 	cout << endl;
	}

	return 0;
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n, m, x; cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep(i, n){
        cin >> c[i];
        rep(j, m){
            cin >> a[i][j];
        }
    }
    ll ans = LINF;
    for(ll bits = 1LL; bits <= 1LL << n; bits++){
        ll cost = 0;
        vector<ll> U(m);
        rep(i, n){
            if(bits & 1 << i){
                cost += c[i];
                rep(j, m) U[j] += a[i][j];
            }
        }
        bool ng = false;
        rep(j, m){
            if(U[j] < x){
                ng = true;
                break;
            }
        }
        if(!ng) ans = min(ans, cost);
    }
    if(ans == LINF) cout << -1 << endl;
    else cout << ans << endl;
}


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

using namespace std;

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

    vector<int> v{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 k;
    cin >> k;
    cout << v[k-1] << endl;

    return 0;
}


Measured memory_bytes: 256
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	cout.precision(10);
	int n;
	cin >> n;
	double ans = (double)((n + 1) / 2) / n;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
        String inputArray[] = br.readLine().split(" ");
        final int N = Integer.parseInt(inputArray[0]);
        final int x = Integer.parseInt(inputArray[1]);
        inputArray = br.readLine().split(" ");
        int prev = 0;
        long sum = 0L;
        for (int i=0; i<N; i++) {
            int a = Integer.parseInt(inputArray[i]);
            if (prev+a>x) {
                int diff = prev+a-x;
                prev = a-diff;
                sum += diff;
            } else {
                prev = a;
            }
        }
        System.out.println(sum);
    }}


Measured memory_bytes: 45524
import java.util.Scanner;
	public class Main{
			  public static void main(String[]args){
			    Scanner sc = new Scanner(System.in);
			    
			    	while(true) {
			    int H = sc.nextInt();
			    int W = sc.nextInt();
                            if(H == 0 && W == 0) break;
		              for(int i = 0;i < H;++i) {
		            	  for(int j = 0;j < W;++j) {
		            		  System.out.printf("#");      		 
		            	  }
		            	  System.out.println("");
		            	  }
		        System.out.println("");
		        
			    	  }
			    
			    
			    	sc.close();   
			  }
			}


Measured memory_bytes: 56780
input_str = input().split(' ')

stack = []

left_num, right_num = 0, 0
for tmp_str in input_str:
    if tmp_str == '+':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num + right_num)

    elif tmp_str == '-':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num - right_num)

    elif tmp_str == '*':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num * right_num)

    elif tmp_str == '/':
        right_num = stack.pop()
        left_num = stack.pop()
        stack.append(left_num / right_num)

    else:
        stack.append(int(tmp_str))

print(stack.pop())


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

public class Main{
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
	
	public static void main (String[] args) throws IOException{
        int k = Integer.parseInt(br.readLine());
		String s = "ACL";
		String op = "";
		for(int i=0;i<k;i++){
			op += s;
		}
		bw.write(op + "\n");
        bw.flush();
    }
  
}

Measured memory_bytes: 37448
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  const char* result;
  switch (N % 10) {
  case 0: case 1: case 6: case 8:
    result = "pon";
    break;
  case 3:
    result = "bon";
    break;
  default:
    result = "hon";
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>

#define rep(i,x) for(int i=0;i<x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)

using namespace std;

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

	char set[10][10]={
		".,!?_",
		"abc",
		"def",
		"ghi",
		"jkl",
		"mno",
		"pqrs",
		"tuv",
		"wxyz",
	};


	rep(i,n)
	{
		string str;
		int keep=0;
		int num[100]={};

		cin >> str;

		rep(j,str.length())
		{
			if(str[j]=='0')
			{
				if( keep-1==0 && (num[keep]-1)%5==4 )cout<<" ";
				else if(num[keep]>=1)cout << set[keep-1][(num[keep]-1)%strlen(set[keep-1])];
				num[keep]=0;
				/*cout << num[keep] <<endl;*/
			}
			else 
			{
				keep=str[j] - '0';
				num[keep]++;
			}
			str[j]=0;
		}
		cout << endl;
	}
	return 0;
}

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


int main() {
    ll H, N;
    cin >> H >> N;
    ll sum = 0;
    rep(i, N){
        ll Ai;
        cin >> Ai;
        sum += Ai;
    }
    if(H - sum <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

const int N = 100005, M = 200005, inf = 1000000000;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m, fa[N], val[N], d[N], e[M];
bool vis[N], flag = true;

int findroot (int u) {
	if (fa[u] == u) return u;
	int r = findroot(fa[u]);
	assert(fa[fa[u]] == r);
	val[u] ^= val[fa[u]], fa[u] = r;
	return r;
}
bool merge (int u, int v) {
	int ru = findroot(u), rv = findroot(v);
	if (ru == rv) return false;
	fa[ru] = rv, val[ru] = val[u] ^ val[v] ^ 1;
	return true;
}
int main () {
	read(n), read(m);
	for (int i = 1; i <= n; i++) {
		fa[i] = i, val[i] = 0;
		vis[i] = false, read(d[i]);
	}
	for (int i = 1; i <= m; i++) {
		int u, v;
		read(u), read(v), e[i] = inf;
		bool need_add = false;
		if (d[v] <= d[u] && !vis[u]) need_add = true;
		if (d[u] <= d[v] && !vis[v]) need_add = true;
		if (need_add) {
			merge(u, v), e[i] = max(d[u], d[v]);
			if (d[v] <= d[u]) vis[u] = true;
			if (d[u] <= d[v]) vis[v] = true;
		}
	}

	for (int i = 1; i <= n; i++) flag &= vis[i];
	if (flag) {
		for (int i = 1; i <= n; i++) findroot(i), putchar(val[i] ? 'B' : 'W');
		putchar('\n');
		for (int i = 1; i <= m; i++) write(e[i]), putchar('\n');
	}
	else puts("-1");
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;

const int N = 100001;
int isp[N];

void p(int u, int v) {
    cout << u << ' ' << v << '\n';
}

int main() {
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i *= 2)
        isp[i] = 1;
    if (isp[n]) {
        cout << "No";
        return 0;
    }
    cout << "Yes\n";
    p(1, 2);
    p(2, 3);
    p(3, n + 1);
    p(n + 1, n + 2);
    p(n + 2, n + 3);
    for (int i = n; i > 4; i -= 2) {
        if (isp[i - 2]) {
            p(i - 1, 1);
            p(i - 2, 2);
            p(i, i - 2);
            p(n + i, 2);
            p(n + i - 1, n + i);
            p(n + i - 2, n + i);
            i--;
        }
        else {
            int x = i ^ (i - 1);
            p(i, i - 1);
            p(i - 1, x);
            p(x, n + i);
            p(n + i, n + i - 1);
        }
    }
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;

///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// ⸜( ⌓̈ )⸝ ///
int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    N--;
    for (size_t a = 1; a <= N; a++) {
        ans += N / a;
    }
    cout << ans << endl;
}

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

int n, m, q;
int t[501][501], s[501][501];

void solve() {
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        t[l][r]++;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + t[i][j];
            //cout << s[i][j] << " ";
        }
        //cout << "\n";
    }
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        cout << s[y][y] - s[x][y] - s[y][x] + s[x][x] << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a;
	if (a < 1200) {
		cout << "ABC" << "\n";
	}
	else if(a < 2800 && a >= 1200) {
		cout << "ARC" << "\n";
	}
	else if (a >= 2800) {
		cout << "AGC" << "\n";
	}
	
	std::cin >> e;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {

public static void main(String [] args){

        long N;
        long M =0,A =0,R =0,C =0,H =0;
        long count =0;
        String name;
        Scanner input = new Scanner(System.in);

        N = input.nextLong();

        for (long i=0; i<N; i++ ) {
                name = input.next();
                if (name.startsWith("M",0) ==true) {
                        M++;
                }else if (name.startsWith("A",0) ==true) {
                        A++;
                }else if (name.startsWith("R",0) ==true) {
                        R++;
                }else if (name.startsWith("C",0) ==true) {
                        C++;
                }else if (name.startsWith("H",0) ==true) {
                        H++;
                }
        }

        count = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C +A*R*H +A*C*H + R*C*H;

        System.out.println(count);
}
}


Measured memory_bytes: 47620
import java.util.*;
 
public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = (int)1e9 + 7;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int len = (int)1e7;
	
	
	void doIt() {
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		int len = S.length;
		int sum = 0;
		for(int i = 0; i < len; i++) {
			if(S[i] != T[i])sum++;
		}
		System.out.println(sum);
	}
	
	public static void main(String[] args) {
		new Main().doIt();
	}
 
}

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

int main() {
  ll n, k, p;
  cin >> n >> k;
  vector<double> wa(n + 1);
  wa[0] = 0;
  rep(i, n) {
    cin >> p;
    if (p % 2 == 0) {
      wa[i + 1] = wa[i] + (p / 2 + p / 2 + 1) / (double)2;
    } else {
      wa[i + 1] = wa[i] + p / 2 + 1;
    }
  }
  double ans = 0;
  rep(i, n - k + 1) ans = max(ans, wa[i + k] - wa[i]);
  printf("%.10lf\n", ans);
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

char s[51][51];
int d[51][51];

struct pos
{
    int x;
    int y;
};

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

void solve()
{
    int H, W;
    cin >> H >> W;
    int blk = 0;

    REP0 (h, H)
    {
        REP0 (w, W)
        {
            cin >> s[h][w];
            if (s[h][w] == '#')
                blk++;
        }
    }

    d[0][0] = 1;

    queue<pos> Q;
    Q.push({0, 0});

    while (Q.size())
    {
        pos p = Q.front();
        Q.pop();

        REP0 (i, 4)
        {
            int y = p.y + dy[i], x = p.x + dx[i];

            if (y < 0 or H - 1 < y or x < 0 or W - 1 < x)
                continue;

            if (s[y][x] == '.' and d[y][x] == 0)
            {
                d[y][x] = d[p.y][p.x] + 1;
                Q.push({x, y});
            }
        }
    }

    if (d[H - 1][W - 1] == 0)
    {
        cout << -1 << endl;
        return;
    }

    cout << H * W - d[H - 1][W - 1] - blk << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

int main(){
    int n, k, h[100000], ans;
    cin >> n >> k;
    for ( int i = 0; i < n; i++ ) {
        cin >> h[i];
    }
    sort(h, h+n);
    
    ans = INT_MAX;
    for ( int i = k-1; i < n; i++ ) {
        ans = min(ans, h[i] - h[i-k+1]);
    }
    cout << ans << endl;
    
    return (0);
}

Measured memory_bytes: 4024
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ld pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	set<int>a;
	int n, b;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b;
		if (a.find(b) == a.end())
			a.insert(b);
		else
			a.erase(b);
	}
	cout << a.size() << endl;
	getchar(); getchar();
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdlib>
#include <cstdio>
using namespace std;

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

int main() {
    string s, ans; cin >> s;

    if(s == "Sunny"){
        ans = "Cloudy";
    }else if(s == "Cloudy"){
        ans = "Rainy";
    }else{
        ans = "Sunny";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256