akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N 51
using namespace std;
int h,w,m;
string mp[N];
int c[N*N],on[N*N],off[N*N];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

vector<int> path;
int used[N*N];
int dfs(int pos,int t){
  if(pos==t) return 1;
  if(used[pos]++) return 0;
  int x = pos%w,y=pos/w;

  for(int i=0;i<4;i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    int npos = w*ny+nx;
    if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]=='#')continue;
    if(dfs(npos,t)){path.push_back(npos);return 1;}
  }
  return 0;
}

vector<int> job;
int calc(){
  int res=0,sta[N*N]={},cnt=2; 
  res+=on[job[0]];
  sta[job[0]] = 1;
  for(int i=0;i<m-1;i++){
    path.clear();
    memset(used,0,sizeof(used));
    dfs(job[i],job[i+1]);
    for(int j=0;j<(int)path.size();j++){
      int pos = path[path.size()-j-1];
      int T = sta[pos];
      if(T==0) res+=on[pos];
      else res+=min(on[pos]+off[pos],c[pos]*(cnt-sta[pos]));
      sta[pos]=cnt++;
    }
  }
  for(int i=0;i<h*w;i++)if(sta[i])res+=off[i];
  return res;
}



int main(){
  cin>>h>>w>>m;
  for(int i=0;i<h;i++) cin>>mp[i];
  for(int i=0;i<h*w;i++) cin>>c[i];
  for(int i=0;i<h*w;i++) cin>>on[i];
  for(int i=0;i<h*w;i++) cin>>off[i];
  for(int i=0,x,y;i<m;i++)cin>>y>>x,job.push_back(y*w+x);
  cout<<calc()<<endl;
  return 0;
}

Measured memory_bytes: 3332
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int n;
	ll x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	int ai = 0;
	rep(i, n) {
		if (x >= a[ai]) {
			ans++;
			x -= a[ai];
			ai++;
		}
		else {
			cout << ans << endl;
			return 0;
		}
	}
	if (x > 0) cout << ans - 1 << endl;
	else cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	char c;
	cin>>c;
	cout<<char(int(c)+1)<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int p,q,r;
	cin >> p >> q >> r;
	int res[3] = {p+q,p+r,q+r};
	int n = res[0];
	if(n > res[1])
		n = res[1];
	if(n > res[2])
		n = res[2];
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
color = [int(i) for i in input()]
n = len(color)
ans = 0

if n%2==1:
    arfa = [1,0]*(n//2) + [1]
    beta = [0,1]*(n//2) + [0]
else:
    arfa = [1,0]*(n//2)
    beta = [0,1]*(n//2)

ansa=0;ansb=0
for i in range(n):
    if color[i]!=arfa[i]:
        ansa += 1
    if color[i]!=beta[i]:
        ansb += 1
print(min([ansa,ansb]))


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

int main() {
    int x1,x2,x3,x4,x5;
    
    cin >> x1 >> x2 >> x3 >> x4 >> x5;
    
    if(x1==0){
        cout << 1;
    }else if(x2==0){
        cout << 2;
        
    }else if(x3==0){
        cout << 3;
        
    }else if(x4==0){
        cout << 4;
    }else{
        cout << 5;
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int MOD = 1e8 + 7;
const int INF = 1001001001;
// const ll INF = 1000000000000000000LL;

int main() {
    int x;
    cin >> x;
    cout << 1-x << endl;
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;cin>>N;
    unordered_map<string,ll> info;
    rep(i,N){
        string S;cin>>S;
        sort(all(S));
        info[S]++;
    }
    ll ans=0;
    for(auto p:info)ans+=p.se*(p.se-1)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10660
#include <algorithm>
#include <cmath>
#include <iostream>
 
using namespace std;
 
long long a, b, n;
 
int main() {
  cin >> a >> b >> n;
  long long x = min(b - 1, n);
  cout << (a * x) / b - a * (x / b) << endl;
  return 0;
}

Measured memory_bytes: 3612
//2020.1.7
//s1270188 xxxmk2
//alds1_07d

#include<stdio.h>
#include<stdlib.h>

//prototype
void fix_post(int,int);

//global
int *pre, *in;

int main(){
  int i, num;

  //input
  scanf("%d",&num);
  pre=(int *)malloc(sizeof(int)*num);
  in=(int *)malloc(sizeof(int)*num);
  for(i=0;i<num;i++) scanf("%d",&pre[i]);
  for(i=0;i<num;i++) scanf("%d",&in[i]);

  //output
  fix_post(0,num);
  
  free(pre);
  free(in);
  return 0;
}

void fix_post(int l,int r){
  int c, m, i=0;
  static int cnt=0;
  
  if(l>=r) return;

  c=pre[cnt++];
  while(in[i]!=c) i++;
  m=i;
  
  fix_post(l,m);
  fix_post(m+1,r);

  if(c==pre[0]) printf("%d\n",c);
  else printf("%d ",c);
}



Measured memory_bytes: 2144
#include<cstdio>

using namespace std;

int w,h,l;
int al,ar,au,ad;
int x,y,a;
int s;

int main()
{
	scanf("%d %d %d",&w,&h,&l);
	al = 0;ar = w;
	au = h;ad = 0;
	for(int i = 1;i <= l;i++){
		scanf("%d %d %d",&x,&y,&a);
		if(a == 1){
			if(x > al){
				al = x;
			}
		}
		else if(a == 2) {
			if(x < ar){
				ar = x;
			}
		}
		else if(a == 3){
			if(y > ad){
				ad = y;
			}
		}
		else if(a == 4){
			if(y < au){
				au = y;
			}
		}
	}
	if((ar - al) <= 0 || au - ad <= 0)  s = 0;
	else s = (ar - al) * (au - ad);
	printf("%d\n",s);
	/*if((ar - al) > 0 && (au - ad >0))
	printf("%d\n",(ar - al) * (au - ad));
	else printf("0\n");*/
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int A[n];

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

    for(int i=0; i<n; i++)
    {
        if(i==n-1)
            cout<<A[i];
        else
            cout<<A[i]<<" ";
    }
    cout<<"\n";

    for(int i =1; i<n; i++)
    {
        int key;
        key = A[i];
        int j = i - 1;
        while( j >= 0 and A[j] > key)
        {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = key;

        for(int i=0; i<n; i++)
        {
            if(i==n-1)
                cout<<A[i];
            else
                cout<<A[i]<<" ";
        }
        cout<<"\n";
    }
}



Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	long long int ans = 0;
	long long int b;
	for (b = k + 1; b <= n; b++)
	{
		ans += n / b * (b - k);
		if (n % b >= k)
			ans += (n % b) - k + 1;
	}
	if (k == 0)
		ans -= n - k;
	printf("%lld\n", ans);
	return 0;
}

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

using namespace std;
using ll = long long;

int count_digits(ll n) {
  int cnt = 0;
  while (n > 0) {
    n /= 10;
    cnt++;
  }
  return cnt;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  cin >> N;
  ll p = sqrt(N);
  for (ll p = sqrt(N); p >= 0; p--) {
    if (N % p == 0) {
      cout << max(count_digits(p), count_digits(N / p)) << '\n';
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
def dfs(i, n):
    if i == len(s) - 1:
        return sum(list(map(int, n.split('+'))))
    return dfs(i+1, n + '+' + s[i+1]) + dfs(i+1, n + s[i+1])
s = input()
print(dfs(0, s[0]))

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

const int MOD=1000000007;
struct modint {
  long long val;
  modint(long long val=0) : val((val % MOD + MOD) % MOD){}
  modint operator-() const { return modint(-val); }
  modint& operator+=(const modint a) { if ((val += a.val)     >= MOD) val -= MOD; return *this; }
  modint& operator-=(const modint a) { if ((val += MOD-a.val) >= MOD) val -= MOD; return *this; }
  modint& operator*=(const modint a) { (val *= a.val) %= MOD; return *this; }
  modint operator+(const modint a) const { return (modint)*this += a; }
  modint operator-(const modint a) const { return (modint)*this -= a; }
  modint operator*(const modint a) const { return (modint)*this *= a; }
  modint pow(long long n) const { modint r(1), m(val); while (n > 0) { if (n & 1) {r *= m;} m *= m; n >>= 1; } return r; }
  modint inv() const { return pow(MOD-2); }
  modint& operator/=(const modint a) { return (*this) *= a.inv(); }
  modint operator/(const modint a) const { return (modint)*this /= a; }
  bool operator==(const modint &p) const { return val == p.val; }
  bool operator!=(const modint &p) const { return val != p.val; }
  friend ostream &operator<<(ostream &os, const modint &p) { return os << p.val; }
  friend istream &operator>>(istream &is, modint &a) { long long t; is >> t; a = modint(t); return (is); }
};

vector<bool> sieve_of_eratosthenes(int n) {
  /* O(n log log n) */
  vector<bool> is_prime(n+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i<=n; i++)
    if(is_prime[i])
      for(int k=i; k * i <= n; k++)
        is_prime[k*i] = false;
  return is_prime;
}

vector<int> prime_list(int n) {
  /* O(n log log n) */
  auto is_prime = sieve_of_eratosthenes(n);
  vector<int> primes;
  for(int i=0; i<=n; i++)
    if(is_prime[i])
      primes.push_back(i);
  return primes;
}

map<int, int> prime_factorization(int n) {
  /* O(n log log n) */
  auto primes = prime_list((int)ceil(sqrt(n)));
  map<int,int> factors;
  for(auto i : primes) {
    while (n%i==0) {
      factors[i]++;
      n /= i;
    }
  }
  if(n!=1) factors[n]++;
  return factors;
}

int N;
int A[10000];

signed main() {
  cin >> N;
  for(int i=0; i<N; i++) cin >> A[i];

  map<int ,int> primes;

  for(int i=0; i<N; i++) {
    for(auto m : prime_factorization(A[i])) {
      primes[m.first] = max(primes[m.first], m.second);
    }
  }

  modint L = 1;
  for(auto p : primes) {
    L *= modint(p.first).pow(p.second);
  }

  modint ans=0;
  for(int i=0; i<N; i++) {
    ans += L / modint(A[i]); 
  }
  cout << ans << endl;
}


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

class UnionFind {
  vector<int> v;
public:
  UnionFind(int n) : v(n, -1) {}

  int root(int n) {
    return v.at(n) < 0 ? n : v.at(n) = root(v.at(n));
  }

  bool same(int a, int b) {
    return root(a) == root(b);
  }

  int64_t size(int n) {
    return -1 * v.at(root(n));
  }

  int64_t unite(int a, int b) {
    if (same(a, b)) return 0;
    int64_t n = size(a) * size(b);
    if (size(a) < size(b)) swap(a, b);
    int ra = root(a);
    int rb = root(b);
    v.at(ra) += v.at(rb);
    v.at(rb) = ra;
    return n;
  }
};

int main()
{
  int64_t n, m;
  cin >> n >> m;

  UnionFind uf(n);
  vector<int> a(m), b(m);

  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
    a.at(i)--; b.at(i)--;
  }

  vector<int64_t> ans;
  int64_t x = n * (n - 1) / 2;

  for (int i = m - 1; i >= 0; i--) {
    ans.push_back(x);
    x -= uf.unite(a.at(i), b.at(i));
  }

  reverse(begin(ans), end(ans));

  for (const auto& e : ans) {
    cout << e << endl;
  }
}


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

int main(void){
int h,w;
int i,j,k;
int ans[2];

while(true){
cin>>h>>w;
if(h==0)return 0;
ans[0]=-1;
for(i=1;i<150;i++){
	for(j=1;j<150;j++){
		if(j<=i)continue;
		if((h*h+w*w)==(i*i+j*j)&&h<i&&!(h==i||h==j)){ans[0]=i;ans[1]=j;break;}
	}
	if(ans[0]!=-1)break;
}
int mintaikaku[3]={45000,150,150};
if(ans[0]==-1){
	for(i=1;i<150;i++){
		for(j=1;j<150;j++){
			if(j<=i)continue;
			if((i*i+j*j)>(h*h+w*w)&&mintaikaku[0]>i*i+j*j&&!(h==i&&w==j)){mintaikaku[0]=(i*i+j*j);mintaikaku[1]=i;mintaikaku[2]=j;}
		}
		if(ans[0]!=-1)break;
	}
}
if(ans[0]==-1)cout<<mintaikaku[1]<<" "<<mintaikaku[2]<<endl;
else cout<<ans[0]<<" "<<ans[1]<<endl;
}
return 0;
}



Measured memory_bytes: 3056
/**
  * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_C
  * Structured Program II - Spreadsheet
  */
object Main {
  def main(args: Array[String]): Unit = {
    val Array(r, c) = io.StdIn.readLine().split(" ").map(_.toInt)
    val initial = Iterator.continually(io.StdIn.readLine()).takeWhile(_ != null).take(r)
      .map(_.split(" ").map(_.toInt).toSeq)
      .toVector
    val columnComputed = initial.map(row => row :+ row.sum)
    val fullComputed = columnComputed :+ columnComputed.foldLeft(Seq.empty[Int]) {
      (acc, x) => acc.zipAll(x, 0, 0).map { case (a, b) => a + b }
    }
    fullComputed.foreach(row => println(row.mkString(" ")))
  }
}

Measured memory_bytes: 49364
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>

int main(){
  std::string s;
  std::cin >> s;
  int n = s.length();
  std::vector<int > num(n);
  for (int i=0; i<n; i++){
    num[i] = int(s[i])-int('0');
  }
  std::reverse(num.begin(), num.end());
  std::vector<int > a(n);
  int mod = 2019;
  int power = 1;
  for (int i=0; i<n; i++){
    a[i] = power * num[i];
    a[i] %= mod;
    power = power*10;
    power %= mod;
  }
  std::vector<int > sum(n+1);
  sum[0] = 0;
  for (int i=0; i<n; i++){
    sum[i+1] = sum[i]+a[i];
    sum[i+1]%=mod;
  }
  std::map<int, int> mp;
  for (int i=0; i<n+1; i++){
    mp[sum[i]]++;
  }
  long long ans = 0;
  for(auto &entry: mp){
    ans += (long long)entry.second*(entry.second-1)/2;
  }
  std::cout << ans << std::endl;
  return 0;
}

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

typedef long long int64;
#define REP(i,n) for(int64 i=0;i<(int64)(n);i++)
#define REPD(i,n) for(int64 i=(int64)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int64 i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int64)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define GSORT(x) sort(ALL(x), greater<int64>());
#define SUM(x) accumulate(ALL(A), 0);
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; }

using namespace std;

void Main()
{
	int64 N,M;
	cin >> N>>M;

	int64 len, area;
	len = 2 * (M + N);
	area = M * N;

	cout << area << " " << len << endl;
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  char mi = 'z';
  rep (i, n) {
    chmin(mi, s[i]);
  }
  DEBUG(mi);

  string t = s;
  reverse(all(t));
  t = s + t;

  int cnt = 0;
  rrep (i, n) {
    if (t[i] == mi) cnt++;
    else break;
  }
  int max_num = cnt;
  
  for (int i = n; i < 2*n; i++) {
    if (t[i] == mi) cnt++;
    else cnt = 0;
    chmax(max_num, cnt);
  }

  DEBUG(max_num);
  int x = max_num;
  rep (i, k - 1) {
    x *= 2;
    if (x >= n) {
      string ans(n, mi);
      cout << ans << endl;
      return 0;
    }
  }

  int nokori = n - x;
  DEBUG(x);
  DEBUG(nokori);
  cnt = 0;
  rrep (i, n) {
    if (t[i] == mi) cnt++;
    else break;
  }
  string suf(nokori, 'z');
  if (cnt == max_num) {
    string temp = t.substr(n - cnt - nokori, nokori);
    reverse(all(temp));
    chmin(suf, temp);
  }

  for (int i = n; i < 2*n; i++) {
    if (t[i] == mi) cnt++;
    else cnt = 0;
    if (cnt == max_num) {
      string temp = t.substr(i + 1 - cnt - nokori, nokori);
      reverse(all(temp));
      chmin(suf, temp);
    }
  }

  string ans(x, mi);
  ans += suf;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,mmin;
    scanf("%d%d%d",&a,&b,&c);
    mmin=(a+b)<(a+c)?(a+b):(a+c);
    mmin=mmin<(b+c)?mmin:(b+c);
    printf("%d\n",mmin);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main() {
	int a,b,c,sum,check = 0;
	scanf("%d %d",&a,&b);
	if(b < 10) c = 10;
	else if(b < 100) c = 100;
	else c = 1000;
	sum = a*c+ b;
	for(int i =1; i * i < 100100;i++) {
		if(sum == i*i) {
			check = 1;
			break;
		}
	}
	if(check == 1) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
#define F for
L E=70;W S(V<W>p){if(!E){return{1,0};}V<V<W>>T(2);F(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1){T[(x[1]+1)&1].push_back({x[0]/2,(x[1]+1)/2});}}F(L i;i<2;i++){L c=0;for(W x:T[!i]){L Q=(2*x[0]+x[1])%3;c^=Q+1;}if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p){v[0]++;}W A=S(p);A[0]--;return A;}int main(){L M=2e17,n,a,b;cin>>n;V<W>p(n);F(L i;i<n;i++){cin>>a>>b;p[i]={a+M,b+M};}W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  double a;
  double count=0.0000000;
  cin >> a;
  for(int i =1; i<=a; i++){
     if(i % 2 != 0){
      count += 1; 
     } 
  }
  cout << count / a << endl;  
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, temp;
	cin >> N;
	vector<int> orig,lev;
	
	REP(i, N)
	{
		cin >> temp;
		orig.push_back(temp);
		lev.push_back(temp);
	}

	sort(lev.begin(), lev.end());

	int C = 0;
	REP(i, N)
	{
		if (orig[i] != lev[i])C++;
	}

	if (C <= 2)
	{
		cout << "YES\n";
	}
	else
	{
		cout << "NO\n";
	}

	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  vector<int> b=a;
  sort(b.begin(),b.end());
  int x=b[n/2];
  int y=b[(n-1)/2];
  for(int i=0;i<n;i++){
    if(a[i]<x){
      cout<<x<<endl;
    }else{
      cout<<y<<endl;
    }
  }
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2*1e5+10;
const int MOD = 1e9 + 7;
const int INF = 1e18 + 10;


void printVector(vector<int> s){
    for(int &x:s){
        cout<<x<<" ";
    }
    cout<<endl;
}



void solve(){
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> h(n+1);
    for(int i = 1 ; i<= n ; i++) cin>>h[i];
    vector<int> dp(n+1 , INF);
    dp[1] = 0;
    for(int i = 2; i <= n ; i++){
        for(int j = 1; j<= k ; j++){
            if(i-j>=1){
                dp[i] = min(dp[i] , abs(h[i-j]-h[i])+dp[i-j]);
            }
        }
    }
//    printVector(dp);
    cout<<dp[n]<<endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
//    cin>>t;
    t = 1;
    for(int i = 0 ; i < t ; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4768
#include <stdio.h>
double max=0,min=10000,a;
int main(){
	while(scanf("%lf",&a)!=EOF){
		if(max<a){
			max=a;
		}
		if(min>a){
			min=a;
		}
	}
	printf("%f\n",max-min);
	return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;

    int pre = 10 * (s.substr(0, 2)[0] - '0') + (s.substr(0, 2)[1] - '0');
    int post = 10 * (s.substr(2)[0] - '0') + (s.substr(2)[1] - '0');

    bool pre_f = false;
    bool post_f = false;
    if(1 <= pre && pre <= 12) pre_f = true;
    if(1 <= post && post <= 12) post_f = true;

    if(pre_f){
        if(post_f) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(post_f) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }


}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

set<int> st;
int power5(int x) {
    int ret = 1;
    rep(i, 5) ret *= x;
    return ret;
}
map<int, int> mp;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, -6000, 6000) {
        st.insert(power5(i));
        mp[power5(i)] = i;
        //st.insert(-power5(i));
        //cout << power5(i) << endl;
    }
    int X; cin >> X;
    REP(j, -6000, 6000) {
        auto itr = st.find(power5(j) - X);
        if(itr != st.end()) {
            cout << j << " " <<  mp[*itr]  << endl;
            return 0;
        }
    }
    


    return 0;
}


Measured memory_bytes: 4928
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		List<Tuple<int,int>> dif = new List<Tuple<int,int>>();
        for(var i = 1; i <= 9; i++)
		{
			if (N <= i * 111)
			{
				dif.Add(new Tuple<int, int>(i * 111 - N, i * 111));
			}
		}
		dif.Sort((a, b) => (a.Item1 - b.Item1));
		Console.WriteLine(dif[0].Item2);
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N,0);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  cout << A.at(N-1) - A.at(0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAXH 20000
#define MAXN 1000
#define MAXA 10000
#define MAXB 10000
#define INF 1000000000000000000
typedef long long ll;

ll DP[MAXN+1][MAXH+1];
int N,H;
int A[MAXA],B[MAXB];

int main(){
    cin>>H>>N;
    int ma=0;
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i];
        ma=max(ma,A[i]);
    }
    for(int i=0;i<=N;i++){
        for(int j=0;j<H+ma;j++){
            DP[i][j]=0;
        }
    }
    for(int j=1;j<H+ma;j++){
        DP[0][j]=INF;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<H+ma;j++){
            if(j<A[i]) DP[i+1][j]=DP[i][j];
            else DP[i+1][j]=min(DP[i][j],DP[i+1][j-A[i]]+B[i]);
        }
    }
    ll ans=INF;
    for(int j=H;j<H+ma;j++){
        ans=min(ans,DP[N][j]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 155520
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
a.sort()
d = [[10 ** 6 for _ in range(N)] for _ in range(N)]
#print(a)

if N == 2:
  if a != [1, 1]:
    print("Impossible")
    exit(0)
else:
  if max(a) < 2:
    print("Impossible")
    exit(0)

mn = min(a)
mnl = []
for i in range(N):
  if a[i] == mn: mnl.append(i)
if len(mnl) > 2:
  print("Impossible")
  exit(0)
for i in range(len(mnl)):
  for j in range(len(mnl)): d[i][j] = 1

for x in range(min(a), max(a)):
  l = []
  r = []
  for i in range(N):
    if a[i] == x: l.append(i)
  for i in range(N):
    if a[i] == x + 1: r.append(i)
  if len(l) == 0:
    print("Impossible")
    exit(0)
  for i in range(len(r)):
    y = l[i % len(l)]
    z = r[i]
    d[y][z] = 1
    d[z][y] = 1

for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j] = min(d[i][k] + d[k][j], d[i][j])

#print(d)
for i in range(N):
  if a[i] != max(d[i]):
    print("Impossible")
    exit(0)
print("Possible")

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

int main() {
  int N;
  cin >> N;
  
  vector<long long> A(N);
  for(int i=0; i<N; i++)
    cin >> A.at(i);
  sort(A.begin(), A.end());
  
  bool er = false;
  
  long long ans = 1;
  for(int i=0; i<N ; i++){
    if(A.at(i) == 0){
      ans *= A.at(i);
      continue;
    }
    if(ans > 1000000000000000000 / A.at(i)){
      er = true;
      break;
    }
    ans *= A.at(i);
  }
  
  if(er == true)
    cout << -1 << endl;
  
  else
    cout << ans << endl;
    
}

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

int main(){
    string S;
    cin >> S;
    // 両端から見ていく
    int l=0;
    int r=S.size()-1;
    ll ans=0;
    while(r-l>0){
        if(S[l]==S[r]){
            l++;
            r--;
            continue;
        }
        if(S[l]=='x'){
            ans++;
            l++;
        }else if(S[r]=='x'){
            ans++;
            r--;
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> v(n + 1, 0);
  rep(i, 1, n + 1) cin >> v[i];

  int ans = 0;
  rep(i, 1, n + 1) {
    if (i == n && v[i] == i)
      ans++;
    else if (v[i] == i) {
      i++;
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.readLine();
            String t = in.readLine();
            int n = s.length();
            for (int i = 0; i < n; i++) {
                boolean valid = true;
                for (int j = 0; j < n; j++) {
                    if (s.charAt(j) != t.charAt((j + i) % n)) {
                        valid = false;
                        break;
                    }
                }
                if (valid) {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r')
                    buf.appendCodePoint(c);
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0)
                s = readLine0();
            return s;
        }

    }
}



Measured memory_bytes: 21588
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

const ll mod = 1000000007LL;

signed main() {
	string s, t; cin >> s >> t;
	cout << (t + s) << endl;
	return 0;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
list = list(map(int, input().split()))
check_x = x
while True:
    if check_x not in list:
        break
    check_x -= 1

check_x_high = x
while True:
    check_x_high += 1
    if check_x_high not in list:
        break

if check_x_high-x < x-check_x:
    print(check_x_high)
else:
    print(check_x)


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

int main() {
  string S; cin >> S;
  int len = S.length();

  if(S[len-1] == 's') cout << S << "es" << endl;
  else cout << S << "s" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define V vector
#define pb push_back
#define mkp make_pair
#define pi pair<int,int>//struct pi {int fi,se;};
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define ln length()
#define sz size()
const int N=100005;
///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    // int t;cin>>t;while(t--)
    {
        int i,j,k,n,m,ans=0,cnt=0,sum=0;
        string a,s;
        cin >> a >> s;
        rep(i,0,a.length()){
            if(a[i] != s[i]){
                ans++;
            }
        }
        cout << ans <<endl;
    }
}

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

const int maxn = 200;
string res[maxn];



string ask(vector<int>& vt) {
	cout << "? ";
	for(int i=0;i<vt.size();i++) cout << vt[i] + 1<<" ";
	
	cout << endl;
	fflush(stdout);
	string s;
	cin >> s;
	return s;
}

int main() {
	//freopen("inp.txt", "r", stdin);
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	int n = 0;
	cin >> n;
	string last = " ";
		vector<int> vt;
	for(int i=0;i<n*2;i++) res[i] = "";
	
	
	
	for(int i=0;i<n;i++) vt.push_back(i);
	
	
	string f = ask(vt);
	int l = 0;
	int r = n;
	int pos = r;
	while (l <= r) {
		int g = (l + r) >> 1;
		vt.clear();
		for(int i=g; i < g + n; i++) vt.push_back(i);
		string t = ask(vt);
		if (t == f) {
			l = g + 1;
		} else {
			pos = g;
			r = g - 1;
		}
	}
	
	int cnt = n / 2;
	int cnt1 = n / 2;
	
	int ll = pos;
	int rr = pos + n - 2;
	for(int i=0; i < 2 * n ; i++) {
		if (i >= ll && i <= rr) {
			continue;
		} else {
			vt.clear();
			for(int j = ll; j<= rr;j++) vt.push_back(j);
			vt.push_back(i);
			res[i] = ask(vt);
		}
	}
	
	vt.clear();
	for(int i=0;i<2*n;i++) {
		if (res[i] != "") {
			if (res[i][0] == 'R') {
				if (cnt1 > 0) {
					vt.push_back(i);
					cnt1--;
				}
			} else {
				if (cnt > 0) {
					vt.push_back(i);
					cnt--;
				}
			}
		}
	}
	
	for(int i=ll;i<=rr;i++) {
		vector<int> vt1 = vt;
		vt1.push_back(i);
		res[i] = ask(vt1);
	}
	
	cout << "! ";
	for(int i=0;i<n*2;i++) {
		cout << res[i][0];
	}
	fflush(stdout);
	return 0;
}


Measured memory_bytes: 724
import math

a,b,n = map(int,input().split())

c = 0
ans = 0
for i in range(1,10**7) :
    x = b*i-1
    if x > n :
        x = n
        c = 1
    ans = max(ans,math.floor((a*x)/b)-a*math.floor(x/b))
    if c == 1 :
        break

print(ans)


Measured memory_bytes: 64064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll N; cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  set<ll> Used;
  vector<bool> ans(1000001, true);
  for (auto i : A) {
    if (Used.find(i) != Used.end()) {
      ans[i] = false;
      continue;
    }
    for (ll j = 2 * i; j < 1000001; j += i) {
      ans[j] = false;
    }
    Used.insert(i);
  }

  ll cnt = 0;
  for (auto i : A) {
    if (ans[i]) cnt++;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 14216
#include<stdio.h>
int main(void){
int i,x[9999],y[9999];
for(i=0;i < 10000;i++){
scanf("%d%d",&x[i],&y[i]);
if(x[i] == 0 && y[i] == 0)return 0;
if(x[i] > y[i])printf("%d %d\n",y[i],x[i]);
else printf("%d %d\n",x[i],y[i]);
}
return 0;
}

Measured memory_bytes: 628
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int A = scan.nextInt();
		int B = scan.nextInt();

		System.out.println(Math.max(A+B, Math.max(A-B, A*B)));

		scan.close();

	}

}


Measured memory_bytes: 27076
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	v := make([]int, 3)
	v[0] = readInt()
	v[1] = readInt()
	v[2] = readInt()
	sort.Ints(v)
	k := readInt()

	for i := 0; i < k; i++ {
		v[2] *= 2
	}
	println(v[0] + v[1] + v[2])

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let (a, b, c, d): (isize, isize, isize, isize) =
        (sc.input(), sc.input(), sc.input(), sc.input());
    println!("{}",
             if a + b == c + d {
                 "Balanced"
             } else if a + b > c + d {
                 "Left"
             } else {
                 "Right"
             });
}


Measured memory_bytes: 4352
// Example program
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    if(n / 10 == 9 or n % 10 == 9){
        cout << "Yes" << endl;   
    }    
    else{
        cout << "No" << endl;   
    }    

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	double a,b, c, d, e, f, x,y;
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF)
	{
		y=(a*f-c*d)/(a*e-d*b);
		x=(c-b*y)/a;
		printf("%.3f %.3f\n",x,y);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    REP(i, 3){
        if (S[i] == T[i]) ans += 1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,f=0,a,b;
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d",&a,&b);
    if(a==0)printf("%d\n",(f+b-1)%n+1);
    else    f=(f+b)%n;
  }
  return 0;
}
      



Measured memory_bytes: 2748
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
 
#include <stdio.h>
 
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, k, n) for (int i = (k); i < (n); i++)
#define rrep(i, k, n) for (int i = (k); i >= (n); i++)
#define pb push_back
#define vec vector
#define ref(a) &(a)
 
typedef long long ll;
 
using namespace std;

int n, u, v;
vec<vec<int>> s;
vec<int> m;

void dfs(int c, int d, int b) {
  m[c] = d;
  for (auto u : s[c]) {
    if (u == b) continue;
    dfs(u, d + 1, c);
  }
}

vec<int> dist(int p) {
  vec<int> d(n);
  m = d;
  dfs(p, 0, -1);
  return m;
}

int solve() {
  vec<int> t = dist(u);
  vec<int> a = dist(v);
  int sum = 0;
  int res = 0;
  rep(i, n) {
    if (t[i] < a[i]) {
      sum = max(sum, a[i]);
    }
  }

  res = sum - 1;
  return res;
}

int main() {
  scanf("%d %d %d", &n, &u, &v);
  u--; v--;
  s = vec<vec<int>>(n);
  rep(i, n - 1) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    s[a].pb(b);
    s[b].pb(a);
  }

  printf("%d\n", solve());
  return 0;
}


Measured memory_bytes: 11128
import java.io.*;

public class Main {

  static int n, m;
  
  public static void main(String[] args) throws Exception {
    
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    m = Integer.parseInt(in[1]);

    br.close();

    if(m % 2 == 1){
      for(int x = 1; x <= m/2; x++){
        System.out.println(x + " " + (m + 1 - x));
      }
      for(int x = m + 1; x <= m + 1 + m / 2; x++){
        System.out.println(x + " " + (3 * m + 2 - x));
      }
    }else{
      for(int x = 1; x <= m/2; x++){
        System.out.println(x + " " + (m + 2 - x));
      }
      for(int x = m + 2; x <= m + 1 + m / 2; x++){
        System.out.println(x + " " + (3 * m + 3 - x));
      }
    }
    
  }

}

Measured memory_bytes: 52416
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N,K = map(int, input().split())

ans = 0
for b in range(K+1,N+1):
    q = N//b
    r = N%b
    ans += q*(b-K) + max(r-K+1,0)

if K==0:
    ans -= N-K
    
print(ans)

Measured memory_bytes: 12064
# -*- coding: utf-8 -*-

NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]

edges = [None] * M

for i in range(M):
    ab = list(map(int, input().split()))
    edges[i] = (ab[0], ab[1])

passed = [1]
queue = [1]
def search(edges, s):
    queue.pop(0)
    for i in range(M - 1):
        # print((passed, queue))
        if (len(passed) == N):
            break
        if (edges[i][0] == s and not edges[i][1] in passed):
            passed.append(edges[i][1])
            queue.append(edges[i][1])
        if (edges[i][1] == s and not edges[i][0] in passed):
            passed.append(edges[i][0])
            queue.append(edges[i][0])
    if(len(passed) != N and queue != []):
        search(edges, queue[0])

edges_save = edges[:]

counter = 0
for i in range(M):
    passed = [1]
    queue = [1]
    edges = edges_save[:]
    edges.pop(i)
    search(edges, 1)
    if(len(passed) != N):
        counter += 1

print(counter)

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

int main() {
    int n,ans=0;cin>>n;

    rep(i,n){
        int a;cin>>a;
        while(a%2==0){
            a/=2;
            ans++;
        }
    }

    cout<<ans<<endl;
}



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

int main(){
	int n, m, c[20];
	//input
	scanf(" %d %d", &n, &m);
	for(int i=0; i<m; ++i) scanf(" %d", &c[i]);	
	
	//solve
	
	//dp[i]:=i?????????????????????????????????????????????????°??????°
	int dp[50001] = {0};
	//???????????§????????°??§?????????
	for(int i=1; i<=50000; ++i) dp[i] = 100000;
	
	for(int i=0; i<=50000; ++i){
		for(int j=0; j<m; ++j){
			if(i+c[j]<=n){
				dp[i+c[j]] = min(dp[i+c[j]],dp[i]+1);	
			}
		}	
	}
	
	printf("%d\n", dp[n]);
}

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

using namespace std;

const int N = 123456;
int n, f[N][2], g[N][2], cnt[N];
map<int, int> ind;
vector<int> e[N];

void dfs(int u, int p, int& res, int& pos) {
  f[u][0] = f[u][1] = 1;
  g[u][0] = g[u][1] = 0;
  for (int i = 0; i < e[u].size(); ++i) {
    int v = e[u][i];
    if (v == p) continue;
    dfs(v, u, res, pos);
    if (f[u][0] < f[v][0] + 1) {
      f[u][1] = f[u][0];
      g[u][1] = g[u][0];
      f[u][0] = f[v][0] + 1;
      g[u][0] = v;
    } else if (f[u][1] < f[v][0] + 1) {
      f[u][1] = f[v][0] + 1;
      g[u][1] = v;
    }
  }
  if (res < f[u][0] + f[u][1]) {
    res = f[u][0] + f[u][1] - 1;
    pos = u;
  }
}

vector<int> sol(int m, int a[]) {
  vector<int> r;
  int beg = 1;
  for (int i = 0; i < m; ++i) {
    int end = beg + a[i] - 1;
    
    for (int j = beg + 1; j <= end; ++j) r.push_back(j);
    r.push_back(beg);

    beg = end + 1;
  }
  return r;
}

int cmp(vector<int>& a, vector<int>& b) {
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] != b[i]) return a[i] - b[i];
  }
  return 0;
}

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

  int res = 0, pos;
  dfs(1, 0, res, pos);

//  cout << res << "," << pos << endl;

  deque<int> path;
  for (int i = pos; i; i = g[i][0]) path.push_back(i);
  for (int i = g[pos][1]; i; i = g[i][0]) path.push_front(i);

//  for (int i = 0; i < path.size(); ++i) cout << path[i] << endl;
  for (int i = 0; i < path.size(); ++i) ind[path[i]] = i;
  memset(cnt, 0x00, sizeof(cnt));
  for (int i = 1; i <= n; ++i) {
    if (ind.count(i)) cnt[ind[i]]++;
    else {
      bool found = false;
      for (int j = 0; j < e[i].size(); ++j) {
        int v = e[i][j];
        if (ind.count(v)) {
          cnt[ind[v]]++;
          found = true;
          break;
        }
      }
      if (!found) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  
  //for (int i = 0; i < path.size(); ++i) cout << cnt[i] << endl; 

  vector<int> r0 = sol(path.size(), cnt);

  reverse(cnt, cnt + path.size());
  vector<int> r1 = sol(path.size(), cnt);

  if (cmp(r0, r1) <= 0) {
    for (int i = 0; i < r0.size(); ++i) cout << r0[i] << (i == r0.size() - 1 ? "\n" : " ");
  } else {
    for (int i = 0; i < r1.size(); ++i) cout << r1[i] << (i == r0.size() - 1 ? "\n" : " ");
  }

  return 0;

}

Measured memory_bytes: 19580
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

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

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 100050;
int col[N], cnt[40], fl, m, n;

int h[N], ne[N<<1], w[N<<1], to[N<<1], tot;
inline void add(int x, int y, int z) {
	ne[++tot] = h[x], to[h[x] = tot] = y, w[tot] = z;
}

void dfs(int x) {
	cnt[col[x]]++;
	for (int i = h[x]; i; i = ne[i]) {
		int y = to[i], tc = (col[x] + w[i]) % 3 + 1;
		if (w[i] == 1) cnt[0]++;
		if (!col[y]) col[y] = tc, dfs(y);
		col[y] != tc && (fl = 1);
	}
}

int main() {
	read(n), read(m);
	for (int i = 1;i <= m; i++) {
		int x, y; read(x), read(y);
		add(x, y, 0), add(y, x, 1);
	}
	
	ll ans = 0;
	for (int i = 1;i <= n; i++)
		if (!col[i]) {
			cnt[0] = cnt[1] = cnt[2] = cnt[3] = fl = 0;
			col[i] = 1, dfs(i);
			if (fl) {
				cnt[0] = cnt[1] + cnt[2] + cnt[3];
				ans += (ll)cnt[0] * cnt[0];
			}
			else if (!cnt[2] || !cnt[3]) ans += cnt[0];
			else ans += (ll)cnt[1] * cnt[2] + (ll)cnt[2] * cnt[3] + (ll)cnt[3] * cnt[1];
		}
		
	printf ("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int a, b;
	cin >> a >> b;
	int ans = max(a, b);
	if (a == b)
		cout << a + b << endl;
	else
		cout << ans + ans - 1 << endl;
}

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

	solve();
}


Measured memory_bytes: 256