akhauriyash/Code-Regression huggingface dataset:
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(3);
    string s,s1,s2;
    cin >> n ; 
    if(n==1)
        cout << "Hello World" <<endl;
    else{ 
        cin >> a >> b;    
        cout << a+b <<endl;
    }
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

const int dd = 2007;

int mn[dd][dd];
int mx[dd][dd];

vector<int> G;

int get(int a, int b) { return abs(G[b] - G[a]); }

int main() {
    int n, X, B;
    cin >> n >> X >> B;

    vector<int> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];


    for (int i = 0; i < n; i++) G.push_back(A[i]);
    G.push_back(X);
    G.push_back(B);

    sort(G.begin(), G.end());
    G.resize(unique(G.begin(), G.end()) - G.begin());

    for (int i = 0; i < n; i++) A[i] = lower_bound(G.begin(), G.end(), A[i]) - G.begin();


    int len = (int)G.size();
    for (int c = 0; c < len; c++) {
        mn[n - 1][c] = mx[n - 1][c] = get(A[n - 1], c);
    }

    int cmn = (int)1e9;
    int cmx = -(int)1e9;

    for (int i = n - 1; i >= 0; i--) {
        for (int c = 0; c < len; c++) {

            mn[i][c] = get(A[n - 1], c);
            mx[i][c] = get(A[n - 1], c);

            mn[i][c] = min(mn[i][c], cmn);
            mx[i][c] = max(mx[i][c], cmx);
        }
        if (i) {
            cmn = min(cmn, mx[i][A[i - 1]]);
            cmx = max(cmx, mn[i][A[i - 1]]);
        }
    }

    int ans = abs(G[A[n - 1]] - B);
    for (int st = 0; st + 1 < n; st++) {
        ans = max(ans, mn[st + 1][A[st]]);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 31616
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := nextInt(), nextInt()
	s := a - b*2
	if s < 0 {
		fmt.Println(0)
	} else {
		fmt.Println(s)
	}
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll mod = 1e9+7;
//LLONG_MIN

//WA

ll test(ll a,ll n){
	ll ans=1;
	while(n>0){
		if(n&1)ans=(ans*a)%mod;
		a=(a*a)%mod;
		n>>=1;
	}
	return ans;
}

int main(void){
	int H,W,A,B;
	ll fact[200010]={},inv[200010]={},ans=0;
	scanf("%d%d%d%d",&H,&W,&A,&B);
	fact[0]=1;
	reg(i,1,H+W)fact[i]=(fact[i-1]*i)%mod;
	inv[H+W] = test(fact[H+W],mod-2);
	ireg(i,0,H+W-1)inv[i]=(inv[i+1]*(i+1))%mod;
	reg(i,1,H-A){
		//C(B+i,i)*C((H-B)+(W-i+1),H-B)
		ll a;
		a = (fact[B+i-2]*inv[i-1])%mod;
		a = (a*inv[B-1])%mod;
		a = (a*fact[(W-(B+1))+(H-i)])%mod;
		a = (a*inv[W-(B+1)])%mod;
		a = (a*inv[H-i])%mod;
		ans = (ans+a)%mod;
	}
	// reg(i,1,W+H)printf("fact[%d]:%lld\n",i,fact[i]);
	// reg(i,1,W+H)printf("inv[%d]:%lld\n",i,inv[i]);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	string S;
	bool flag = false;

	if ( s.substr(0, 7) == "keyence" || s.substr(s.size()-7, 7) == "keyence" ) flag = true;

	for ( int i = 0; i < 7; i++ ) {
		S = s;
		S.erase(i, s.size() - 7);
		if ( S == "keyence" ) flag = true;
	}

	if ( flag ) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(int x,int y){
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x]) swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool findSet(int x,int y){return root(x)==root(y);}
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x) {return -data[root(x)];}
};


int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  UF uf(n+m);
  rep(i,n){
    int t,x;
    cin>>t;
    rep(j,t){
      cin>>x; --x;
      uf.unite(i,x+n);
    }
  }
  int f=1;
  rep(i,n) if(!uf.findSet(i,0)) f=0;
  cout<<(f?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    string s,t;
    cin>>s;
    cin>>t;
    int ans = 0;
    rep(i,3) {
        if(s[i]==t[i]) ans++;
    }
    cout<<ans<<endl;

    return 0;
}


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

int main()
{
	int test[3];
	int sum = 0;
	int i;

	while (1) {
		for (i = 0; i < 3; i++) {
			cin >> test[i];
		}

		for (i = 0; i < 2; i++) {
			if (test[i] != -1) {
				sum += test[i];
			}
		}

		if (test[0] == -1 && test[1] == -1 && test[2] == -1) {
			break;
		}

		if ((test[0] == -1 || test[1] == -1) || (sum < 30)) {
			cout << "F" << endl;
		} else if (sum < 50) {
			if (test[2] >= 50) {
				cout << "C" << endl;
			} else {
				cout << "D" << endl;
			}
		} else if (sum < 65) {
			cout << "C" << endl;
		} else if (sum < 80) {
			cout << "B" << endl;
		} else {
			cout << "A" << endl;
		}
		sum = 0;
	}

	return 0;
}

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


long long solve(vector<int>&a, int n, int m){

    priority_queue<int>Q;
    for(int i = 0; i < n; i++){
        Q.push(a[i]);
    }
    
    while(m > 0){
        int top_element = Q.top();
        Q.pop();
        top_element = top_element/2;
        Q.push(top_element);
        
        m -= 1;
    }
    long long solution = 0;
    while(!Q.empty()){
        
        solution += Q.top();
        Q.pop();
    }
    
    
    return solution;
    
    
}





int main(){
    
    int n, m;
    cin >> n >> m;
    vector<int>a(n);
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    cout << solve(a, n, m) << endl;
    
    
    return 0;
    
}


Measured memory_bytes: 4320
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    string hoge; cin>>hoge;
    rep(i,hoge.size()){
        if(hoge[i]==',')cout<<" ";
        else cout<<hoge[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9
 
struct Puzzle{
int f[N2];
int space;
string path;
 
bool operator < (const Puzzle &p) const{
for(int i = 0; i < N2; i++){
if(f[i] == p.f[i]) continue;
return f[i] > p.f[i];
}
return false;
}
};
 
static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char dir[4] = {'u','l','d','r'};
 
bool isTarget(Puzzle p){
for(int i = 0; i < N2; i++)
if(p.f[i] != (i + 1)) return false;
return true;
}
 
string bfs(Puzzle s){
queue<Puzzle> Q;
map<Puzzle, bool> V;
Puzzle u, v;
s.path = "";
Q.push(s);
V[s] = true;
 
while(!Q.empty()){
u = Q.front(); Q.pop();
if(isTarget(u)) return u.path;
int sx = u.space / N;
int sy = u.space % N;
for(int r = 0; r < 4; r++){
int tx = sx + dx[r];
int ty = sy + dy[r];
if(tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
v = u;
swap(v.f[u.space], v.f[tx * N + ty]);
v.space = tx * N + ty;
if(!V[v]){
V[v] = true;
v.path += dir[r];
Q.push(v);
}
}
}
return "unsolvable";
}
 
int main(){
Puzzle in;
for(int i = 0; i < N2; i++){
cin >> in.f[i];
if(in.f[i] == 0){
in.f[i] = N2;
in.space = i;
}
}
string ans = bfs(in);
cout << ans.size() << endl;
 
return 0;
}


Measured memory_bytes: 30480
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (50 + 2)
typedef vector<VL> matrix;

//行列A * B % m
matrix mulMod(matrix &A, matrix &B, int m){
  matrix C(A.size(), VL(B[0].size()));
  for (int i = 0; i < A.size(); i++){
    for (int k = 0; k < B.size(); k++){
      for (int j = 0; j < B[0].size(); j++){
        C[i][j] = (C[i][j] + (A[i][k] * B[k][j] % m)) % m;
      }
    }
  }
  return C;
}

//A^n
matrix powMod(matrix A, ll n, int m){
  matrix B(A.size(), VL(A.size()));
  for (int i = 0; i < A.size(); i++){
    B[i][i] = 1;
  }
  while(n > 0){
    if(n & 1) B = mulMod(B, A, m);
    A = mulMod(A, A, m);
    n >>= 1;
  }
  return B;
}
void exec(){
  ll n, k, tmp;
  cin >> n >> k;

  matrix a(n, VL(n));

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      scanf("%lld", &tmp);
      a[i][j] = tmp;
    }
  }

  matrix b = powMod(a, k, MOD);
  // for (int i = 0; i < n; i++){
  //   for (int j = 0; j < n; j++){
  //     printf("%02lld ", b[i][j]);
  //   }
  //   cout << endl;
  // }

  ll sum = 0;

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      sum = (sum + b[i][j]) % MOD;
    }
  }

  cout << sum << endl;


}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  int res=0;
  long long tmp;
  for(int i=0;i<n;++i){
    cin>>tmp;
    res+=tmp%2;
  }
  if(res%2==0)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

void dfs(vector<long long>& a, int pos, long long num){
	if(pos > 32){
		a.emplace_back(num);
		return;
	}

	dfs(a, pos + 2, num + (1LL << pos));
	dfs(a, pos + 2, num);
}

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

	if(n == 0){
		cout << 0 << endl;
		return 0;
	}

	vector<long long> a, b;
	dfs(a, 0, 0);
	dfs(b, 1, 0);
	sort(all(b));


	rep(i,a.size()){
		long long t = n - a[i];

		auto it = lower_bound(all(b), -t);
		if(it == b.end() or *it != -t) continue;

		long long ans = a[i] bitor *it;

		string s;
		while(ans != 0){
			s += '0' + ans % 2;
			ans /= 2;
		}
		reverse(all(s));
		cout << s << endl;
		return 0;
	}
	assert(false);
}


Measured memory_bytes: 2292
#!/usr/bin/env python3
import sys

sys.setrecursionlimit(10 ** 8)
ni = lambda: int(sys.stdin.readline())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
ns = lambda: sys.stdin.readline().rstrip()

N = ni()
S = ns()
assert len(S) == N
Q = ni()
qs = []
for i in range(Q):
    q = ns().split()
    qs.append(q)


def main():
    orda = ord("a")
    ords = [ord(ch) - orda for ch in S]
    bits = [BIT(N) for _ in range(26)]
    for i, ch in enumerate(ords):
        bits[ch].add(i + 1, +1)  # 1-origin
    for q in qs:
        if q[0] == "1":
            j = int(q[1])  # 1-origin
            nch = ord(q[2]) - orda
            och = ords[j - 1]
            if nch != och:
                ords[j - 1] = nch
                bits[och].add(j, -1)
                bits[nch].add(j, +1)
        else:
            assert q[0] == "2"
            l, r = int(q[1]), int(q[2])  # 1-origin
            n = 0
            for i in range(26):
                b = bits[i]
                if b.sum(r) - b.sum(l - 1) > 0:
                    n += 1
            print(n)


# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


main()


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

using namespace std;

int n;
int a[100005];

int main()
{
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        int t;
        scanf("%d", &t);
        a[t] = i;
    }
    for(int i = 1; i <= n; i++)
    {
        printf("%d ", a[i]);
    }
    return 0;
}


Measured memory_bytes: 1152
'use strict'

function main(o) {
  o = o.split('\n').map(v => ~~v)
  const k = o[5]
  const a = o.slice(0, 5)
  let i2 = 0
  for (let i = 0; i < a.length; i++) {
    for (let j = i + 1; j < a.length; j++) {
      if (a[j] - a[i] > k) {
        console.log(':(')
        return
      }
    //   console.log(a[j] - a[i])
    }
  }

  console.log('Yay!')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
s = input()
it=0
con = 1
while it+1 < len(s):
	if s[it] == s[it+1]:
		if it + 2 == len(s):
			it += 2
			con += 0
		elif it + 3 == len(s):
			it += 3
			con += 1
		else:
			it += 3
			con += 2
	else:
		it += 1
		con += 1
print(con)

Measured memory_bytes: 3500
S=input()
n=len(S)
ans=0

for bit in range(1<<(n-1)):
  f=S[0]
  for i in range(n-1):
    if bit & (1<<i):
      f+="+"
    f+=S[i+1]
  ans+=sum(map(int,f.split("+")))
print(ans)

      	
  


Measured memory_bytes: 41452
#include<bits/stdc++.h>
using namespace std;
#define ll   long long int
#define T int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define PI 3.141592653589793238462643383

vector<int> dp;
vector<int> arr;


int main(){
   
    fast;
    int n;
    cin>>n;
    arr.resize(n+1);;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    dp.resize(n+1);
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0])+dp[0];
    for(int i=2;i<n;i++){
        int op1 = abs(arr[i-1]-arr[i]) + dp[i-1];
        int op2 = abs(arr[i-2]-arr[i]) + dp[i-2];
        dp[i] = min(op1,op2);
    }

    cout<<dp[n-1]<<endl;
       
}

Measured memory_bytes: 3968
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>

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

using namespace std;

int main() {
    int N;
    int ans;
    scanf("%d", &N);
    REP(i, 7){
        if(N==1){
            ans = 1;
            break;
        }
        if(N>=(2<<i) && N<(2<<i+1)){
            ans = 2<<i;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(long long i=0;i<(n);i++)
#define rep2(i,m,n) for(long long i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back







int main(){

    ll n ;
    cin>>n;

    string x;
    cin>>x;

    vector<ll> red(n);
    vector<ll> white(n);

    ll rtmp=0;
    ll wtmp=0;

    rep(i,n){
        if (x.at(i)=='R'){
            rtmp++;
        }
        
        if (x.at(i)=='W'){
            wtmp++;

        }

        red.at(i)=rtmp;
        white.at(i)=wtmp;

        

    }

    ll totalred=red.at(n-1);
    ll totalwhite=white.at(n-1);

    ll answer=0;

    rep(i,n){
        if (white.at(i)>=totalred-red.at(i)){
            answer=totalred-red.at(i);
            break;
        }


    }

    cout<<answer<<endl;







}








            






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

using namespace std;
using ll = long long;

#define int ll
#define all(x) x.begin(), x.end()
#define mp make_pair
#define mt make_tuple
#define x first
#define y second
#define pb push_back
#define sz(x) int(x.size())

signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	int a;
	int b;
	if (a > b) {
		swap(a, b);
	}
	cin >> n >> a >> b;
	int answer = min(max(a - 1, b - 1), max(n - a, n - b));
	if (a % 2 == b % 2) {
		answer = min(answer, abs(a - b) / 2);
	} else {
		answer = min(answer, a + (b - a - 1) / 2);
		answer = min(answer, n - b + 1 + (b - a - 1) / 2);
	}
	cout << answer << "\n";
	return 0;
}


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

#[allow(dead_code)]
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 h = read::<usize>();
    let w = read::<usize>();
    let mut field = vec![vec![]; h];
    for y in 0..h {
        field[y] = read::<String>().chars().collect::<Vec<char>>();
    }
    for y in 0..h {
        if field[y].iter().all(|&c| c == '.') {
            continue;
        }
        for x in 0..w {
            let mut all = true;
            for ty in 0..h {
                all &= field[ty][x] == '.'
            }
            if all {
                continue;
            }
            print!("{}", field[y][x]);
        }
        println!("");
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#define N 200000
 
int main(){
  int i;
  int n, maxv, minv;
  int r[N];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%d", &r[i]);
  }

  maxv = r[1] - r[0];
  minv = r[0];

  for(i = 1; i < n; i++){

      if(maxv < r[i] - minv) maxv = r[i] - minv;
      if(minv > r[i]) minv = r[i];

  }

  printf("%d\n", maxv);

  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int a[5], b[5];

int main() {
	inc(i, 5) { cin >> a[i]; }
	
	int sum = 0;
	inc(i, 5) { sum += b[i] = ce(a[i], 10) * 10; }
	
	int ans = sum;
	inc(i, 5) { setmin(ans, sum - b[i] + a[i]); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int n;
while(cin>>n,n){
vector<long long int>in;
rep(i,n){
long long int in1;
cin>>in1;
pb(in,in1);
}
sort(all(in));
long long int sum=0;
rep(i,n-1)
sum+=in[i]*(n-i-1);
cout<<sum<<endl;
}
}

Measured memory_bytes: 1348
N, Q = map(int, input().split())
S = input()
num = {}
n = 0

for i in range(N):
    if S[i] == 'C' and S[i-1] == 'A':
        n += 1
    
    num[i] = n

for i in range(Q):
    l, r = map(int, input().split())
    print(num[r-1] - num[l-1])

Measured memory_bytes: 16624
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
//    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 10
#else
#define SIZE 223450
#endif

int N,M;
int A[SIZE], B[SIZE];

void solve() {
    cin>>N;
    REP1(i,N)cin>>A[i];
    RREP1(i,N) {
        int sum = 0;
        for (int j=2; i*j<=N; j++) {
            sum += B[i*j];
        }
        if (A[i]!=sum%2) {
            B[i]=1;
            M++;
        }
    }
    cout << M << endl;
    REP1(i,N) if (B[i]) out("%lld ", i);
    if (M) cout << endl;
}


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

using namespace std;

int main() 
{
    int N, M;
    int64_t K;

    cin >> N >> M >> K;

    int64_t A[N];
    int64_t B[M];

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

    vector <int64_t> sumA( N+1, 0 ), sumB( M+1, 0 );
    for ( int i = 1; i <= N; i ++ ) sumA[i] = sumA[i-1] + A[i-1];
    for ( int i = 1; i <= M; i ++ ) sumB[i] = sumB[i-1] + B[i-1];

/*
    for ( int i = 0; i < N+1; i ++ ) cout << sumA[i] << " ";
    cout << endl;
    for ( int i = 0; i < M+1; i ++ ) cout << sumB[i] << " ";
    cout << endl;
*/

    int maxcount = 0;
    int n = N;
    int m = 0;
    for ( ; n>=0; n -- ) {
        if ( sumA[n] > K ) continue;

//        cout << "test A " << n << " sum:" <<  sumA[n] << " remain " << K-sumA[n] << endl;

        for ( ; m <= M; m ++ ) {
//           cout << "  test B " << m << " sumB " << sumB[m] << endl; 
            if ( sumB[m] > K-sumA[n] ) {
                break;
            }
        }    
//        cout << "  b-> " << m << endl;
        m --;

//       cout << "   count " << n+m << endl;
        maxcount = max( maxcount, n+m );
    }

   cout << maxcount << endl; 

    return 0;
}

Measured memory_bytes: 9508
import math
a, b, h, m = map(int, input().split())
H = (30 * h)%360 + 0.5 * m
M = 6 * m
angle = abs(H - M)

ans = a**2 + b**2 - (2 * a * b * math.cos(math.radians(angle)))
print(math.sqrt(ans))

Measured memory_bytes: 9508
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <climits>
#include <algorithm>
#include <utility>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

// 基本的な演算
namespace BasicMath {
    // 二つの値の最小値を求める関数
    static Int Min(const Int a, const Int b);
    // 二つの値の最小値を求める関数
    Int Min(const Int a, const Int b) {
        if (a <= b) {
            return a;
        } else {
            return b;
        }
    }
}
using namespace BasicMath;

int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    cout << Min(b / a, c) << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<ll>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define possible(n) cout<<((n)?"possible":"impossible")<<endl
#define Possible(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
	int n,m;
	ll sum=0;
	int buf;
	cin>>n>>m;
	map<int,int> x;
	REP(i,n){
		x[sum]++;
		cin>>buf;
		sum=(sum+buf)%m;
	}
	x[sum]++;
	ll ans=0;
	for(auto a:x){
		ll s=a.second;
		ans+=s*(s-1)/2;
	}
	cout<<ans<<endl;


	return 0;
}


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

char chess(int h,int w){
    if((h+w)%2==0){
        return '#';
    }
    return '.';
}
int main(void){
    int H,W;
    while(true){
    cin >> H >> W;
    if(H == 0 && W == 0){
           break;
    }
    for(int j=0;j<H;j++){
        for(int i=0;i<W;i++){
            cout << chess(i,j);
        }
        cout << endl;
    }
    cout << endl;
    }
}


Measured memory_bytes: 3060
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,m int
    fmt.Scan(&n)
    sum := 0
    t := make([]int, n)
    for i:=0;i<n;i++{
        fmt.Scan(&t[i])
        sum += t[i]
    }
    fmt.Scan(&m)
    ans := make([]int, m)
    for i:=0;i<m;i++{
        var p,x int
        fmt.Scan(&p,&x)
        ans[i] = sum - (t[p-1]-x)
    }
    for i:=0;i<m;i++{
        fmt.Println(ans[i])
    }
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	int K;
	cin >> K;
	int A, B;
	A = (K + 1) / 2;
	B = K / 2;
	cout << A * B << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>

#define N 100010

int a[N];

long long Find(int x){
	return a[x]==x? a[x]:Find(a[x]);
}

int main(){
	while(true){
		int n,q;
		scanf("%d%d",&n,&q);
		if(!(n||q))
			break;
		a[1]=1;
		for(int i=2;i<=n;i++)
			scanf("%d",a+i);
		long long ans=0ll;
		while(q--){
			char tmp[10]={};
			int x;
			scanf("%s%d",tmp,&x);
			if(*tmp=='Q')
				ans+=Find(x);
			else
				a[x]=x;
		}
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long int
int main(void){
    // Your code here!
 int i,c,m,n,x,y;
 c=0;
 cin >> n >> m;
 int a[n];
 for(i=0;i<n;i++)
 cin >> a[i];
 vector<set<int>> v(n);
 while(m--)
 {
  cin >> x >> y;
  x--;
  y--;
  v[x].insert(a[y]);
  v[y].insert(a[x]);
 }
 for(i=0;i<n;i++)
 {
  auto it=v[i].lower_bound(a[i]);
  if(it==v[i].end())
  c++;
 }
 cout << c;
 return 0;
}

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

int main(void){

	char s[100001];
	scanf("%s",s);
	int len = strlen(s);
	
	int ans[len];
  	int memo[len];
	for(int i=0;i<len;i++){
      ans[i]=0;
      memo[i]=0;
    }
	int zahyo;
	for(int i=0;i<len;i++){
		zahyo=i;
      	if(i!=0){
          	if(s[i-1]==s[i]){
            	if((memo[i-1]-i)%2==0)	ans[memo[i-1]]++;
              	else	ans[memo[i-1]+1]++;
            	memo[i]=memo[i-1];
              continue;
            }
        }
      
		for(int j=0;j<len;j++){
			if(s[zahyo]=='R' && s[zahyo+1]=='L' && zahyo<len-1){
				if(j%2==0)  ans[zahyo]++;
				if(j%2==1)	ans[zahyo+1]++;
              	memo[i]=zahyo;
              	break;
			}else if(s[zahyo]=='R'){
				zahyo++;
			}else if(s[zahyo]=='L'){
				zahyo--;
			}
		}
	}
	
	for(int i=0;i<len;i++){
		printf("%d ", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 1280
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());
#define N 100007
vector<ll> gf[N];
ll n,m,k,par[N],siz[N];

ll root(ll x)
{
	return (par[x]==x?x:par[x]=root(par[x]));
}

void merge(ll x,ll y)
{
	ll px=root(x),py=root(y);
	if(px==py) return;
	if(siz[px]<siz[py]) swap(px,py);
	par[py]=px;
	siz[px]+=siz[py];
	root(y);
	root(x);
}



int main()
{
	IOS;
	ll i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m>>k;
		// n=s.length();
		ll a[n+1];
		ll p,q;
		// memset(vis,0,sizeof vis);
		memset(a,0,sizeof a);
		rep(i,n+2)
			par[i]=i,siz[i]=1;
		rep(i,m)
		{
			cin>>p>>q;
			gf[p].pb(q);
			gf[q].pb(p);
			merge(p,q);
		}
		rep(i,n)
			root(i+1);
		rep(i,k)
		{
			cin>>p>>q;
			if(root(p)==root(q))
			{
				a[q]++;
				a[p]++;
			}
		}
		repe(i,1,n+1)
		{
			// debug3(i,siz[root(i)],root(i));
			cout<<siz[root(i)]-gf[i].size()-a[i]-1<<" ";
		}

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 9460
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    int n;
    cin>>n;
    vector<int> cnt(100001);
    ll sum=0;
    for(int i=0; i<n; i++){
        int tmp;
        cin>>tmp;
        cnt[tmp]+=1;
        sum+=tmp;
    }
    int q;
    cin>>q;
    while(q--){
        ll a,b;
        cin>>a>>b;
        sum=sum-a*cnt[a]+b*cnt[a];
        cnt[b]+=cnt[a];
        cnt[a]=0;
        cout<<sum<<"\n";
    }

    return 0;
}


Measured memory_bytes: 3708
def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

# 解説AC
def examE():
    N = I()
    Bnum = [-1]*N
    Wnum = [-1]*N
    B = {}
    W = {}
    for i in range(2*N):
        c, a = LSI()
        a = int(a)-1
        if c=="W":
            W[i] = a+1
            Wnum[a] = i
        else:
            B[i] = a+1
            Bnum[a] = i
    SB = [[0]*(N*2) for _ in range(N+1)]; SW = [[0]*(N*2) for _ in range(N+1)]
    for i in range(2*N):
        if not i in B:
            continue
        cur = B[i]
        cnt = 0
        SB[cur][i] = 0
        for j in range(2*N):
            if not j in B:
                SB[cur][j] = cnt
                continue
            if B[j]<=cur:
                cnt += 1
            SB[cur][j] = cnt
    for i in range(2*N):
        if not i in W:
            continue
        cur = W[i]
        cnt = 0
        SW[cur][i] = 0
        for j in range(2*N):
            if not j in W:
                SW[cur][j] = cnt
                continue
            if W[j]<=cur:
                cnt += 1
            SW[cur][j] = cnt
    #for b in SB:
        #print(b)
    #print(SW)
    #print(SW,len(SW))

    dp = [[inf]*(N+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        dp[0][i+1] = dp[0][i]+Bnum[i]-SB[i][Bnum[i]]
        dp[i+1][0] = dp[i][0]+Wnum[i]-SW[i][Wnum[i]]
    #print(dp)
    for i in range(N):
        w = Wnum[i]
        for j in range(N):
            b = Bnum[j]
            costb = b - (SB[j][b]+SW[i+1][b])
            costw = w - (SB[j+1][w]+SW[i][w])
            #if i==2 and j==4:
            #    print(w,SB[i][w],SW[j+1][w])
            #    print(b,SB[i][b],SW[j+1][b])
            #print(costb,costw,i,j)
            #input()
            if costb<0:
                costb = 0
                #print(i,j)
            if costw < 0:
                costw = 0
                #print(i,j)
            dp[i+1][j+1] = min(dp[i+1][j+1],dp[i+1][j]+costb,dp[i][j+1]+costw)
    ans = dp[-1][-1]
    #for v in dp:
    #    print(v)
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 242856
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	cin>>a;
	if(a=="SUN") cout<<7;
	else if(a=="MON") cout<<6;
	else if(a=="TUE") cout<<5;
	else if(a=="WED") cout<<4;
	else if(a=="THU") cout<<3;
	else if(a=="FRI") cout<<2;
	else if(a=="SAT") cout<<1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vint v;
		v.PB(0);
		rep(i,n+m){
			int t;
			cin>>t;
			v.PB(t);
		}
		sort(ALL(v));
		vint a;
		rep(i,v.size()-1){
			a.PB(v[i+1]-v[i]);
		}
		sort(ALL(a));
		cout<<a.back()<<endl;
	}
}

Measured memory_bytes: 1420
# Problem A - Subscribers

# input process
N, A, B = map(int, input().split())

# initilization
min_ans = 0
max_ans = 0

# calc process
if A<=B:
    min_ans = A
else:
    min_ans = B

if N>=A+B:
    max_ans = 0
else:
    max_ans = A + B - N

print("%d %d"%(min_ans, max_ans))


Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<algorithm>
#define int long long
using namespace std;
const int N=1e3+2;
const int M=2e4+2;
pair<pair<int,int>,int>  lis[N];
int dp[M];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>lis[i].first.first>>lis[i].first.second>>lis[i].second;
	}
	sort(lis+1,lis+1+n,[&](pair<pair<int,int>,int> x,pair<pair<int,int>,int> y){
		return x.first.first+x.first.second>y.first.first+y.first.second;
	}); 
	for(i=1;i<=n;i++){
		for(j=lis[i].first.first;j<=lis[i].first.second+lis[i].first.first;j++){
			dp[j-lis[i].first.first]=max(dp[j-lis[i].first.first],dp[j]+lis[i].second);
		}
//		for(j=1;j<=5;j++){
//			cout<<dp[j]<<" ";
//		}
//		cout<<endl;
	}
	cout<<dp[0];
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if(a<k)
    {
        cout<<0<<" "<<max((ll)0,(a+b-k))<<endl;
    }
    else
    {
        cout<<(a-k)<<" "<<b<<endl;
    }
    return 0;
}


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

int main(){
	int a, b;
	cin >> a >> b;
	int d = a / b;
	int r = a % b;
	double A = a;
	double B = b;
	double f = A / B;
	//http://minus9d.hatenablog.com/entry/20120528/1338213396
	cout << d << ' ' << r << ' ' << fixed << setprecision(6) << f << endl;
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll gcd(ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}

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

int main() {
  int n;
  cin >> n;
  vll t(n);
  rep(i,n) cin >> t.at(i);
  ll ans = t[0];
  rep(i,n-1) ans = lcm(ans,t[i+1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
INF = 10**20
MOD = 10**9 + 7
import numpy as np

def main():
    n,a,b = map(int,input().split())
    H = np.array([int(input()) for _ in range(n)])

    a -= b
    def ok(x): #x回の爆発で倒せるか
        list = (H - b * x + a - 1)//a
        return list[list>0].sum() <=  x
    
    l = -1
    r = 10 ** 10
    while r - l > 1:
        mid = (r + l)//2
        if ok(mid):
            r = mid
        else:
            l = mid  
    print(r)

if __name__=='__main__':
    main()

Measured memory_bytes: 17028
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;

const ll INF = 9223372036854775807;
const int inf = 2147483647;

ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}


int n;
int a[100];
int b[100];
int c[100];
int d[100];
int res = 0;
int main() {
    cin >> n;
    REP(i,n){
        cin >> a[i] >> b[i];
    }
    REP(i,n){
        cin >> c[i] >> d[i];
    }
    //n<=100なので、あらかじめソートしておく必要がない
    REP(j,n){
        int minx = inf;//青の中で最小のx
        int num1;
        int maxy = -1;//minxの青と仲良しの赤の中で最大のy
        int num2;
        REP(i,n){
            if(c[i]<minx){
                minx = c[i];
                num1 = i;
            }
        }
        if(minx!=inf){
            REP(i,n){
                if(a[i]<c[num1]&&b[i]<d[num1]){
                    if(maxy<b[i]){
                        maxy = b[i];
                        num2 = i;
                    }
                }
            }
            //ペアを作ったものはエスケープしておく
            c[num1] = inf;
            d[num1] = inf;
        }
        if(maxy!=-1){
            res++;
            //ペアを作ったものはエスケープしておく
            a[num2] = -1;
            b[num2] = -1;
        }
    }
    put(res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 510;
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
int n,vis[N][N],dis[N][N];
queue<pa>q;

int main(){
	n=read();
	For(i,1,n) For(j,1,n) dis[i][j]=min({i-1,j-1,n-i,n-j}),vis[i][j]=1;
	int ans=0;
	For(i,1,n*n){
		int p=read(),x=(p-1)/n+1,y=p%n==0?n:p%n;
		ans+=dis[x][y],vis[x][y]=0;
		//For(j,1,n){
		//	For(k,1,n) printf("%d ",vis[j][k]);
		//	puts("");
		//}
		//printf("%d %d\n",x,y);
		q.push(mp(x,y));
		while (!q.empty()){
			int x=q.front().fi,y=q.front().se;q.pop();
			FOR(k,0,4){
				int i=x+dx[k],j=y+dy[k];
				if (i>=1&&i<=n&&j>=1&&j<=n&&dis[x][y]+vis[x][y]<dis[i][j]){
					dis[i][j]=dis[x][y]+vis[x][y],q.push(mp(i,j));
				}
			}
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5672