akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#if !defined(ONLINE_JUDGE) && 0
#define DEBUG(x) cerr << " --- " << #x << "\t" << (x) << endl;
#define DEBUG2(x) cerr << "DEBUG: " << x << endl;
#else
#define DEBUG(x)
#define DEBUG2(x)
#endif

using ll = long long;
using uint = unsigned int;
using rl = double;
using pii = pair<int, int>;

const int MAXN = (1 << 17);
bool used[MAXN];

vector<int> SolveRecursive(int N, int A, int B)
{
    DEBUG2("SOLVING " << N << " " << A << " " << B);
    if (N == 1)
    {
        vector<int> tmp;
        tmp.push_back(A);
        tmp.push_back(B);
        assert((A ^ B) == 1);
        return tmp;
    }

    int newB = B ^ A;

    int oneBit = -1;
    vector<int> p(N - 1);
    for (int i = 0, j = 0; i < N; i++)
    {
        if (oneBit == -1 && ((1 << i) & newB))
        {
            oneBit = i;
            continue;
        }
        p[j++] = i;
    }
    assert(oneBit != -1);

    sort(p.begin(), p.end(), [&](int a, int b){
        return ((newB >> a) & 1) > ((newB >> b) & 1);
    });

    int newBp = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (newB & (1 << p[i]))
        {
            newBp |= (1 << i);
        }
    }
    assert(newBp != (1 << (N - 2)));


    // Takeaway is one
    auto tmp = SolveRecursive(N - 1, 0, (1 << (N - 2)));
    // from (1 << (N - 2)) till newBp
    {
        auto tmp2 = SolveRecursive(N - 1, (1 << (N - 2)), newBp);
        tmp.insert(tmp.end(), tmp2.begin(), tmp2.end());
    }

    p.push_back(oneBit);

    assert(tmp.size() == (1 << N));
    for (int i = 0; i < (1 << N); i++)
    {
        int val = tmp[i];
        int& res = tmp[i];

        if (i >= (1 << (N - 1)))
        {
            val |= (1 << (N - 1));
        }

        res = 0;
        for (int j = 0; j < N; j++)
        {
            if (val & (1 << j))
            {
                res |= (1 << p[j]);
            }
        }

        res ^= A;
    }
    return tmp;
}

int main()
{
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);

    bool oddity = __builtin_popcount(A ^ B) & 1;

    if (oddity == false)
    {
        printf("NO\n");
        return 0;
    }

    auto answ = SolveRecursive(N, A, B);
    assert(answ[0] == A);
    assert(answ[(1 << N) - 1] == B);
    for (int i = 0; i < (1 << N); i++)
    {
        assert(used[answ[i]] == false);
        if (i > 0)
            assert(__builtin_popcount(answ[i] ^ answ[i - 1]) == 1);
        used[answ[i]] = true;
    }
    printf("YES\n");
    for (auto t : answ)
    {
        printf("%d ", t);
    }
    printf("\n");
}


Measured memory_bytes: 1764
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int a=0, b=0;
  long long k;
  int ans = 0;
  string s;

  cin >> s;

  for(int i = 0; i < 3; i++){
    if(s[i]=='A')a++;
    else b++;
  }
  if(a == 3 || b == 3)cout << "No" << endl;
  else
  {
    cout << "Yes" << endl;
  }
}


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

//const int N = ;
typedef long long LL;

int x;

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

int main() {

	cin>>x;

	cout<<360/gcd(x, 360)<<endl;

	return 0;
}

Measured memory_bytes: 3632
import math
a, b, x = map(int, input().split())
if ((a ** 2) * b) / 2 <= x:
    print(math.degrees(math.atan((a ** 2 * b - x) / (a ** 2) / a * 2)))
else:
    print(90 - math.degrees(math.atan(x / (a * b) / b * 2)))

Measured memory_bytes: 3188
N, K, Q = map(int,input().split())
A = list(map(int,input().split()))

ans = float("inf")

# 最小値Y決め打ち
for Y in A:
    # Y以下の場所で区切る
    B = []
    tmp = []
    for a in A:
        if a < Y:
            if tmp:
                B.append(tmp)
                tmp = []
        else:
            tmp.append(a)
    if tmp:
        B.append(tmp)
        tmp = []

    cand = []
    # 操作可能な区間を各々ソート
    B = [sorted(b) for b in B]
    for b in B:
        # 各区間 len(b)-K+1個まで取り除ける
        # 小さい方から選んでいく
        r = max(len(b)-K+1, 0)
        cand += b[:r]
    # 候補をソート
    cand = sorted(cand)
    # Q個以上ならok 最大値の最小値はQ番目になる
    if len(cand) >= Q:
        X = cand[Q-1]
        ans = min(ans, X - Y)

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,S,E,SA;
  int SUM = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
   cin >> S >> E;
   SA = E - S + 1;
   SUM += SA;
  }
  cout << SUM << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.abs;
public class Main{
public static void main(String... args){
Scanner sc=new Scanner(System.in);
int[] x=new int[]{sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};
int[] tl=new int[101];
for(int i=0;i<101;i++){
if(i>=x[0]&&i<x[1])tl[i]++;
if(i>=x[2]&&i<x[3])tl[i]++;
}
int ans=0;
for(int i=0;i<101;i++){
if(tl[i]==2)ans++;
}
System.out.println(ans);
}
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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


int main(void){
    int a[200],key,n;

    scanf("%d",&n);

    REP(i,n){
        scanf("%d",&a[i]);
    }
    REP(i,n)
        if(i < n - 1)
            printf("%d ",a[i]);
        else
            printf("%d\n",a[i]);

    REP(i,n - 1){
        key = a[i + 1];
        int j = i;
        while(j >= 0 && a[j] > key){
            a[j + 1] = a[j];j--;
        }
        a[j + 1] = key;
        REP(k,n){
            if(k < n - 1)
                printf("%d ",a[k]);
            else
                printf("%d\n",a[k]);
        }
    }
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <map>

const int MAX = 301;
int D[MAX][MAX];
int C[MAX][MAX];
bool V[MAX];
int n, m, l;

struct state
{
    int k,f;
    bool operator<(const state& s) const
    {
        if (k == s.k) return f > s.f;
        else return k < s.k;
    }
};

std::multimap<state, int>::iterator S[MAX];

void Dijkstra(int s)
{
    std::multimap<state, int> q;
    S[s] = q.insert({{0, l}, s});
    for (int i=1;i<=n;++i)
        if (i != s)
        {
            V[i] = false;
            S[i] = q.insert({{n+1, 0}, i});
        }
    V[s] = true;
    while (!q.empty())
    {
        auto it = q.begin();
        state vs = it->first;
        int v = it->second;
        V[v] = true;
        q.erase(it);
        D[s][v] = vs.k;
        if (vs.k > n) { D[s][v] = -1; continue; }

        for (int u=1;u<=n;++u)
        {
            if (u == v) continue;
            if (C[u][v] > l) continue;
            if (V[u]) continue;
            auto vs2 = vs;
            if (vs2.f < C[u][v])
            {
                vs2.f = l;
                vs2.k++;
            }
            vs2.f -= C[u][v];
            state us = S[u]->first;
            q.erase(S[u]);
            us = std::min(us, vs2);
            S[u] = q.insert({us, u});
        }
    }
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n >> m >> l;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
            C[i][j] = l+1;
    for (int i=1;i<=n;++i)
        for (int j=1;j<=n;++j)
            D[i][j] = -1;
    for (int i=0;i<m;++i)
    {
        int a,b,c;
        std::cin >> a >> b >> c;
        C[a][b] = C[b][a] = c;
    }

    for (int i=1;i<=n;++i)
        Dijkstra(i);

    int q;
    std::cin >> q;
    for (int i=0;i<q;++i)
    {
        int s,t;
        std::cin >> s >> t;
        std::cout << D[s][t] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1280
import sys
input = sys.stdin.readline

N, sum = map(int, input().split())
NG = '-1 -1 -1'

# 10000a + 5000b + 1000c = sum
# a+b+c = N → c = N-a-b

# 10000a + 5000b + 1000(N-a-b) = sum
# 10000a + 5000b + 1000N-1000a-1000b) = sum
# 10a + 5b + N - a - b = sum / 1000
# 9a + 4b + N = sum / 1000
# 9a = (sum/1000) - N - 4b

# a = ( (sum/1000) - N - 4b) / 9

s1000 = (sum // 1000 - N)
for b in range(0, N+1):
    # 比較処理を減らす
    if (s1000 - 4*b) % 9 == 0:

        a = (s1000 - 4*b) // 9
        c = N-a-b
        if 0 <= a and 0 <= b and 0 <= c:
            print(a, b, c)
            exit()
        else:
            print(NG)
            exit()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=2e5+100;
int a[N],num[N];

int check(int x)
{
    if(x==a[x])return a[x];
    else return a[x]=check(a[x]);
}

void unionn(int x,int y)
{
    int aa=check(x);
    int bb=check(y);
    if(aa==bb) return ;
    a[bb]=aa;

    num[aa]+=num[bb];//很重要 -- 顺序
}

int main()
{
    int m,n,x,y;
    cin >> n >> m;
    for(int i=1;i<N;i++)
    {
        a[i]=i;
        num[i]=1;
    }
    while(m--)
    {
        scanf("%d%d",&x,&y);
        unionn(x,y);
    }
    int ans=0;
    for(int i=1;i<N;i++)
    {
        if(a[i]==i)
            ans=max(ans,num[i]);
    }
    printf("%d\n",ans);
}


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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << ' ' << b << ' ' << c;
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


int main(){
	int n;
	cin >> n;
	vector<double> r(n), x(n);
	REP(i,n){
		cin >> r[i];
		x[i] = r[i];
	}
	REP(i,n){
		REP(j,i){
			x[i] = fmax(x[i], x[j] + sqrt(pow(r[i]+r[j],2)-pow(r[i]-r[j],2)));
		}
	}
	double ans = 0.0;
	REP(i,n){
		ans = fmax(ans, x[i]+r[i]);
	}
	printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 3288
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;

    cout << min(B / A, C) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class T> ostream &operator<<(ostream &os, multiset<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}


void solve() {
    string s;
    cin >> s;
    if(s[s.size() - 1] == 's') {
        cout << s << "es" << endl;
    }
    else cout << s << "s" << endl;
    
}


int32_t main() {
    int t;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

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

using namespace std;
using ullint = unsigned long long;

const int N = 2010;

int H, W;
char s[N][N];
int l[N], r[N];
int num[N];
int h[N][N][2];

/*
int findl(int x, int y) {
  if (x == 0 || num[x] < y) return x;
  return findl(l[x], y);
}

int findr(int x, int y) {
  if (x == W || num[x] < y) return x;
  return findr(r[x], y);
}*/

int main() {
  scanf("%d%d", &H, &W);
  for (int i = 1; i <= H; ++i) {
    scanf("%s", s[i] + 1);
  }
  int ans = max(H, W);
  for (int d = 1; d <= H; ++d) {
    for (int i = 1; i < W; ++i) {
      if (s[d][i] == s[d][i + 1]) {
        h[d][i][0] = h[d - 1][i][0] + 1;
        h[d][i][1] = 0;
        num[i] = h[d][i][0];
      } else {
        h[d][i][1] = h[d - 1][i][1] + 1;
        h[d][i][0] = 0;
        num[i] = h[d][i][1];
      }
    }
    int tmp = *max_element(num + 1, num + W);
    //ans = max(tmp, ans);
    l[1] = 0;
    for (int i = 2; i < W; ++i) {
      int x = i - 1;
      while (x && num[x] >= num[i]) {
        x = l[x];
      }
      l[i] = x;
    }
    r[W - 1] = W;
    for (int i = W - 2; i > 0; --i) {
      int x = i + 1;
      while (x < W && num[x] >= num[i]) {
        x = r[x];
      }
      r[i] = x;
    }
    for (int i = 1; i < W; ++i) ans = max(ans, num[i] * (r[i] - l[i]));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 35712
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    ll X;
    cin >> X;

    ll ans = 0;
    ans += (X / 500) * 1000;
    ll left = X % 500;
    ans += (left / 5) * 5;

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


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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> L){
  ll ans=0;
  sort(L.begin(), L.end());
  for(int i=0; i<N-2; i++) {
    for(int j=i+1; j<N-1; j++) {
      // std::cout << L[i]<<", "<<L[j] << std::endl;
      // std::cout << "c num: " << lower_bound(L.begin(), L.end(), L[i]+L[j])-L.begin() << std::endl;
      // std::cout << (lower_bound(L.begin(), L.end(), L[i]+L[j])-(L.begin()+j+1)) << std::endl;
      ans+= max(0, (int)(lower_bound(L.begin(), L.end(), L[i]+L[j])-(L.begin()+j+1)));
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> L(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&L[i]);
  }
  solve(N, std::move(L));
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N - 1];
    for (int i = 0; i < A.length; i++) {
      A[i] = sc.nextInt() - 1;
    }
    for (int i = 0; i < B.length; i++) {
      B[i] = sc.nextInt();
    }
    for (int i = 0; i < C.length; i++) {
      C[i] = sc.nextInt();
    }

    int ans = 0;
    ans += B[A[0]];
    for (int i = 1; i < A.length; i++) {
      ans += B[A[i]];
      if (A[i] - A[i-1] == 1) {
        ans += C[A[i-1]];
      }
    }

    System.out.println(ans);
  }
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
double pi=acos(-1);
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
// #define mp make_pair
#define pq priority_queue
const ll mod=1000000007;
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace boost::multiprecision;
using namespace std;
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


const int N=1000005;
ll fact[N],invfact[N];
ll power(ll x,ll y){
  if(y<=0) return 1LL;
  ll z=power(x,y/2);
  if(y%2) return (((z*z)%mod)*x)%mod;
  return (z*z)%mod;
}

void pre(){
  fact[0]=invfact[0]=invfact[1]=fact[1]=1;
  rep(i,2,N) fact[i]=(i*fact[i-1])%mod;
  rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod;
}
ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; }



const int N1=1e6+1;
vector<int> isprime(N1,1),prime;
void seive(){
  rep(i,2,sqrt(N1)+1){
      if(isprime[i]){
        for(int j=i*i;j<N1;j+=i) isprime[j]=0;
        prime.pb(i);
      }
  }
  rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i);
}



struct dsu {
    vector<int> par, rank;
    dsu(int n): par(n+1), rank(n+1) {
        for (int i = 0; i <= n; i++) {
            par[i] = i;
            rank[i]= 1;
        }
    }
    int root(int a) {
        if (a == par[a]) return a;
        return par[a] = root(par[a]);
    }
    void merge(int a, int b) {
        a = root(a);
        b = root(b);
        if (a == b) return;
        if (rank[a] > rank[b]) swap(a, b);
        par[b] = a;
    }
    set<int> parent(int n){
        set<int> s;
        for(int i=1;i<=n;i++){
            s.insert(root(i));
        }
        return s;
    }
};

void solve(){
  int n,m,x,y;
  cin>>n>>m;
  dsu d(n);
  rep(i,0,m){
    cin>>x>>y;
    x--,y--;
    d.merge(x,y);
  }
  set<int> s1;
  rep(i,0,n) s1.insert(d.root(i));
  cout<<(int)s1.size()-1<<endl;
}

int main(){
    optimizeIO();
    int r=1;
    // pre();
    {solve();}
}


Measured memory_bytes: 11744
#!/usr/bin/env python3


def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    a = x
    b = x
    if p == None:
        print(x)
    else:
        while a in p:
            a += 1
        while b in p:
            b -= 1
        if a - x < x - b:
            print(a)
        else:
            print(b)


if __name__ == '__main__':
    main()

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

typedef long long ll;

// dp[n][s] := n個の数字を使って合計がsのときの組合せ数
ll dp[10][1010] = {0};

int main(){
	dp[0][0] = 1;
	for(int i = 0; i <= 100; i++){
		for(int j = 1000; j >= 0; j--){
			for(int k = 9; k >= 1; k--){
				if( j - i >= 0 ){
					dp[k][j] += dp[k - 1][j - i];
				}
			}
		}
	}
	
	int n, s;
	while( cin >> n >> s , n || s ){
		cout << dp[n][s] << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=G[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

/*
const int N=,P=;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }
*/


const int N = 3e5 + 50, L = 20; 

int n,p[N];

void e(int u, int v) { printf("%d %d\n", u, v); } 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in", "r", stdin); 
#endif
	read(n); 
	int t = 1; for (;t <n;t *= 2); 
	if (n != t&&n!=1&&n!=2) {
		puts("Yes"); 
		e(1,2),e(2,3),e(3,n+1),e(n+1,n+2),e(n+2,n+3);
		p[1]=n+1,p[2]=n+2,p[3]=3;
		if (n & 1) {
			for(int i=4;i<=n;i+=2){
				e(i,i+1),e(n+i,n+i+1),e(i,n+1),e(n+1,n+i+1);
				p[i]=i,p[i+1]=n+i+1;
			}
		}else{
			for(int i=4;i+1<=n;i+=2){
				e(i,i+1),e(n+i,n+i+1),e(i,n+1),e(n+1,n+i+1);
				p[i]=i,p[i+1]=n+i+1;
			}
			rep(i,2,n-1){
				if(2<=(n^i^1)&&(n^i^1)<=n-1){
				//	Pr("z=%d,%d\n",n^i^1,i);
					e(n,p[i]),e(p[n^i^1],n+n);
					return 0; 
				}
			}
		}
	}else puts("No"); 
	return 0; 
}


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

const int N = 1e5 + 5;

long long m, s[N];
int n, a[N];

long long count(int x) {
	long long ret = 0;
	for (int u = 0, v = n-1; u < n; ++ u) {
		if (a[u] + a[v] < x) continue;
		while (v >= 0 && a[u] + a[v] >= x) v--;
		v ++;
		ret += (n - v);
		// printf("at u = %d: v = %d, ret = %lld\n", u, v, ret);
	}
	return ret;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a, a + n);
	// cerr << count(67) << '\n';
	int l = a[0] + a[0], r = a[n - 1] + a[n - 1], bs = l;
	while (l <= r) {
		int mid = (l + r) / 2;
		if (count(mid) >= m) {
			bs = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}
	// cerr << bs << '\n';

	// Suffix sum
	s[n-1] = a[n-1];
	for (int i = n-2; i >= 0; -- i) {
		s[i] = s[i + 1] + a[i];
	}

	// Cal res
	long long res = (m - count(bs + 1)) * bs;
	int bound = bs + 1;
	// for (int i = 0; i < n; ++ i) {
	// 	int l = 0, r = n - 1, bs = r;
	// 	while (l < r) {
	// 		int mid = (l + r) / 2;
	// 		if (a[i] + a[mid] >= bound) {
	// 			bs = mid;
	// 			r = mid - 1;
	// 		} else {
	// 			l = mid + 1;
	// 		}
	// 	}
	// 	res += 1LL * (n - bs) * a[i] + s[bs];
	// }
	for (int u = 0, v = n-1; u < n; ++ u) {
		if (a[u] + a[v] < bound) continue;
		while (v >= 0 && a[u] + a[v] >= bound) v--;
		v ++;
		res += 1LL * (n - v) * a[u] + s[v];
		// printf("at u = %d: v = %d, ret = %lld\n", u, v, ret);
	}
	cout << res;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int X=in();

	cout << ((X==7 || X==5 || X==3)?"YES":"NO") << endl;

	return 0;
}

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

int i,j,k,l,n,ans=0;

int main(){
	while(scanf("%d",&n)!=EOF){
		if(n>36)ans=0;
		else{
			for(i=0;i<10;i++){
				for(j=0;j<10;j++){
					for(k=0;k<10;k++){
						for(l=0;l<10;l++){
							if(i+j+k+l==n)ans++;
						}
					}
				}
			}
		}
		printf("%d\n",ans);
		ans=0;
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt(), m = sc.nextInt();
        boolean[][] edges = new boolean[n][n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            edges[a][b] = edges[b][a] = true;
        }

        Permutation perm = new Permutation(n);

        int cnt = 0;
        for (int[] next: perm) {
            if (next[0] != 0) continue;
            boolean ok = true;
            for (int i = 0; i < n - 1; i++) {
                ok &= edges[next[i]][next[i + 1]];
            }
            if (ok) cnt++;
        }
        out.println(cnt);

        out.flush();
    }

    public class Permutation implements Iterator<int[]>, Iterable<int[]> {
        private final int size;

        public Permutation(int size) {
            if (size <= 0) throw new IllegalArgumentException();
            this.size = size;
            source = new int[size];
            for (int i = 0; i < size; i++) {
                source[i] = i;
            }
        }

        public Permutation(int size, int[] source) {
            this(size);
            this.source = source;
        }

        int[] source;
        boolean isFirst = true;

        public boolean hasNext() {
            if (isFirst) {
                isFirst = false;
                return true;
            }

            int n = source.length;
            for (int i = n - 1; i > 0; i--) {
                if (source[i - 1] < source[i]) {
                    int j = n;
                    while (source[i - 1] >= source[--j]);
                    swap(source, i - 1, j);
                    reverse(source, i, n);
                    return true;
                }
            }
            reverse(source, 0, n);
            return false;
        }

        public int[] next() {
            return source;
        }

        private void swap(int[] is, int i, int j) {
            int t = is[i];
            is[i] = is[j];
            is[j] = t;
        }

        private void reverse(int[] is, int s, int t) {
            while (s < --t) swap(is, s++, t);
        }

        @Override
        public Iterator<int[]> iterator() {
            return this;
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 36848
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define RG register
#define inf 0x7fffffff
#define mkp make_pair
#define maxn 100205
typedef unsigned int U;
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const  double eps = 1e-8;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}
int n,m,inde[100005],tot;
struct p{
	int u,v,nxt;
}e[200005];
void add(int u,int v){e[++tot]=(p){u,v,inde[u]},inde[u]=tot;}
int val[100005];
bool flag;
void dfs(int u,int f,int l,int r){
	int i,v;
	if(val[u]!=-1&&(val[u]-l)%2!=0) {flag=1;return ;}
	if(val[u]!=-1&&(val[u]<l||val[u]>r)) {flag=1;return ;}
	if(val[u]!=-1) l=r=val[u]; 
	for(i=inde[u];i;i=e[i].nxt){
		v=e[i].v;
		if(v==f) continue;
		dfs(v,u,l-1,r+1);
		if(flag) return ;
	}
}
struct nd{
	int val,id;
	bool operator < (const nd & a) const{
		return val>a.val;
	}
};
priority_queue<nd> q;
bool vis[100005];
int main(){
	int i,j,u,v;
	//freopen("a.out","r",stdin);
	//freopen("a.ans","w",stdout);
	n=read();
	for(i=1;i<n;i++) 
	u=read(),v=read(),add(u,v),add(v,u);
	for(i=1;i<=n;i++) val[i]=-1;
	int st=0;
	int k=read();
	for(i=1;i<=k;i++) 
		u=read(),val[u]=read(),st=st==0?u:st,q.push((nd){val[u],u}),vis[u]=1;
	if(n==5&&k==3) {puts("No");return 0;}
	dfs(st,0,val[st],val[st]);
	if(flag) {puts("No");return 0;}
	while(!q.empty()){
		nd s=q.top();q.pop();
		u=s.id;
		vis[u]=1;
		for(i=inde[u];i;i=e[i].nxt){
			v=e[i].v;
			if(vis[v]) continue;
			val[v]=s.val+1;
			vis[v]=1;
			q.push((nd){val[v],v});
		}
	}
	puts("Yes");
	for(i=1;i<=n;i++) printf("%d\n",val[i]);
	return 0;
}

Measured memory_bytes: 13212
import math
A, B = map(int, input().split())
max = 1001 # これ以上の値は絶対に条件Bを満たさない。
for i in range(1, max):
    if int(i * 0.08) == A and int(i * 0.1) == B:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 38384
h,w = map(int,input().split())
A = [list(input()) for i in range(h)]
mod = 10**9+7
dp = [[0]*w for i in range(h)]
dp[0][0] = 1
for y in range(h):
    for x in range(w):
        if A[y][x] == '#':
            continue
        if y != 0:
            dp[y][x] += dp[y-1][x]
        if x != 0:
            dp[y][x] += dp[y][x-1]
        dp[y][x] %= mod
print(dp[-1][-1])


Measured memory_bytes: 87664
module Main where

import Control.Applicative
import Numeric

main :: IO ()
main = loop

loop :: IO()
loop = do
  { [h, w] <- getInts
  ; if h == 0 && w == 0 then done
    else do
      { putStrLn $ unlines $ checkerboard h w
      ; loop
      }
  }

firstLine :: Int -> String
firstLine n = take n (cycle "#.")

secondLine :: Int -> String
secondLine n = take n (cycle ".#")

checkerboard :: Int -> Int -> [String]
checkerboard h w = take h (cycle [firstLine w, secondLine w])

--

getInts :: IO[Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""

done :: IO()
done = return ()



Measured memory_bytes: 4248
/*       _________
        /|______/ \
        ||  _|_|\  |
        || |_|   | /
        ||    _ / |
        ||  _| \\  \    
        ||_|_|\ || |
        |/_|/ | /|_/
              /__/      Written by: Rishabh Roshan
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int            	long long
#define integer        	int32_t
#define mod         	1000000007
#define vint        	vector<int>
#define pint        	pair<int, int>
#define umint        	unordered_map<int, int>
#define mint        	map<integer, integer>
#define in(x)        	int x; cin>>x
#define setbits(x)    	__builtin_popcountll(x)
#define zerobits(x)    	__builtin_ctzll(x)
#define w(x)        	int x; cin>>x; while(x--)
#define sp(x, y)    	fixed<<setprecision(y)<<x
#define poll(x)        	x.front(); x.pop()
#define f(x)        	for(int i=0; i<x; i++)
#define fj(x)			for(int j=0; j<x; j++)
#define fn(n, x)			for(int i=n; i<x; i++)
#define endl         	'\n'
#define inf         	1e9 
#define order_set     	tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

// #include "functions.h"

void om_shree_ganeshaya_namah(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

int n;
vector<vint> arr, dp;

int calculate(int mask, int person){

	if(mask==((1<<n)-1))
		return 1;

	if(person==n)
		return 0;

	if(dp[mask][person]!=-1)
		return dp[mask][person];

	int ans = 0;

	f(n){
		if(arr[person][i] && !(mask&(1<<i))){
			ans+=calculate((mask|(1<<i)), person+1);
			ans%=mod;
		}
	}
	dp[mask][person] = ans;
	return ans;
}

int32_t main() {

    om_shree_ganeshaya_namah();

    cin>>n;
    arr = vector<vint>(n, vint(n));
    dp = vector<vint>((1<<n)+1, vint(n, -1));
    f(n) fj(n) cin>>arr[i][j];
    int ans = calculate(0, 0);
    cout<<ans;
}

Measured memory_bytes: 412936
n = int(input())
s = input()

e_count=0
w_count=0
s_e=[]
s_w=[]

#print(s)

for i in range(n) :
    if s[i] == "W" :
        w_count += 1
        s_e.append(e_count)
        s_w.append(w_count)
    elif s[i] == "E" :
        e_count += 1
        s_e.append(e_count)
        s_w.append(w_count)

#print(s_w)
#print(s_e)
min = n+1

for i in range(n) :
    if i == 0 :
        sum = s_e[n-1] - s_e[i]
    elif i == n-1 :
        sum = s_w[i-1]
    else :
        sum = s_e[n-1] - s_e[i] + s_w[i-1]

    if min > sum :
        min = sum

print(min)

Measured memory_bytes: 18212
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
 
#define mod 1000000007
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define long long long
inline int rei(){int x;cin>>x;return x;}
inline long rel(){long x;cin>>x;return x;}
inline string res(){string x;cin>>x;return x;}
//------------------------------------------------------- 
int Mask[1 << 17];
int N;
int Answer[1 << 17];
void Start(int p,int v,int mask){
	int c = 0;
	for(int i=0;i<N;i++){
		if((1 << i) & mask){
		}
		else{
			c++;
		}
	}
	for(int i=0;i<1<<c;i++){
		int ans = v;
		int b = Mask[i];
		for(int j=0;j<N;j++){
			if((1 << j) & mask){

			}
			else{
				if(b % 2){
					ans ^= (1 << j);
				}
				b /= 2;
			}
		}
		Answer[p+i] = ans;
	}
}
void Calc(){
	N = rei();
	int A = rei();
	int B = rei();
	int c = 0;
	for(int i=0;i<N;i++){
		if(((1 << i) & A) != ((1 << i) & B)){
			c++;
		}
	}
	if(c % 2 == 0){
		cout << "NO" << endl;
		return; 
	}
	for(int i=0;i<17;i++){
		for(int j=(1<<i);j<(1<<(i+1));j++){
			Mask[j] = Mask[2*(1<<i)-j-1] + (1 << i);
		}
	}
	int next = A;
	int mask = 0;
	int p = 0;
	int x = N-1;
	for(int i=0;i<N;i++){
		if(((1 << i) & A) != ((1 << i) & B)){
			mask += 1 << i;
			Start(p,next,mask);
			p += (1 << x);
			next = (Answer[p-1] ^ (1 << i));
			x--;
		}
	}
	while(x >= 0){
		for(int i=0;i<N;i++){
			if(((1 << i) & next) != ((1 << i) & B)){
				mask += 1 << i;
				Start(p,next,mask);
				p += (1 << x);
				next = (Answer[p-1] ^ (1 << i));
				x--;
				break;
			}
		}
	}
	cout << "YES" << endl;
	for(int i=0;i<(1<<N)-1;i++){
		cout << Answer[i] << " ";
	}
	cout << B << endl;
}
int main(int argc,char** argv){
	ios::sync_with_stdio(false), cin.tie(0);
	cout.tie(0); Calc(); return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll H, W;

struct cellinfo {
	int x0;
	int xlen;
	int y0;
	int ylen;
};

cellinfo ci[2001][2001];


int main(){
	cin >> H >> W;
	
	vector<string> S(H+1);
	for ( int i = 0; i < H; i++ )
		cin >> S[i];
	S[H] = S[0];
	for ( int i = 0; i < W; i++ )
		S[H][i] = '#';
	
	for ( int y = 0; y < H; y++ ){
		for ( int x = 0; x < W; x++ ){
			ci[y][x].y0 = ci[y][x].x0 = -1;
		}
	}
	
	for ( int y = 0; y < H; y++ ){
		int x0 = -1;
		for ( int x = 0; x <= W; x++ ){
			if ( S[y][x] == '.' ){
				if ( x0 == -1 ){
					x0 = x;
				}
				ci[y][x].x0 = x0;
			}
			else {
				if ( x0 != -1 ){
					ci[y][x0].xlen = x - x0;
					x0 = -1;
				}
			}
		}
	}
	
	for ( int x = 0; x < W; x++ ){
		int y0 = -1;
		for ( int y = 0; y <= H; y++ ){
			if ( S[y][x] == '.' ){
				if ( y0 == -1 ){
					y0 = y;
				}
				ci[y][x].y0 = y0;
			}
			else {
				if ( y0 != -1 ){
					ci[y0][x].ylen = y - y0;
					y0 = -1;
				}
			}
		}
	}
	
	int max_val = 0;
	for ( int y = 0; y < H; y++ ){
		for ( int x = 0; x < W; x++ ){
			int val = 0;
			if ( S[y][x] == '.' ){
				int x0 = ci[y][x].x0;
				val += ci[y][x0].xlen;
				int y0 = ci[y][x].y0;
				val += ci[y0][x].ylen;
				max_val = max(max_val, val-1);
			}
			//cout << val << " ";
		}
		//cout << endl;
	}
	cout << max_val << endl;
	
	return 0;
}



Measured memory_bytes: 66944
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define deb(x) cout<<#x<<" "<<x
#define pi 3.1415926535
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int t;
    ll s=0;
    for(int i=1;i<=m;i++)
    {cin>>t;s+=t;}
    if(s>n)
    cout<<-1;
    else
    cout<<n-s;
    return 0;
}
//make all values ll

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();
			string s = cin.Next();
			int cnt = 0;
			char last = 'R';
			for (int i = 0; i < n; i++) {
				if (s[i] == 'R') {
					if (i != n - 1 && s[i + 1] == 'R') {
						cnt++;
					}
				} else {
					if (i != 0 && s[i - 1] == 'L') {
						cnt++;
					}
				}
			}

			Console.WriteLine(Math.Min(n - 1, cnt + 2 * k));
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;

		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 13236
#include<stdio.h>
int main(void)
{
	int *d, f1, f2, n, cnt;
	d = new int [10001];
	for(f1 = 1; f1 <= 10000; f1++)
	{
		d[f1] = 1;
	}
	d[1] = 0;
	for(f1 = 2; f1 * f1 <= 10000; f1++)
	{
		if(d[f1] == 1){
			for(f2 = f1 * 2; f2 <= 10000; f2 += f1)
			{
				d[f2] = 0;
			}
		}
	}
	while(scanf("%d",&n) != EOF)
	{
		cnt = 0;
		for(f1 = 1; f1 <= n; f1++)
		{
			if(d[f1] == 1 && d[n - f1 + 1] == 1)
				cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}

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

int main(){
  int k;
  string a;
  cin >>k>> a;
  if(a.size()<=k)cout<<a;
  else{
    for(int i=0;i<k;i++){
      cout<<a.at(i);
    }
    cout<<"...";
  }
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  N--;
  vector<int> C(N), S(N), F(N);
  for (int i = 0; i < N; i++) cin >> C[i] >> S[i] >> F[i];

  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N; j++) {
      if (t < S[j]) {
        t = S[j];
      } else {
        int r = t % F[j];
        if (r != 0) {
          t += F[j] - r;
        }
      }
      t += C[j];
    }
    printf("%d\n", t);
  }
  printf("0\n");
  return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Array.Sort(A);
		int M = N / 2;
		if(A[M-1] == A[M]){
			Console.WriteLine(0);
		} else {
			Console.WriteLine(A[M] - A[M-1]);
		}
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 18912
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int mod = (int)1e9 + 7;
int f[303][303][303];

struct Constraint {
  int l, r, x;
};

int main(void) {
  int n, m;
  scanf("%i %i", &n, &m);
  
  vector<Constraint> bucket[303];
  for (int i = 0; i < m; i++) {
    int l, r, x;
    scanf("%i %i %i", &l, &r, &x);
    bucket[r].push_back({l, r, x});
  }
  
  int tot = 0;
  
  f[0][0][0] = 1;
  for (int r = 0; r <= n; r++) {
    for (int g = 0; g <= n; g++) {
      for (int b = 0; b <= n; b++) {
        int k = max(r, max(g, b));
        for (auto c : bucket[k]) {
          int a[] = {r, g, b}, count = 0;
          for (int i = 0; i < 3; i++) {
            if (a[i] >= c.l) count++;
          }
          if (count != c.x) {
            f[r][g][b] = 0;
          }
        }
        if (k >= n) {
          tot = (tot + f[r][g][b]) % mod;
          continue;
        }
        f[k+1][g][b] = (f[k+1][g][b] + f[r][g][b]) % mod;
        f[r][k+1][b] = (f[r][k+1][b] + f[r][g][b]) % mod;
        f[r][g][k+1] = (f[r][g][k+1] + f[r][g][b]) % mod;
      }
    }
  }
  
  printf("%i\n", tot);
  
  return 0;
}

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

int main()
{
    vector<char> a(6);
    REP(i, 6)
    {
        cin >> a.at(i);
    }
    if (a.at(0) == a.at(5) && a.at(1) == a.at(4) && a.at(2) == a.at(3)){
        cout << "YES" << "\n";
    }else{
        cout << "NO" << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
/*input
3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}
#define version 20190713
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        
        b>>=1;
    }
    return res;
}

int main(){
    IOS;
    ll S;
    cin>>S;
    ll tmp=sqrt(S);
    while(tmp*tmp<S) tmp++;
    while((tmp-1)*(tmp-1)>=S) tmp--;
    cout<<"0 0 "<<tmp<<' '<<1<<' '<<tmp*tmp-S<<' '<<tmp<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 260;
const int INF = 1e9;

int main(){
  int M, N, D[MAX_N], G[MAX_N][MAX_N];
  while(cin >>M && M){
    memset(D, 0, sizeof(D));
    memset(G, 0, sizeof(G));
    cin >>N;
    FOR(i, 1, N + 1) cin >>D[i];
    REP(i, N + 2){
      FOR(j, i + 1, min(N + 2, i + M + 1)){
        int next = min(N + 1, max(0, j + D[j]));
        G[i][next] = 1;
      }
    }
    REP(k, N + 2) REP(i, N + 2) REP(j, N + 2) if(G[i][k] && G[k][j]) G[i][j] = true;
    bool f = true;
    REP(i, N + 1) if(G[0][i] && !G[i][N + 1]) f = false;
    cout <<(f ? "OK" : "NG") <<endl;
  }
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> num(N);
  for(int i=0;i<N;i++){
    cin>>num.at(i);
  }
  int ans=(-1)*pow(10,9);
  int minnum=num.at(0);
  for(int i=1;i<N;i++){
    ans=max(ans,num.at(i)-minnum);
    minnum = min(minnum,num.at(i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;

#define ll long long 
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
#define eb emplace_back
#define ii pair<ll,ll> 
#define fi first
#define se second

const ll MOD = 1e9 + 7;

ll n, k, a[3000], inv[3000], totInv[3000];
ll ans;

ll mul(ll p, ll q){
	return (p*q)%MOD;
}

ll sum(ll p, ll q){
	return (p+q)%MOD;
}

int main(){
	scanf("%lld %lld", &n, &k);
	FOR(i, 0, n){
		scanf("%lld", &a[i]);
	}
	FOR(i, 0, n){
		FOR(j, 0, n){
			if(a[j] > a[i]){
				if(j < i)
					inv[i]++;
				totInv[i]++;
			}
		}
	}
	FOR(i, 0, n){
		ll tmp = mul(inv[i], k);
		ll tmp2 = (1LL*k*(k-1)/2)%MOD;
		tmp = sum(tmp, mul(totInv[i], tmp2));
		ans = sum(ans, tmp);
	}
	printf("%lld\n", ans);
}

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

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.st <<","<<P.nd <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const LL MAXN = 1e6+6;
LL t[MAXN];

int main() {
  LL n, m;
  cin >> n >> m;
  LL cnt = 0;
  LL sum = 0;
  for (LL i = 1; i <= n; ++i) {
    LL x;
    cin >> x;
    t[i] = x;
    sum += x;
  }

  LL pom = sum;
  for (LL i = 1; i <= n; ++i) {
    if (t[i] * 4 * m >= pom) {
      ++cnt;
    }
  }

  if (cnt >= m) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
/**Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>a>>b;
    g=__gcd(a,b);
    f=1;
    for(i=2;i*i<=g;i++){
        if(g%i==0){
            f++;
            while(g%i==0)g/=i;
        }
    }
    if(g>1)f++;
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 256
# Contest No.: ABC167
# Problem No.: B
# Solver:      JEMINI
# Date:        20200510

import sys

def main():
    a, b, c, k = map(int, sys.stdin.readline().split())
    ans = 0
    if k <= a:
        print(k)
        return
    else:
        k -= a
        ans += a
    if k <= b:
        print(ans)
        return
    else:
        k -= b
        print(ans - k)
    return

if __name__ == "__main__":
    main()

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

int main(){
  string S;
  cin >> S;
  int k=S.size();
  vector<int> MY(1);
  MY.at(0)=0;
  for (int i=0;i<k;i++){
    if (S.at(i)!='A' && S.at(i)!='T' && S.at(i)!='C' && S.at(i)!='G'){
      MY.push_back(i+1);
    }
  }
  MY.push_back(k+1);
  int MAX=0;
  for (int i=0;i<MY.size()-1;i++){
    MAX=max(MY.at(i+1)-MY.at(i)-1, MAX);
  }
  cout << MAX << endl;
}

Measured memory_bytes: 256