akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

double dis(pair<int,int> x, pair<int,int> y) {
	return sqrt((double)((x.F - y.F) * (x.F - y.F) + (x.S - y.S) * (x.S - y.S)));
}

bool solve() {
	int a,b,c; cin >> a >> b >> c;
	if (a <= c && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

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


int main() {
	string s;
	string t;
	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());

	if (s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s.at(i) != s.at(n - 1 - i)) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	if (!('a' <= s[1] && s[1] <= 'z')) {
		cout << "WA" << endl;
		return 0;
	}
	bool flag = false;
	for (int i = 2; i < s.size() - 1; i++) {
		if (s[i] == 'C'&&flag) {
			cout << "WA" << endl;
			return 0;
		}
		if (s[i] == 'C' && !(flag)) {
			flag = true;
			continue;
		}
		if (!('a' <= s[i] && s[i] <= 'z')) {
			cout << "WA" << endl;
			return 0;
		}
	}
	if (flag == false) {
		cout << "WA" << endl;
		return 0;
	}
	if (!('a' <= s[s.size()-1] && s[s.size()-1] <= 'z')) {
		cout << "WA" << endl;
		return 0;
	}
	cout << "AC" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,ans,c[100005],a[100005],an;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%d",a+i);
    for(int i=0;i<n;i+=2){
        c[a[i]]++;
    }
    int m=0,x=0;
    for(int i=1;i<=100000;i++){
        if(m<c[i]){
            m=c[i];
            x=i;
        }
        c[i]=0;
    }
    ans+=(n/2-m);
    for(int i=1;i<n;i+=2){
        c[a[i]]++;
    }
    m=0;
    for(int i=1;i<=100000;i++){
        if(x!=i)m=max(m,c[i]);
        c[i]=0;
    }
    ans+=(n/2-m);
    for(int i=1;i<n;i+=2){
        c[a[i]]++;
    }
    m=0;
    x=0;
    for(int i=1;i<=100000;i++){
        if(m<c[i]){
            m=c[i];
            x=i;
        }
        c[i]=0;
    }
    an+=(n/2-m);
    for(int i=0;i<n;i+=2){
        c[a[i]]++;
    }
    m=0;
    for(int i=1;i<=100000;i++){
        if(x!=i)m=max(m,c[i]);
        c[i]=0;
    }
    an+=(n/2-m);
    printf("%d\n",min(ans,an));
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    cout << (k * 500 >= x ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i

ans = 0

a=0
while a <= A
  b = 0
  while b <= B
    c = 0
    while c <= C
      if (a*500 + b*100 + c*50 == X)
        ans += 1
      end
      c += 1
    end
    b += 1
  end
  a += 1
end

puts ans


Measured memory_bytes: 1916
h,w = map(int, input().split())
s = eval('list(input()),' *h)
for i in range(h):
    for j in range(w):
        c = 0
        for a in range(i-1,i+2):
            for b in range(j-1,j+2):
                c += all((min(a,b)>=0, a<h, b<w)) and s[a][b] == '#'
                
        if s[i][j] == '.':
            s[i][j] = c
for c in s:
    print(*c,sep='')

Measured memory_bytes: 3572
# include <bits/stdc++.h>
# define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
typedef long long ll;
ll read(){
	ll x=0;char c=getchar();
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return x;
}
const int maxn = 1e5+10;
int n,k;
int a[maxn];
int cnt[maxn];
int dep[maxn];
int q[maxn];
int ans = 0;
int main(){
	n=read(),k=read();
	rep(i,1,n)a[i]=read(),cnt[a[i]]++;
	if(a[1]!=1){--cnt[a[1]];a[1]=1;ans++;}
	int l=0,r=0; 
	rep(i,1,n) if(!cnt[i])q[r++]=i;
	while (l<r){
		int h=q[l++]; if (h==1)break;
		if (a[h]!=1&&dep[h]==k-1)++ans;
		else dep[a[h]]=max(dep[a[h]],dep[h]+1);
		--cnt[a[h]]; if (!cnt[a[h]])q[r++]=a[h];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }



int main() {
  ll N;
  scanf("%lld", &N);
  ll a[N],b[N];
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &a[i]);
    b[i] = a[i];
  }

  ll sum = 0;
  ll act = 0;
  FOR(i,0,N-1){
    sum += a[i];
    if(i%2==0){
      if(sum<=0){
        act += -(sum)+1;
        sum = 1;
      }
    }
    else{
      if(sum>=0){
        act += sum + 1;
        sum = -1;
      }
    }
  }

  sum = 0;
  ll act2 = 0;
  FOR(i,0,N-1){
    sum += a[i];
    if(i%2==0){
      if(sum>=0){
        act2 += sum + 1;
        sum = -1;
      }
    }
    else{
      if(sum<=0){
        act2 += -(sum)+1;
        sum = 1;
      }
    }
  }

  chmin(act,act2);

  cout << act << endl;

}



Measured memory_bytes: 1792
// AOJ ALDS1_11_D Connected Components
// 2018.5.2 bal4u

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

#define MAX 100005

/* UNION-FIND library */
int id[MAX], size[MAX];
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q)
{
    int i = root(p), j = root(q); if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int main()
{
	int n, m, q, s, t;

	n = in(), m = in();
	init(n);
	while (m--) {
		s = in(), t = in();
		unite(s, t);
	}
	
	q = in();
	while (q--) {
		s = in(), t = in();
		puts(connected(s, t)? "yes": "no");
	}
	return 0;
}


Measured memory_bytes: 2392
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int a,b,c,d,r=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    a+=b;c+=d;
    //for(i=1;i<=n;i++){scanf("%d",&a[i]);}
    if(a>c){printf("Left\n");}
    if(a==c){printf("Balanced\n");}
    if(a<c){printf("Right\n");}
    return 0;
}

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

static const int N = 100;

int main(){
    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i - 1] >> p[i];
    }
    
    for(int i = 1; i <= n; i++) m[i][i] = 0;
    for(int l = 2; l <= n; l++){
        for(int i = 1; i <= n - l + 1; i++){
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for(int k = i; k <= j - 1; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        } 
    }
    cout << m[1][n] << endl;
    
    return 0;
}


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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

int main(){
  int N;
  cin>>N;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i);
  }

  int64_t ans=A.at(0);
  for(int i=0;i<N;++i){
    ans=gcd(ans,A.at(i));
  }

  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = ll(b)-1; i >= (a); i--)
#define MAPIT(i,c,k) for (auto i = (c).equal_range((k)).first; i!= (c).equal_range((k)).second; i++)

#define sz(c) ll((c).size())
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define xx first
#define yy second
#define has(c, i) ((c).find(i) != (c).end())
#define DBG(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);

	string c[3], B, C;
	cin >> c[0] >> c[1] >> c[2];

	int n[3];
	n[0] = n[1] = n[2] = 0;

	int act = 0;
	while(1){
		if(n[act] >= sz(c[act])){
		   cout << char(act+'A') << endl;
		   break;
		}
		char ne = c[act][n[act]];
		n[act]++;
		act = ne-'a';
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;

tuple<ll, ll> calc(ll const& X) {
  for(auto A=1ll; ; ++A) {
    auto const T = X - A*A*A*A*A;
    if(T == 0) return { A, 0 };
    auto const sign = T > 0 ? 1ll : -1ll;
    auto const U = T * sign;
    for(auto B=1ll, B5 = B*B*B*B*B; B5 <= U; ++B, B5=B*B*B*B*B) {
      if(B5 == U) return { A, -1 * sign * B };
    }
  }
}

int main() {
  ll X;
  cin >> X;
  
  auto const [A, B] = calc(X);

  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main (){
    char a[50],b[50];
    while(cin >> a >> b){
            int c,d,f;
            c=strlen(a);
            d=strlen(b);
            f=max(c,d);
            int i=0;
            while(a[i]!='\0'&&b[i]!='\0'){
                printf("%c%c",a[i],b[i]);
                i++;
            }
            int j;
            for(j=i;j<f;j++){
            if(c>d)
            printf("%c",a[j]);
            else
            printf("%c",b[j]);

            }

    }
    printf("\n");
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
map<ll,bool>mp;
void solve(){
	ll n;
	cin>>n;
	if(n==2){cout<<1;return;}
	ll ans=2;
	for(ll i=2;i<=sqrt(n);i++){
		ll nn=n;
		while(nn%i==0)nn/=i;
		nn%=i;
		if(nn==1){
            ans++;
            // cout<<i<<endl;
        }
		mp[i]=1;
		nn=n;
		ll j=n/i;
		if(mp[j])continue;
		while(nn%j==0)nn/=j;
		nn%=j;
		if(nn==1){
            // cout<<j<<endl;
            ans++;
        }
		mp[j]=1;
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 128584
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

int main(){
	int n;cin>>n;
	string s;cin>>s;
	char moji;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		if(i==0)moji=s[i],ans=1;
		else if(moji!=s[i])moji=s[i],ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

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

#ifndef ONLINE_JUDGE
    #define gc getchar
    #define pc putchar
#else
    #define gc getchar_unlocked
    #define pc putchar_unlocked
#endif

using namespace std;

#define vi vector<int>
#define si set<int>
#define vs vector<string>
#define pii pair<int,int>
#define vpi vector<pii>
#define pri priority_queue<int>
#define rev_pri priority_queue<int,vector<int>,greater<int> >
#define mpi map<int,int>
#define i64 long long int
#define endl '\n'
#define pi acos(-1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf INT_MAX/2
#define infll LLONG_MAX/3
#define For(i,n) for(int i=0;i<n;i++)
#define Fre(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define eps 1e-8
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define READ freopen("in.txt", "r", stdin)
#define WRITE freopen("out.txt", "w", stdout)
#define sz size()
#define dbg(i) printf("yo %d\n", i)
#define foreach(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define sqr(a) (a) * (a)
#define clr clear()
#define CASE(a) printf("Case %d: ",a)

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


//i64 gcd(i64 a,i64 b){if(!b)return a;return gcd(b,a%b);}

//inline void fastRead(int *a){register char c=0;while(c<33)c=gc();*a=0;while(c>33){*a=*a*10+c-'0';c=gc();}}

//inline void fastWrite(int a){char snum[20];int i=0;do{snum[i++]=a%10+48;a=a/10;}while(a!=0);i=i-1;while(i>=0)pc(snum[i--]);pc('\n');}

//i64 bigmod(i64 num,i64 n){if(n==0)return 1;i64 x=bigmod(num,n/2);x=x*x%mod;if(n%2==1)x=x*num%mod;return x;}

//i64 modinverse(i64 num){return bigmod(num,mod-2)%mod;}

//i64 po(i64 a,i64 b){i64 ans=1;while(b--)ans *= a;return ans;}

//i64 ncr(i64 n,i64 r){if(n==r)return 1;if(r==1)return n;if(dp[n][r]!=-1)return dp[n][r];return dp[n][r]=ncr(n-1,r)+ncr(n-1,r-1);}


// bit manipulations

//bool checkbit(int mask,int bit){return mask & (1<<bit);}

//int setbit(int mask,int bit){ return mask  (1<<bit) ; }

//int clearbit(int mask,int bit){return mask & ~(1<<bit);}

//int togglebit(int mask,int bit){return mask ^ (1<<bit);}



int main()
{

        vi v;
        int n,x,inp;
        sff(n,x);

        while(n--)
        {
                sf(inp);
                v.pb(inp);
        }

        int ans = 0;

        sort(all(v));

        For(i,v.sz)
        {
                if(v[i]>x)
                        break;
                ans++;
                x -= v[i];
        }

        if(x && ans==v.sz)
                ans--;

        cout << ans << endl;
//        cout << x << endl;













        return 0;
}




Measured memory_bytes: 256
N = int(input())
s = [0]*(N+1)
for i in range(N):
    tmp = sorted(list(input()))
    s[i] = ''.join(tmp)
s[-1] = 'zzzzzzzzzzz'
s.sort()

ans = 0
i = 0
while i < N:
    k = 1
    while s[i] == s[i+k]:
        k += 1
    ans += (k-1)*k/2
    i += k
        
print(int(ans))

Measured memory_bytes: 10572
#include<iostream>
using namespace std;
int main(){
    int N,n;
    cin >> N;
    n = N % 10;
    if(n == 2||n == 4||n == 5||n == 7||n == 9){
        cout << "hon";
    }
    else if(n==0||n==1||n==6||n==8){
        cout << "pon";
    }
    else{
        cout << "bon";
    }
    return 0;
}


Measured memory_bytes: 3524
let n=read_int()open Array
let a=init n(fun _->Scanf.scanf"%d "(fun e->e))and b=make n 0and c=make 10001 0;;iter(fun e->c.(e)<-c.(e)+1)a;iteri(fun i _->if i<>0then c.(i)<-c.(i)+c.(i-1))c;for i=n-1downto 0do c.(a.(i))<-c.(a.(i))-1;b.(c.(a.(i)))<-a.(i);done;print_int b.(0);for i=1to n-1do print_string" ";print_int b.(i);done;print_newline()

Measured memory_bytes: 36204
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 305

using namespace std;
typedef long long int ll;

ll A[SIZE][SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++) scanf("%lld",&A[i][j]);
	}
	ll ret=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			bool up=false;
			for(int k=0;k<n;k++)
			{
				if(k==i||k==j) continue;
				if(A[i][j]>A[i][k]+A[k][j])
				{
					puts("-1");
					return 0;
				}
				if(A[i][j]==A[i][k]+A[k][j]) up=true;
			}
			if(!up) ret+=A[i][j];
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 896
#include "iostream"
#include <array>

const uint32_t COIN_NUM = 3;

const std::array<const uint32_t, COIN_NUM> COIN_COST = {
    500, 100, 50
};

void recursiveExec(const std::array<uint32_t, COIN_NUM>& coinNumList, int32_t money, uint32_t coinIndex, uint32_t* patternNum)
{

    const uint32_t coinMaxNum = coinNumList[coinIndex];

    for (uint32_t num = 0; num <= coinMaxNum; num++) {
        int32_t remainMoney = money - num * COIN_COST[coinIndex];

        if (remainMoney == 0) {
            *patternNum += 1;
            continue;
        }

        else if (remainMoney < 0) {
            continue;
        }

        else if (coinIndex + 1 >= COIN_NUM) {
            continue;
        }

        recursiveExec(coinNumList, remainMoney, coinIndex + 1, patternNum);
    }

    return;
}

int main()
{
    std::array<uint32_t, COIN_NUM> coinNumList;
    for (auto& coinNum : coinNumList) {
        std::cin >> coinNum;
    }

    int32_t money;
    std::cin >> money;


    uint32_t counter = 0;
    recursiveExec(coinNumList, money, 0, &counter);

    std::cout << counter << std::endl;

    return 0;
}



Measured memory_bytes: 256
/*
.....   .   .   .   .
  .    . .   . .   . .
  .   .....   .   .....
  .  .     .  .  .     .
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>
#include <sstream>
 
using namespace std;

#define int long long
#define double long double
#define time time228
#define left left228
#define right right228

template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}

template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}

const int maxn = 200 * 1000 + 228, MOD = 1e9 + 7;

int n;
int a[maxn], dp[maxn];
vector<int> g[maxn], rr[maxn];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int mx = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        uax(mx, a[i]);
        g[a[i]].push_back(i);
    }
    for (int c = 1; c <= mx; ++c) {
        for (int i = 0; i < (int)g[c].size() - 1; ++i) {
            if (g[c][i] + 1 < g[c][i + 1]) {
                int l = g[c][i], r = g[c][i + 1];
                rr[r].push_back(l);
            }
        }
    }
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        dp[i] = dp[i - 1];
        for (int l : rr[i]) {
            dp[i] += dp[l];
            dp[i] %= MOD;
        }
    }
    cout << dp[n] << '\n';
    return 0;
}

Measured memory_bytes: 20992
unittest
{
	assert( [ "10 13" ].parse.expand.solve == 3 );			// 追加ケース
	assert( [ "10 8" ].parse.expand.solve == 4 );			// 追加ケース
	assert( [ "10 -13" ].parse.expand.solve == 4 );			// 追加ケース
	assert( [ "10 -8" ].parse.expand.solve == 3 );			// 追加ケース
	assert( [ "-10 13" ].parse.expand.solve == 4 );			// 追加ケース
	assert( [ "-10 8" ].parse.expand.solve == 3 );			// 追加ケース
	assert( [ "-10 -13" ].parse.expand.solve == 5 );		// 追加ケース
	assert( [ "-10 -8" ].parse.expand.solve == 2 );			// 追加ケース
	
	assert( [ "10 20" ].parse.expand.solve == 10 );
	assert( [ "10 -10" ].parse.expand.solve == 1 );
	assert( [ "-10 -20" ].parse.expand.solve == 12 );
}



import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto xy = input.front.split.to!( long[] );
	return tuple( xy[ 0 ], xy[ 1 ] );
}

auto solve( long x, long y )
{
	auto ans = 0L;
	if( ( 0 <= x && 0 <= y ) || ( x < 0 && y < 0 ) )
	{
		// 両方が＋か、両方が－のとき
		if( y < x ) x = -x, ans++;		// Bボタン押す
	}
	else
	{
		// 片方が＋で、もう片方が－のとき
		if( -x < y ) x = -x, ans++;		// Bボタン押す
	}
	while( x.abs != y.abs ) x++, ans++;		// Aボタン押す
	ans += ( y != x );						// Bボタン押す
	return ans;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
 
  public static void main(String args[])
  {
   
    Scanner sc = new Scanner(System.in);
    
    int l = sc.nextInt();
    int r = sc.nextInt();
    
    int d = sc.nextInt();
    
    int rem = l%d;
    
    if(rem!=0)
    l = l+ d - rem;
    
    int re = r%d;
    r = r - re ;
    
    int ans = (r - l)/d+1;
   
    
    System.out.println(ans);
    
  }
  
  
  
}

Measured memory_bytes: 35656
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int n,a;//,b,c;
      //string s;
      //cin >> a >> b >> c;
      cin >> n >> a;
      if(n%500<=a)cout << "Yes" << endl;
      //else cout << (a+b)/2 << endl;
      else cout << "No" << endl;
      //cout << 2018 << s.substr(4,6) << endl;
      return 0;
    }

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  SCIN(a,b);
  if (a.size() < b.size()) {
    cout << "LESS" << endl;
    return 0;
  } else if (a.size() > b.size()) {
    cout << "GREATER" << endl;
    return 0;
  }
  if (a == b) {
    cout << "EQUAL" << endl;
  } else if (a < b){
    cout << "LESS" << endl;
    
  } else {
    cout << "GREATER" << endl;
  }

  return 0;
}



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

int main(){

  int N, L;
  cin >> N >> L;
  int min_d = INF;
  int min_i;
  int tot_t = 0;
  for(int i=1; i < N+1; i++){
    if(abs(L+i-1) < min_d){
      min_i = i;
      min_d = abs(L+i-1);
    }
    tot_t += L+i-1;
  }

  cout << tot_t - (L+min_i-1) << endl;
}


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<P> coor;
  vector<int> a;
  rep(i, n) {
    int x, y, z;
    cin >> x >> y;
    coor.emplace_back(x, y);
    cin >> z;
    a.push_back(z);
  }
  
  // 始点と終点の座標を狭めていく
  P start = make_pair(0, 0), end = make_pair(w, h);
  rep(i, n) {
    if (a[i] == 1) start.first = max(start.first, coor[i].first);
    else if (a[i] == 2) end.first = min(end.first, coor[i].first);
    else if (a[i] == 3) start.second = max(start.second, coor[i].second);
    else end.second = min(end.second, coor[i].second);
  }
  
  // 始点と終点の間の面積が答え
  int ww, wh;
  ww = end.first - start.first;
  wh = end.second - start.second;
  if (end.first <= start.first) ww = 0;  // 白い部分が残っていない
  if (end.second <= start.second) wh = 0;  // 同上
  
  cout << ww * wh << endl;
}

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

int  main()
{
	int h,w;
	cin >> h >> w;
	string s[h];
	rep(i, h)
	{
		cin >> s[i];
	}
	string ans = "Yes";
	rep(i, h)
	{
		rep(j, w)
		{
			if (s[i][j] == '#')
			{
				if (s[i][j + 1] != '#' && s[i][j-1] != '#' && s[i-1][j] != '#' && s[i+1][j] != '#')
				{
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << ans << endl;	
	return (0);
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i64> = readnc();

    let mut left = BinaryHeap::new();
    let mut sum: i64 = 0;
    for i in 0..n {
        sum += a[i];
        left.push(-a[i]);
    }
    let mut ll: Vec<i64> = vec![];
    ll.push(sum);
    for i in n..(2*n) {
        sum += a[i];
        left.push(-a[i]);
        let x = left.pop().unwrap();
        sum -= -x;
        ll.push(sum);
    }


    let mut sum: i64 = 0;
    let mut right = BinaryHeap::new();
    for i in ((2*n)..(3*n)).rev() {
        sum += a[i];
        right.push(a[i]);
    }
    let mut rr: Vec<i64> = vec![];
    rr.push(sum);
    for i in (n..(2*n)).rev() {
        sum += a[i];
        right.push(a[i]);
        let x = right.pop().unwrap();
        sum -= x;
        rr.push(sum);
    }

    let mut best = i64::min_value();
    for i in 0..(n+1) {
        best = max(best, ll[i] - rr[n-i]);
    }
    println!("{}", best);
}

Measured memory_bytes: 14196
from collections import defaultdict

#[[素因数,数]]を出力
def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

#n以下の素数列挙(O(n log(n))
def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

  
n=int(input())
dd = defaultdict(int)
mod=10**9+7

for i in range(1,n+1):
	for item in fctr1(i):
	    dd[item[0]] += item[1]

res=1

for item in dd.values():
  res=(res*(item+1))%mod
print(res)

Measured memory_bytes: 3436
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rrep(i, n) for(ll i = n - 1; i > -1; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define fi first
#define se second
#define debug(V) rep(i, V.size()) cout << V[i] << " ";
const ll INF = (1LL << 61) - 1;
const ll MOD = 1000000007 /*988244353*/;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v;
string S, T;
vl A, B;
void solve() {
    if(abs(a - b) > t * (v - w))
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
}
int main() {
    // cout<<fixed<<setprecision(15);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> v >> b >> w >> t;
    solve();
}

Measured memory_bytes: 3652
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let arr: Vec<i64> = (0..n).map(|_| read()).collect();
    let sum: i64 = arr.iter().sum();

    let mut mini = sum;
    let mut prefix_sum = 0i64;
    for i in 0..n {
        prefix_sum += arr[i];
        mini = min(mini, (prefix_sum - (sum - prefix_sum)).abs());
    }
    println!("{}", mini);
}


Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5+5;
vector<int> adj[N];
bool visited[N];
int cnt = 0;
void dfs(int cur_node)
{
	visited[cur_node] = true;
	++cnt;
	for(int i = 0; i < (int)adj[cur_node].size();++i){
		int next_node = adj[cur_node][i];
		if(!visited[next_node])
			dfs(next_node);
	}
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);	
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m;++i){
		int u,v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	memset(visited,false,sizeof(visited));
	int ans = 0;
	for(int i = 1; i <= n;++i){
		if(!visited[i]){
			cnt = 0;
			dfs(i);
			ans = max(ans,cnt);
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 20932
# 入力
N, M, Q = map(int, input().split())
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
    a[i] -= 1
    b[i] -= 1

# スコア計算
def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp

# DFS
def dfs(A):
    if len(A) == N:
        return score(A) # 数列 A のスコアを返す
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A)) # 再帰呼出しながら、スコア最大値も更新
        A.pop()
    return res

# 求める
print(dfs([]))

Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  string S, T, U;
  cin >> S;
  
  for (int i=0; i<S.size(); i++) {
    cout << "x";
  }
  cout << endl;
  
  
  return 0;
  
}

Measured memory_bytes: 256
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
bool is_pri(int n)
{
for(int i=3;i<=sqrt(n);i+=2)
{
if(n%i==0)
{
return 0;
}
}
return 1;
}
int main()
{
int n;
cin>>n;
if(n==2)
{
cout<<n;
}
else
{
if(n%2==0)
{
n++;
}
while(!is_pri(n))
{
n+=2;
}
cout<<n<<endl;
}
}

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int k,n,a[200005];
void solve(){
    cin>>k>>n;
    rep(i,0,n) cin>>a[i];
    int mx=a[0]+k-a[n-1];
    rep(i,1,n) mx=max(mx,a[i]-a[i-1]);
    cout<<k-mx<<endl;
}

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

int main()
{
  int n, w, z;
  cin>>n>>w>>z;
  ll arr[n];
  if(n == 1)
  {
    cin>>arr[0];
    cout<<(abs(z - arr[0]))<<endl;
    return 0;
  }
  rep(i, 0, n)
    cin>>arr[i];
  ll ans = max(abs(z-arr[n-1]), abs(arr[n-1] - arr[n-2]));
  cout<<ans<<endl;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }

int n;
int u, v;
vector<int> g[100005];
int d1[100005], d2[100005];
void length(int s, int* d) {
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> que;
    que.emplace(0, s);

    d[s] = 0;
    while (!que.empty()) {
        auto p = que.top(); que.pop();
        rep(i, g[p.second].size()) {
            auto v = g[p.second][i];
            if (p.first + 1 < d[v]) {
                d[v] = p.first + 1;
                que.emplace(p.first + 1, v);
            }
        }
    }
}

void solve() {
    cin >> n >> u >> v; --u; --v;
    fill(d1, d1 + n, iinf);
    fill(d2, d2 + n, iinf);
    rep(i, n - 1) {
        int a, b; cin >> a >> b; --a; --b;
        g[a].push_back(b); g[b].push_back(a);
    }

    length(u, d1);
    length(v, d2);

    int ans = 0;
    rep(i, n) {
        if (d1[i] <= d2[i]) maxs(ans, d2[i]);
    }

    cout << ans - 1 << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 7692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef ll Weight;
typedef vector<vector<Weight>> Graph;
void add_edge(vector<vector<Weight>>& g, Weight from, Weight to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

int n;

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

  cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	ll kabu = 0, money = 1000;
	rep (i,n-1) {
	  if (a[i] >= a[i+1]) { 
			money += kabu*a[i];
			kabu = 0;
		}
		else if (a[i] <= a[i+1]) {
			kabu += money / a[i];
			money = money % a[i];
		}

		//cerr << i << " " << money << " " << kabu << endl;
	}

	cout << money + a[n-1]*kabu << endl;
	
}

Measured memory_bytes: 3648
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int num_divisor[] = new int[1001];
        
        for (int i = 2; i <= n; i++){
            int divisor = 2;
            int i2 = i;
            while (i2 != 1){
                //System.out.println(i2);
                while(i2 % divisor == 0){
                    i2 /= divisor;
                    num_divisor[divisor]++;    
                }
                divisor++;
            }
        } 
        long ans = 1;
        for (int i = 2; i <= n; i++){
            if (num_divisor[i] != 0) ans = (ans * (num_divisor[i] + 1)) % 1000000007;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

bool ok[MAXn];
int main(){
    IOS();
    int n,m;
    cin >> n >> m;
    if (n&1) {
        REP (i,m) {
            cout << i+1 << ' ' << n-i-1 << endl;
        }
    }
    else {
        int cur1 = 1;
        int cur2 = 1+m+1;
        bool c = true;
        for (int i=m;i>=1;i--) {
            if (c) {
                cout << cur1 << ' ' << cur1 + i << endl;
                cur1++;
            }
            else {
                cout << cur2 << ' ' << cur2 + i << endl;
                cur2++;
            }
            c ^= 1;
        }
    }
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int getMinimumCost(int *arr,int i,int n)
{
int cost[n];
cost[0]=0;
cost[1]=abs(arr[0]-arr[1])+cost[0];
for(int i=2;i<n;i++)
{
cost[i]=min(abs(arr[i-1]-arr[i])+cost[i-1],abs(arr[i-2]-arr[i])+cost[i-2]);
}
return cost[n-1];
}
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
cout<<getMinimumCost(arr,0,n)<<endl;
return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド
		Scanner sc = new Scanner(System.in);

		for(int i = 0;;i++) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a == 0&&b == 0)
			break;
		for(int j = 0;j < a; j++) {
			if(j==0||j==a-1) {
				for(int k = 0; k < b; k++) {
					System.out.print("#");
				}
				System.out.println("");
			}else {
				for(int l = 0;l<b;l++) {
					if(l==0||l==b-1) {
						System.out.print("#");
					}else {
						System.out.print(".");
					}

				}
				System.out.println("");
			}

		 }
			System.out.println("");
		}
	}
}



Measured memory_bytes: 34492
#include<stdio.h>

#define N 100000

int n ;
int a[N];

int pt(int a[],int b, int c){

  int x=0,j,i,d;

  x = a[c];
  i = b-1;

  for(j=b; j<c; j++){
    if(a[j] <= x){
      i++;
      d = a[i];
      a[i] = a[j];
      a[j] = d;
    }
  }
  d = a[i+1];
  a[i+1] = a[c];
  a[c] = d;

  return i+1;
}

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

  e =  pt(a,0,n-1);

  for(i=0;i<n;i++){
    if(i != 0) printf(" ");
    if(i == e) printf("[%d]",a[i]);
    else {
      printf("%d",a[i]);
    }
  }

  printf("\n");

  return 0;
}

Measured memory_bytes: 992
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc074/tasks/arc083_a
WA
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    A, B, C, D, E, F = map(int, input().split())

    w = []
    s = []
    for i in range(int(F/100/A+1)):
        for j in range(int(F/100/B+1)):
            water = 100*A*i + 100*B*j
            if  water <= F and water > 0:
                w.append(water)

    for i in range(int(F/C+1)):
        for j in range(int(F/D+1)):
            sugar = C*i + D*j
            if sugar <= F and sugar > 0:
                s.append(sugar)

    max_density = (E*100) / (E+100)
    record_density = 0.0
    record = [w[0], 0]
    for i in w:
        for j in s:
            if i+j <= F:
                density = (100 * j) / (i + j)
                if density > record_density and density <= max_density:
                        record_density = density
                        record = [i+j, j]

    print(*record)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 12460