akhauriyash/Code-Regression huggingface dataset:
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int A, B;

    AtCoder(FastScanner sc) {
        A = sc.nextInt();
        B = sc.nextInt();
    }

    void solve(PrintWriter out) {
        int ans = 0;
        if (A >= 13) {
            ans = B;
        } else if (A >= 6 && A <= 12) {
            ans = B / 2;
        }
        out.println(ans);
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22868
#include<stdio.h>

int main() {
  int n, m;
  int i;
  int x, y;
  int r[51] = {};
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i = i+1) {
    scanf("%d %d", &x, &y);
    r[x] = r[x] + 1;
    r[y] = r[y] + 1;
  }
  for (i = 1; i < n+1; i = i+1) {
    printf("%d\n", r[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if(s.size()%2!=0){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<s.size();i+=2){
		if(s[i]!='h'||s[i+1]!='i'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n m s ->
  let es = Array.make_matrix n 3001 [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d %d %d\n" @@ fun u v a b ->
      for i = a to 3000 do
        es.(u - 1).(i) <- ((v - 1, i - a), b) :: es.(u - 1).(i);
        es.(v - 1).(i) <- ((u - 1, i - a), b) :: es.(v - 1).(i);
      done
  done;
  for v = 0 to n - 1 do
    Scanf.scanf "%d %d\n" @@ fun c d ->
      for j = 0 to 3000 do
        es.(v).(j) <- ((v, min 3000 (j + c)), d) :: es.(v).(j)
      done
  done;
  let d = Array.make_matrix n 3001 12345678901234 in
  d.(0).(min 3000 s) <- 0;
  let rec dijkstra q =
    match IntMap.min_binding q with
    | exception Not_found -> ()
    | (w, us) ->
        dijkstra @@ List.fold_left (fun q (u, u') ->
          if d.(u).(u') < w
          then q
          else List.fold_left (fun q ((v, v'), c) ->
            if compare d.(v).(v') (w + c) <= 0
            then q
            else begin
              d.(v).(v') <- w + c;
              IntMap.add (w + c) ((v, v') :: try IntMap.find (w + c) q with Not_found -> []) q
  end) q es.(u).(u')) (IntMap.remove w q) us in
  dijkstra (IntMap.singleton 0 [(0, min 3000 s)]);
  for i = 1 to n - 1 do
    Printf.printf "%d\n" @@ Array.fold_left min max_int d.(i)
  done



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

using namespace std;

int main () {
    long long a; long double b; cin >> a >> b;


    long double s = a * b;
    
    unsigned long long ss = s;


    cout << ss << endl;
}

Measured memory_bytes: 3188
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
cnt = [0]*m
for i in range(n):
    query = LI()
    for j in query[1:]:
        cnt[j-1] += 1
ans = 0
for i in cnt:
    if i == n:
        ans += 1
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,k;
    cin>>n>>k;
    if(n==0||k==1){
        cout<<"0"<<endl;
        return 0;
    }
    if(k>n){
        if(abs(n-k)<n){
            cout<<abs(n-k)<<endl;
            return 0;
        }
        else{
            cout<<n<<endl;
        }
    }
    else if(n==k){
        cout<<"0"<<endl;
    }
    else if(n>k){
            if(n%k==0){
                cout<<"0"<<endl;
                return 0;
            }
        ll x=n%k;
        if(x<abs(k-x)){
            cout<<x<<endl;
        }
        else{
            cout<<abs(k-x)<<endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()
 
using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}
 
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w, ch,cw, dh, dw;
	cin >>h >>w >>ch >>cw >>dh >>dw;
	vector<string> ba(h);
	rep(i, h) cin >>ba[i];
	ch--;cw--;dh--;dw--;
	
	const int dr[]={0,1,0,-1,0};
	typedef tuple<ll, int, int> pli;
	const ll INF = 1e18;
	priority_queue< pli, vector<pli>, greater<pli> > que;
	vector<VL> d(h, VL(w, INF));
	d[ch][cw] = 0;
	que.emplace(0, ch, cw);
	while(!que.empty()){
		auto [cost, cy, cx ] = que.top(); que.pop();
		if(d[cy][cx] < cost) continue;
 
		rep(i, 4){
			int ny = cy+dr[i], nx=cx+dr[i+1];
			if(ny<0 || ny>=h || nx<0 || nx>=w || ba[ny][nx] !='.') continue;
			ll ncst = d[cy][cx];
			if(d[ny][nx]> ncst){
				d[ny][nx] = ncst; que.emplace(ncst, ny, nx);
			}
		}
		rep2(yy, -2,3) rep2(xx, -2,3){
			int ny = cy+yy, nx=cx+xx;
			if(ny<0 || ny>=h || nx<0 || nx>=w || ba[ny][nx] !='.') continue;
			ll ncst = d[cy][cx] + 1;
			if(d[ny][nx] > ncst){
				d[ny][nx] = ncst; que.emplace(ncst, ny, nx);
			}
		}
	}
 
	ll ans = d[dh][dw];
	cout << (ans!=INF? ans: -1) <<"\n";
	return 0;
}

Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll a, b;
    cin >> a >> b;
    ll t = 0;
    for (ll i = b - a; i > 0; --i) t += i;
    cout << t - b << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
p_list=[]
score=0
for i in range(len(t)):
    if i<k:
        if t[i]=='r':
            p_list.append('p')
            score+=p
        elif t[i]=='s':
            p_list.append('r')
            score+=r
        else:
            p_list.append('s')
            score+=s
    else:
        if t[i]=='r':
            if p_list[i-k]=='p':
                if i+k>=len(t):
                    p_list.append('a')
                else:
                    p_list.append(t[i+k])
            else:
                p_list.append('p')
                score+=p
        elif t[i]=='s':
            if p_list[i-k]=='r':
                if i+k>=len(t):
                    p_list.append('a')
                else:
                    p_list.append(t[i+k])
            else:
                p_list.append('r')
                score+=r
        else:
            if p_list[i-k]=='s':
                if i+k>=len(t):
                    p_list.append('a')
                else:
                    p_list.append(t[i+k])
            else:
                p_list.append('s')
                score+=s
print(score)

Measured memory_bytes: 4212
import java.util.Scanner;


public class Main {
	void insertionSort(int[] a, int n) {
		System.out.print(a[0]);
		for (int k = 1; k < n; k++) {
			System.out.print(" " + a[k]);
		}
		System.out.println();
		for (int i = 1; i < n; i++) {
			int v = a[i];
			int j = i - 1;
			while (j >= 0 && a[j] > v) {
				a[j+1] = a[j];
				j--;
			}
			a[j+1] = v;
			System.out.print(a[0]);
			for (int k = 1; k < n; k++) {
				System.out.print(" " + a[k]);
			}
			System.out.println();
		}
	}
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		new Main().insertionSort(a, n);
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    int N; cin >> N;
    REP(notc, N){
        int sum = 0, max = 0;
        REP(i, 3){
            int a; cin >> a;
            sum += a * a;
            chmax(max, a * a);
        }
        cout << (((sum - max) == max) ? "YES" : "NO") << endl;
    }
    
    return 0;
}




Measured memory_bytes: 2996
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

char getc(int n){
    return '0' + n;
}

char geti(char c){
    return c - '0';
}

string getstr(int n){
    return string() + getc(n/1000) + getc(n/100%10) + getc(n/10%10) + getc(n%10);
}

int toint(string str){
    return geti(str[0])*1000+geti(str[1])*100+geti(str[2])*10+geti(str[3]);
}

int getl(int n){
    string str = getstr(n);
    sort(str.begin(),str.end());
    reverse(str.begin(),str.end());
    return toint(str);
}

int gets(int n){
    string str = getstr(n);
    sort(str.begin(),str.end());
    return toint(str);
}

int solve(int n){
    if(n == 6174) return 0;
    string str = getstr(n);
    if(str[0] == str[1] && str[1] == str[2] && str[2] == str[3])
        return -1;
    int i;
    for(i=0;n != 6174;i++){
        int l = getl(n);
        int s = gets(n);
        n = l-s;
        //cout << "--" << i << endl;
        //cout << "l:" << l << endl;
        //cout << "s:" << s << endl;
        //cout << "n:" << n << endl;
    }
    return i;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0)break;
        int ans = solve(n);
        if(ans != -1){
            cout << ans << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
using System;
using System.Linq;
namespace HelloWorld
{
    class Program
    {
        static void Main()
        {
            string line;
            while ((line = Console.ReadLine()) != "0 0")
            {
                int[] date = line.Split().Select(int.Parse).ToArray();
                var dt = new DateTime(2004, date[0], date[1]);
                Console.WriteLine(dt.DayOfWeek);
            }
        }
    }
}


Measured memory_bytes: 16328
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef long long i64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	const int n = read_item();
	const int r = read_item();

	const int ans = r + 100 * max(10 - n, 0);
	printf("%d\n", ans);

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int

int main(void)
{
    char c;
    cin >> c;
    c++;
    cout << c << endl;


}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
const int MAX_N = 100000;
const int MAX_V = 1000000000;
int N;
int X[MAX_N];
int L[MAX_N];
void input(){
scanf("%d", &N);
for(int i = 0; i < N; ++i){
scanf("%d%d", X + i, L + i);
}
}
P ps[MAX_N];
int solve(){
for(int i = 0; i < N; ++i){

ps[i] = P(X[i] + L[i], X[i] - L[i]);
}
sort(ps, ps + N);
int cur = -MAX_V;
int ans = 0;
for(int i = 0; i < N; ++i){
if(cur <= ps[i].second){
ans++;
cur = ps[i].first;
}
}
return ans;
}
int main(){
input();
int ans = solve();
printf("%d\n", ans);
return 0;
}

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

int main() {
	bool flag = true;
	string input;
	string abc[26] = {"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"};
	cin >> input;
	for(int i = 0;i < 26;i++){
		if((int)input.find(abc[i]) == -1){
			cout << abc[i];
			flag = false;
			break;
		}
	}
	if (flag) cout << "None";
	return 0;
}

Measured memory_bytes: 512
import bisect
n = int(input())
L = list(map(int, input().split()))
L.sort()

count = 0
for i in range(0, n-2):
  for j in range(i+1, n-1):
    t = L[i] + L[j]
    idx = bisect.bisect_left(L, t)
    count += idx - (j+1)

print(count)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#define maxn 100009
using namespace std;
int n;
long long a[maxn];
long long dp[maxn][2];
const long long INF = 1e18;
int main(){
	cin >> n;
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	dp[1][0] = a[1];
	dp[1][1] = -INF;
	
	for(int i = 2; i <= n; i++){
		dp[i][0] = a[i] + max(dp[i - 1][0], dp[i - 1][1]);
		dp[i][1] = max(-a[i] + dp[i - 1][0] - a[i - 1] - a[i - 1], -a[i] + dp[i - 1][1] - (-a[i - 1]) + a[i - 1]);
	}
	cout << max(dp[n][0], dp[n][1]) << endl;
	return 0;
}

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

typedef struct Node {
    int key;
    struct Node *prev, *next;
} Node;

Node *nil;

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int val){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = val;
    x->next = nil->next;
    nil->next->prev = x;
    x->prev = nil;
    nil->next = x;
}

Node* listSearch(int val){
    Node *cur=nil->next;
    while(cur != nil && cur->key != val){
        cur=cur->next;
    }
    return cur;
}

void deleteNode(Node *cur){
    if(cur==nil) return;
    cur->prev->next=cur->next;
    cur->next->prev=cur->prev;
    free(cur);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int val){
    deleteNode(listSearch(val));
}


void trace(){
    int i=0;
    Node *cur=nil->next;
    while(cur != nil){
        if(i>0) printf(" ");
        printf("%d", cur->key);
        i++;
        cur=cur->next;
    }
    printf("\n");
}
int main(){
    int num, i, value;
    char s[100];
    scanf("%d", &num);
    init();
    for(i=0; i<num; i++){
        scanf("%s%d", s, &value);
        if(!strcmp(s, "deleteFirst")) deleteFirst();
        else if(!strcmp(s, "deleteLast")) deleteLast();
        else if(!strcmp(s, "insert")){
            insert(value);
        }else{
            deleteKey(value);
        }
    }
    trace();
    return 0;
}

Measured memory_bytes: 33820
#include <stdio.h>

int main(void)
{
	int x, n;
	
	for(x = 0; x < 10000; x++){
		scanf("%d", &n);
		if(n == 0) break;
		printf("Case %d: %d\n", x+1, n);
	}
	
	return(0);
}



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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	ll ret=0, cur=0;
	for (auto ch : s)
		if(ch=='B') cur++;
		else ret+=cur;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 720
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const ll INF=1000000000000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret;
	ret %= M;
	if(k%2 == 1){
		ret *= x;
		ret %= M;
	}
	return ret;
}

int main(){
	ll n,k;
	cin >> n >> k;
	
	static ll dp[102][5060] = {};
	dp[k][0] = k;
	dp[k][1] = 1;
	for(int i = k-1 ; i >= 1 ; i --){
		for(int j = 0 ; j < 5060 ; j ++){
			dp[i][j] += dp[i+1][j]*(k-i);
			dp[i][j+j/i] += dp[i+1][j]*(i-j%i);
			dp[i][j+j/i+1] += dp[i+1][j]*(j%i+1);
		}
		for(int j = 0 ; j < 5060 ; j ++){
			dp[i][j] %= M;
		}
	}
	
	ll ret = modpow(k+1,k)*n*k; ret %= M;
	ret *= modpow(2,M-2); ret %= M;
	rep1(i,5059){
		dp[1][i] *= i;
		dp[1][i] %= M;
		ret += M-dp[1][i];
	}
	ret %= M;
	ret *= modpow(k+1,n-k);
	cout << ret%M << endl;
}
	



Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
#define MOD 1000000007
/*
H=2*10^3,W=2*10^3なので、
最初に思いついた方法だと、
O(HW(H+W))になってしまって厳しい、、、
 
前処理をすることで計算量を減らせないか考える
*/

int main()
{
  int H,W;cin>>H>>W;
  char S[2020][2020];
  
  for (int i=1;i<=H;i++)
  {
    for (int j=1;j<=W;j++)
      cin>>S[i][j];
  }
  
  //DPみたいな感じで前処理をしておく
  //L[i][j]=i,jに明かりを置いた時に照らされるマスの総数
  int L[2020][2020];
  int R[2020][2020];
  int T[2020][2020];
  int D[2020][2020];
  
  for (int i=1;i<=H;i++)
  {
    for (int j=1;j<=W;j++)
    {
      if (S[i][j]=='#') L[i][j]=0;
      else 
      {
        if (j==1) L[i][j]=1;
		else L[i][j]=L[i][j-1]+1;
      }
    }
  }
  
  for (int i=1;i<=H;i++)
  {
    for (int j=W;j>=1;j--)
    {
      if (S[i][j]=='#') R[i][j]=0;
      else 
      {
        if (j==W) R[i][j]=1;
        else R[i][j]=R[i][j+1]+1; 
      }
    } 
  }
  
  for (int i=1;i<=H;i++)
  {
    for (int j=1;j<=W;j++)
    {
      if (S[i][j]=='#') T[i][j]=0;
      else 
      {
        if (i==1) T[i][j]=1;
		else T[i][j]=T[i-1][j]+1;
      }
    }
  }
  
  for (int i=H;i>=1;i--)
  {
    for (int j=1;j<=W;j++)
    {
      if (S[i][j]=='#') D[i][j]=0;
      else 
      {
        if (i==H) D[i][j]=1;
        else D[i][j]=D[i+1][j]+1; 
      }
    } 
  }
  /*
  for (int i=1;i<=H;i++)
  {
    for (int j=1;j<=W;j++)
    {
      cout<<"("<<i<<","<<j<<")=";
      cout<<T[i][j]<<" "<<D[i][j]<<endl;
    }
  }*/
  
  int mx=0;
  int light;
  for (int i=1;i<=H;i++)
  {
    for (int j=1;j<=W;j++)
    {
      light = L[i][j]+R[i][j]+T[i][j]+D[i][j];
      mx = max(mx,light);
    }
  }
  
  cout<<mx-3<<endl;
}

Measured memory_bytes: 67840
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = read_str()
K = read_int()[0]

def solve():
    ans = ""
    sk = S[K - 1]
    for i in range(N):
        if S[i] != sk:
            ans += "*"
        else:
            ans += S[i]
    return ans

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 4076
// https://atcoder.jp/contests/agc029/tasks/agc029_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  multiset<ll> as;
  rep(i, N) {
    ll a;
    cin >> a;
    as.insert(a);
  }

  ll res = 0;

  while (!as.empty()) {
    auto num_it = --as.end();
    ll num = *num_it;

    ll sum = 1;
    while (sum <= num) sum *= 2;

    ll pair = sum - num;
    auto pair_it = as.find(pair);

    if (pair_it != as.end() && !(num_it == pair_it && as.count(num) == 1)) {
      res++;
      as.erase(pair_it);
    }

    as.erase(num_it);
  }

  cout << res << endl;
}

void solve2() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll res = 0;

  map<ll, ll> m;
  rep(i, N) m[-as[i]]++;

  auto dec = [&](ll val) {
    m[val]--;
    if (m[val] == 0) m.erase(val);
  };

  while (!m.empty()) {
    ll num = -m.begin()->first;
    dec(-num);

    ll sum = 1;
    while (sum <= num) sum *= 2;

    ll p = sum - num;

    if (m.count(-p)) {
      res++;
      dec(-p);
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

int h, w;
int a[80][80];
bool dp[80][80][2 * 80 * 80 + 1];

int solve() {
  const int kmax = 2 * 80 * 80;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int diff = a[i][j];
      if (i == 0 && j == 0) {
        dp[i][j][diff] = true;
      } else {
        for (int k = 0; k <= kmax; ++k) {
          for (int type : { 1, -1 }) {
            int pk = k + type * diff;
            if (pk < 0) pk = -pk;
            if (pk > kmax) continue;
            bool u = i == 0 ? false : dp[i - 1][j][pk];
            bool l = j == 0 ? false : dp[i][j - 1][pk];
            if (!u && !l) continue;
            dp[i][j][k] = true;
          }
        }
      }
    }
  }
  
  for (int k = 0; k <= kmax; ++k) {
    if (dp[h - 1][w - 1][k]) return k;
  }
  return 1e9;
}

void input() {
  cin >> h >> w;
  int tmp[80][80];
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> tmp[i][j];
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int buf;
      cin >> buf;
      a[i][j] = abs(buf - tmp[i][j]);
    }
  }
}

int main() {
  input();
  cout << solve() << endl;
}

Measured memory_bytes: 79488
(defun shift-only (n a)
  (let ((res 0)
        (exist-odd nil))
    (loop
       (dotimes (i n)
         (if (not (zerop (rem (aref a i) 2)))
             (setf exist-odd t)))
       (if (eq exist-odd t) (return))
       (dotimes (i n)
         (setf (aref a i) (/ (aref a i) 2)))
       (incf res))
    res))

(defun create-data ()
  (let* ((n (read))
         (a (make-array `(,n))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (values n a)))

(multiple-value-bind (n a) (create-data)
  (format t "~A~%" (shift-only n a)))

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<vector<int>> vecA(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vecA.at(i).at(j);
    }
  }
  
  vector<vector<int>> vecB(M,vector<int>(2));
  for(int k=0; k<M; k++){
    for(int l=0; l<2; l++){
      cin >> vecB.at(k).at(l);
    }
  }
  
  for(int m=0; m<N; m++){
    long ans = 10000000000;
    int abs_x = 0;
    int ans_x = 0;
    for(int n=0; n<M; n++){
     abs_x = abs(vecA.at(m).at(0) - vecB.at(n).at(0)) + abs(vecA.at(m).at(1) - vecB.at(n).at(1));
      if(ans > abs_x){
     ans = abs_x;
     ans_x = n+1;
      }
    }
    cout << ans_x << endl;
  }
       
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

int main()
{
  ll N;
  cin >> N;
  string S;
  cin >> S;

  if (N % 2 == 1)
    FINALANS("No");

  cout << ((S.substr(0, N / 2) == S.substr(N / 2, N / 2)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int W = scanner.nextInt();
		int H = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int r = scanner.nextInt();
		if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 26396
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int n = sc.nextInt();
        Data[] d = new Data[n];
        for(int i = 0; i < n; i++) {
            d[i] = new Data(sc.next(), sc.nextInt());
        }
        Arrays.sort(d);
        for(int i = 0; i < n; i++) {
            System.out.println(d[i].id);
        }
    } 
    static class Data implements Comparable<Data> {
        static int ID = 1;
        int id;
        String s;
        int p;
        Data(String a, int b) {
            s = a;
            p = b;
            id = ID++;
        }

        public int compareTo(Data o) {
            if(s.equals(o.s)) return -this.p + o.p;
            return s.compareTo(o.s);
        }        
    }
}

Measured memory_bytes: 21716
#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++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=1e5+10;

int x[10][10];

int main(){
  int n, d;
  cin>>n>>d;
  rep(i,n)rep(j,d)cin>>x[i][j];

  int ans=0;
  rep(i,n)rep(j,n)if(i<j){
    int ds=0;
    rep(k,d)ds+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
    int dist = sqrt(ds);
    if(dist*dist == ds)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
long long int X;
long long int XX = 100;
int count = 0;
  
    scanf("%lld", &X);

    while(XX < X){
      count += 1;
      XX = XX * 1.01;
    }

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


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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}

int main() {
  int n,k;cin>>n>>k;
  string s;cin>>s;
  s[k-1]=s[k-1]-('A'-'a');
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,c,k,ans;
signed main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	if(k<=a)
	{
		printf("%lld",k);
		return 0;
	}
	k-=a;
	ans+=a;
	if(k<=b)
	{
		printf("%lld",a);
		return 0;
	}
	k-=b;
	printf("%lld",ans-k);
    return 0;
}

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

int main(){
	long long N,digit,i,j;
	long long result=0;
	string S,T;
	cin>>N;
	cin>>S;
	
	for(i=0;i<1000;i++){
		digit=0;
		T=to_string(i);
		if(T.size()==1)T="00"+T;
		if(T.size()==2)T='0'+T;
		for(j=0;j<N;j++){
			if(S[j]==T[digit]){
				digit++;
			}
			if(digit>=3){
				result++;
				break;
			}
		}
	}
	cout<<result<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define ll long long
#define m 100005 
#define min(a,b) a<b ? a : b

int main()
{
	ll n;
	scanf("%lld",&n);
	ll ar[m],dp[m];
	for(int i = 1; i<=n ; i++)
		scanf("%lld",&ar[i]);

	dp[1] = 0;
	
	for(ll i = 2; i<=n; i++)
	{
		dp[i] = dp[i-1] + fabs(ar[i] - ar[i-1]);
		if(i > 2)
			dp[i] = min(dp[i], dp[i-2] + fabs(ar[i-2] - ar[i])); 
	}
	
	printf("%lld\n",dp[n]);	
}

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

int main(){
  int a, b = 0;
  double x_d = 0.0;
  cin >> a >> b;
  x_d = (a+b)/2.0;
  double q = 0;
  q = x_d-(a+b)/2;
  int x_i = 0;
  x_i = (a+b)/2+2*q;
  cout << x_i << endl;
}

Measured memory_bytes: 256
Module Module1

    Sub Main()
        'let'
        Dim N As Long = Console.ReadLine()
        Dim A() As String = Console.ReadLine().Split()

        'var'
        Dim ans As Long = Long.MaxValue

        For i As Long = 0 To N - 1
            'var'
            Dim cnt As Long = 0
            Dim j As Long = CLng(A(i))

            While j Mod 2 = 0
                cnt += 1
                j \= 2
            End While

            ans = Math.Min(ans, cnt)
        Next

        Console.WriteLine(ans)

    End Sub

End Module


Measured memory_bytes: 13252
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>

typedef long long ll;
ll c[60][60];
ll odd,even,n,p,x,ans;

int main(){
    for(int i=0;i<=51;i++){
        c[i][0]=c[i][i]=1;
    }for(int i=2;i<=50;i++){
        for(int j=1;j<i;j++){
            c[i][j]=c[i-1][j]+c[i-1][j-1];
        }
    }
    scanf("%lld %lld",&n,&p);
    for(int i=1;i<=n;i++){
        scanf("%lld",&x);
        if(x&1) odd++;
        else even++;
    }if(p&1){
        for(int i=1;i<=odd;i+=2){
            ans+=c[odd][i];
        }printf("%lld\n",ans<<even);
    }else{
        for(int i=0;i<=odd;i+=2){
            ans+=c[odd][i];
        }printf("%lld\n",ans<<even);
    }return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int a[4];
  int b[4];
  int i, j;

  for(;;)
    {
      int hit=0, blow=0;

      if(scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) == EOF)
	break;
      scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
      
      for(i = 0; i < 4; i++)
	for(j = 0; j < 4; j++)
	  if(a[i] == b[j])
	    {
	      if(i == j)
		hit++;
	      else
		blow++;
	    }
      
      printf("%d %d\n", hit, blow);
      
    }
  
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld ",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define fo(i,a,b) for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define ll long long
const int M=1e9+7;
#define endl "\n"
const double pyi=3.14159265358979323846;




int main() 
{ 
    string st1,st2;
    cin>>st1;
    cin>>st2;

    int l=st1.size();
    int temp=0;
    fo(i,0,l)
    {
    	if(st1[i]!=st2[i])
    	{
    		temp=1;
    	}
    }
    if(temp==1)
    {
    	d1("No");
    }
    else
    {
    	d1("Yes");
    }
    return(0);
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;
const int maxn=1e5+5;
ll ans=1ll;
long long inf=1e18;
int n;
ll a[maxn];
int main()
{
	cin>>n;
	bool flag=0;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		if(a[i]==0)flag=1;
	}
	if(flag)
	{
		cout<<0;return 0;
	}
	for(int i=1;i<=n;++i)
	{
		if(inf/a[i]<ans)
		{
			cout<<-1<<endl;
			return 0;
		}
		ans*=a[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

long double distance(int x1, int y1, int x2, int y2){
  int X=(x1-x2)*(x1-x2);
  int Y=(y1-y2)*(y1-y2);
  long double D=pow((long double)X+Y, 0.5);
  return D;
}

int fact(int n){
  if (n==1) return 1;
  else return n*fact(n-1);
}

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for(int i=0; i<N; i++) cin >> x[i] >> y[i];
  
  vector<int> num(N); for(int i=0; i<N; i++) num[i]=i;
  
  long double sum=0;
  do{
    for(int i=0; i+1<N; i++) sum+=distance(x[num[i]], y[num[i]], x[num[i+1]], y[num[i+1]]);
  }while(next_permutation(num.begin(), num.end()));
  
  long double ans=(long double)sum/fact(N);
  cout << fixed << setprecision(10) << ans <<endl;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  REP(i,3){
	string s;
	cin >> s;
	cout << (char)(s[0] -'a' + 'A');
  }
  cout  << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,s,t;
  cin >> n >> s >> t;
  s--,t--;
  vector<int> v[n];
  rep(i,n-1) {
    ll x,y;
    cin >> x >> y;
    x--,y--;
    v[x].pb(y);
    v[y].pb(x);
  }
  int d[2][n];
  rep(k,2) {
    fill(d[k],d[k]+n,MAX);
    queue<int> que;
    if(k==0) {
      d[k][s]=0;
      que.push(s);
    } else {
      d[k][t]=0;
      que.push(t);
    }
    while(!que.empty()) {
      int x=que.front();que.pop();
      rep(i,v[x].size()) {
        int y=v[x][i];
        if(d[k][y]==MAX) {
          d[k][y]=d[k][x]+1;
          que.push(y);
        }
      }
    }
  }
  int ans=0;
  rep(i,n) {
    if(d[0][i]<=d[1][i]) ans=max(ans,d[1][i]-1);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 6656
import math
from decimal import *

n = int(input())
l = [[int(i) for i in input().split()] for j in range(n)]

def newT(t, ratio):
    a = Decimal(t[0]) / Decimal(ratio[0])
    b = Decimal(t[1]) / Decimal(ratio[1])
    if a <= 1 and b <= 1:
        return ratio
    else:
        c = math.ceil(max([a, b]))
        return [i*c for i in ratio]

to = l[0]
for li in l[1:]:
    to = newT(to, li)

print(to[0]+to[1])


Measured memory_bytes: 5032
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int D = scanner.nextInt();
        long[] X = new long[N];
        long[] Y = new long[N];
        int count = 0;

        for (int i = 0 ; i < N ; i++) {
            X[i] = scanner.nextLong();
            Y[i] = scanner.nextLong();

            double distance = Math.sqrt(X[i] * X[i] + Y[i] * Y[i]);
            if (distance <= D) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 64460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct Node{
    int v;
    Node *l, *r;
};

Node* new_node(){
    Node *ret;
    ret = (Node*)malloc(sizeof(Node));
    ret->l = NULL;
    ret->r = NULL;
    return ret;
}

void dfs(string s, Node *root){
    // dbg(s);
    int n = s.size();

    int d = 0;
    int lidx,ridx;
    rep(i,n){
        if(s[i]=='(') ++d;
        if(s[i]==')') --d;

        if(s[i]=='['){
            if(d==0){
                lidx = i;
                ridx = i;
                while(s[ridx]!=']') ++ridx;
                break;
            }
        }
    }

    int val = 0;
    for(int i=lidx+1; i<ridx; ++i) val = val*10 + s[i]-'0';

    string ls = "", rs = "";
    for(int i=1; i<lidx-1; ++i) ls += s[i];
    for(int i=ridx+2; i<n-1; ++i) rs += s[i];

    root->v = val;

    if(ls!=""){
        root->l = new_node();
        dfs(ls,root->l);
    }
    if(rs!=""){
        root->r = new_node();
        dfs(rs,root->r);
    }
}

void merge(Node *a, Node *b, Node *c){
    c->v = a->v + b->v;
    if(a->l!=NULL && b->l!=NULL){
        c->l = new_node();
        merge(a->l,b->l,c->l);
    }
    if(a->r!=NULL && b->r!=NULL){
        c->r = new_node();
        merge(a->r,b->r,c->r);
    }
}

string recover(Node *root){
    if(root == NULL) return "";

    string ret = "";

    ret += '(';
    ret += recover(root->l);
    ret += ')';

    ret += '[';
    ret += to_string(root->v);
    ret += ']';

    ret += '(';
    ret += recover(root->r);
    ret += ')';

    return ret;
}

int main(){
    string a,b;
    cin >>a >>b;

    Node *ra, *rb;

    ra = new_node();
    dfs(a,ra);

    rb = new_node();
    dfs(b,rb);

    Node *rc;
    rc = new_node();
    merge(ra,rb,rc);

    cout << recover(rc) << endl;
    return 0;
}



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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code
int main(int argc, char const* argv[])
{
	string s;
	int k;
	cin >> s >> k;
	set<string> strs;
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < s.size() - i + 1; j++) {
			strs.insert(s.substr(j,i));
		}
	}
	int i = 0;
	for (auto&& var : strs) {
		if (i == k-1) cout << var << endl;
		i++;
	}
	return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <math.h>

int main(void) {
	double harada_hitomi = atan(1) * 4.0;
	double r;
	if (scanf("%lf", &r) != 1) return 1;
	printf("%.15f %.15f\n", r * r * harada_hitomi, 2.0 * r * harada_hitomi);
	return 0;
}



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

using namespace std;


int main(){
	
	int A, B, T, T_A, sum;
	sum = 0;
	cin >> A >> B >> T;
	T_A = T / A;
	for (int i = 0; i < T_A; i++) {
		sum = sum + B;
	}
	cout << sum << endl;

	return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool check_prime(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int setbits(int n)
{
    int count=0;
    while(n)
    {
        if(n%2==1)
            count++;
        n>>=1;
    }
    return count;
}

int lcm(int a,int b)
{
    return (a*b)/__gcd(a,b);
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}


int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int a,b;
    cin>>a>>b;
    if(500LL*a>=b)
    cout<< "Yes";
    else cout<< "No";

    return 0;
}


Measured memory_bytes: 256