akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i++)

int main(void)
{
    string sa,sb,sc;
    int n = INT32_MAX;
    char c;

    cin >> sa;
    cin >> sb;
    cin >> sc;
    c = sa[0];

    do
    {
        char tmp_c;
        switch(c)
        {
            case 'a':
                if(sa.length() >= 1)
                {
                    tmp_c = sa[0];
                    sa.erase(sa.begin());
                }
                else
                {
                    cout << "A" << endl;
                    return 0;
                }
                break;
            case 'b':
                if(sb.length() >= 1)
                {
                    tmp_c = sb[0];
                    sb.erase(sb.begin());
                }
                else
                {
                    cout << "B" << endl;
                    return 0;
                }
                break;
            case 'c':
                if(sc.length() >= 1)
                {
                    tmp_c = sc[0];
                    sc.erase(sc.begin());
                }
                else
                {
                    cout << "C" << endl;
                    return 0;
                }
                break;
            default:
                break;
        }
        c = tmp_c;
    }while(1);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, K, A[1 << 18], B[1 << 18];
map<long long, long long> Map;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; A[i]--;
		B[i] = (B[i - 1] + A[i]) % K;
	}

	long long cnt = 0;
	for (int i = 0; i <= N; i++) {
		cnt += Map[B[i]];
		Map[B[i]]++;
		if (i >= K - 1) Map[B[i - K + 1]]--;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 19144
#include<bits/stdc++.h>
#define mms(x,l) memset(x,0,sizeof(x[0])*(l))
#define mmp(x,y,l) memcpy(x,y,sizeof(y[0])*(l))

using namespace std;
typedef long long ll;

const int N=900005,M=1050005,L=6666666,P=1e9+7;

int n,m,k,fac[N],ifac[N],p3[N],ans,X[M],Y[M],Z[M];
inline int fpow(int a,int t){static int r;for(r=1;t;t>>=1,a=(ll)a*a%P)if(t&1)r=(ll)r*a%P;return r;}
inline int C2(int n,int a,int b){return (ll)fac[n]*ifac[a]%P*ifac[b]%P*ifac[n-a-b]%P;}

namespace MaoFFT{
	const double PI=acos(-1);
	struct num{
		double r,i;
		num(double _r=0,double _i=0){r=_r,i=_i;}
		inline friend num operator+(const num&a,const num&b){return num(a.r+b.r,a.i+b.i);}
		inline friend num operator-(const num&a,const num&b){return num(a.r-b.r,a.i-b.i);}
		inline friend num operator*(const num&a,const num&b){return num(a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r);}
		inline friend num operator*(const num&a,const double&b){return num(a.r*b,a.i*b);}
		inline friend num operator/(const num&a,const double&b){return num(a.r/b,a.i/b);}
		inline num conj(){return num(r,-i);}
		inline num mult(){return num(-i,r);}
	};
	num pol[L],*ed=pol;
	num *ww[22],*iww[22],*_w;
	num *nmalloc(int len){num*R=ed;ed+=len;return R;}
	void getwn(int lmax){
		for(int i=1,j=1;j<=lmax;i++,j<<=1){
			ww[i]=nmalloc(j);
			iww[i]=nmalloc(j);
			for(int k=0;k<j;k++){
				ww[i][k]=num(cos(PI/j*k),sin(PI/j*k));
				iww[i][k]=ww[i][k].conj();
			}
		}
	}
	void fft(num a[],int n,int dft){
		int i,j,k,l,c=0;num u,v;
		for(i=1,j=n>>1;i<n-1;i++){
			if(i<j)swap(a[i],a[j]);
			for(k=n>>1;(j^=k)<k;k>>=1);
		}
		for(l=2,c=1;l<=n;l<<=1,c++){
			if(dft==-1)_w=iww[c];else _w=ww[c];
			for(i=l>>1,j=0;j<n;j+=l)for(k=0;k<i;k++){
				u=a[j+k],v=a[j+k+i]*_w[k];
				a[j+k]=u+v,a[j+k+i]=u-v;
			}
		}
	}
	inline int get(int x){
		int l=1;
		while(l<=x)l<<=1;
		return l;
	}
	void convol(int A[],int B[],int R[],int n){
		static int s1,s2,tmp[M];
		s1=s2=0;
		for(int i=0;i<n;i++)s1+=A[i]?1:0,s2+=B[i]?1:0;
		static num x[M],y[M],tx[M],ty[M],p0,p1,q0,q1,u,v,s,t;
		mms(x,n),mms(y,n);
		for(int i=0;i<n;i++){
			x[i]=num(A[i]&32767,A[i]>>15);
			y[i]=num(B[i]&32767,B[i]>>15);
		}
		fft(x,n,1),fft(y,n,1);
		for(int i=0;i<n;i++){
			u=x[i],v=x[i?n-i:0].conj(),s=y[i],t=y[i?n-i:0].conj();
			p0=(u+v)/2,p1=(v-u).mult()/2,q0=(s+t)/2,q1=(t-s).mult()/2;
			tx[i]=p0*q0,ty[i]=p0*q1+p1*q0+p1*q1.mult();
		}
		mmp(x,tx,n),mmp(y,ty,n);
		fft(x,n,-1),fft(y,n,-1);
		for(int i=0;i<n;i++){
			p0=x[i],p1=y[i];
			p0.r/=n,p1.r/=n,p1.i/=n;
			ll a=p0.r+0.5,b=p1.r+0.5,c=p1.i+0.5;
			a%=P,b%=P,c%=P;
			R[i]=(a+(b<<15)+(c<<30))%P;
		}
	}
};

int main(){
	cin>>n>>m>>k;
	fac[0]=p3[0]=1;
	for(int i=1;i<=n+m+k;i++)fac[i]=(ll)fac[i-1]*i%P,p3[i]=p3[i-1]*3u%P;
	ifac[n+m+k]=fpow(fac[n+m+k],P-2);
	for(int i=n+m+k;i>=1;i--)ifac[i-1]=(ll)ifac[i]*i%P;
	int len=MaoFFT::get(m+k);
	MaoFFT::getwn(len);
	for(int i=0;i<=m;i++)X[i]=ifac[i];
	for(int i=0;i<=k;i++)Y[i]=ifac[i];
	MaoFFT::convol(X,Y,Z,len);
	for(int i=0;i<=m+k;i++)
		ans=(ans+(ll)Z[i]*p3[m+k-i]%P*fac[n+i-1]%P*ifac[n-1])%P;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 192896
# 70

m, n = map(int, input().split())


def modpow(a, n, mod):
    ret = 1
    while n > 0:
        if n & 1:
            ret = ret * a % mod
        a = a * a % mod
        n >>= 1
    return ret


print(modpow(m, n, 10**9 + 7))



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

int linearSearch(int *A, int q, int n) {
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (A[i] == q) {
            sum += 1;
            break;
        }
    }
    return sum;
}

int main() {
    int n, q, sum = 0;
    int A[100001];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        sum += linearSearch(A, t, n);
    }
    cout << sum << endl;

    return 0;
}



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

const int N = 2e5 + 10, mod = 1e9 + 7, base = 2e3 + 2;
typedef long long ll;
ll n, a[N], b[N], ans;
ll fac[N], f[4010][4010], inv[N];

ll quick_pow(ll a, ll b) {
    ll ret = 1;
    for (; b; b >>= 1) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
    } return ret;
}

void pre(int n) {
    fac[0] = inv[0] = 1;
    rep(i, 1, n) fac[i] = fac[i - 1] * i % mod;
    inv[n] = quick_pow(fac[n], mod - 2);
    for (int i = n - 1; i >= 1; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

void upd(ll &x, ll y) { x = (x + y) % mod; }

int main() {
    cin >> n;
    rep(i, 1, n) {
        scanf("%lld%lld", &a[i], &b[i]);
        f[-a[i] + base][-b[i] + base]++;
    }
    pre(10000);
    rep(i, 1, 4002)
        rep(j, 1, 4002)
            upd(f[i][j], (f[i - 1][j] + f[i][j - 1]) % mod);
    rep(i, 1, n)
        upd(ans, f[a[i] + base][b[i] + base] - C(2 * a[i] + 2 * b[i], 2 * a[i]) + mod);
    ans = ans * quick_pow(2, mod - 2) % mod;
    printf("%lld\n", ans);
    return 0;
}


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

int main () {
  int N , K ;
  int answer = 1 ;
  cin>>N>>K;
  for(int i = 0 ; i<N ; i++){
    if(2*answer <= answer+K){
      answer *= 2 ;
    }
    else {
      answer += K ;
    }
  }
  cout<<answer<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int A, B, X;
    cin >> A >> B >> X;
    if(X>=A){
        if(B >= X-A){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N;
inline void solve(){
  IN(N);
  OUT(N*(N+1)/2);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

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

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

    li ans = 0;
    for (int d = 1; d < n; ++d) {
        li sum = 0;
        set<li> lvisit;
        for (int l = 0, r = n - 1; l < n && r >= 0; l += d, r -= d) {
            const li a = r;
            const li b = a - d;
            if (a <= 0 || b <= 0) {
                break;
            }
            lvisit.insert(l);
            if (lvisit.find(r) != lvisit.end()) {
                break;
            }
            sum += ss[l] + ss[r];
            ans = max(sum, ans);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {

  int N, l, r, sum = 0;

  cin >> N;

  for(int i = 0; i < N; i++){

    cin >> l >> r;

    sum = sum + (r - l + 1);
  }

  cout << sum << endl;
}

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


signed main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  vector<int> var={a*c,a*d,b*c,b*d};
  cout<<*max_element(var.begin(),var.end());
}

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() {
            String str = "";
            try  {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args){
        int N, K;
        FastReader sc = new FastReader();
        N = sc.nextInt(); K = sc.nextInt();
        String S = sc.nextLine();
        int L = 0, R = 0;
        boolean Lstate = false, Rstate = false;
        for (int i=0; i<N; i++){
            if (S.charAt(i) == 'L'){
                Rstate = false;
                if (!Lstate){
                    Lstate = true;
                } else {
                    L++;
                }
            } else if (S.charAt(i) == 'R'){
                Lstate = false;
                if (!Rstate){
                    Rstate = true;
                } else {
                    R++;
                }
            }
        }
        int ans = Math.min(L+R+2*K, N-1);
        System.out.printf("%d\n", ans);
    }
}


Measured memory_bytes: 24532
#include <list>
#include <iostream>
#include <vector>
#include <sstream>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <map>
#include <sstream>
#include <set>
#include <cmath>
#include <iomanip>
#include <queue>

#define endl "\n"
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rr return 0

using namespace std;


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = dp[0] + abs(h[1] - h[0]);
    for(int i = 2;i < n;i++){
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]),dp[i-1] + abs(h[i] - h[i-1]));
    }
    cout << dp[n-1];
    rr;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
  int N, tmp;
  vector<int> H;
  cin >> N;
  for (int i=0; i<N; i++){
    cin >> tmp;
    H.push_back(tmp);
  }
  int ans = -1;
  int count = 0;
  for (int i=0; i<H.size() - 1; i++){
    if (H[i] < H[i + 1]){
      ans = max(ans, count);
      count = 0;
    }
    else{
      count++;
    }
  }
  ans = max(ans, count);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main() {
  int W, H, N;
  cin >> W >> H >> N;

  int top = H;
  int right = W;
  int bottom = 0;
  int left = 0;
  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;

    if (a == 1)
      left = max(left, x);
    if (a == 2)
      right = min(right, x);
    if (a == 3)
      bottom = max(bottom, y);
    if (a == 4)
      top = min(top, y);
  }

  int answer =
      top < bottom || right < left ? 0 : (top - bottom) * (right - left);

  cout << answer << endl;
}


Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc114

#define SUBMIT

#include <bits/stdc++.h>

using namespace std;

bool can_divide(int x) {
    auto s = to_string(x);

    if (s.find('3') == string::npos) return false;
    if (s.find('5') == string::npos) return false;
    if (s.find('7') == string::npos) return false;

    set<char> chars;
    for (auto c : s) chars.insert(c);
    return chars.size() == 3;
}

int main() {
#ifdef SUBMIT
    auto& in = cin;
#else
    stringstream in(R"(999999999
)");
#endif
    string s;
    in >> s;

    queue<int> q;
    q.push(0);

    auto ans = 0;
    int n = stoi(s);
    for (int i = 0; i < s.length(); ++i) {
        queue<int> next_q;
        while (!q.empty()) {
            auto v = q.front();
            q.pop();
            if (v <= n && can_divide(v)) {
//                cout << v << endl;
                ans++;
            }

            next_q.push(v * 10 + 3);
            next_q.push(v * 10 + 5);
            next_q.push(v * 10 + 7);
        }
        q = next_q;
    }

    while (!q.empty()) {
        auto v = q.front();
        q.pop();
        if (v <= n && can_divide(v)) {
//            cout << v << endl;
            ans++;
        }
    }

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

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int LIS(vi in){//Longest Increasing Subsequence
	int n=in.size();
	int r=1;
	vi out(n+1,inf);
	rep(i,n){
		*lower_bound(all(out),in[i])=in[i];
	}
	return lower_bound(all(out),inf)-out.begin();
}
int main(){
	int n;
	cin>>n;
	vi a(n);
	rep(i,n)cin>>a[i];
	cout<<LIS(a)<<endl;
}

Measured memory_bytes: 2064
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
    int N;

    cin >> N;

    vector<int> v;

    int v_tmp;

    for(int i = 0; i < N; i++) {
        cin >> v_tmp;
        v.push_back(v_tmp);
    }

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

    double ans = v[0];

    for(int i = 1; i < N; i++) {
        ans = (ans + v[i]) / 2.0;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 384
n, k = map(int,input().split())
s = input()
sento = 0
ketu = 0
tmp = '1'
zeroichi = []
cnt = 0

for i in range(n):
    if tmp == s[i]:
        cnt += 1
    else:
        zeroichi.append(cnt)
        cnt = 1
        tmp = s[i]

zeroichi.append(cnt)

if len(zeroichi)%2 == 0:
    zeroichi.append(0)

if len(zeroichi) == 1:
    zeroichi.append(0)
    zeroichi.append(0)

i = 0
ans = 0
ans_list = []
j = 0
right = min(1+k*2,len(zeroichi))
left = 0

while i != right:
    ans += zeroichi[i]
    i += 1

ans_list.append(ans)

while right != len(zeroichi):
    ans -= zeroichi[left]
    ans -= zeroichi[left+1]
    ans += zeroichi[right]
    ans += zeroichi[right+1]
    ans_list.append(ans)
    left += 2
    right += 2

print(max(ans_list))


Measured memory_bytes: 11320
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int[] a = new int[10001];
		int g = 0;
		for ( int x=1; x<=100; x++ ) {
			int x2 = x*x;
			for ( int y=1; y<=100; y++ ) {
				int y2 = y*y;
				int xy = x*y;
				for ( int z=1; z<=100; z++ ) {
					int f = x2 + y2 + z*z + xy + z*x + y*z;
					if ( f<=10000 ) a[f]++;
				}
			}
		}

		for ( int i=1; i<=n; i++ ) System.out.println(a[i]);
	}
}


Measured memory_bytes: 39156
local mma = math.max
local h, w = io.read("*n", "*n", "*l")
local map = {}
for i = 1, h do
  local s = io.read()
  for j = 1, w do
    map[(i - 1) * w + j] = s:sub(j, j) == "."
  end
end


local function getlength(start_idx, dst_idx)
  local taskstate = {}
  for i = 1, h * w do taskstate[i] = false end
  local tasks = {}
  local tasknum = 0
  local done = 0

  local len = {}
  local inf = -1
  for i = 1, h * w do len[i] = inf end
  len[start_idx] = 0

  local function addtask(idx)
    if not taskstate[idx] then
      taskstate[idx] = true
      tasknum = tasknum + 1
      tasks[tasknum] = idx
    end
  end
  addtask(start_idx)

  local function walk(src, dst)
    if map[dst] then
      if len[dst] == inf or len[src] + 1 < len[dst] then
        len[dst] = len[src] + 1
        addtask(dst)
      end
    end
  end

  while done < tasknum do
    done = done + 1
    local idx = tasks[done]
    taskstate[idx] = false
    local tmp = {}

    if w < idx then walk(idx, idx - w) end
    if idx <= (h - 1) * w then walk(idx, idx + w) end
    if 1 < w then
      if idx % w ~= 0 then walk(idx, idx + 1) end
      if idx % w ~= 1 then walk(idx, idx - 1) end
    end
  end
  local ret = 0
  for i = 1, h * w do
    if 0 < len[i] then
      ret = mma(ret, len[i])
    end
  end
  return ret
end
local totret = 0
for i = 1, h * w do
  if map[i] then
    totret = mma(totret, getlength(i))
  end
end
print(totret)


Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	// Atcoder用のサンプルプログラム
    public static void main(String[] args) {
    	String line="";
    	try  {
        	line = readLine();	

    	
        StringTokenizer st = new StringTokenizer(line, " ");
        String k = st.nextToken();
        String s = st.nextToken();
        
        int k1Value = Integer.parseInt(k);
        int sValue = Integer.parseInt(s);
        int cnt=0;
        int x=0;
        // x y S-x-y
        for (int i = 0;i < sValue+1;i++) {
        	if (i > k1Value) {
        		continue;
        	}
        	for (int j = 0;j < sValue+1;j++) {
        		if (j > k1Value) {
            		continue;
            	} else if (sValue-i-j > k1Value){
            		continue;
            	}
        		
        		if (i+j<=sValue) {
            		//System.out.println(String.valueOf(i) + "," + String.valueOf(j) + "," + String.valueOf(sValue-i-j));
                	cnt++;        			
        		}
        	}
        }
        System.out.println(cnt);
    	} catch(Exception e) {
    		e.printStackTrace();
    	}
    }

    private static String readLine() throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        return br.readLine();
    }

}


Measured memory_bytes: 21076
n,M=map(int,input().split())
l,r,ans=0,10**18,-1
while(l<=r):
    m=(l+r)//2
    ns=max(0,m-n)
    uc=(2*ns+2*m)
    if(uc<=M):
        ans=m
        l=m+1
    else:
        r=m-1
print(ans)


Measured memory_bytes: 9088
#include <stdio.h>
#include <string.h>
 
void BS(char a[]){
int i, len;
len = strlen(a);
 
for(i = 0; i < len; i++){
    if('A' <= a[i] && a[i] <= 'Z')
        a[i] += 32;
}
}
 
 
     
 
 
 
int main(void)
{
    char x[10] ,y[100];
    int i = 0;
 
    scanf("%s",&x);
 
    while(1){
    if(scanf("%s",&y) == EOF)
        break;
BS(y);
if(strcmp(x,y) == 0){
        i++;
}
}
 
 
 
printf("%d\n",i);
 
return 0;
}

Measured memory_bytes: 560
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int len = s.length(), i = 0;
	bool flag = false;
	while (i < len) {
		if (s == t) {
			flag = true;
			break;
		}
		char c = s[0];
		s.erase(0, 1);
		s += c;
		// cout << s << endl;
		i++;	
	}
	if (flag) cout << "Yes";
	else {
		cout << "No";
	}
    return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions 

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    priority_queue<int> pq;
    REP(i, N) pq.push(A[i]);

    REP(i,N) {
        int hi = pq.top(); pq.pop();
        if (hi == A[i]) {
            int hi2 = pq.top();
            cout << hi2 << endl;
        } else {
            cout << hi << endl;
        }
        pq.push(hi);
    }

    return 0;
}

Measured memory_bytes: 3316
#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 pb push_back
#define ins insert
#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};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
    ll n,m;cin >> n >>m;
    n--;
    vl v(m);
    rep(i,m)cin >> v[i];
    while(true){
        bool end=false;
        n++;
        ll p=n;
        while(p){
            ll d=p%10;
            rep(i,m){
                if(v[i]==d){
                    end=true;
                    break;
                }
            }
            p/=10;
        }
        if(end)continue;
        cout << n << endl;
        return 0;
    }
}

Measured memory_bytes: 256
"use strict"

function Main(input) {
  input = input.trim();
  let alp = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  
  let ret = 'None';
  for(let i=0; i<26; i++){
    if(input.indexOf(alp[i]) === -1){
      ret = alp[i];
      break
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
def isprime(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

def main():
    N = int(input())
    PRIMES = [i * 10 + 1 for i in range(2, 146) if isprime(i * 10 + 1)]
    print(' '.join(map(str, PRIMES[:N])))

main()


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  while(true){
    int n, min, max;
    cin >> n >> min >> max;
    if(n == 0 && min == 0 && max == 0) break;
    int a[n];
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    int max_gap = 0;
    int target = 0;
    for(int i = min; i <= max; i++){
      int gap = a[i - 1] - a[i];
      if(max_gap <= gap){
        max_gap = gap;
        target = i;
      }
    }

    cout << target << endl;
  }
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)
#define N 1000;
#define INF 1000000007

int main() {

  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  r(i,ty-sy)cout<<"U";
  r(i,tx-sx)cout<<"R";
  r(i,ty-sy)cout<<"D";
  r(i,tx-sx)cout<<"L";
  cout<<"L";
  r(i,ty-sy+1)cout<<"U";
  r(i,tx-sx+1)cout<<"R";
  cout<<"DR";
  r(i,ty-sy+1)cout<<"D";
  r(i,tx-sx+1)cout<<"L";
  cout<<"U"<<endl;


return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  string s; cin >> s;
  int l = s.find_first_of('A'), r = s.find_last_of('Z');
  int ans = r - l + 1;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long int lli;

const int MOD = 1e9 + 7;

int Ti[100010];
int Ai[100010];

int Max_[100010];
bool isSame[100010];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> Ti[i];
  for (int i = 0; i < N; i++) cin >> Ai[i];
  
  bool isP = false;

  Max_[0] = Ti[0], isSame[0] = false;
  Max_[N - 1] = Ai[N - 1], isSame[N-1] = false;

  if (Ti[N - 1] != Ai[0])  isP = true;

  for (int i = 1; i < N - 1; i++) {
    if (Ti[i - 1] != Ti[i]) isSame[i] = false;
    else isSame[i] = true;
    Max_[i] = Ti[i];
  }
  
  for (int i = N - 2; i > 0; i--) {
    if (Ai[i] != Ai[i + 1]) {
      isSame[i] = false;
      Max_[i] = Ai[i];
    }
    if (!isSame[i] && Max_[i] > Ai[i]) isP = true;
    if (isSame[i]) Max_[i] = min(Max_[i], Ai[i]);
  }
  
  lli ans = 1;
  if (isP) ans = 0;

  for (int i = 0; i < N; i++) {
    if (isSame[i]) {
      ans = (ans * Max_[i]) % MOD;
    }
    
    //    cout << i << " " << Max_[i] << " " << isSame[i] << endl;
    
  }
  
  cout << ans << endl;

  return 0;  
}


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

typedef long long ll;

const ll N = 21;

ll n, m, c, a[N], b[N], sum, res;

 
int main() {
	cin >> n >> m >> c;
	for (ll i = 1; i <= m; ++i) cin >> b[i];
	
	while (n--) {
		sum = 0;
		for (ll i = 1; i <= m; ++i) {
			cin >> a[i];
			sum += a[i] * b[i];
		}
		if (sum + c > 0) ++res;
	}
	cout << res;
	
	return 0;
}


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

int main() {
  int N; cin >> N;
  int max_high = 0;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int high_i; cin >> high_i;
    if (high_i >= max_high) {
      max_high = high_i;
      ans++;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
    
    int n; cin >> n;
    cin.ignore();
    
    string s1, s2;
    cin >> s1;
    cin >> s2;
    
    for (int i=0; i<s1.length(); i++)
    {
        cout << s1[i] << s2[i];
    }
    
    cout << endl;
    
    
    
    
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 256
N,Y = map( int, input().split() )

# 10000x + 5000y + 1000z = Y
#/ かつ
# x + y + z = N

#3重ループは流石につらいので
# z = N - x - y

x = 0
y = 0
z = 0

isExist = False

for x in range(N+1):
  for y in range(N - x+1):
    z = N - x - y
    
    if( 10000*x + 5000*y + 1000*z == Y  ):
      isExist = True
      break
    
  if(isExist == True):
      break
      
if(isExist == True):
  print(x, y, z)
else:
  print(-1, -1, -1)

Measured memory_bytes: 3064
#include <iostream>

int main(void) {

	std::string S, T;

	std::cin >> S;
	std::cin >> T;

	if (S.length() < 1 && 10 < S.length()) {
		std::cout << "No" << std::endl;
		return 0;
	}

	if (T.length() != S.length() + 1) {
		std::cout << "No" << std::endl;
		return 0;
	}


	if (T.compare(0, T.length() -1, S) ){
		std::cout << "No"<< std::endl;
	}
	else {
		std::cout << "Yes" << std::endl;
	}
};

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

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int a=0,b=0,count1=0,count2=0,count3=0,count4=0,flag=0;
  for(int i=0;i<3;i++){
    scanf("%d %d",&a,&b);
    if(a==1)count1++;
    if(a==2)count2++;
    if(a==3)count3++;
    if(a==4)count4++;
    if(b==1)count1++;
    if(b==2)count2++;
    if(b==3)count3++;
    if(b==4)count4++;
  }
  if(count1==2)flag++;
  if(count2==2)flag++;
  if(count3==2)flag++;
  if(count4==2)flag++;

  if(flag == 2)printf("YES");
  else printf("NO");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define translow transform(s.begin(),s.end(),s.begin(),::tolower);
#define transup transform(s.begin(),s.end(),s.begin(),::toupper);
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;
 
 
int main() {
				fast
                // #ifndef ONLINE_JUDGE
                // freopen("input.txt","r",stdin);
                // freopen("output.txt","w",stdout);
                // #endif

               string s;
               cin>>s;
               if(s[2]==s[3] and s[4]==s[5])
                cout<<"Yes";
            else
                cout<<"No";

                return 0;
            }

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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int n;
pair<int,int> a[2001];
int dp[2001][2001];
int32_t main() {
    nitin;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a+1,a+n+1,greater<>());
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]+a[i].first*abs(a[i].second-i);
//        cout<<dp[i][0]<<" "<<i<<endl;
    }
    for(int i=1;i<=n;i++)
    {
        dp[0][i]=dp[0][i-1]+a[i].first*abs((n-i+1)-a[i].second);
//        cout<<dp[0][i]<<" "<<i<<endl;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i+j<=n)
            dp[i][j]=max(dp[i-1][j]+a[i+j].first*abs(a[i+j].second-i),dp[i][j-1]+a[i+j].first*abs((n-j+1)-a[i+j].second));
        }
    }
    int ans=0;
    for(int i=0;i<=n;i++)
    {
        ans=max(ans,dp[i][n-i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

inline int read()
{
	int x=0,f=1,c=getchar();
	while(c<48) c=='-'&&(f=-1),c=getchar();
	while(c>47) x=x*10+c-'0',c=getchar();
	return x*f;
}

const int MAXN = 5005;
const int mod = 1e9+7;
int f[MAXN][MAXN];
int n,m;

inline int dp(int x,int y,int ret=0)
{
	memset(f,0,sizeof(f));
	for(int i=0;i<=x;++i) f[0][i]=1;
	for(int i=1;i<=y;++i)
		for(int j=0;j<=x;++j)
		{
			if(j<x) (f[i][j]+=f[i-1][j+1])%=mod,(f[i][j]+=f[i-1][j])%=mod;
			if(j) (f[i][j]+=f[i-1][j])%=mod,(f[i][j]+=f[i-1][j-1])%=mod;
		}
	for(int i=0;i<=x;++i) (ret+=f[y][i])%=mod;
	return ret;
}

int main(int argc, char const *argv[])
{
	n=read(); m=read();
	printf("%d\n", (dp(n,m)-dp(n-1,m)+mod)%mod);
	return 0;
}



Measured memory_bytes: 101516
def sumNum(num, sums):
    if num == 0:
        return sums
    sums += num % 10
    num = num // 10
    return sumNum(num, sums)

N = int(input())
keta = 0

for A in range(1, N):
    B = N - A
    _A = sumNum(A, 0)
    _B = sumNum(B, 0)
    ret = _A + _B
    if keta == 0:
        keta = ret
    if keta <= ret:
        continue
    keta = ret

print(keta)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const LL mod = (1e9 + 7);

int n;
char ch[3][55];
LL ans = 1;


int main()
{
    scanf("%d", &n);
    scanf("%s", ch[0] + 1);
    scanf("%s", ch[1] + 1);
    int pr = 0;
    for(int i = 1;i <= n;i++)
    {
        if(i == 1)
        {
            if(i < n&&ch[0][i] == ch[0][i + 1])
                i++, pr = 2, ans = ans * 6;
            else if(ch[0][i] == ch[1][i])
                pr = 1, ans = ans * 3;
        }
        else
        {
            if(pr == 1)
            {
                ans = ans * 2 % mod;
                if(i < n&&ch[0][i] == ch[0][i + 1])
                    i++, pr = 2;
                else if(ch[0][i] == ch[1][i])
                    pr = 1;
            }
            else
            {
                if(i < n&&ch[0][i] == ch[0][i + 1])
                    i++, pr = 2, ans = ans * 3 % mod;
                else if(ch[0][i] == ch[1][i])
                    pr = 1;
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
m,d=map(int, input().split())
count=0
if d <= 10:
  print(0)
else:
  for i in range(1,m+1):
    for j in range(11,d+1):
      dl = list(str(j))
      if int(dl[0]) >=2 and int(dl[1]) >= 2 and int(dl[0])*int(dl[1]) == i:
        count+=1

  print(count)

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

ll grundy(ll a, ll k){
    if(a < k) return 0;
    if(a%k == 0) return a/k;
    return grundy(a-((a-a/k*k-1)/(a/k+1)+1)*(a/k+1), k);
}

int main(){
    ll n; cin >> n;
    ll ans = 0;
    rep(i,n){
        ll a, k; cin >> a >> k;
        ans ^= grundy(a, k);
    }
    cout << (ans ? "Takahashi" : "Aoki") << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int W,H;
int grid[100][100];
int d[100][100];

int BFS(void){
	int dy[4]={-1,1,0,0}, dx[4]={0,0,-1,1};

	memset(d,-1,sizeof(d));

	d[0][0]=1;

	queue<P> Q;	Q.push( {0,0} );
	
	while(Q.size()){
		P u=Q.front();	Q.pop();
		int y=u.first, x=u.second;

		for(int i=0;i<4;i++){
			int nY=y+(dy[i]*2), nX=x+(dx[i]*2);
			if(nY<0||nX<0||nY>=H*2||nX>=W*2)continue;
			if(grid[ y+dy[i] ][ x+dx[i] ])continue;

			if(d[nY][nX]!=-1)continue;

			d[nY][nX]=d[y][x]+1;
			Q.push( {nY,nX} );

		}
	}

	int ret=d[H*2-2][W*2-2];
	if(ret<0)ret=0;

	return ret;
}

int main(){
	while(cin>>W>>H, W||H){
		for(int i=0; i<2*H-1; i++){
			int row=i/2;
			row*=2;

			if(i%2==0){
				for(int j=1;j<W*2-1;j+=2){
					cin>>grid[row][j];
				}
			}else{
				for(int j=0;j<W*2;j+=2){
					cin>>grid[row+1][j];
				}
			}
		}

		cout<<BFS()<<endl;
	}

	return 0;
}



Measured memory_bytes: 3124
import sys
import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
start=time.time()
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n,k = rl()

s=rs()
now="1"
cnt=0

nums=[]
for i in s:
    if i==now:
        cnt+=1
    else:
        now=str(1-int(now))
        nums.append(cnt)
        cnt=1
if cnt!=0: nums.append(cnt)

if len(nums)%2==0:nums.append(0)
SUM=[0]
for i in range(len(nums)):
    SUM.append(SUM[i]+nums[i])

skip=2*k+1
ans=0
for i in range(0,len(SUM),2):
    right=min(i+skip, len(SUM)-1)
    left =i
    ans=max(ans,-SUM[left]+SUM[right])
print(ans)

Measured memory_bytes: 49240
pencil = input()
o      = pencil[len(pencil)-1]
if o == str(2) or o== str(4) or o== str(5) or o== str(7) or o== str(9):
    print("hon")
elif o==str(0) or o==str(1) or o==str(6) or o==str(8):
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, x, y;
vector<int> edge[100100];
int tdis[100100];
int adis[100100];

void dfs(int v, int arr[]) {
    for(auto&&u:edge[v]) {
        if(arr[u] == -1) {
            arr[u] = arr[v] + 1;
            dfs(u, arr);
        }
    }    
}

signed main() {

    int a, b;
    cin >> n >> x >> y;

    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        edge[a].bash(b);
        edge[b].bash(a);
    }

    memset(tdis, -1, sizeof(tdis));
    memset(adis, -1, sizeof(adis));

    tdis[x] = adis[y] = 0;

    dfs(x, tdis);
    dfs(y, adis);

    int ans = 0;

    for(int i = 1; i <= n; i++) {
        if(tdis[i] <= adis[i])
            chmax(ans, adis[i] - 1);
    }

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



Measured memory_bytes: 10368
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m; cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;

    return 0;
}


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

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
//void out(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	int n;
	while ((n = in())) {
		vector<int> v(n + 1);
		for (int i = 0; i < n; ++i) {
			int sum = 0;
			for (int j = 0; j < n; ++j) {
				int d = in();
				printf("%5d", d);
				v[j] += d;
				sum += d;
			}
			v[n] += sum;
			printf("%5d\n", sum);
		}
		for (int d: v)
			printf("%5d", d);
		out('\n');
	}
}


Measured memory_bytes: 2692
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-06 17:28:28
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 50

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l) {
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int h, w;
char s[INF][INF];

int group(int i, int j)
{
    int cnt = 1;
    s[i][j] = '.';

    int v[4][2] = {{i, j-1}, {i-1, j}, {i+1, j}, {i, j+1}};
    for (int k = 0; k < 4; k++) {
        int p, q;
        p = v[k][0]; q = v[k][1];

        if (p >= 0 && p <= h-1 && q >= 0 && q <= w-1) {
            if (s[p][q] == '#') {
                cnt += group(p, q);
            }
        }
    }

    return cnt;
}

void solve()
{
    int ok = 1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == '#') {
                int g = group(i, j);
                if (g <= 1) {
                    ok = 0;
                }
            }
        }
    }

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

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string t;
        cin >> t;
        for (int j = 0; j < w; j++) {
            s[i][j] = t[j];
        }
    }

    solve();

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N>>M;
    vector<string> a(N), b(M);
    rep(i,N) cin>>a[i];
    rep(i,M) cin>>b[i];
    rep(i, N - M + 1){
        rep(j, N - M + 1){
            bool ok = true;
            rep(k, M){
                rep(l, M){
                    if(a[i+k][j+l] != b[k][l]){
                        ok = false;
                        break;
                    }
                }
            }
            if(ok){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	k = int(input())
	#b , c = tin()
	#s = input()
	ret = 'ACL'*k
	return ret
	
	
#+++++
isTest=False

def pa(*vl):
	if not isTest:
		return
	for v in vl:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 61964