akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}
int main() {
  int N;
  cin >> N;
  VEC<int> X(N), Y(N);
  REP(i, 0, N) {
    std::cin >> X[i] >> Y[i];
    X[i]--;
    Y[i]--;
  }
  map<pair<int, int>, int> pairs;
  REP(i, 0, N) {
    REP(j, 0, N) {
      if (i == j) continue;
      int p = X[i] - X[j];
      int q = Y[i] - Y[j];
      pairs[{p, q}]++;
    }
  }
  int ma = 0;
  for (auto p : pairs) {
    ma = max(ma, p.second);
  }
  cout << N - ma << endl;

  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

void trace(int A[], int N){
	int i;
	for( i = 0; i < N; i++ ) {
		if( i > 0) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

void insertionSort(int A[], int N) {
	int j, i, v;
	for( i = 1; i < N; i++ ) {
		v = A[i];
		j = i - 1;
		while( j >= 0 && A[j] > v ) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main() {
	int N, i, j;
	int A[100];
	
	scanf("%d", &N);
	for( i = 0; i < N; i++ ) scanf("%d", &A[i]);
	
	trace(A, N);
	insertionSort(A, N);
	
	return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

const int maxn = 1000 * 1000 + 218;
const ll mod = 998244353;

ll mu[maxn], a[maxn], b[maxn], c[maxn];
ll inv[maxn], w[maxn];

ll GetPower(ll x, ll n) {
  ll result = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      result *= x;
      result %= mod;
      n--;
    } else {
      x *= x;
      x %= mod;
      n /= 2;
    }
  }
  return result;
}

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

  for (int i = 0; i < maxn; ++i) {
    b[i] = a[i] * i % mod;
    c[i] = a[i] * ll(i) * ll(i) % mod;
  }

  mu[1] = 1;
  for (int d = 1; d < maxn; ++d) {
    if (d != 1) mu[d] *= -1;
    for (int x = 2 * d; x < maxn; x += d) {
      mu[x] += mu[d];
    }
  }

  for (int i = 1; i < maxn; ++i) {
    inv[i] = GetPower(i, mod - 2);
  }

  for (int d = 1; d < maxn; ++d) {
    for (int n = d; n < maxn; n += d) {
      w[n] += mu[n / d] * inv[d];
    }
  }

  for (int i = 0; i < maxn; ++i) {
    w[i] = (w[i] % mod + mod) % mod;
  }

  ll result = 0;

  for (int d = 1; d < maxn; ++d) {
      ll sum = 0;
      ll sum2 = 0;
      for (ll x = d; x < maxn; x += d) {
        sum += b[x];
        sum2 += c[x];
      }
      sum %= mod;
      sum2 %= mod;
      result += (sum * sum - sum2) % mod * w[d] % mod;
  }
  result %= mod;
  result *= GetPower(2, mod - 2);
  result = (result % mod + mod) % mod;
  cout << result << endl;
  return 0;


  for (int g = 1; g < maxn; ++g) {
    ll revg = GetPower(g, mod - 2);
    for (int d = g; d < maxn; d += g) {
      if (mu[d / g] == 0) continue;
      ll sum = 0;
      ll sum2 = 0;
      for (ll x = d; x < maxn; x += d) {
        sum += b[x];
        sum2 += c[x];
      }
      sum %= mod;
      sum2 %= mod;
      ll cur = (sum * sum - sum2) % mod;
      cur *= mu[d / g];
      cur *= revg;
      cur %= mod;
      result += cur;
    }
  }
  result %= mod;
  result *= GetPower(2, mod - 2);
  result = (result % mod + mod) % mod;
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 47104
#include <stdio.h>

int main(void)
{
	int A, B, C, max;
	long long int brock;

	scanf("%d%d%d", &A, &B, &C);

	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
		brock = 0;
	} else {
		max = A > B ? A : B;
		max = max > C ? max : C;
		if (max == A)
			brock = (long long int)B * C;
		else if (max == B)
			brock = (long long int)A * C;
		else
			brock = (long long int)A * B;		
	}

	printf("%lld\n", brock);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 100000000
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int a;
     cin>>a;
     ll int x=a+(a*a)+(a*a*a);
     cout<<x<<endl;
     
 return 0;    
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
    int x;
    scanf("%d", &x);

    if (x==3 || x==5 || x==7){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
} 



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

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;

#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back

ll f(ll x) {
    if (x == -1) return -1; 
    int res = 0;
    while (x != 0) {
        res++;
        x %= __builtin_popcountll(x);
    }
    return res;
}

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    reverse(all(s));
    ll pc = 0;
    for (int i = 0; i < n; i++) pc += (s[i] == '1');

    ll lpc = pc - 1;
    ll upc = pc + 1;

    bool badl = 0;

    if (lpc <= 0) lpc = 1, badl = 1;


    vector<ll> ldiv(n + 1);
    vector<ll> udiv(n + 1);
    ll lcur = 1, ucur = 1;
    for (int i = 0; i <= n; i++) {
        ldiv[i] = lcur;
        udiv[i] = ucur;
        lcur *= 2, ucur *= 2;
        lcur %= lpc, ucur %= upc;
    }

    ll up = 0;
    ll low = 0;
    for (int i = 0; i < n; i++) {
        up += udiv[i] * (s[i] == '1');
        low += ldiv[i] * (s[i] == '1');
        up %= upc;
        low %= lpc;
    }

    vi res(n);

    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            res[i] = up + udiv[i];
            res[i] %= upc;
        } else {
            if (badl) {
                res[i] = -1;
            } else {
                res[i] = low - ldiv[i] + lpc;
                res[i] %= lpc;
            }
        }
    }

    reverse(all(res));
    for (auto &i : res) cout << f(i) + 1 << '\n';


}

int main() {
    solve();
}

Measured memory_bytes: 8408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int f=1;
    int x; cin>>x;
    while(f){
        f=0;
        int i;
        for( i=2;i<=sqrt(x);i++){
            if(x%i==0){
            f=1;
            }
        }
        if(f)
        {
            x++;
        }
        else
            cout<<x;
    }
}


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

//vector<pair<int, int>> graph[1005];
int64_t costs[1005][1005];
int n, att;

constexpr int64_t mi = 0x8080808080808080, larges = static_cast<int64_t>(1e16);
void solve()
{
   for (int k = 1; k <= n; k++)
   {
      for (int i = 1; i <= n; i++)
      {
         if (//i != k &&
            mi != costs[i][k])
         {
            for (int j = 1; j <= n; j++)
            {
               if (//i != j && j != k &&
                  mi != costs[k][j])
               {
                  costs[i][j] = min(larges, max(costs[i][j], costs[i][k] + costs[k][j]));
               }
            }
         }
      }
   }
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int m;
   while (cin >> n >> m) {
      memset(costs, 0x80, sizeof costs);
      for (int i = 0; i < m; ++i) {
         int a, b, c; cin >> a >> b >> c;  //graph[a].push_back(make_pair(b, c));
         costs[a][b] = max(costs[a][b], static_cast<int64_t>(c));
      }

      solve();
      auto ans = costs[1][n];
      ++att;
      solve();
      auto ans2 = costs[1][n];

      if (ans2 != ans || larges == ans)
         cout << "inf" << '\n';
      else
         cout << ans << '\n';
   }
   return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, D;
    cin >> N >> D;

    vector<vector<int>> X(N);
    int x_nd;
    for (int n = 0; n < N; n++) {
        for (int d = 0; d < D; d++) {
            cin >> x_nd;
            X[n].emplace_back(x_nd);
        }
    }

    int ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < i; j++) {
            int dist = 0;
            for (int k = 0; k < D; k++) {
                dist += pow(X[i][k] - X[j][k], 2);
            }

            //cout << dist << "\n";
            int l = 0;
            while (pow(l, 2) <= dist) {
                if (pow(l, 2) == dist) {
                    ans++;
                }
                l++;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

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

int dfs(int h, int w, int depth, vector<vector<bool>> &grid){
    int ans = depth;
    for (int i = 0; i < 4; ++i) {
        if(grid[h+dy[i]][w+dx[i]]){
            grid[h][w] = false;
            ans = max(ans, dfs(h+dy[i], w+dx[i], depth+1, grid));
            grid[h][w] = true;
        }
    }
    return ans;
}


int main() {
    int w, h;
    while(cin >> w >> h, w|h){
        auto grid = make_v(h+2, w+2, false);
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                int x;
                cin >> x;
                grid[i+1][j+1] = (x == 1);
            }
        }
        int ans = 0;
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                if(grid[i][j]) ans = max(ans, dfs(i, j, 1, grid));
            }
        }
        cout << ans << "\n";
    }
    
    return 0;
}



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

int main() {
  int n, m, t, u, v;
  int a[100][100];
  cin >> n;
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      a[i][j] = -1;
    }
    a[i][i] = 0;
  }
  for (int i=0; i<n; i++) {
    cin >> t >> u;
    --t;
    for (int j=0; j<u; j++) {
      cin >> v;
      --v;
      a[t][v] = 1;
    }
  }
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      for (int k=0; k<n; k++) {
        if (a[j][i] == -1 || a[i][k] == -1) continue;
        if (a[j][k] == -1) {
          a[j][k] = a[j][i] + a[i][k];
        } else if (a[j][k] > a[j][i] + a[i][k]) {
          a[j][k] = a[j][i] + a[i][k];
        }
      }
    }
  }
  cin >> m;
  for (int i=0; i<m; i++) {
    cin >> t >> u >> v;
    --t;
    --u;
    if (a[t][u] != -1 && a[t][u] < v) {
      cout << a[t][u]+1 << endl;
    } else {
      cout << "NA" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector <ll> ctr(100001,0);
        ll val=0ll;
        for(int i=1;i<=n;i++){
            ll a;
            cin>>a;
            ctr[a]++;
            val+=a;
        }
        ll q;
        cin>>q;
        while(q--){
            ll b,c;
            cin>>b>>c;
            val+=(c-b)*ctr[b];
            ctr[c]+=ctr[b];
            ctr[b]=0;
            cout<<val<<"\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
char c[100001];
int main()
{
	int a,b=0,w=0,i,l;
	scanf("%s",c);
	l=strlen(c);
	for(i=1;i<=l;i++)
	{
		a=c[i-1]-'0';
		if(a==0)
			b++;
		else if(a==1)
			w++;
	}
	printf("%d",min(b,w)*2);
    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
//こういう問題もAns(B-A)=Ans(B)-Ans(A-1)という解き方ができる
//要はA-1とBを二進数にしてその排他的論理和を10進数に直せばよい？
class Program
{
    static void Main()
    {
        long[] In = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        long a = In[0];
        long b = In[1];
        long ans = Calc(b) ^ Calc(a - 1);
        Console.WriteLine(ans);
    }
    static public long Calc(long x)
    {
        if (x <= 0) return 0;
        //10^12=(10^3)^4=(2^10)^4=40桁
        long ans = 0;
        x++;
        //i桁目の偶奇を調べる
        for (int i = 0; i < 50; i++)
        {
            //周期　0桁目->2, 1桁目->4
            long loop = (long)1 << (i + 1);
            //例えばx=2,i=0の時loop=2,cnt=1となる
            //x=3だとi=0,loop=2,cnt=1+0=1 そしてi=1,loop=4,cnt=0+1=1となり、
            long cnt = (x / loop) * (loop / 2);
            cnt += (long)Math.Max(0, (x % loop) - (loop / 2));
            //その桁の1の数が奇数だったら足し算
            if (cnt % 2 == 1)
            {
                ans += (long)1 << i;
            }
        }
        return ans;
    }
}


Measured memory_bytes: 28180
#include <iostream>

int main()
{
    unsigned long long a, b;
    std::cin >> a >> b;

    if (a % 2 && b % 2) {
        std::cout << (a ^ ((b - a) / 2 % 2)) << std::endl;
        return 0;
    }

    if (a % 2) {
        std::cout << (((b - a) / 2 % 2) ^ a ^ b) << std::endl;
        return 0;
    }

    if (b % 2) {
        std::cout << ((b - a + 1) / 2 % 2) << std::endl;
        return 0;
    }

    std::cout << (b ^ (b - a) / 2 % 2) << std::endl;
}


Measured memory_bytes: 256
/*
  AUTHOR:SOURABH
  CREATED:07:03:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,a,b,c,d,i;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>a>>b;
        fs(i,1,10001)
        {
            //ld x=(ld)i*(.08);
            ll c=i*(.08);
            ll d=i*(.10);
            //ld y=(ld)i*(.10);

            /*if(x-(ld)c>.50)
            c++;
            if(y-(ld)d>.50)
            d++;*/

            /*if(i==19)
            cout<<c<<" "<<d<<" "<<x<<" "<<y<<endl;*/
            if(c==a && d==b)
            {cout<<i;return 0;}
        }
        cout<<-1;
    }
    return 0;
}














Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main(void){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    
    ll r = 0;
    ll m = 0;

    rep (i, a) {
        if (m >= k) break;
        r++;
        m++;
    }
    rep (i, b) {
        if (m >= k) break;
        m++;
    }
    rep (i, c) {
        if (m >= k) break;
        r--;
        m++;
    }

    cout << r;

}

Measured memory_bytes: 3564
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<usize>();
    let mut a = a.into_iter().collect::<PriorityQueue<_>>();
    let mut b = Vec::new();
    while let Some(x) = a.pop() {
        b.push(x);
    }
    b.reverse();
    debug!(b);
    let mut alice = 0;
    let mut bob = 0;
    for i in 0..n {
        if i % 2 == 0 {
            alice += b[i];
        } else {
            bob += b[i];
        }
    }
    println!("{}", alice - bob);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[derive(Clone, Debug)]
struct PriorityQueue<T>
where
    T: std::cmp::Ord + std::clone::Clone + std::marker::Copy,
{
    heap: Vec<T>,
}

impl<T> PriorityQueue<T>
where
    T: std::cmp::Ord + std::clone::Clone + std::marker::Copy,
{
    fn new() -> PriorityQueue<T> {
        PriorityQueue {
            heap: Vec::<T>::new(),
        }
    }

    fn push(&mut self, x: T) {
        let mut i = self.heap.len() as i64;
        self.heap.push(x);
        while i > 0 {
            let p = (i as usize - 1) / 2;
            if self.heap[p] <= x {
                break;
            }
            let temp = self.heap[i as usize];
            self.heap[i as usize] = self.heap[p];
            self.heap[p] = temp;
            i = p as i64;
        }
    }

    fn is_empty(&self) -> bool {
        self.heap.is_empty()
    }

    fn pop(&mut self) -> Option<T> {
        if self.is_empty() {
            return None;
        }
        let ret = self.heap[0];
        let x = self.heap[self.heap.len() - 1];
        let mut i = 0;
        let new_len = self.heap.len() - 1;
        while i * 2 + 1 < new_len {
            let mut a = i * 2 + 1;
            let b = i * 2 + 2;
            if b < new_len && self.heap[b] < self.heap[a] {
                a = b;
            }
            if self.heap[a] >= x {
                break;
            }
            self.heap[i] = self.heap[a];
            i = a;
        }
        self.heap[i] = x;
        self.heap.swap_remove(new_len);
        Some(ret)
    }

    fn peek(&self) -> Option<T> {
        if self.is_empty() {
            return None;
        }
        Some(self.heap[0])
    }
}

impl<T> std::iter::FromIterator<T> for PriorityQueue<T>
where
    T: std::cmp::Ord + std::clone::Clone + std::marker::Copy,
{
    fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
        let mut c = PriorityQueue::new();
        for i in iter {
            c.push(i);
        }
        c
    }
}


Measured memory_bytes: 4352
from bisect import bisect_left,bisect

icase=0
if icase==0:
    a,b,q=map(int,input().split())
    s=[0]*a
    for i in range(a):
        s[i]=int(input())
    t=[0]*b
    for i in range(b):
        t[i]=int(input())
    x=[0]*q
    for i in range(q):
        x[i]=int(input())
elif icase==1:
    a,b,q=2,3,4
    s=[100, 600]
    t=[400, 900, 1000]
    x=[150,2000,899,799]

si=[0]*a
j=-1
for i in range(a):
    si[i]=b-1
    while j+2<b:
        j+=1
        if abs(s[i]-t[j])<abs(s[i]-t[j+1]):
            si[i]=j
            j-=1
            break

ti=[0]*b
j=-1
for i in range(b):
    ti[i]=a-1
    while j+2<a:
        j+=1
        if abs(t[i]-s[j])<abs(t[i]-s[j+1]):
            ti[i]=j
            j-=1
            break
    
for k in range(q):
    sk=max(min(bisect(s,x[k])-1,a-1),0)
    tk=max(min(bisect(t,x[k])-1,b-1),0)
#    print(sk,tk)
    r1=abs(x[k]-s[sk])+abs(s[sk]-t[si[sk]])
    if sk+1<a:
        r2=abs(x[k]-s[sk+1])+abs(s[sk+1]-t[si[sk+1]])
    else:
        r2=r1
    r3=abs(x[k]-t[tk])+abs(t[tk]-s[ti[tk]])
    if tk+1<b:
        r4=abs(x[k]-t[tk+1])+abs(t[tk+1]-s[ti[tk+1]])
    else:
        r4=r3
#    print(min((r1,r2,r3,r4)),r1,r2,r3,r4)
    print(min((r1,r2,r3,r4)))


Measured memory_bytes: 90144
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

    char a;
    cin >> a;
    if(a>='A' && a<='Z') cout << 'A' << endl;
    else cout << 'a' << endl;
}

Measured memory_bytes: 3640
N = int(input())
myList = []
for i in range(N):
    S,P = input().split()
    myList.append([S,int(P),i+1])
myList = sorted(myList)
while len(myList)!=0:
    n = myList[0][0]
    tmp = []
    while len(myList)!=0:
        if myList[0][0] == n :
            d = myList.pop(0)
            tmp.append([d[1],d[2]])
        else :
            break
    tmp = sorted(tmp,reverse=True)
    for i in range(len(tmp)):
        print(tmp[i][1])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

const int MAX_V = 3000;

int X[MAX_V][MAX_V], Y[MAX_V][MAX_V];
int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    rep(i, H) cin >> S[i];

    repd(i, 1, H + 1) {
        repd(j, 1, W + 1) {
            if (S[i - 1][j - 1] == '.') {
                X[i][j] = X[i][j - 1] + 1;
            }
        }
    }

    repd(i, 1, H + 1) {
        int ct = X[i][W];
        for (int j = W - 1; j >= 1; j--) {
            if (X[i][j] == 0) {
                ct = 0;
                continue;
            }
            if (ct == 0) ct = X[i][j];
            else {
                X[i][j] = ct;
            }
        }
    }

    repd(j, 1, W + 1) {
        repd(i, 1, H + 1) {
            if (S[i - 1][j - 1] == '.') {
                Y[i][j] = Y[i - 1][j] + 1;
            }
        }
    }

    repd(j, 1, W + 1) {
        int ct = Y[H][j];
        for (int i = H - 1; i >= 1; i--) {
            if (Y[i][j] == 0) {
                ct = 0;
                continue;
            }
            if (ct == 0) ct = Y[i][j];
            else {
                Y[i][j] = ct;
            }
        }
    }
/*
    rep(i, H + 1) {
        rep(j, W + 1) {
            cout << X[i][j] << ":" << Y[i][j] << " ";
        }
        cout << endl;
    }
*/
    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            chmax(ans, X[i + 1][j + 1] + Y[i + 1][j + 1] - 1);
        }
    }

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

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

int h,w,ban[20][20];

void search(int i, int j) {
   if (i+1<h && (ban[i+1][j]==0 || ban[i+1][j]>ban[i][j]+1)) {
      ban[i+1][j]=ban[i][j]+1;
      search(i+1,j);
   }
   if (i-1>=0 && (ban[i-1][j]==0 || ban[i-1][j]>ban[i][j]+1)) {
      ban[i-1][j]=ban[i][j]+1;
      search(i-1,j);
   }
   if (j+1<w && (ban[i][j+1]==0 || ban[i][j+1]>ban[i][j]+1)) {
      ban[i][j+1]=ban[i][j]+1;
      search(i,j+1);
   }
   if (j-1>=0 && (ban[i][j-1]==0 || ban[i][j-1]>ban[i][j]+1)) {
      ban[i][j-1]=ban[i][j]+1;
      search(i,j-1);
   }
}

int main(){
   int i,j,ii,jj,bano[20][20],ans,max;
   char s[20][21];
 
   scanf("%d %d",&h,&w);
   for (i=0;i<h;i++) scanf("%s",s[i]);
   for (ii=0;ii<h;ii++)
      for (jj=0;jj<w;jj++)
          if (s[ii][jj]=='.') bano[ii][jj]=0;
          else                bano[ii][jj]=-1;
   for (ans=i=0;i<h;i++) 
      for (j=0;j<w;j++)
         if (s[i][j]=='.') {
            memcpy(ban,bano,sizeof(ban));
            ban[i][j]=1;
            search(i,j);
            for (max=ii=0;ii<h;ii++)
               for (jj=0;jj<w;jj++)
                  if (max<ban[ii][jj]) max=ban[ii][jj];
            if (max>ans) ans=max;
         }
   printf("%d\n",ans-1);
   return 0;
}


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

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

	int x,y;
	int res = 0;
	cin >> x >> y;

	if(x==1)
	{
		res += 3e5;
	}
	else if(x==2)
	{
		res += 2e5;
	}
	else if(x==3)
	{
		res += 1e5;
	}
	if(y==1)
	{
		res += 3e5;
	}
	else if(y==2)
	{
		res += 2e5;
	}
	else if(y==3)
	{
		res += 1e5;
	}

	if(x==1 && y==1)
	{
		res += 4e5;
	}

	cout << res << '\n';

	return 0;
}

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

def main():
    n,t=map(int,input().split())
    AB=[list(map(int,input().split())) for _ in range(n)]
    AB.sort()
    DP=[[0]*(6001) for _ in range(n+1)]
    for i,(a,b) in enumerate(AB):
        for j in range(1,6001):
            if j<a:
                DP[i+1][j]=max(DP[i][j],DP[i+1][j-1])
            elif j-a<t:
                DP[i+1][j]=max(DP[i][j],DP[i+1][j-1],DP[i][j-a]+b)
            else:
                DP[i+1][j]=max(DP[i][j],DP[i+1][j-1])
    print(max(DP[-1]))
    
if __name__=='__main__':
    main()

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



string s, t;
void solve(){
	cin >> s >> t;
	int n = s.size(), m = t.size();
	
	for(int i = n-m; i >= 0; i--){
		bool ok = 1;
		for(int j = 0; j < m; j++){
			if(s[i+j]=='?' || s[i+j]==t[j]) continue;
			ok = 0;
		}
		if(!ok) continue;
		for(int j = 0; j < m; j++){
			s[i+j] = t[j];
		}
		for(int j = 0; j < n; j++){
			if(s[j] == '?') s[j] = 'a';
		}
		cout << s << endl;
		return;
	}
	cout << "UNRESTORABLE" << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#辞書順で最も小さいものが答えだから、後ろから文字列の後ろから処理していく。
#後ろから考えるのは面倒くさいので、逆順にソートする。

s = str(input())
t = str(input())

sr = ''.join(list(reversed(s)))
tr = ''.join(list(reversed(t)))

slen = len(sr)
tlen = len(tr)

for i in range(slen-tlen+1):
    flg = i
    for j in range(tlen):
        if sr[i+j] == tr[j] or sr[i+j] == "?":
            continue
        else:
            flg = -1
            break
    else:
        #breakせずに正常にループが終了したら、Tが入る適切な場所が見つかったということなのでbreakする。
        #ここでbreakできなかったら、"UNRESTORABLE"が出力され終了する。
        break
else:
    flg = -1
    print("UNRESTORABLE")
    exit()


#before_resultではまだ"?"が残っている。
before_result_reversed = sr[:flg] + tr + sr[flg+tlen:]
before_result = ''.join(list(reversed(before_result_reversed)))


print(before_result.replace("?","a"))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  int V[N], C[N];
  REP(i, N) { cin >> V[i]; }
  REP(i, N) { cin >> C[i]; }
  int sum = 0;
  REP(i, N) {
    int tmp = V[i] - C[i];
    if (tmp > 0) {
      sum += tmp;
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int64_t a, b, c, d; cin >> a >> b >> c >> d;
	cout << max({b * d, a * c, a * d, b * c}) << '\n';
	return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
inline int read(){
	int f=1,ans=0;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=100001;
int m,k,ans,n,x[MAXN],d[MAXN],a[MAXN],fa[MAXN][61],p[MAXN];
signed main(){
//	freopen("2.in","r",stdin);
	n=read();
	for(int i=1;i<=n;i++) x[i]=read(),d[i]=i,p[i]=x[i]-x[i-1];
	m=read(),k=read();
	for(int i=1;i<=m;i++) a[i]=read(),swap(d[a[i]],d[a[i]+1]);
	for(int i=1;i<=n;i++) fa[i][0]=d[i];
	for(int j=1;j<=60;j++)
		for(int i=1;i<=n;i++) fa[i][j]=fa[fa[i][j-1]][j-1];
	for(int i=1;i<=n;i++){
		int res=i;
		int K=k;
		for(int j=60;j>=0;j--) if(K-(1ll<<j)>=0) K-=(1ll<<j),res=fa[res][j];
		ans+=p[res];
		printf("%lld.0\n",ans);
	}return 0;
}/*
3
1 -1 1
2 2
2 2
*/

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

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

using ll = long long;
using P = pair<int,int>;
using mp =  map<char,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    string s;
    cin >> s;

    int ans = 0, cnt = 0;
    rep(i, s.size()){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            cnt++;
        }else{
            ans = max(ans, cnt);
            cnt = 0;
        }
    }

    cout << max(ans, cnt) << endl;

    return 0;
}

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

int main(void) {
  int N;
  int left;
  int now;

  cin >> N;

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    cin >> now;
    if ( i == 0 ) {
      ans += now;
    } else {
      int def = now - left;
      if ( def > 0 ) ans += def;
    }

    left = now;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
S = input()
opt = ['+', '-']

flag = 1
if flag:
    for i in opt:
        if flag:
            for j in opt:
                if flag:
                    for k in opt:
                        temp = S[0] + i + S[1] + j + S[2] + k + S[3]
                        ans = eval(temp)
                        if ans == 7:
                            flag = 0
                            break
                    
print(''.join(list(temp)), end = '')
print('=7')                

Measured memory_bytes: 3060
x, y, z = map(int, input().split())

A = []
for _ in range(x):
    A.append([int(x) for x in list(input().split())])

B = []
for _ in range(y):
    B.append([int(x) for x in list(input().split())])


C = [[0] * z for _ in range(x)]

for k in range(z):
    for i in range(x):
        for j in range(y):
            C[i][k] += A[i][j] * B[j][k]

for i in range(len(C)):
    for j in range(len(C[i])):
        if j != len(C[i]) - 1:
            print("{} ".format(C[i][j]), end="")
        else:
            print(C[i][j])




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

string s;

int solve();

int main() {
  cin >> s;

  cout << solve() << endl;
  return 0;
}

int solve() {
  int ans = 0, g = 0, sum = 0, ssize = s.size();
  for(int i = 0; i < ssize; ++i)
    if(s[i] == 'p') ++sum;
  for(int i = 0; i < ssize; ++i) {
    if(s[i] == 'g') {
      if(sum >= g || g == 0)
        ++g;
      else
        --g, ++ans;
    }
    else {
      --g;
      --sum;
    }
  }
  return ans;
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, A;
    cin >> N;
    int res = 100000;
    REP(i, N) {
        cin >> A;
        int cnt = 0;
        while (A % 2 == 0) {
            A /= 2;
            cnt++;
        }
        amin(res, cnt);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include<bits/stdc++.h>
#include <ios>
#include <iterator>
using namespace std;
#define ll long long
#define f(n)  for(int i=0;i<n;i++) 
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define all(v)   v.begin(),v.end()  
void speed (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main() {
    speed();
   string s;
   cin>>s;
   if(s[2]==s[3]&&s[4]==s[5]){
       cout<<"Yes";
   }else{
       cout<<"No";
   }
   
    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if((a+b) % 2 == 0){
    cout << (a+b) / 2 << endl;
  }
  else{
    cout << ((a+b) / 2) + 1<< endl;
  }
}

Measured memory_bytes: 256
/* ex5_4
melo */
#include <stdio.h>
#include <string.h>
int main(void){
    char text[11],acgt[11]="",*ptr;
    int len=0,maxi=0;
    scanf("%s",text);
    ptr=&text[0];
    while(*ptr){
        if(*ptr!='A'&&*ptr!='C'&&*ptr!='G'&&*ptr!='T'){
            len=0;
        }
        else{
            len++;
            if(len>maxi){
                maxi=len;
            }
        }
        ptr++;
    }
    printf("%d\n",maxi);
    return 0;
}

Measured memory_bytes: 1668
#include<stdio.h>
#include<stdlib.h>

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

int min(int a, int b){
  if(a < b) return a;
  else return b;
}


int main(){

  int sx,sy,tx,ty;
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);

  for(int i = 0; i < abs(tx-sx); ++i){
    printf("R");
  }

  for(int i = 0; i < abs(ty-sy); ++i){
    printf("U");
  }

  for(int i = 0; i < abs(tx-sx); ++i){
    printf("L");
  }

  for(int i = 0; i < abs(ty-sy); ++i){
    printf("D");
  }

  printf("D");

  for(int i = 0; i < abs(tx-sx)+1; ++i){
    printf("R");
  }

  for(int i = 0; i < abs(ty-sy)+1; ++i){
    printf("U");
  }

  printf("LU");

  for(int i = 0; i < abs(tx-sx)+1; ++i){
    printf("L");
  }

  for(int i = 0; i < abs(ty-sy)+1; ++i){
    printf("D");
  }

  printf("R\n");

  return 0;

}


Measured memory_bytes: 128
a,b,m=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
minimum=200000
x=[0]*m
y=[0]*m
c=[0]*m
for i in range(m):
    x[i],y[i],c[i]=map(int,input().split())
    sum=A[x[i]-1]+B[y[i]-1]-c[i]
    if sum<minimum:
        minimum=sum
sum=min(A)+min(B)
if sum<minimum:
    print(sum)
else:
    print(minimum)

Measured memory_bytes: 23396
n, m = map(int, raw_input().split())
ans = 0
for i in xrange(n):
    A = map(int, raw_input().split())
    if i: A = [e^1 for e in A]
    ans += max(max(A[0]+A[-1] + sum(A[k]^1^(k==j) for k in xrange(1, m-1)) for j in xrange(1, m-1)) if m>2 else 0, max(A[0] + sum(e^1 for e in A[1:]), A[-1] + sum(e^1 for e in A[:-1])))
print ans

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

int main() {
  long n,m,s=0;
  cin >> n >> m;
  vector<long> a(n);
  for(int i=0;i<n;i++) {
    cin >> a[i];
    s+=a[i];
  }
  sort(a.begin(),a.end());
  if(a[n-m]*4*m>=s) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

const int maxn = 200010;
int n, s1[maxn], s2[maxn], cnt[100][100];
long long a[maxn];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        long double x; cin >> x;
        a[i] = round(x * 1e9);
        while (!(a[i] % 2)) s1[i]++, a[i] /= 2;
        while (!(a[i] % 5)) s2[i]++, a[i] /= 5;
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= 60; j++) {
            for (int k = 0; k <= 60; k++) {
                if (j + s1[i] >= 18 && k + s2[i] >= 18) ans += cnt[j][k];
            }
        }
        cnt[s1[i]][s2[i]]++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6864
#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s == "RRR") {
    cout << 3 << endl;
  } else if (s == "SRR" || s == "RRS") {
    cout << 2 << endl;
  } else if (s == "SSS") {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#define co(n) cout << (n) << endl;
#define cn(n) cin >> n;
#define all(x) (x).begin(), (x).end()

int main(){
  int n,u,v;
  cin >> n >> u >> v;
  --u; --v;
  vector<list<int>> node(n);
  vector<pair<int,int>> c(n,pair<int,int>(make_pair(-1,-1)));
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    --a; --b;
    node[a].push_back(b);
    node[b].push_back(a);
  }
  stack<int> stk;
  stk.push(u);
  c[u].first = 0;
  while(!stk.empty()){
    int t = stk.top(); stk.pop();
    rpv(node[t]){
      if (c[v].first == -1 ){
        stk.push(v);
        c[v].first = c[t].first + 1;
      }
    }
  }
  stk.push(v);
  c[v].second = 0;
  while(!stk.empty()){
    int t = stk.top(); stk.pop();
    rpv(node[t]){
      if (c[v].second == -1 ){
        stk.push(v);
        c[v].second = c[t].second + 1;
      }
    }
  }
  ll ans = 0;
  rpv(c){
    if (v.first < v.second){
      if (ans < v.second)ans=v.second;
    }
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is #" << (x) <<"#" <<endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e2+5;
const ll inf = 1e18+7;

ll a[MAX],cont[MAX];

int main() {
  fastio;
  ll x,k,d,ans;
  cin>>x>>k>>d;
  x=abs(x);
  if(x/d>=k) ans=x-k*d;
  else if((x/d-k)%2==0) ans=x%d;
  else ans=d-x%d;
 
  cout<<ans<<"\n";
 return 0;
}
 

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i,l,r) for(ll i=(l); i<(r); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int inf = 1001001001;
const ll mod = 1000000007;
using pp=pair<ll,ll>;
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
   }
   void init(ll sz_) {
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x) { // 根の検索
      while (par[x] != x) {
           x = par[x] = par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y) {
       x = root(x);
       y = root(y);
       if (x == y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x] < siz[y]) swap(x, y);
       siz[x] += siz[y];
       par[y] = x;
       return true;
  }
 
  bool same(ll x, ll y) { // 連結判定
       return root(x) == root(y);
  }
 
  ll size(ll x) { // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n) {
   x = x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1) {
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k) {
   ll x = 1;
   for(int i=n-k+1; i<=n; i++) {
      x = x*i%mod;
   }
 
   ll y = 1;
   for(int i=1; i<=k; i++) {
       y = y*i%mod;
   }
   y = modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n > 3 が保証された
 
   if(n % 2 == 0 || n % 3 == 0) return false;
   // n は 2 と 3 のいずれの倍数でもないことが保証された
   // これより n は (6の倍数)-1 か (6の倍数)+1 である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i * i <= n; i += 6) {
       if(n % i     == 0) return false; // (6の倍数)-1
       if(n % (i+2) == 0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n) {
   int res = 0;
   while(n > 0) {
       res += n%10; //ここをres++;に変えたら桁数を求める関数になる
       n /= 10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i = 1 ; i*i <= n ; i++){
       if(n%i == 0){
           ret.push_back(i);
           if(i*i != n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}
 
int main(){

    ll n;
    cin >> n;
    ll ans=n-1;
    vector<ll>a;
    a=divisor(n);
    for(auto x:a){
        chmin(ans,x-1+(n/x)-1);
        
    }

    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <algorithm>
#include <complex>
#include <map>
#include <cmath>
#include <string>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <istream>
//------------------------------------define------------------------//
#define PB push_buck
#define MP make_pair
//------------------------------------typedef-----------------------//
typedef long long ll;

using namespace std;

int h,w;
char a[1000000][8];
int sum = 0;
//--------------------------------------------------------------//
int main() {
	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				sum++;
				if (a[i - 1][j] != '#' && a[i][j - 1] != '#' && i != 0 && j != 0 ) {
					cout << "Impossible" << endl;
					return 0;
				}
				else if (i == 0 && j!=0) {
					if (a[0][j - 1] != '#') {
						cout << "Impossible" << endl;
						return 0;
					}
				}
				else if (i != 0 && j == 0) {
					if (a[i - 1][0] != '#') {
						cout << "Impossible" << endl;
						return 0;
					}
				}
			}
		}
	}
	if (sum == h + w - 1 && a[h-1][w-1]=='#' && a[0][0]=='#') {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}

}

Measured memory_bytes: 384
N, *AB = [int(x) for x in input().split()]
A, B = sorted(AB)
if (B - A) % 2 == 0:
    ans = (B - A) // 2
else:
    ans = (B - A + 2 * min(N - B, A - 1) + 1) // 2
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
const ll inf = 2e18 + 7;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 7;
const ld pi = 3.14159265358979;

void solve() {
    ll a,b;
    cin>>a>>b;
    cout<<(a*b);
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<"\n";
    }
    return 0; 

}


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

int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q), points(N, 0);
    for (int i = 0; i < Q; i++)
    {
        cin >> A.at(i);
        points.at(A.at(i)-1)++;

    }
    for(int i=0;i<N;i++)
    {
        if(points.at(i)-Q>-K)
        {
            cout << "Yes" << endl;
        }else
        {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
int arr[N] ;
pii pir[N];


int main()
{   int mn = 10 , sum = 0;
    lp(i,5){
        int x ;cin >> x;
        if(x%10)
            sum += x + (10-x%10);
        else
            sum += x;
        if(x%10 && x%10 < mn)mn = x%10;
    }
    cout << sum - 10 + mn << endl;


    return 0;
}


Measured memory_bytes: 256