akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input!(
        h: usize,
        w: usize,
        a: [String; h],
    );

    let a: Vec<Vec<char>> = a.iter().map(|aa| aa.chars().collect::<Vec<char>>()).collect();
    let dx = vec![1, 0, -1, 0];
    let dy = vec![0, 1, 0, -1];

    let mut dist = vec![vec![-1; w]; h];

    let mut queue: VecDeque<(usize, usize)> = VecDeque::new(); 

    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '#' {
                dist[i][j] = 0;
                queue.push_back((i, j));
            }
        }
    }

    loop {
        match queue.pop_front() {
            Some((x, y)) => {
                for i in 0..4 {
                    let nx = x as isize + dx[i];
                    let ny = y as isize + dy[i];
                    if nx < 0 || ny < 0 { continue; }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if nx >= h || ny >= w { continue; }
                    if dist[nx][ny] == -1 {
                        dist[nx][ny] = dist[x][y] + 1;
                        queue.push_back((nx, ny));
                    }
                }
            },
            None => break,
        }
    }

    let ans = dist.iter().map( |aa| aa.iter().max().unwrap() ).max().unwrap();
    println!("{:?}", ans);
}


Measured memory_bytes: 27660
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}
int size[2100][2100]={};
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b=0;
    cin>>a;
    for(int i=1;i<a;i++){
	b++;
    }
    b-=1;
    cout<<(b+1)/2<<"\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_N = 1e2+10;

int main(int argc, char const *argv[])
{
    int n, x, l[MAX_N]={0};
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    int d[MAX_N]={0}, ans = 1;

    for (int i = 0; i < n; ++i) {
        d[i+1] = d[i]+l[i];
        if (d[i+1]>x) break;
        ans++;
    }

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

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

def readlines(n):
    for i in range(n):
        for j, x in enumerate(input().split()):
            yield int(x), (i, j)


def main():
    N = int(input())
    K = int(input())

    for x in (map(int, input().split())):
        yield min(x, K - x) * 2

print(sum(main()))


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long
#define MOD 1000000007

int main(){
  string S;
  cin>>S;
  int n=S.size();
  LINT dp[n+1][4]={}; //残りの処理数[処理した文字数][付けた丸の数]
  REP(i, 3) dp[n][i]=0;
  dp[n][3]=1;
  string abc="ABC";

  for(int i=n-1; i>-1; --i){
    dp[i][3] = (dp[i+1][3] * (S[i]=='?' ? 3 : 1))%MOD;
    REP(j, 3){
      dp[i][j] = (dp[i+1][j] * (S[i]=='?' ? 3 : 1)
               + dp[i+1][j+1] * (S[i]=='?' || S[i]==abc[j] ? 1 : 0))%MOD;
    }
  }
  cout << dp[0][0] <<endl;


  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <numeric>
#include <climits>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm> 
#include <map> 
#include <set>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{"; for(auto nth : list){ cout << nth << " ";}cout << "}" << endl;

using namespace std;

template<class T> T MIN(const T& a, const T& b) { return a < b ? a : b; }
template<class T> T MAX(const T& a, const T& b) { return a > b ? a : b; }
template<class T> void MIN_UPDATE(T& a, const T& b) { if (a > b) a = b; }
template<class T> void MAX_UPDATE(T& a, const T& b) { if (a < b) a = b; }


struct data{
	data(int a,int b){
		length=a;
		id=b;
	}
	int length;
	int id;
};

vector<data> sys;

void write(int id,int len){
	if(sys.size()==0){
		sys.push_back(data(len,id));
	}else{
		int n=sys.size();
		rep(i,n){
			if(len<=0) return;
			if(sys[i].id==-1){
				if(len-sys[i].length==0){
					sys[i].id=id;
					len-=sys[i].length;
				}else if(len-sys[i].length<0){ //length???????????§??????
					sys.insert(sys.begin()+i+1,data(sys[i].length-len,-1));
					sys[i].id=id;
					sys[i].length=len;
					return;
				}else if(len-sys[i].length>0){
					sys[i].id=id;
					len-=sys[i].length;
				}
			}
		}
		if(len>0){//????????????????´???????????????§????????¨??????????????????????????????
				sys.push_back(data(len,id));	
		}

	}
}

void read(int id){
	int len=0;
//	rep(i,sys.size()){
//		cout << sys[i].id << ":" << sys[i].length << " ";
//	}
//	cout << endl;

	rep(i,sys.size()){
		len+=sys[i].length;
		if(len>id){
			cout <<  sys[i].id << endl;
			return;
		}
	}
	
	cout << -1 << endl;
}

void del(int id){
	rep(i,sys.size()){
		if(sys[i].id==id){
			sys[i].id=-1;
		}
	}
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;
		sys.clear();
		
		rep(i,n){
			char c;
			int I,S;
			cin >> c;
		
			if(c=='D'){
				cin >> I;
				del(I);
			}else if(c=='W'){
				cin >> I >> S;
				write(I,S);
			}else if(c=='R'){
				cin >> I;
				read(I);
			}		
		
		}
		cout << endl;
	}
}

Measured memory_bytes: 1304
#include <stdio.h>

int main()
{
        int a,b,c,d;

        scanf("%d %d %d %d", &a, &b, &c, &d);
        printf("%d\n", (a+b+c+d)/60);
        printf("%d\n", (a+b+c+d) - (a+b+c+d)/60*60);

        return 0;

}

Measured memory_bytes: 0
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=2e5;
int n,x,y,tot;
int pre[maxn*4+8],son[maxn*4+8];
bool can[maxn+8];
queue<int>st;

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

struct Tree
{
    int now[maxn+8],dep[maxn+8],f[maxn+8][20];
    void add(int u,int v)
    {
	pre[++tot]=now[u];
	now[u]=tot;
	son[tot]=v;
    }
    void build(int x)
    {
	dep[x]=dep[f[x][0]]+1;
	for (int i=1;i<=log(dep[x])/log(2);i++) f[x][i]=f[f[x][i-1]][i-1];
	for (int p=now[x];p;p=pre[p])
	    {
		int child=son[p];
		if (f[x][0]==child) continue;
		f[child][0]=x;
		build(child);
	    }
    }
    int Get_Lca(int x,int y)
    {
	if (dep[x]<dep[y]) swap(x,y);
	for (int i=log(dep[x])/log(2);~i;i--)
	    if (dep[f[x][i]]>=dep[y]) x=f[x][i];
	if (x==y) return x;
	for (int i=log(dep[x])/log(2);~i;i--)
	    if (f[x][i]!=f[y][i]) x=f[x][i],y=f[y][i];
	return f[x][0];
    }
    int Get_Dis(int x,int y){return dep[x]+dep[y]-dep[Get_Lca(x,y)]*2;}
}T1,T2;

void solve()
{
    //for (int i=1;i<=n;i++) printf("%d ",can[i]);puts("");
    int ans=0;
    for (int i=1;i<=n;i++)
	if (can[i])
	    {
		ans=max(ans,T2.dep[i]-1);
		for (int p=T1.now[i];p;p=pre[p])
		    {
			int child=son[p];
			if (T2.Get_Dis(child,i)>2)
			    {
				puts("-1");
				exit(0);
			    }
		    }
	    }
    printf("%d\n",ans*2);
}

void prepare()
{
    can[x]=1;
    st.push(x);
    while(!st.empty())
	{
	    int x=st.front();st.pop();
	    for (int p=T1.now[x];p;p=pre[p])
		{
		    int child=son[p];
		    if (can[child]) continue;
		    if (T1.dep[child]<T2.dep[child]) can[child]=1,st.push(child);
		}
	}
}

int main()
{
    n=read(),x=read(),y=read();
    if (x==y)
	{
	    puts("0");
	    return 0;
	}
    for (int i=1;i<n;i++)
	{
	    int u=read(),v=read();
	    T1.add(u,v),T1.add(v,u);
	}
    for (int i=1;i<n;i++)
	{
	    int u=read(),v=read();
	    T2.add(u,v),T2.add(v,u);
	}
    T1.build(x),T2.build(y);
    prepare();
    solve();
    return 0;
}


Measured memory_bytes: 46976
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <fstream>
#include <set>
#define mp make_pair
#define Debug(...) fprintf(stdout, __VA_ARGS__)

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef set<pli>::reverse_iterator sit;

const int MAXN = 1e5 + 7;

inline void proc_status() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

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

int n, rt;
set<pli> D;

int f[MAXN], siz[MAXN];
LL dis[MAXN], sum[MAXN];
bool vis[MAXN];
int dex, head[MAXN], to[MAXN], nxt[MAXN];

inline void Link(int x, int y) { nxt[++dex] = head[x]; to[dex] = y; head[x] = dex; }

void dfs(int u) {
	vis[u] = 1;
	for(int i = head[u]; i; i = nxt[i]) {
		int v = to[i];
		if(vis[v]) { puts("-1"); exit(0); }
		dfs(v);
		sum[u] += sum[v] + siz[v];
	}
}

inline void init() {
	n = read<int>();
	for(int i = 1; i <= n; ++i) {
		D.insert(mp(read<LL>(), i));
	}
	rt = (*D.begin()).second;
}

inline void solve() {
	int cnt = 0;
	for(sit it = D.rbegin(); it != D.rend(); ++it) {
		int u = (*it).second;
		dis[u] = (*it).first;
		++siz[u];
		if(u == rt) break;
		LL nxt = dis[u] + (siz[u] << 1) - n;
		pli fa = (*D.lower_bound(mp(nxt, 0)));
		if(fa.first == nxt) {
//			printf("%d %d\n", fa.second, u);
//			printf("Linked\n\n");
			f[u] = fa.second;
			Link(f[u], u);
			siz[f[u]] += siz[u];
		}
//		if(siz[f[u]] == n) { rt = f[u]; break; }
	}

//	cout << rt << endl;
//	exit(0);
	dfs(rt);
	if(dis[rt] != sum[rt]) {
		puts("-1");
		exit(0);
	}
	for(int i = 1; i <= n; ++i) if(i != rt) {
		printf("%d %d\n", i, f[i]);
	}
}

int main() {

	init();
	solve();

	return 0;
}



Measured memory_bytes: 12800
#include<cstdio>
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cctype>
#include<vector>
#include<ctime>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
#define fi first
#define se second
using namespace std;
LL n;
inline int read(){
	int v = 0,c = 1;char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-') c = -1;
		ch = getchar();
	}
	while(isdigit(ch)){
		v = v * 10 + ch - 48;
		ch = getchar();
	}
	return v * c;
}
int main(){
	n = read();
	LL ans = n * (n - 1) / 2;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl; }

const LL INF = 1LL << 60;

int main(void) {
	double A, B;
	cin >> A >> B;

	if (A == B) {
		cout << 0 << endl;
	}
	else if (ceil((A + B) / 2) == floor((A + B) / 2)) {
		printf("%.0lf", (A + B) / 2);
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
using namespace std;
int main() {
    string ss, tt;
    cin >> ss;
    cin >> tt;
    bool ans = true;
    for(int i = 0; i < ss.size(); ++i) {
        if(ss[i] != tt[i])
            ans = false;
    }
    if(ans)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3596
A = int(input())
import collections
total = 0
listN = list(map(int,input().split()))
dic = collections.Counter(listN)
listB = list(dic.values())
for i in listB:
    total += i * (i-1) // 2
dic_keys = list(dic.keys())
dic_values = list(dic.values())
for i in range(len(dic_values)):
    B = dic_values[i]
    dic_values[i] = total-(B-1)
dic = {}
for i in range(len(dic_values)):
    dic[dic_keys[i]] = dic_values[i]
for i in listN:
    print(dic[i])

Measured memory_bytes: 32060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
double dp[3000][3000];
int main()
{
    int n;
    cin >> n;
    vector<double> prob(n);
    for (int i = 0; i < n; i++)
        cin >> prob[i];
    dp[0][0] = 1.0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= i; j++)
        {
            dp[i + 1][j + 1] += dp[i][j] * prob[i];
            dp[i + 1][j] += dp[i][j] * (1.0 - prob[i]);
        }
    }
    double res = 0.0;
    for (int j = (n + 1) / 2; j <= n; j++)
        res += dp[n][j];
    cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 68864
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <unordered_map>

using namespace std;

#define int long long
#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 range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using ll=long long;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
//int read(){int a;scanf("%lld",&a);return a;}

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

signed main()
{
	int N, K, S; cin >> N >> K >> S;
	rep(i, K) printf("%lld ", S);
	rep(i, N-K) printf("%d ", S == TEN(9) ? TEN(9) - 1 : TEN(9));
	puts("");
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n;
    cin>>n;
    long long int b[n-1];
    for(long long int i=0;i<n-1;i++)cin>>b[i];
    long long int a[n];
    a[0]=b[0];
    for(long long int i=1;i<=n-2;i++)
    {
        a[i]=min(b[i-1],b[i]);
    }

    a[n-1]=b[n-2];
    long long int sum=0;
    for(auto x:a)sum+=x;
    cout<<sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


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

long N;
string S;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin >> N;
    cin >> S;
    long cnt;
    long ans = 1e6;
    for(int i=0; i<N; i++){
        if(S[i]=='E') cnt++;
    }
    for(int i=0; i<N; i++){
        //cout << S[i] << endl;
        if(S[i]=='E'){
            ans = min(ans, --cnt);
        }else{
            ans = min(ans, cnt++);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w;
    cin>>h>>w;
    h+=2; w+=2;
    vs f(h,string(w,'#'));
    rep(i,h-2){
        string t; cin>>t;
        f[i+1]="#"+t+"#";
    }
    ll sy,sx;
    ll ans=0;
    rep(i,h)rep(j,w)if(f[i][j]=='.'){
        sy=i,sx=j;
        vvl cost(h,vl(w,-1));
        queue<tlll> q;
        q.emplace(sy,sx,0);
        while(!q.empty()){
            ll y,x,c; tie(y,x,c)=q.front(); q.pop();
            if(cost[y][x]!=-1)continue;
            cost[y][x]=c;
            rep(v,4){
                if(f[y+dy[v]][x+dx[v]]=='.' and cost[y+dy[v]][x+dx[v]]==-1)q.emplace(y+dy[v], x+dx[v], c+1);
            }
        }
        ll v=0;

        rep(i,h)rep(j,w)if(f[i][j]=='.')chmax(v,cost[i][j]);
        chmax(ans,v);
    }
    puta(ans);

    return 0;
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad

solve :: Int -> Int
solve n =
    let f m = filter (\d -> m `mod` d == 0) [1 .. m]
    in length $ filter ((== 8) . length) $ fmap f [1, 3 .. n]

main :: IO ()
main = do
    n <- readLn
    print $ solve n

Measured memory_bytes: 508
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 2100000000
using namespace std;
int main(void)
{
	int n,i,x,h[100000],dp[100001];
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&h[i]);
	for(i=0;i<=n;i++)	dp[i]=MM;
	dp[0]=0;
	for(i=0;i<n-1;i++)	{
		x=h[i+1]-h[i];
		if(x<0)	x=-x;
		dp[i+1]=min(dp[i]+x,dp[i+1]);
		x=h[i+2]-h[i];
		if(x<0)	x=-x;
		dp[i+2]=min(dp[i]+x,dp[i+2]);		
	}
	printf("%d\n",dp[n-1]);
	return 0;
}

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

int main() {
  int N, A, B, plan1, plan2;
  cin >> N >> A >> B;
  plan1 = A * N;
  plan2 = B;
  
  if (plan2 >= plan1)
    cout << plan1 << endl;
  else
  	cout << plan2 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
int a[21], b[21];

int ans;

int main()
{
 cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    cin >> b[i];
  for (int i = 1; i <= n; i++)
  {
   if (a[i] > b[i])
     ans += a[i] - b[i];
  }
  cout << ans;
return 0;
}

Measured memory_bytes: 256
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    n = int(input())
    S = [i for i in MI()]
    
    q = int(input())
    T = [i for i in MI()]
    
    ret = 0
    for t in T:
        if t in S:
            ret += 1
            
    print(ret)

if __name__ == "__main__":
    main()


Measured memory_bytes: 7896
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

signed main(){
	IOS;
	int n;
	cin >> n;
	if(n == 22)dump("Christmas Eve Eve Eve");
	if(n == 23)dump("Christmas Eve Eve");
	if(n == 24)dump("Christmas Eve");
	if(n == 25)dump("Christmas");
}	

Measured memory_bytes: 256
/*********************************
*include
*********************************/
#include <stdio.h>

/*********************************
*define
*********************************/
#define PI ( 3.141592653589 )	/* ?????¨??? */

/*********************************
*function
*********************************/
int main( void )

{
	double r;
	double area;
	double circum;
char ch;
	scanf( "%lf", &r );
	
	area = ( r * r ) * PI;		/* ??¢??? */
	circum = ( 2 * r ) * PI;	/* ?????¨ */
	
	printf( "%.7f %.7f\n", area, circum );
while( (ch = getchar())!=EOF );
	return 0;
}

Measured memory_bytes: 656
n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
cnt=0
for i in range(n):
    if a[i]>=b[i]:
        cnt += b[i]
        a[i] -= b[i]
    else:
        cnt += a[i]
        b[i]-=a[i]
        a[i]=0
        if b[i] <= a[i+1]:
            a[i+1] -= b[i]
            cnt += b[i]
        else:
            cnt += a[i+1]
            a[i+1]=0
print(cnt)

Measured memory_bytes: 18624
n = int(input())
a_list = list(map(int, input().split()))

sum_a = 0
for a in a_list:
    sum_a += a

sub_sum_a = 0

for index in range(len(a_list)):
    middle_index_big = index
    sub_sum_a += a_list[index]
    if sub_sum_a >= (sum_a // 2):
        break

diff_big_index = abs(sub_sum_a - (sum_a - sub_sum_a))
sub_sum_a_small = sub_sum_a - a_list[middle_index_big]
diff_small_index = abs(sub_sum_a_small - (sum_a - sub_sum_a_small))

diff = min(diff_big_index, diff_small_index)
print(diff)


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

//dp[i] = True if the first player wins if there are i stones remaining
int main(void)
{
	int n,k;
	cin >> n;
	cin >> k;

	vector<int> arr;
	for(int i = 0;i < n;i++)
	{
		int u;
		cin >> u;
		arr.push_back(u);
	}

	vector<bool> dp(k+1);

	for(int stones = 0;stones <= k;++stones)
	{
		for(int i = 0;i < n;i++)
		{
			if(arr[i] <= stones && !dp[stones-arr[i]])
				dp[stones] = true;
		}
	}

	if(dp[k] == 1)
		cout << "First";
	else
		cout << "Second";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define prique priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, B[100]; cin >> N;
  REP(i, N-1) cin >> B[i];
  int ans = B[0]+B[N-2];
  REP(i, N-2){
    ans += min(B[i], B[i+1]);
  }
  cout << ans << endl;
}

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

using namespace std;

const long long int INF=1e9;

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> rs(R);
    for(int r=0; r<R; r++) {
        cin >> rs[r];
    }
    sort(rs.begin(), rs.end());
    
    vector<vector<long long int> > C(N+1, vector<long long int>(N+1, INF));
    for(int m=0; m<M; m++) {
        long long int a, b, c;
        cin >> a >> b >> c;
        C[a][b] = c;
        C[b][a] = c;
    }

    for(int k=1; k<=N; k++) {
        for(int i=1; i<=N; i++) {
            for(int j=1; j<=N; j++) {
                C[i][j] = min(C[i][j], C[i][k]+C[k][j]);
            }
        }
    }
    
    long long int ans=INF;
    do {
        // for(int r=0; r<R; r++) {
        //     cout << rs[r] << " ";
        // }
        // cout << endl;

        long long int tmp=0;
        for(int r=1; r<R; r++) {
            tmp += C[rs[r-1]][rs[r]];
        }
        ans = min(ans, tmp);
    } while(next_permutation(rs.begin(), rs.end()));
    
    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 512
/*input
2
1 1
*/

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                int x = a[i], y = a[j], z = a[k];
                if (x == y || y == z || z == x) continue;
                if (abs(x-y) < z && z < x+y) ans++;
            }
        }
    }
    cout << ans << endl;
}

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

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rep2(i,a,b,c) for(i=a;i<=b;i+=c)
#define maxn 100000
#define ll long long
ll mod=(ll)1000000007;
ll fact[maxn+1];

void prekom(){
	fact[0]=1;
	int i;
	rep(i,1,maxn){
		fact[i]=(fact[i-1]*(ll)i)%mod;
	}
}

int main(){
	prekom();
	int N,M;
	cin>>N>>M;
	if(abs(N-M) > 1){
		cout<<"0\n";
	}
	else if(N==M){
		cout<<(fact[N]*fact[M]*(ll)2)%mod<<"\n";
	}
	else{
		cout<<(fact[N]*fact[M])%mod<<"\n";
	}
}


Measured memory_bytes: 4408
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
struct edge{int from, to; ll cost;};

signed main(){
	ll a,b,c;
	cin >>a >> b >> c;
	if(a == b && b == c && a % 2 == 0) cout << "-1";
	else{
		ll cnt = 0;
		while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
			ll aa = a/2, bb = b/2, cc = c/2;
			a = bb+cc;
			b = cc+aa;
			c = aa+bb;
			cnt++;
		}
		cout << cnt;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define MAXN 1000007
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
 
using namespace std;

int main()
{
    fastio;
    int T = 1;
    //cin>>T;
    while(T--){
        ll n, m;
        cin>>n>>m;
        if(m==n) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }                
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60;
const ll mod=1e9+7 ;

int main(){
  ll n,x;
  cin >> n >> x;
  ll ans=n;
  n-=x;
  while(x){
    ans+=2*x*(n/x);
    if(n%x==0)ans-=2*x;
    ll temp=n%x;
    n=x;
    x=temp;
  }
  ans+=n;
  cout << ans << endl;
return 0;}

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

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

using ll = long long;

int dp[3100][3100];

int main() {
  string S, T;
  cin >> S >> T;
  int n = S.size();
  int m = T.size();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i==0 || j==0) dp[i][j] = 0;
      if (S.at(i) == T.at(j)) dp[i+1][j+1] = max(dp[i][j]+1, max(dp[i][j+1], dp[i+1][j]));
      else {
        dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
      }
    }
  }
  int i = n;
  int j = m;
  string ans;
  while (i>0&&j>0) {
    if(dp[i][j] == dp[i-1][j]) {
      i--;
    }
    else if(dp[i][j] == dp[i][j-1]) {
      j--;
    }
    else if(dp[i][j] == dp[i-1][j-1]+1) {
      i--;
      j--;
      ans = S.at(i) + ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 37120
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

const int mod = 1000000007;

int main(){
  int N; cin >> N;

  //N文字目まで作る方法（N-1文字目、N-2文字目、N-3文字目の値がそれぞれ記載されているとおりの時）
  int dp[110][4][4][4];

  for(int pos = 0; pos < 110; pos++){
    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
        for(int k = 0; k < 4; k++){
          dp[pos][i][j][k] = 0;
        }
      }
    }
  }

  dp[0][3][3][3]=1;

  for(int pos = 1; pos < N+1; pos++){
    for(int i = 0; i < 4; i++){
      for(int j = 0; j < 4; j++){
        for(int k = 0; k < 4; k++){
          for(int l = 0; l < 4; l++){
            //i , j , k,  l とも A -> 0, C -> 1, G -> 2, T -> 3
            if(i == 1 && j == 2 && k == 0) continue;
            if(i == 1 && j == 0 && k == 2) continue;
            if(i == 2 && j == 1 && k == 0) continue;
            if(i == 1 && j == 2 && l == 0) continue;
            if(i == 1 && k == 2 && l == 0) continue;
            dp[pos][i][j][k] += dp[pos-1][j][k][l];
            dp[pos][i][j][k] %= mod;
          }
        }
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 4; j++){
      for(int k = 0; k < 4; k++){
        ans += dp[N][i][j][k];
        ans %= mod;
      }
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
using namespace std;
const long long mod=1000000007;
int n;
long long pows(long long z,int a){
	if(a==0)return 1;
	long long x=pows(z,a/2);
	x=x*x%mod;
	if(a&1)x=x*z%mod;
	return x;
}
int main(){
	scanf("%d",&n);
	long long x=pows(10,n)-2*pows(9,n)+pows(8,n)+10*mod;
	x%=mod;
	printf("%I64d\n",x);
	return 0;
}


Measured memory_bytes: 1732
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  map<int, int> cnt;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    cnt[x]++;
  }
  vector<int> A;
  for (auto& it : cnt) {
    A.emplace_back(it.second);
  }
  sort(A.begin(), A.end(), greater<int>());
  int ret = 0;
  for (int i = m; i < A.size(); ++i) {
    ret += A[i];
  }
  printf("%d\n", ret);
  return 0;
}


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

int main() {
    int N;
    while (cin >> N, N) {
        N = 1000 - N;
        int v[] = {500, 100, 50, 10, 5, 1};

        int ans = 0;
        for (int i = 0; i < 6; i++) {
            ans += N / v[i];
            N %= v[i];
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  bool res = true;
  int A;
  for (int i = 0; i < N; i++){
    cin >> A;
    if (A % 2 == 0){
      if (A % 3 != 0 && A % 5 != 0){
        res = false;
      }
    }
  }
  cout << (res ? "APPROVED" : "DENIED");
}

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

int search(int v, vector<int>& pp, int pivot) {
  int n = pp.size();
  int result = -1;
  for(int j = n; j > 0; j--) {
    int p = pp.at(j-1);
    if ( p >= pivot ) {
      continue;
    }
    result = p;
    break;
  }
  return result;
}

int check(int v, vector<vector<int>>& pos, vector<bool>& flag) {
  int ok_count = 0;
  for ( auto p : pos.at(v-1) ) {
    int pre = p;
    bool result = true;
    for(int j = v-1; j > 0; j--) {
      int p0 = search(j,pos.at(j-1),pre);
      if ( p0 < 0 ) {
        flag.at(p) = false;
        result = false;
        break;
      }
      else {
        pre = p0;
      }
    }
    if ( result ) {
      ok_count++;
    }
  }
  return ok_count;
}

int main() {
  //input
  int N;
  cin >> N;
  vector<int> a(N);
  vector<vector<int>> pos(N,vector<int>(0));
  int v;
  rep(i,N) {
    cin >> v;
    a.at(i) = v;
    pos.at(v-1).push_back(i);
  }
  //calc
  vector<bool> flag(N,true);
  int answer = -1;
  for(v = N; v > 0; v--) {
    int ok_count = check(v, pos, flag);
    if ( ok_count > 0 ) {
      answer = N - v;
      break;
    }
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 12800
from math import inf


def main():
    s = input()
    t = input()
    tlen = len(t)
    min = inf
    for i in range(len(s) - tlen + 1):
        count = 0
        for j, c in enumerate(s[i:i + tlen]):
            if not t[j] == c:
                count += 1
        if count < min:
            min = count
    print(min)


if __name__ == '__main__':
    main()

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

int main(){
    int n;
    cin >> n;
    pair<pair<string,int>,int> p[101];
    rep(i,n){
        cin >> p[i].first.first >> p[i].first.second;
        p[i].second = i+1;
        p[i].first.second = 100 - p[i].first.second;
    }
    sort(p,p+n);
    rep(i,n) cout << p[i].second << endl;
    return 0;
}

Measured memory_bytes: 256
/*g++ file.cpp -o file.out*/
/*./file.out*/

#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
#define Mod 1000000007
#define L_Mod 17100000013

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))

int s[11][11]= {0};
int visit[11]= {0};
int n,m,a,b,sov=0,sum=0;

void dfs(int x,int dot)
{
    if(dot==n)
    {
        sum++;
        return;
    }
    rep(i,n+1)if(s[x][i]==1&&visit[i]!=1)
    {
        visit[i]=1;
        dfs(i,dot+1);
        visit[i]=0;
    }
    return;
}

int main()
{
    scanf("%d%d",&n,&m);
    rer(i,1,m)
    {
        scanf("%d%d",&a,&b);
        s[a][b]=1;
        s[b][a]=1;
    }
    visit[1]=1;
    dfs(1,1);
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
fn solve(x: u64, y: u64) -> i32 {
    if x > y {
        0
    } else {
        1 + solve(x * 2, y)
    }
}
fn main() {
    let (x, y): (u64, u64) = readln();
    println!("{}", solve(x, y));
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::HashSet;

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int a, b;
	cin >> a >> b;
	for(int i = 1; i <= 1251; i++) {
		if(i*8/100 == a && i/10 == b)	{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}



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

using namespace std;

int main(int argc, char* argv[]) {
    if (argc > 1) {
	freopen(argv[1], "r", stdin);
    }

    int n;
    cin >> n;

    int xa = 0, ya = 0, pre = 0;
    for (int i = 0; i < n; i++) {
	int x, y, t;
	cin >> t >> x >> y;
	int dis = abs(x - xa) + abs(y - ya);
	int rem = t - pre;
	if (dis > rem) {
	    cout << "No";
	    return 0;
	}
	if (dis % 2 != rem % 2) {
	    cout << "No";
	    return 0;
	}
    }

    cout << "Yes";

    return 0;
}


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

int days(int y,int m,int d){
  if(m<3)y--,m+=12;
  return 365*y+y/4-y/100+y/400+(153*m+8)/5+d;
}

void ymd(int day,int &y,int &m,int &d){
  int lo=-1,hi=100000,mid;
  while(lo+1<hi){
    mid=(lo+hi)/2;
    if(days(mid,12,31)<day)lo=mid;
    else hi=mid;
  }
  y=hi;
  for(m=1;m<12;m++)if(days(y,m+1,1)>day)break;
  d=day-days(y,m,0);
}

int main() {
  int y1,m1,d1,y2,m2,d2,a1=-1,a2=-1,ans=-1;
  cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
  int s=min(days(y1,m1,d1),days(y2,m2,d2));
  for(int i=s; i<=s+3500*366; i++) {
    int y,m,d;
    ymd(i,y,m,d);
    if(i>=days(y1,m1,d1)) {
      if(m==m1&&d==d1) a1++;
      else if(m1==2&&d1==29) {
        int yy,mm,dd;
        ymd(i-1,yy,mm,dd);
        if(mm==2&&dd==28) a1++;
      }
    }
    if(i>=days(y2,m2,d2)) {
      if(m==m2&&d==d2) a2++;
      else if(m2==2&&d2==29) {
        int yy,mm,dd;
        ymd(i-1,yy,mm,dd);
        if(mm==2&&dd==28) a2++;
      }
    }
    if(a1>=0&&a2>=0) ans=max(ans,abs(a1-a2));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3096
import sys
input = sys.stdin.readline
from collections import defaultdict
n = int(input())
UR = defaultdict(list)
UD = defaultdict(list)
UL = defaultdict(list)
DR = defaultdict(list)
DL = defaultdict(list)
RL = defaultdict(list)

for i in range(n):
    x,y,u = input().split()
    x,y = int(x), int(y)
    if u == "U":    
        UD[x].append((y,1))
        UR[x+y].append((x-y,0))
        UL[y-x].append((x+y,1))
    elif u == "D":    
        UD[x].append((y,0))
        DR[y-x].append((x+y,0))
        DL[x+y].append((x-y,1))
    elif u == "R":   
        RL[y].append((x,1))
        DR[y-x].append((x+y,1))
        UR[x+y].append((x-y,1))
        
    else:
        RL[y].append((x,0))
        UL[y-x].append((x+y,0))
        DL[x+y].append((x-y,0))

ans = float("INF")

for x in [UD, UL, UR, DR, DL, RL]:
    for v in x.values():
        V = sorted(v)

        for i in range(len(V)-1):
            if V[i][1] and not V[i+1][1]:
                ans = min(ans,V[i+1][0]-V[i][0])


if ans == float("INF"):
    print("SAFE")
else:
    print(ans*5)


Measured memory_bytes: 216552
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib> 
using namespace std;
int n,m,a[1010];
int main()
{
  cin>>n>>m;
  int tt=0,ans1=999999999,ans2=0;
  for(int i=1;i<=n;i++) a[i]=m+i-1,tt+=a[i];
  for(int i=1;i<=n;i++)
    if(abs(tt-(tt-a[i]))<ans1) ans1=abs(tt-(tt-a[i])),ans2=tt-a[i];
  cout<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
if len(set(s)) == 1:
    print(0)
    exit()

alpha = "abcdefghijklmnopqrstuvwxyz"
ans = float("inf")
for tar in alpha:
    t = s
    cnt = 0
    flag = True
    while flag:
        nt = ""
        cnt += 1
        flag = False
        for i in range(len(t)-1):
            if t[i] == tar or t[i+1] == tar:
                nt += tar
            else:
                nt += t[i]
                flag = True
        t = nt
    ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 9000
#include<stdio.h>
#define	SIZE	1000 
int main(){
	int num[SIZE];
	int i, n, numbuff=0;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &num[i]);
	}
	int rev[n];
	for(i=0;i<n;i++){
		rev[i] = 0;
	}
	for(i=0;i<n;i++){
		rev[n-1-i] = num[i];
	}
	i=0;
	while (1){
		printf("%d", rev[i]);
		i++;
		if(i<n){
			printf(" ");
		}else{
			break;
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}


template<class T=ll>struct Graph{
	int n;
	vector<vector<tuple<ll,T>>>edge;
	Graph(int N=1):n(N){edge.resize(n);}
	void add(ll f,ll t,T c,bool d=false){
		edge[f].emplace_back(t,c);
		if(!d)edge[t].emplace_back(f,c);
	}
	void view(){
		rep(i,n)for(auto&e:edge[i])
			puta(i,"=>",get<0>(e),", cost :",get<1>(e));
	}
};



int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll k;
	cin>>n>>k;
	Graph<ll> g(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;a--;b--;
		g.add(a,b,0,false);
	}
	vl ans(n,k+1);
	ans[0]=k;
	stack<int> stk;
	stk.push(0);
	while(!stk.empty()){
		int i=stk.top();
		stk.pop();
		ll cnt=0;
		if(i!=0)cnt+=1;
		for(auto x:g.edge[i]){
			if(ans[get<0>(x)]!=k+1)continue;
			ans[get<0>(x)]=k-1-cnt;
			cnt++;
			stk.push(get<0>(x));
		}
	}
	ll an=1;
	rep(i,n){
		an*=ans[i];
		an%=MOD;
	}
	cout<<an<<endl;
}


Measured memory_bytes: 8576