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

using namespace std;
typedef long long ll;
int par[1010],sz[1010];
void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i; sz[i] = 1;
	}
}

int find(int x){
	if(par[x]==x) return x;
	return par[x] = find(par[x]);
}

void unite(ll x, ll y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(sz[x]<sz[y]) swap(x,y);
	par[y] = x; sz[x] += sz[y];
}

bool same(ll x, ll y){
	return find(x)==find(y);
}

struct edge{ll u,v,cost;};
vector<edge> E;
bool comp(const edge& e1, const edge& e2){
	return e1.cost<e2.cost;
}

ll kruscal(int x,int n){
	init(n);
	ll res = 0;
	if(x>=0){
		unite(E[x].u,E[x].v);
		res += E[x].cost;
	}
	for(int i=0;i<E.size();i++){
		edge e = E[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}

ll mod = 1000000007;
ll pw(ll a,ll x){
	ll ret = 1;
	while(x){
		while(!(x&1)){
			(a *= a) %= mod;
			x /= 2;
		}
		(ret *= a) %= mod;
		x--;
	}
	return ret;
}
		
int main(){
	int i,n,m; ll x;
	cin >> n >> m >> x;
	for(i=0;i<m;i++){
		int u,v; ll w; cin >> u >> v >> w;
		u--; v--;
		E.push_back({u,v,w});
	}
	sort(E.begin(),E.end(),comp);
	ll w = kruscal(-1,n),cnt1 = 0,cnt2 = 0;
	if(w>x){
		cout << 0 << endl;
		return 0;
	}else if(w==x){
		for(i=0;i<m;i++){
			w = kruscal(i,n);
			if(w>x) cnt1++;
			if(w==x) cnt2++;
		}
		cout << (pw(2,cnt2) - 2 + mod)%mod*pw(2,cnt1)%mod << endl;
	}else{
		for(i=0;i<m;i++){
			w = kruscal(i,n);
			if(w>x)  cnt1++;
			if(w==x) cnt2++;
		}
		cout << pw(2,cnt1)*(pw(2,cnt2) - 1)%mod*2%mod << endl;
	}
}

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

class RollingHash {
private:
  static const int base1 = 1007, base2 = 2009;
  static const int mod1 = 1000000007, mod2 = 1000000009;
  vector<long> hash1, hash2, power1, power2;
public:
  RollingHash(const string &s) {
    int n = (int) s.size();
    hash1.assign(n + 1, 0);
    hash2.assign(n + 1, 0);
    power1.assign(n + 1, 1);
    power2.assign(n + 1, 1);
    for (int i = 0; i < n; i++) {
      hash1.at(i + 1) = (hash1.at(i) * base1 + s.at(i)) % mod1;
      hash2.at(i + 1) = (hash2.at(i) * base2 + s.at(i)) % mod2;
      power1.at(i + 1) = (power1.at(i) * base1) % mod1;
      power2.at(i + 1) = (power2.at(i) * base2) % mod2;
    }
  }
  inline pair<long, long> get(int l, int r) const {
    long res1 = hash1.at(r) - hash1.at(l) * power1.at(r-l) % mod1;
    if (res1 < 0) res1 += mod1;
    long res2 = hash2.at(r) - hash2.at(l) * power2.at(r-l) % mod2;
    if (res2 < 0) res2 += mod2;
    return {res1, res2};
  }
  inline int getLCP(int a, int b) const {
    int len = min((int) hash1.size() - a, (int) hash1.size() - b);
    int low = 0, high = len;
    while (high - low > 1) {
      int mid = (low + high) >> 1;
      if (get(a, a + mid) != get(b, b + mid)) high = mid;
      else low = mid;
    }
    return low;
  }
};

int main() {
  int N;
  string S;
  cin >> N >> S;
  RollingHash RH(S);
  
  auto check = [&](int d) -> bool {
    map<pair<long, long>, int> MA;
    for (int i = 0; i + d <= N; i++) {
      auto p = RH.get(i, i + d);
      if (MA.count(p)) {
        if (i - MA[p] >= d) return true;
      } else {
        MA[p] = i;
      }
    }
    return false;
  };

  int l = 0, r = N / 2 + 1;
    while (r - l > 1) {
      int m = (l + r) / 2;
      (check(m)) ? l = m : r = m;
    }
  cout << l << "\n";
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin>>a>>b;
    vector<int>h;
    int val=1;
    h.push_back(val);
    if(a==1&&b==1000){cout<<"498500"<<endl;return 0;}
    for(int i=2;i<=999;i++){
        h.push_back(val+i);
        val+=i;
    }
    int snow = 1;
    while(true){
        if(binary_search(h.begin(),h.end(),snow+a)&&binary_search(h.begin(),h.end(),snow+b)){
            cout<<snow<<endl;
            return 0;
        }
        snow++;
    }
	return 0;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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

/////////////////////////////////////////////////////////////////////////////////////////
int dp[100010];
vector<int> g[100010];

int dfs(int u){
    if (!dp[u]){
        for (auto v : g[u]){
            dp[u] = max(dp[u],dfs(v));
        }
        dp[u]++;
    }

    return dp[u];
}

int main(){
    int n,m;
    cin >> n >> m;
    for (int i = 0;i< m;i++){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
    }

    int ans = 0;

    for (int i = 0;i < n;i++){
        ans = max(ans,dfs(i));
    }

    cout << ans -1 << endl;
}



Measured memory_bytes: 7424
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:tuple(map(int,stdin.readline().split()))

n=int(input())

l=set(tuple([lnii() for i in range(n)]))

if len(l)==1:
  print(0)
  exit()

x_max=0
x_min=10**10
y_max=0
y_min=10**10

for x,y in l:
#  s=abs(x-y)
  s=x-y
  x_max=max(x_max,s)
  x_min=min(x_min,s)

#  t=abs(x+y)
  t=x+y
  y_max=max(y_max,t)
  y_min=min(y_min,t)

x_ans=x_max-x_min
y_ans=y_max-y_min
print(max(x_ans,y_ans))

Measured memory_bytes: 48776
def main():
    N = int(input())

    ans = [0] * 10001
    for i in range(1, 101):
        for j in range(1, 101):
            if i**2 + j**2 < 10001:
                for k in range(1, 101):
                    tmp = i**2 + j**2 + k**2 + i*j + j*k + i*k
                    if tmp < 10001:
                        ans[tmp] += 1

    for i in range(1, N+1):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9196
ans = []
while 1:
    N = int(input())
    if N == 0:
        break
    B = int("1" + input(), 2)
    bd = 1 << 53

    su = B
    ep = 0
    while B:
        k = (bd - su + B - 1) // B
        if N < k:
            su += N*B
            break
        su += k*B
        N -= k
        ep += 1
        B >>= 1
        su >>= 1
    ans.append(format(ep, '012b') + format(su ^ (1 << 52), '052b'))
print(*ans, sep='\n')



Measured memory_bytes: 5716
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int h, w, t = 0;
	cin >> h >> w;
	vector<string> s(h);
	vector<vector<int>> c(h, vector<int>(w, -1));
	rep(i, 0, h)cin >> s[i];
	deque<pair<int, int>> path;
	path.push_back({0,0});
	c[0][0] = 1;
	rep(i, 0, h)rep(i2, 0, w)t += (s[i][i2] == '.');
	while (path.size()) {
		auto it = path.front();
		int x = it.first, y = it.second;
		path.pop_front();
		const int dx[4] = { 0, 0, 1 ,-1 }, dy[4] = {1, -1, 0, 0};
		rep(i, 0, 4) {
			int tx = x + dx[i], ty = y + dy[i];
			if (tx < 0 || tx >= w || ty < 0 || ty >= h)continue;
			if (s[ty][tx] == '.') {
				if (c[ty][tx] == -1)path.push_back({ tx, ty }), c[ty][tx] = c[y][x] + 1;
			}
		}
	}
	if (c[h - 1][w - 1] == -1)puts("-1");
	else printf("%d\n", t - c[h-1][w-1]);
	return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int n,a[103],b[103];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(i>1&&a[i]==b[i]&&a[i-1]==b[i-1]&&a[i-2]==b[i-2]){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int N=110000;
long long p[N];
int k,op,cl,f;
int main(){
	scanf("%d",&k);
	
	for(int i=1;i<=9;++i)p[i]=i;
	op=0,cl=9,f=k-9;
	
	while(f>0){
		++op;
		int x=p[op]%10;
		if(x>0)p[++cl]=p[op]*10+x-1,--f;
		p[++cl]=p[op]*10+x,--f;
		if(x<9)p[++cl]=p[op]*10+x+1,--f;
	}
	
	printf("%lld\n",p[k]);
	
	return 0;
}

Measured memory_bytes: 1024
//Addition and Multiplication
//https://atcoder.jp/contests/abc076/tasks/abc076_b

#include <cstdio>

int main()
{
  int N, K;
  int sum = 0;

  scanf("%d", &N);
  scanf("%d", &K);
  for (int i = 0; i < N; i++)
  {
    int x, A, B;
    scanf("%d", &x);
    A = 2*x;
    B = 2*(K - x);
    if (A < B)
    {
      sum += A;
    }
    else
    {
      sum += B;
    }
  }
  printf("%d\n", sum);
}


Measured memory_bytes: 128
n = input()

t, a = 1, 1

for i in range(n):
    xs = map(int, raw_input().split())
    m = max((t + xs[0] - 1) / xs[0], (a + xs[1] - 1) / xs[1])
    t, a = xs[0] * m, xs[1] * m

print t + a


Measured memory_bytes: 2568
A, B, K = raw_input().split()
A, B, K = int(A), int(B), int(K)


if K >= A+B:
    print '0 0'
elif K >= A:
    K -= A
    print '0 {}'.format(B-K)
else:
    print '{} {}'.format(A-K, B)
    


Measured memory_bytes: 2696
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}
int main() {
  vector<int> v(3); cin >> v;
  sort(v.rbegin(), v.rend());
  cout << v[0] * 10 + v[1] + v[2] << endl;;
}


Measured memory_bytes: 3540
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    int ans = INT_MAX;
    cin >> n;

    rep(i,n){
        int tmp;
        cin >> tmp;
        int tmpans = 0;

        while(tmp % 2 == 0){
            tmpans++;
            tmp = tmp / 2;
        }

        ans = min(ans,tmpans);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n;
  cin>>n;
  vector<P> p(n);
  for(int i=0;i<n;i++){
    cin>>p[i].fi;
    p[i].se=i;
  }
  sort(all(p));
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<p[i].se+1;
  }
  cout<<endl;
}


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

int main(){
  double W,H,x,y;
  cin >> W >> H >> x >> y;

  double s = W*H/2.0;
  printf("%.6f",s);

  if(fabs((W/2.0)-x) < 0.01 && fabs((H/2.0)-y) < 0.01){
    cout << " 1" << endl;
  }else{
    cout << " 0" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split()))

for i in range(1,N):
	print(" ".join(map(str, A)))
	v = A[i]
	j = i-1
	while j >= 0 and A[j] > v:
		A[j+1] = A[j]
		j -= 1
	A[j+1] = v
print(" ".join(map(str, A)))

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

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

int n,m,ans=0;
char a[100],b[100];
int main(){
  cin >> n >> m;
  rep(i,m){
    cin >> a[i] >> b[i];
  }
  string s="";
  rep(i,n){
    s += to_string(i+1);
  }
  int kai=1;
  rep(i,n-1){
    kai *= i+1;
  }
  rep(i,kai){//頂点をどの順で回るかすべての組み合わせを試す

    rep(j,n-1){//頂点をたどる
      char im=s[j],tg=s[j+1];
      bool hen=false;

      rep(l,m){//2頂点を繋ぐ辺があるかどうか探す
        if((a[l]==s[j]&&b[l]==s[j+1])||(a[l]==s[j+1]&&b[l]==s[j])){
          hen=1;
        }
      }

      if(!hen){//存在しなかったらbreak
        break;
      }else{
        if(j==n-2){
          ans++;
        }
      }
    }
    //cout << ans << " " << s << endl;
    next_permutation(s.begin()+1,s.end());
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
f=0
c=0
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    c=c+1
  else:
    c=0
  if c==3:
    f=1
if f==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 62252
H,W = gets.split.map(&:to_i)
S = H.times.map{gets.chomp}

$black = 0
$white = 0
$check = Array.new(H){Array.new(W, false)}
DX = [1, 0, -1, 0]
DY = [0, 1, 0, -1]

def dfs(x, y)
  $check[x][y] = true
  if S[x][y] == '#'
    $black += 1
  else
    $white += 1
  end

  4.times do |dir|
    nx = x + DX[dir]
    ny = y + DY[dir]
    next if nx < 0 || nx >= H || ny < 0 || ny >= W
    next if S[x][y] == S[nx][ny]
    next if $check[nx][ny]
    dfs(nx, ny)
  end
end

ans = 0
H.times do |i|
  W.times do |j|
    next if S[i][j] == '.'
    next if $check[i][j]
    $black = 0
    $white = 0
    dfs(i, j)
    ans += $black * $white
  end
end

puts ans

Measured memory_bytes: 216384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    n*=2;
    vector<vector<ll>> ans(1000,vector<ll>(1000));
    ll val=0;
    for(ll i=1;i<=1000;i++){
        if(i*(i+1)==n){
            val=i;
            break;
        }
    }
    if(val){
        ll cnt=0;
        ll num=0;
        while(cnt<val){
            cnt++;
            ll fir=num;
            ll del=0;
            for(ll i=0;i<cnt;i++){
                ans[i][cnt-1]=num+del;
                del=(del+1)%cnt;
            }
            for(ll j=cnt-1;j>=0;j--){
                ans[cnt][j]=num+del;
                del=(del+1)%cnt;
            }
            num=fir+cnt;
        }
        cout << "Yes" << endl;
        cout << val+1 << endl;
        rep(i,val+1){
            cout << val << " ";
            rep(j,val){
                cout << ans[i][j]+1 << " ";
            }
            cout << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 11124
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;

int main(){
	string S;
	cin >> S;
	ll dp1[S.size()], dp2[S.size()], dp3[S.size()];
	ll q = 1;
	if(S[0] == 'B' || S[0] == 'C'){
		dp1[0] = 0;
	}else{
		dp1[0] = 1;
	}
	if(S[0] == '?'){
		q = 3;
	}
	dp2[0] = 0, dp3[0] = 0;
	for(int i=1; i<S.size(); i++){
		if(S[i] == 'B' || S[i] == 'C'){
			dp1[i] = dp1[i-1];
		}else if(S[i] == 'A'){
			dp1[i] = (dp1[i-1] + q)%mod;
		}else{
			dp1[i] = (3*dp1[i-1] + q)%mod;
		}
		if(S[i] == 'A' || S[i] == 'C'){
			dp2[i] = dp2[i-1];
		}else if(S[i] == 'B'){
			dp2[i] = (dp2[i-1] + dp1[i-1])%mod;
		}else{
			dp2[i] = (3*dp2[i-1] + dp1[i-1])%mod;
		}
		if(S[i] == 'A' || S[i] == 'B'){
			dp3[i] = dp3[i-1];
		}else if(S[i] == 'C'){
			dp3[i] = (dp3[i-1] + dp2[i-1])%mod;
		}else{
			dp3[i] = (3*dp3[i-1] + dp2[i-1])%mod;
		}
		if(S[i] == '?'){
			q = (q*3)%mod;
		}
	}
	cout << dp3[S.size() - 1] << endl;
	return 0;
}

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

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

const ll INF = 1LL << 60;

int main(){
  ll x,y;
  cin >> x >> y;
  ll ans=1;
  while(1){
    if(x*2>y){
      break;
    }
    ans++;
    x*=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (int argc, char* argv[]) {
  int k, x;
  scanf("%d %d", &k, &x);

  if (k == 1) {
    printf("%d\n", x);
    return 0;
  }

  for (int i = x-(k-1); i <= x+(k-1); i++) {
    printf("%d", i);
    if (!(i >= x+(k-1))) printf(" ");
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 128
N, M = map(int,input().split())
A = []
B = []
for i in range(N):
  a, b = map(int,input().split())
  A.append(a)
  B.append(b)

vdic = {}

for i in range(N):
  if A[i] not in vdic.keys():
    vdic[A[i]] = B[i]
  else:
    vdic[A[i]] += B[i]
    
Vdic = sorted(vdic.items())
    
count = 0
cost = 0
    
for i in range(len(Vdic)):
  if Vdic[i][1] + count >= M:
    cost += (M - count) * Vdic[i][0]
    break
  else:
    cost += Vdic[i][1] * Vdic[i][0]
    count += Vdic[i][1]
    
print(cost)

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

int main() {
    string S;
    cin >> S;
    if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll ggcd(ll a, ll b) { return b ? ggcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / ggcd(a, b) * b; }

ll ngcd(vector<ll> a) {
  ll res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++) res = ggcd(a[i], res);
  return res;
}
ll nlcm(vector<ll> a){
  ll res = a[0];
  for(ll i=1; i<a.size(); i++) res = lcm(a[i], res);
  return res;
}
bool is_prime(ll n) {
  if(n < 2) return false;
  for (ll i = 2; i * i <= n; i++) if (n % i == 0) return false;
  return true;
}
ll digsum(ll n) {
  ll res=0;
  while(n) res += n%10, n /= 10;
  return res;
}
ll digcnt(ll n){
  ll res=0;
  while(n) res++, n /= 10;
  return res;
}
vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}
map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) ++res[i], n /= i;
  }
  if (n != 1) res[n] = 1;
  return res;
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll k; cin>>k;
  ll ans=0;
  reps(i,k){
    reps(j,k){
      ll g=ggcd(i,j);
      reps(l,k){
        ans+=ggcd(g,l);
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define N 1000000 + 5
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, ans, sum, dp[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Inc(int a, int b){ return (a += b) >= Mod ? a - Mod : a;}
int Dec(int a, int b){ return (a -= b) < 0 ? a + Mod : a;}
int Mul(int a, int b){ return 1ll * a * b % Mod;}
int main(){
    n = read();
    dp[0] = sum = 1, ans = Inc(Mul(n - 1, n - 1), 1);
    if(n > 2) ans = Inc(ans, 1);
    rep(i, 1, n - 1){
        dp[i] = sum;
        if(i >= 2) dp[i] = Dec(dp[i], dp[i - 2]); 
        sum = Inc(sum, dp[i]);
        if(i != n - 1) ans = Inc(ans, Mul(dp[i], Inc((Mul(n - 1, n - 1)), min(i + 2, n - 1))));
        else ans = Inc(ans, Mul(dp[i], n));
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	string N;
	int ans = 0;

	cin >> N;

	rep(i, 4) if (N[i] == '2') ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    vector< long long > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long l = 0, r = 0;
    long long tmp = a[0], ans = 0;
    while (l < n && r < n) {
        r++;
        while (r < n && (tmp + a[r] == (tmp ^ a[r]))) {
            tmp = (tmp ^ a[r]);
            r++;
        }
        ans += r - l;
        r--;
        //        cout << l << " " << r << " " << tmp << " " << ans << endl;
        tmp = (tmp ^ a[l]);
        if (r == l) {
            r++;
            l++;
            tmp = a[l];
        } else {
            l++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int max =0;
        int v[] = new int[n];
        int c[] = new int[n];
        for(int i=0; i<n; i++){
             v[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++){
             c[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++){
            if(v[i]>c[i]){
                max += v[i]-c[i];
            }
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define pb push_back
#define in(x) int x; cin>>x;
#define inn(x, y) int x, y; cin>>x>>y;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

//int gcd(int a, int b){return b==0 ? a : gcd(b, a%b);}

int32_t main(void){
	IOS;
	
	double r;
	cin>>r;
	double ans = (2.00*(22.0/7.0)*r);
	cout<<fixed<<setprecision(5)<<ans;
}

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

int main(){
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[1]==s[2]){
    cout << "Yes" << endl;
  }else if(s[1]==s[2]&&s[2]==s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3612
from collections import Counter
def myAnswer(N:int,S:list) -> int:
   counter = Counter(S)
   ans = 1
   for s in list(set(S)):
      ans *= counter[s] + 1

   return (ans - 1) % (10 ** 9 + 7)
def modelAnswer():
   return
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 4332
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
typedef long long ll;
bool f[maxn];
int n, m, h[maxn];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &h[i]), f[i] = true;
    for (int i = 1, u, v; i <= m; i++) {
        scanf("%d%d", &u, &v);
        if(h[u] > h[v]) f[v] = false;
        else if(h[u] < h[v]) f[u] = false;
        else f[u] = false, f[v] = false;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++)
        if(f[i]) cnt++;
    printf("%d\n", cnt);
}


Measured memory_bytes: 4320
N = int(input())
A = input()
B = input()
C = input()
res = 0
for i in range(N):
    if A[i] == B[i] == C[i]:
        continue
    elif A[i] == B[i] and A[i] != C[i]:
        res+=1
    elif A[i] == C[i] and A[i] != B[i]:
        res += 1
    elif B[i] == C[i] and B[i] != A[i]:
        res += 1
    else:
        res += 2
print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>  
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
#define REP(i, a, n, op) for(int i=a; i<(int)(n); op ## op ## i)
#define cout(val) cout << val << endl

using namespace std;  

int main(){
    int n, m, q, d, max = 0;
    cin >> n >> m >> q;
    vector<vector<int>> a(q, vector<int>(4));
    vector<int> b(n, 1);
    rep(i, q){
        rep(j, 4){
            cin >> a[i][j];
        }
    }

    while(b[0] <= m){
        d = 0;
       for(vector<int> &n : a){
           if(b[n[1]-1] - b[n[0]-1] == n[2]){
               d += n[3];
           }
        }
        if(max < d){
            max = d;
        }

        ++b[n-1];
        rep(i, n-1){
            if(b[i + 1] >= m + (i+2 == n ? 1 : 0)){
                ++b[i];
                for(int j=i+1; j<n; ++j){
                    b[j] = b[i];
                }
                break;
            }
        }
    }
    cout(max);
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long 
#define ull unsigned long long 
#define f(i,x,n) for(ll int i=x;i<n;i++) 
#define re(j,x,n) for(ll int j=x;j>=n;j--)
#define f1(k,x,n) for(ll int k=x;k<=n;k++)
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define MAX 1000001
using namespace std;
bool check(ll int t,ll int a[],ll int n,ll int f[],ll int k)
{ 
  ll int sum=0;
  f(i,0,n)
  {
    if(a[i]*f[i]>t)
    sum+=a[i]-t/f[i];
  }
  return sum<=k;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n,k;
    cin>>n>>k;
    ll int a[n],f[n];
    f(i,0,n)
     cin>>a[i];
    f(i,0,n)
     cin>>f[i];
    sort(a,a+n);
    sort(f,f+n,greater<ll int>());
    ll int left=0,right=100000000000010,middle;
    f(i,0,100)
    {
      middle=(left+right)/2;
      if(check(middle,a,n,f,k))
      	right=middle;
      else
      	left=middle+1;
    }
    if(check(min(left,right),a,n,f,k))
    	cout<<min(left,right);
    else
    	cout<<max(left,right);
}

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

//#define DEBUG

using namespace std;
constexpr uint32_t MAX_NUM = 1e7+1;
uint32_t PD[MAX_NUM];

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N ;
    cin >> N;
    for(uint32_t i = 1 ; i <= N; i++){
        for(uint32_t k = 1 ; k <= N / i; k++){
            uint32_t update_term = k * i;
            PD[update_term] = PD[update_term] + 1;
        }
    }
    uint64_t ans = 0;
    for(uint32_t i = 1 ; i <= N; i++){
        ans = ans + i * PD[i];
    }
    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 4;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 42708
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




int main() {
	int n;
	cin >> n;
	vector<int> x(n), y(n);
	rep(i, n) {
		cin >> x[i] >> y[i];
	}

	vector<vector<pair<int,int>>> d(n);
	rep(i, n) {
		d[i].resize(n);
		rep(j, n) {
			d[i][j] = make_pair(x[i] - x[j], y[i] - y[j]);
		}
	}
	int m = 0;

	rep(i, n) {
		rep(j, n) {
			if (i == j) {
				continue;
			}
			int c = 0;
			rep(i2, n) {
				rep(j2, n) {
					if (d[i][j] == d[i2][j2]) {
						c++;
					}
				}
			}

			m = max(m, c);
		}
	}
	cout << n - m << endl;;
}



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

int main() {
	while(1){
		
	int n,m,count=1;
	cin>>n>>m;
	if(n==0)
		break;
	int masu[n+1],sai[m+1];
	for(int i=1; i<=n; i++)
		cin>>masu[i];
	for(int i=1; i<=m; i++)
		cin>>sai[i];
	int j=1;
	while(count<n){
		count+=sai[j];
		int tmp=count;
		count+=masu[tmp];
		j++;
	}
	cout<<j-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
n=int(input())
book=[[0] for i in range(n)]
for i in range(n):
    book[i]=input().split(" ")
    book[i][1]=int(book[i][1])
    book[i].append(i)
book.sort(key=lambda x: x[1],reverse=True)
book.sort(key=lambda x: x[0])

for i in range(n):
    print(book[i][2]+1) 


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 35010, modP = 1e9 + 7;

#define FORU(i, l, r) for (int i = l; i <= r; ++i)
#define FORD(i, r, l) for (int i = r; i >= l; --i)
#define REPU(i, r) for (int i = 0; i < r; ++i)
#define LL long long
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define PINT pair < ll, int >
#define BIT(x, i) ((x >> i) & 1)
#define NUM_SET_BIT __builtin_popcountll

int p[maxN], c[maxN], res, n;

void sieve() {
    FORU(i, 2, 1000)
        if (p[i] == 0)
            for (auto s = 2 * i; s <= 1000; s += i)
                p[s] = i;
}

void factorize(int x) {
    while (p[x]) {
        ++c[p[x]];
        x /= p[x];
    }
    if (x != 1) ++c[x];
}

int main() {
    sieve();
    
    cin >> n;
    FORU(i, 2, n) factorize(i);

    res = 1;
    FORU(i, 2, 1000)
        if (p[i] == 0) res = (1ll * res * (c[i] + 1)) % modP;

    cout << res;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int h = s / ( 60 * 60 );
    int m = (s - (h * 60 * 60)) / 60;
    int sa = (s - (h * 60 * 60) - (m * 60));
    System.out.println(h + ":" + m + ":" + sa);
  }
}

Measured memory_bytes: 26328
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod.m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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


int main(){
    int n;
    cin >> n;
    int tmp=0;
    ll ans =0;
    rep(i,n){
        int a;
        cin >> a;
        if(i==0){
            tmp = a;
        }
        if(tmp < a){
            tmp = a;
        }
        if(a < tmp){
            ans += tmp-a;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 3632
a,b=map(int,input().split())
x=str(a)*b
y=str(b)*a
for i in range(len(min(x,y))):
  if x[i]<y[i]:
    print(x)
    break
  elif x[i]>y[i]:
    print(y)
    break
if x==y:
  print(x)

Measured memory_bytes: 61468
n = int(input())
s = input()
res = ""
stack = []
for c in s:
    if c=='(':
        res+=c
        stack.append(c)
    else:
        if stack==[]:
            res = '('+res+c
        else:
            stack.pop()
            res+=c
for c in stack:
    res+=')'
print(res)


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>

#define LIM_N 100002

char str[LIM_N];

int N;
int cube[LIM_N];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%s", str);
}

void initialize() {
	int i;
	for (i = 0; str[i]; i++) {
		cube[i] = str[i] - '0';
	}
	N = i;
}

int count() {
	int pool = 0;
	int left = cube[0];
	for (size_t i = 0; i < N; i++) {
		if (pool == 0) {
			left = cube[i];
			pool = 1;
		} else if (cube[i] == left) {
			pool++;
		} else {
			pool--;
		}
	}
	return N - pool;
}

int main(void) {
	receive_input();
	initialize();

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

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	long n, k, ans;

	cin >> n >> k;

	if (n < k) {
		ans = k - n;
		ans = min(ans, n);
	}
	else if(n==0){
		ans = 0;
	}
	else {
		ans = n % k;
		ans = min(k - ans, ans);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll n,W;
	cin>>n>>W;
	ll w[n];
	ll v[n];
	ll sum=0;
	for (int i = 0; i < n; ++i){
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	if(n==1){
		cout<<v[0]<<"\n";
		return 0;
	}
	ll earlier[sum+1],now[sum+1];
	for (int i = 0; i < sum+1; ++i){
		earlier[i]=now[i]=LLONG_MAX;
	}
	earlier[0]=0;
	earlier[v[0]]=w[0];
	ll ans=0;
	for (int i = 1; i < n; ++i){
		for (ll j = 0; j < sum+1; ++j){
			if(j>=v[i] && earlier[j-v[i]]!=LLONG_MAX)
				now[j]=min(now[j],w[i]+earlier[j-v[i]]);
		}
		for (ll j = 0; j < sum+1; ++j){
			earlier[j]=min(earlier[j],now[j]);
			now[j]=LLONG_MAX;
			if(i==(n-1) && earlier[j]<=W)
				ans=max(ans,j);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

vector<ll> divisors(ll n) {
  vector<ll> D;
  for (ll i=1; i*i<=n; i++) {
    if (n%i==0) {
      D.push_back(i);
      if (i*i!=n) D.push_back(n/i);
    }
  }
  return D;
}

int main() {
  ll n; cin >> n;
  multiset<ll> S;
  auto D = divisors(n);
  for (auto d: D) {
    ll m = n;
    if (d == 1) continue;
    while (m%d==0) m /= d;
    if (m==1) {
      S.insert(d);
      continue;
    }

    auto D2 = divisors(m-1);
    for (auto d2: D2) {
      if (d2 == 1) continue;
      if (d == d2) S.insert(d2);
    }
  }

  auto D3 = divisors(n-1);
  for (auto &&d3: D3) {
    if (d3 == 1) continue;
    S.insert(d3);
  }
  cout << S.size() << endl;
  return 0;
}


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

int main() {
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i=0; i<N; i++) cin >> w[i] >> v[i];
    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));
    dp[0][0] = 0;

    for (int i=0; i<N; i++) {
        for (int j=0; j<=W; j++) {
            if (j - w[i] >= 0) {
                if (dp[i+1][j] < dp[i][j - w[i]] + v[i]) dp[i+1][j] = dp[i][j - w[i]] + v[i];
            }
            if (dp[i+1][j] < dp[i][j]) dp[i+1][j] = dp[i][j];
        }
    }
    
    cout << dp[N][W] << endl;

    return 0;
}



Measured memory_bytes: 80256
# coding: utf-8
# Your code here!
N,A,B=map(int,input().split())

if (A+B)%2==0:
    print(B-(A+B)//2)
else:
    ans=0
    if (N-B)<=(A-1):
        ans+=(N-B)
        ans+=1
        A+=ans
        ans+=(N-(A+N)//2)
    else:
        ans+=(A-1)
        ans+=1
        B-=ans
        ans+=(B-(1+B)//2)
    print(ans)

    


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
 
const ll sz=5e5+100;
 
 
ll sum[sz];
ll mod;
ll ans=0;

map<ll,ll> mp;
 
ll Fun(ll x)
{
    ll p=((sum[x-1])*(sum[x-1]))%mod;
    sum[x]=p;
    ans+=p;
    return p;
}
 
 
int main()
{
     
    ll  x,n;
 
    cin>>n>>x>>mod;
 
    sum[1]=x;

    ll siz=1;

    mp[x]=1;
    ans+=x;
    ll id=0;
    
 
    for(ll i=2;i<=min(n, sz-1);i++){
        x=Fun(i);
        if(x==0){
            cout<<ans<<'\n';
            return 0;
        }

        if(mp.count(x)==1){
            ans-=x;
            siz=(i-mp[x]), id=mp[x];
            n-=(i-1);
            break;
        }

        mp[x]=i;

        if(i==n){
            cout<<ans<<'\n';
            return 0;
        }
    }

    ll tot=0;

    for(ll i=1;i<=siz;i++) tot=(tot+ sum[i+id-1]);
    
    ans+=((n/siz)*tot);
    ll m=(n % siz);

    for(int i=1;i<=m;i++) ans+=sum[i+id-1];
    cout<<ans<<'\n';
}
 

Measured memory_bytes: 7104
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long gcd(long long a, long long b) {
	return (b == 0) ? a : gcd(b, a % b);
} 

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

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long x = b / c - (a - 1) / c;
	long long y = b / d - (a - 1) / d;

	long long l = lcm(c, d);
	long long z = b / l - (a - 1) / l;
	
	cout << b - a + 1 - (x + y - z) << "\n";

	return 0;

}

Measured memory_bytes: 256
l, r = map(int, input().split())

ll = l % 2019
rr = r % 2019

if r - l >= 2019 or ll >= rr:
    print(0)
else:
    m = 2019
    for i in range(ll, rr):
        for j in range(i + 1, rr + 1):
            m = min(m, (i * j) % 2019)
    print(m)

Measured memory_bytes: 40812
import random

class Dice:
    def __init__(self, hoge):
        self.num = hoge
        self.face = {'U': 0, 'W': 3, 'E': 2, 'N': 4, 'S': 1, 'B': 5} 
    
    def move(self, direct):
        previouse = {k: v for k, v in self.face.items()}
        if direct == 'E':
            self.face['U'] = previouse['W']
            self.face['W'] = previouse['B']
            self.face['E'] = previouse['U']
            self.face['B'] = previouse['E']
        elif direct == 'W':
            self.face['U'] = previouse['E']
            self.face['W'] = previouse['U']
            self.face['E'] = previouse['B']
            self.face['B'] = previouse['W']
        elif direct == 'N':
            self.face['U'] = previouse['S']
            self.face['N'] = previouse['U']
            self.face['S'] = previouse['B']
            self.face['B'] = previouse['N']
        elif direct == 'S':
            self.face['U'] = previouse['N']
            self.face['N'] = previouse['B']
            self.face['S'] = previouse['U']
            self.face['B'] = previouse['S']
    
    def get_num(self, place):
        return self.num[self.face[place]]
    
    def getFace(self):
        for k, v in sorted(self.face.items()):
            yield self.num[v]
    
        
if __name__ == '__main__':
    num_dice = int(input())
    dice = list()
    
    for _ in range(num_dice):
        dice.append(Dice([int(x) for x in input().split()]))
        
    d = ['E', 'W', 'N', 'S']
    
    for yuki in range(1, num_dice):
        haruhi = 0
        for k in range(1000):
            c = 0
            rand_num = random.randint(0, 3)
            dice[yuki].move(d[rand_num])
        
            for v1, v2 in zip(dice[0].getFace(), dice[yuki].getFace()):
                if v1 == v2:
                    c += 1
            if c == 6:
                haruhi += 1
                break
        if haruhi:
            print ('No')
            break 
    if not haruhi:
        print ('Yes')


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

int main(){
  int n;
  cin>>n;
  REP(i,10)if(i*111>=n){
    cout<<(i*111)<<endl;
    return 0;
  }
  return 0;
}

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

int main()
{
    int n,a[20],m=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=1;i<n-1;i++)
    {
        if((a[i]<a[i+1]&&a[i]>a[i-1])||(a[i]>a[i+1]&&a[i]<a[i-1]))
            m++;
    }
    cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
int l[10], r[10];
// dp[i] = 範囲 [1, i] に到着する場合の数
ll dp[200001]={};
int main()
{
    ll n, k;
    cin >> n >> k;
    for(int i=0; i<k; ++i)cin >> l[i] >> r[i];
    dp[1]=1;
    for(int i=2; i<=n; ++i){
        dp[i] = dp[i-1];
        for(int j=0; j<k; ++j){
            int ll = max(1, i-r[j]);
            int rr = min(i-1, i-l[j]);
            if(ll<=rr){
                dp[i] += dp[rr] - dp[ll-1];
            }
        }
        dp[i] = (dp[i]%MOD + MOD)%MOD;
    }
    cout << (dp[n]-dp[n-1]+MOD)%MOD << endl;
    return 0;
}


Measured memory_bytes: 5148
import heapq
N, M = map(int, input().split())

AB = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a in AB:
        AB[a].append(b)
    else:
        AB[a] = [b]

count = 0
current = []

for day in range(1, M + 1):
    if day in AB:
    	for work in AB[day]:
            heapq.heappush(current, -work)

    #print("day{}:{}".format(day, current))
    if len(current) > 0:
        count += -heapq.heappop(current)

print(count)





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

int main() {
	string S;
	cin >> S;
	rep(i, S.length()) {
		S.at(i) = 'x';
	}
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	if a == b && b == c && a%2 == 0 {
		fmt.Println(-1)
		return
	}

	var cnt int
	for {
		if a%2 == 1 || b%2 == 1 || c%2 == 1 {
			fmt.Println(cnt)
			return
		}
		a, b, c = b/2+c/2, a/2+c/2, a/2+b/2
		cnt++
	}
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
    int n, ans = 0;
    int buf1 = 10e5, buf2 = 10e5;
    cin >> n;

    for(int i = 0; i < n - 1; ++i) {
        buf2 = buf1;
        cin >> buf1;
        ans += buf1 < buf2 ? buf1 : buf2;
    }

    cout << ans + buf1;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const uint64_t MOD = 998244353;

class ModuloOps
{
private:
  std::vector<uint64_t> _fact, _fact_inv;

  void _calc_fact(uint64_t n)
  {
    for (uint64_t i = 2; i <= n; ++i) {
      _fact[i] = (_fact[i - 1] * i) % MOD;
      _fact_inv[i] = inv(_fact[i]);
    }
  }

public:
  ModuloOps(uint64_t n)
  {
    _fact = std::vector<uint64_t>(n + 1);
    _fact_inv = std::vector<uint64_t>(n + 1);

    _fact[0] = 1;
    _fact[1] = 1;
    _fact_inv[0] = 1;
    _fact_inv[1] = 1;

    _calc_fact(n);
  }

  uint64_t power(uint64_t x, uint64_t y) const
  {
    if (y <= 1) {
      return (y == 0) ? 1 : (x % MOD);
    }

    uint64_t w = power(x, y >> 1);
    uint64_t z = (w * w) % MOD;

    if (y % 2 == 1) {
      z = (x * z) % MOD;
    }

    return z;
  }

  uint64_t inv(uint64_t n) const { return power(n, MOD - 2); } 

  uint64_t fact(uint64_t n) const { return _fact[n]; }
  uint64_t fact_inv(uint64_t n) const { return _fact_inv[n]; }

  uint64_t perm(uint64_t n, uint64_t k) const {
    return (_fact[n] * _fact_inv[n - k]) % MOD;
  }

  uint64_t comb(uint64_t n, uint64_t k) const {
    return (perm(n, k) * _fact_inv[k]) % MOD;
  }

  uint64_t prem_rep(uint64_t k, uint64_t l) const
  {
    uint64_t x = _fact[k + l];
    x = (x * _fact_inv[k]) % MOD;
    x = (x * _fact_inv[l]) % MOD;
    return x;
  }

  uint64_t prem_rep(const std::vector<uint64_t> &a) const
  {
    uint64_t n = std::accumulate(a.begin(), a.end(), 0);
    uint64_t x = _fact[n];
    for (uint64_t y : a) {
      x = (x * _fact_inv[y]) % MOD;
    }
    return x;
  }

  uint64_t comb_rep(uint64_t n, uint64_t k) const {
    return comb(n + k - 1, k);
  }
};

int main()
{
  uint64_t N, M, K;
  cin >> N >> M >> K;

  ModuloOps mod_ops(N + 1);

  uint64_t S = 0;
  for (uint64_t k = 0; k <= K; ++k) {
    // M * (M - 1)^((N - 1) - k) * comb(N - 1, k)
    uint64_t x = (M * mod_ops.power(M - 1, (N - 1) - k)) % MOD;
    uint64_t y = mod_ops.comb(N - 1, k);

    uint64_t T = (x * y) % MOD;
    S = (S + T) % MOD;
  }
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 6304