akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/math>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  using namespace atcoder;
  
  int t;
  cin>>t;
  REP(_, t){
    long long n, m, a, b;
    cin>>n>>m>>a>>b;
    long long ans = floor_sum(n, m, a, b);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define maxn 100110
int n,a[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i) scanf("%d",&a[i]);
	sort(a,a+n);
	int ans=a[0],ret=a[0]>a[n-1]/2?a[n-1]-a[0]:a[0];
	for(int i=1;i<n-1;++i)
	{
		int tmp=a[i]>a[n-1]/2?a[n-1]-a[i]:a[i];
		//printf("a[%d]=%d,tmp=%d\n",i,a[i],tmp);
		if(tmp>ret)
		{
			ret=tmp;
			ans=a[i];
		}
	}
	printf("%d %d\n",a[n-1],ans);
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
#include <algorithm>
#include <complex>
#define FIXED_FLOAT(x)  std::fixed <<std::setprecision(7)<<(x)
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace  std;

using ll = long long;
const ll mod = 1e9 + 7;
typedef pair<int , int > pairs;
typedef complex<ll> G;
const int N=2e5+5;

const ll INF = 1e18;

void done() {
    string a, b;
    cin >> a >> b;
    int n, k;
    cin >> n >> k;
    string p;
    cin >> p;
    if(p==a) {
        cout << n-1 << " "  << k;
    }
    else cout << n << " " << k-1 << '\n';

}
void solve() {

    int n;
    cin >>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<long double>c;
    for(int i=0;i < n;i++) {
        cin >> a[i];
    }
    int r = 0;
    for(int i=0;i < n;i++) {
        cin >> b[i];
        if(a[i]!=0) {
            c.push_back(b[i]/a[i]*1.0);
        }else if(b[i]=='0') {
            r++;
            c.push_back(-999999999);
        }
        else {
            c.push_back(-999999999);
        }
    }
    int sum = 1;
    int best = 0;
    sort(c.begin(), c.end());
    for(int i=1;i < n;i++) {
        if(c[i]==c[i-1] && c[i-1]!=-999999999) {
                sum++;
        }
        else {
            if(sum > best && c[i-1]!=-999999999) {
                best = sum;
                sum = 1;
            }
        }
    }
    if(sum > best && c[n-1]!=-999999999) {
        best = sum;
    }
    cout << best+r << '\n';
}
void another() {
    int n;cin >> n;

    string s;
    cin >> s;
    int left= 0, right = 0;
    int d = (s[0]=='<') ?1 : 0;
    int c = (s[n-1]=='>')?1 : 0;

    for(int i=0;i < n;i++) {
        if(i!=0 && s[i]=='<')left++;
        else if(i!=n-1 && s[i]=='>')right++;
    }
    if(left <= right) {
        swap(left, right);
        swap(d, c);
    }
    if(d) {
        cout << max(1, right-1) << '\n';
    }
    else cout << max(0, right-1) << '\n';



}
void test_case() {
    int t;
    cin >> t;
    while(t--)solve();
}
int main() {

    fast;
    done();

}



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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long X;
    cin >> X;
    long long U = 1;
    while ((U * U * U * U) <= X) {
        ++U;
    }
    map<long long, long long> M;
    for (long long i = -U; i <= U; ++i) {
        long long P = (i * i * i * i * i);
        if (M.count(P - X)) {
            cout << i << ' ' << M[P - X] << '\n';
            return 0;
        }
        if (M.count(P + X)) {
            cout << M[P + X] << ' ' << i << '\n';
        }
        M[P] = i;
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define getcx getchar_unlocked
#define MSV(A,a) memset(A, a, sizeof(A))
#define MP make_pair
#define PB push_back
#define INF (int(1e9))
#define INFL (LL(1e18))
#define EPS 1e-12
#define chkbit(s, b) (s & (1<<b))
#define setbit(s, b) (s |= (1<<b))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define MOD 1000000007
#define MAX 100005
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

int main() {

	string s;
	int i, l, rem = 0;

	cin>>s;
	l = s.length();

	for(i = 0 ; i < l; i++) {
		rem = (rem + (s[i] - '0')) % 9;
	}

	if(rem == 0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3720
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int arr[100001];
    int h[100001];
    int n,m;
    int a,b;
    int cnt=0;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) arr[i]=1;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&h[i]);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d %d",&a,&b);
        if(h[a]<=h[b]) arr[a]=0;
        if(h[a]>=h[b]) arr[b]=0;
    }
    for(int i=1;i<=n;i++)
    {
        if(arr[i]==1)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define SF scanf
#define PF printf
#define MAXN 100010
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll a[MAXN],A,B;
int n,lasA1[MAXN],lasB1[MAXN];
ll dp[MAXN][2],sum0[MAXN],sum1[MAXN];
int find(ll val){
	int l=1,r=n,res=0;
	while(l<=r){
		int mid=(l+r)>>1;
		if(a[mid]<=val){
			res=mid;
			l=mid+1;
		}
		else
			r=mid-1;
	}
	return res;
}
int main(){
	//freopen("division.in","r",stdin);
	//freopen("division.out","w",stdout);
	SF("%d%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)
		SF("%lld",&a[i]);
	for(int i=1;i<=n;i++){
		lasA1[i]=lasA1[i-1];
		lasB1[i]=lasB1[i-1];
		if(a[i]-a[i-1]<A||i==1)
			lasA1[i]=i;
		if(a[i]-a[i-1]<B||i==1)
			lasB1[i]=i;
	}
	sum0[0]=sum1[0]=1;
	for(int i=1;i<=n;i++){
		sum0[i]=sum0[i-1];
		sum1[i]=sum1[i-1];
		int i1=lasA1[i]-1;
		int i2=find(a[i+1]-B);
		if(i==n)
			i2=n;
		if(i1<=i2){
			if(i1==0)
				dp[i][0]=sum1[i2];
			else
				dp[i][0]=(sum1[i2]-sum1[i1-1]+MOD)%MOD;
		}
	//	PF("<%d %d>\n",i1,i2);
		i1=lasB1[i]-1;
		i2=find(a[i+1]-A);
		if(i==n)
			i2=n;
		if(i1<=i2){
			if(i1==0)
				dp[i][1]=sum0[i2];
			else
				dp[i][1]=(sum0[i2]-sum0[i1-1]+MOD)%MOD;
		}
		//PF("[%d %d]\n",i1,i2);
		/*if(dp[i][0]!=0){
		PF("{%lld %lld}\n",dp[i][0],dp[i][1]);
		PF("--------\n");
	}*/
		sum0[i]=(sum0[i-1]+dp[i][0])%MOD;
		sum1[i]=(sum1[i-1]+dp[i][1])%MOD;
	}
	PF("%lld",(dp[n][0]+dp[n][1])%MOD);
}

Measured memory_bytes: 4864
N=int(input())
A=[]
for i in range(1,N+1):
  if i%3==0 and i%5==0:
    s=0
  elif i%3==0 and i%5!=0:
    s=0
  elif i%3!=0 and i%5==0:
    s=0
  else:
    s=i
  A.append(s)
print(sum(A))

Measured memory_bytes: 33904
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
c = 0
ans = 0

for i in range(N):
    if c + a[i] <= x:
        c += a[i]
        ans += 1
    else:
        print(ans)
        exit()

if c == x:
    print(N)
else:
    print(N-1)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){
	int n,count,a,b,c,d;
	while(cin >> n){
		count = 0;
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				for(c=0;c<10;c++){
					for(d=0;d<10;d++){
						if(a+b+c+d == n) count += 1;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    string S, T;
    cin >> S;
    cin >> T;

    int target = (int)T.size();
    int ans = (int)T.size();
    int tmp = 0;

    for(int i=0; i+target<=(int)S.size(); i+=1){
        tmp=0;
        for(int j=0; j<target; j+=1){
            if(S[i+j] == T[j]){
                tmp++;
            }
        }
        if(ans > (target - tmp)){
            ans = (target - tmp);
        }
    }

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

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int g, mx = 0;
  rep(i, n){
    int a;
    cin >> a;
    if(i == 0)g = a;
    else g = __gcd(g, a);
    mx = max(mx, a);
  }
  if((k <= mx) && ((k % g) == 0)) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 256
local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

function dbgpr_t(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in ipairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

function dbgpr_t2d(tbl2d)
    if DBG then
        dbgpr(tbl2d)
        for i,t in ipairs(tbl2d) do
            io.write("[dbg]")
            for j,v in ipairs(t) do
                io.write("(" .. tostring(i) .. "," .. tostring(j) .. "): ")
                io.write(tostring(v))
                io.write("; ")
            end
            print("")
        end
    end
end
function create_tbl(a, initial)
    local tbl = {}
    for i=1,a do
        tbl[i] = initial
    end
    return tbl
end

function create_2d_tbl(a, b, initial)
    local tbl = {}
    for i=1,a do
        local t = {}
        for j=1,b do
            t[j] = initial
        end
        tbl[i] = t
    end
    return tbl
end

function parse_problem()
    local N, M = io.read("n", "n")
    local stores = {}
    for i=1,N do
        local a, b = io.read("n", "n")
        stores[i] = {a, b}
    end
    table.sort(stores, function (x, y) return x[1] < y[1] end)
    return N, M, stores
end

function main()
    local N, M, stores = parse_problem()
    dbgpr(N, M)
    dbgpr("====stores")
    dbgpr_t2d(stores)
    local remain = M
    local total_price = 0
    local idx = 1
    while remain > 0 do
        local unit_price, stock = stores[idx][1], stores[idx][2]
        local units = stock
        if remain - units < 0 then
            units = remain
        end
        total_price = total_price + unit_price * units
        remain = remain - units
        dbgpr(idx, remain)
        idx = idx + 1
    end
    print(total_price)
end

main()


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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	int N, Q;
	vector<int> a;
	
	cin>>N>>Q;
	
	a.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>a[i];
	}
	
	sort(a.begin(), a.end());
	
	for(int i = 0; i < Q; i++){
		int l , r;
		
		cin>>l>>r;
		
		int num = upper_bound(a.begin(), a.end(), r) - lower_bound(a.begin(), a.end(), l);
		
		cout<<num<<endl;
	}
	return 0;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
#define inf 1e18
#define ll long long
using namespace std;
ll h,w;
inline ll solve();
int main(){
    cin>>h>>w;
    if(h%3==0 || w%3==0){
        cout<<0<<endl;
        return 0;
    }else{
        cout<<solve()<<endl;
        return 0;
    }
    return 0;
}

inline ll solve(){
    ll res=inf;
    for(ll i=1;i<w;i++){
        ll m=min(i*h,min((w-i)*(h/2),(w-i)*(h-h/2)));
        ll ma=max(i*h,max((w-i)*(h/2),(w-i)*(h-h/2)));
        res=min(res,ma-m);
        //cout<<"ma="<<ma<<"m="<<m<<endl;
        //cout<<"i="<<i<<"res="<<res<<endl;
    }
    for(ll i=1;i<h;i++){
        ll m=min(i*w,min((h-i)*(w/2),(h-i)*(w-w/2)));
        ll ma=max(i*w,max((h-i)*(w/2),(h-i)*(w-w/2)));
        res=min(res,ma-m);
        //cout<<"i="<<i<<"res="<<res<<endl;
    }
    res=min(res,h);
    res=min(res,w);
    return res;
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
  cout<<"Left"<<endl;}
  if(A+B==C+D){
  cout<<"Balanced"<<endl;}
  if(A+B<C+D){
  cout<<"Right"<<endl;}
}

Measured memory_bytes: 256
// Auther : Asmaa Saad  date: 2020-04-08 
#include <bits/stdc++.h>
using namespace std;
#define loop(v, st, en) for (int v = st; v < en; v++)
#define INF 1E9
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define MP make_pair
#define P(x) cout << #x  << x<<endl ;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
string s,t;
int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,arr[25],ans=0;
    cin>>n;

    loop(i,0,n){
        cin>>arr[i];
    }
    loop(i,1,n-1){
        int a=arr[i-1],b=arr[i+1];
        int tmp[]={a,b,arr[i]};
        sort(tmp,tmp+3);
        if(tmp[1]==arr[i]) ans++;
         
    }
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M = list(map(int,input().split()))

AB = []
for i in range(M):
    AB.append(list(map(int,input().split())))

out = 0
for broken in range(M):
    Network = UnionFind(N)
    for j in range(M):
        if j!=broken:
            A,B=AB[j][0],AB[j][1]
            Network.union(A-1, B-1)
    if Network.group_count()==2:
        out+=1
print(out)

Measured memory_bytes: 74044
S = input()
S = S[::-1]


C = False
CB = False
cbcount = 0
ans = 0
for i in range(len(S)):
    if S[i] == "C":
        if CB:
            C = True
            CB = False

        elif not C:
            C = True

        else:
            cbcount = 0

    elif S[i] == "B":
        if C:
            CB = True
            C = False
            cbcount += 1
        else:
            C = False
            CB = False
            cbcount = 0
    else:
        if CB:
            ans += cbcount
        else:
            C = False
            CB = False
            cbcount = 0
print(ans)


Measured memory_bytes: 3500
#include <iostream>

int a,b,c,d,e,f;
int ans1=0,ans2=0;
int i,j,k,l,x,y;
int main(){
  std::cin>>a>>b>>c>>d>>e>>f;
  
  for(i=0;100*i<=f;i+=a)
    for(j=0,x=100*i+100*j;x<=f;j+=b,x=100*i+100*j)
      for(k=0;x+k<=f&&k<=e*(i+j);k+=c)
        for(l=0,y=k+l;x+y<=f&&y<=e*(i+j);l+=d,y=k+l)
          if(x+y==0)
            continue;
          else if(ans1==0||y*10000/(x+y)>ans2*10000/ans1){
            ans1=x+y;
            ans2=y;
          }
  
  std::cout<<ans1<<' '<<ans2<<std::endl;
  return 0;
}

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

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
#define DEBUG

void qread(int &x){
	int neg=1;x=0;
	char c=getchar(); 
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=20;
int n;
string s;
ll ans,dp[maxn][maxn];

void calc(string red,string blue){
	rep(i,blue.size()+1)rep(j,red.size()+1)dp[i][j]=0;
	dp[0][0]=1;
	rep(i,blue.size()+1)rep(j,red.size()+1){
		int pos=2*n-1-i-j;
		if(pos<n)continue;
		if(s[pos]==blue[i])dp[i+1][j]+=dp[i][j];
		if(s[pos]==red[j])dp[i][j+1]+=dp[i][j]; 
	} 
	ans+=dp[blue.size()][red.size()];
}

void go(int k,string red,string blue){
	if(k==n){calc(red,blue);return;}
	go(k+1,red+s[k],blue);
	go(k+1,red,blue+s[k]);
}

int main(){
#ifndef DEBUG
	freopen("my.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	cin>>n>>s;
	go(0,"","");
	cout<<ans;
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll n,a,b;
    cin>>n>>a>>b;
    if(a==b)
    cout<<0<<endl;
    else
    {
    	ll sum=0;
    	if((b-a)%2!=0)
    	{
    		if(a-1<=n-b)
    		sum+=a-1+1+(b-a-1)/2;
    		else
    		sum+=n-b+1+(b-a-1)/2;
		}
		else
		{
			sum+=(b-a)/2;
		}
		cout<<sum<<endl;
	}
	
	return 0;
}


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

const ll INF = 5e15;
vector<vector<ll>> edges;
ll N, K;

P dfs(ll now, ll pre, ll depth, ll bound1, ll bound2){
    P ret(0, 0);
    for(ll nxt : edges[now]){
        if(nxt == pre) continue;
        P tmp = dfs(nxt, now, depth + 1, bound1, bound2);
        ret.first += tmp.first;
        ret.second += tmp.second;
    }
    if(depth > bound1) ret.first++;
    if(depth > bound2) ret.second++;
    return ret;
}

ll calc(ll parent){
    vector<P> costs;
    for(ll nxt : edges[parent]) costs.push_back(dfs(nxt, parent, 1, K / 2, (K + 1) / 2));
    sort(costs.begin(), costs.end(), [](const P &a, const P &b){ return a.first - a.second > b.first - b.second; });
    ll ret = 0;
    ret += costs[0].second;
    for(ll i = 1; i < costs.size(); i++) ret += costs[i].first;
    return ret;
}

int main(){
    cin >> N >> K;
    edges.resize(N);
    for(ll i = 1; i < N; i++){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    ll ans = INF;
    for(ll i = 0; i < N; i++) ans = min(ans, calc(i));
    cout << ans << endl;
    return 0;
}


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

using namespace std;

#define MAX 110

int H,W;
int bdg[MAX][MAX];
bool visited[MAX][MAX];
int dx[2][6] = {{-1,0,-1,1,-1,0},{0,1,-1,1,0,1}};
int dy[6] = {-1,-1,0,0,1,1};

bool inField(int x,int y){
  return 0 <= x && x <= W+1 && 0 <= y && y <= H+1;
}

int solve(int x,int y){
  visited[y][x] = true;

  int res = 0;
  for(int i = 0 ; i < 6 ; i++){
    int nx = x + dx[y%2][i];
    int ny = y + dy[i];
    if(!inField(nx,ny)) continue;
    if(bdg[ny][nx] == 1){
      res++;
    }else if(!visited[ny][nx]){
      res += solve(nx,ny);
    }
  }
  return res;
}

int main(){
  cin >> W >> H;
  memset(bdg,0,sizeof(bdg));
  for(int i = 1 ; i <= H ; i++){
    for(int j = 1 ; j <= W ; j++){
      cin >> bdg[i][j];
    }
  }
  memset(visited,false,sizeof(visited));
  cout << solve(0,0) << endl;
  return 0;
}

Measured memory_bytes: 1540
import * as fs from 'fs';


function main(input) {
  input = input.split('\n');
  const N = parseInt(input[0]);
  const xyList: [number, number][] = input.splice(1, N)
    .map(i => i.split(' ').map(x => parseInt(x)));
  let max = 0, Xmin = Infinity, Xmax = - Infinity, Ymin = Infinity, Ymax = - Infinity;
  xyList.map(([x, y]) => {
    const X = x + y;
    const Y = x - y;
    Xmax = Math.max(Xmax, X);
    Xmin = Math.min(Xmin, X);
    Ymax = Math.max(Ymax, Y);
    Ymin = Math.min(Ymin, Y);

    const xdist1 = Math.abs(X - Xmax);
    const xdist2 = Math.abs(X - Xmin);
    const ydist1 = Math.abs(Y - Ymax);
    const ydist2 = Math.abs(Y - Ymin);
    max = Math.max(max, xdist1, xdist2, ydist1, ydist2);
  });
  console.log('%d', max);
}

main(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 96376
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    dp = [0] * (N + 1)
    safe = [True] * (N + 1)
    for _ in range(M):
        a = int(input())
        safe[a] = False

    dp[0] = 1
    for i in range(1, N + 1):
        if i == 1 and safe[i]:
            dp[i] = dp[i - 1]
        else:
            if safe[i]:
                dp[i] = dp[i - 1] + dp[i - 2]
                dp[i] %= MOD

    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 7668
#include <bits/stdc++.h> //g++-9で実行（gcc version 9.3.0），g++だとデフォルトのclang

using namespace std;

//#define int long long                         //intでオーバフローした時の切り替え用
#define OUT(x) std::cout << x << std::endl
#define DEBUG(x) cerr << #x << ": " << x << endl //エラー出力として変数名と変数の中身表示
#define DEBUG_VEC(v)                   \
    cerr << #v << ":";                 \
    for (int i = 0; i < v.size(); i++) \
        cerr << " " << v[i];           \
    cerr << endl;
#define DEBUG_MAT(v)                          \
    cerr << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cerr << v[i][j] << " ";           \
        }                                     \
        cerr << endl;                         \
    }
#define Sp(p) cout << setprecision(25) << fixed << p << endl; //小数点以下を25桁で表示
#define all(obj) (obj).begin(), (obj).end()
#define pb push_back

//usingエイリアス（別名という意味，型定義のこと）
using ll = long long;
//template <class T> using Vec = std::vector<T>;//エイリアステンプレート

const ll MOD = (ll)1e9 + 7;
//const ll MOD = 998244353;あ
const ll INF = (ll)1e18 + 1;
const double EPS = 1e-9;
const long double pi = 3.1415926535897932384626433832795028841971L;

//マクロでintをlong longと定義したときはsinged
int main()
{
    cin.tie(0);                  //cinとcoutの同期を切る（高速化)
    ios::sync_with_stdio(false); //iostreamとstdioの同期を切る（高速化)

    string s,t;
    cin >> s >>t ;
    int num=0;
    for (int i=0;i<s.length();i++) if(s[i] != t[i]) {num++;};
    OUT(num);
    return 0;
}

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

using P = pair<long long, long long>;
struct dat {
  long long n, l;
};

long long n, q;
vector<long long> v, w, res;
vector<vector<dat>> query;

void solve();
void dfs(int now, int dep, vector<P> &lst);

int main() {
  cin >> n;
  v.resize(n);
  w.resize(n);
  for (int i = 0; i < n; ++i) cin >> v[i] >> w[i];
  cin >> q;
  query.resize(n + 1);
  for (int i = 0; i < q; ++i) {
    long long vn, li;
    cin >> vn >> li;
    query[vn].push_back({i, li});
  }
  solve();
  for (int i = 0; i < q; ++i) cout << res[i] << endl;
  return 0;
}

void solve() {
  res.assign(q, 0);
  vector<P> dummy(1, P(0, 0));
  dfs(1, 0, dummy);
}

void dfs(int now, int dep, vector<P> &lst) {
  if (now > n) return;
  if (dep == 9) reverse(lst.begin(), lst.end());
  auto f = [](long long nw, long long nv, vector<P> &nlst) {
    int len = nlst.size();
    for (int i = 0; i < len; ++i)
      nlst.emplace_back(nlst[i].first + nw, nlst[i].second + nv);
    inplace_merge(nlst.begin(), nlst.begin() + len, nlst.end());
  };
  if (dep < 9) {
    f(w[now - 1], v[now - 1], lst);
    for (auto qu : query[now])
      for (auto p : lst)
        if (p.first <= qu.l) res[qu.n] = max(res[qu.n], p.second);
  } else {
    vector<P> suf(1, P(0, 0));
    long long x = now;
    while (x >= (1 << 9)) {
      f(w[x - 1], v[x - 1], suf);
      x >>= 1;
    }
    for (auto qu : query[now]) {
      long long nres = 0, lim = qu.l, plen = lst.size(), slen = suf.size();
      for (long long i = 0, id = 0, val = 0; i < plen; ++i) {
        if (lst[i].first > lim) continue;
        while (id < slen && lst[i].first + suf[id].first <= lim)
          val = max(val, suf[id++].second);
        nres = max(nres, val + lst[i].second);
      }
      res[qu.n] = nres;
    }
  }
  vector<P> dummy = lst;
  dfs(now * 2, dep + 1, lst);
  dfs(now * 2 + 1, dep + 1, dummy);
}


Measured memory_bytes: 17764
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	rep(i, l, r + 1) {
		if (i % d == 0)ans++;
	}
	cout << ans << endl;
}



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

int main() {
  
  int N; cin >> N; bool ans = true;
  
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    if (A % 2 == 0 && (A % 3 != 0 && A % 5 != 0)) {
      ans = false;
    }
  }
  
  if (ans) {
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll calc(ll n) {

    auto check = [](ll x, ll y, ll z) -> ll {
        return x * x + y * y + z * z + x * y + y * z + z * x;
    };
    ll ans = 0;
    for (ll x = 1; check(x, 1, 1) <= n; x++) {
        for (ll y = 1; check(x, y, 1) <= n; y++) {
            for (ll z = 1; check(x, y, z) <= n; z++) {
                if (check(x, y, z) == n) ans++;
            }
        }
    }
    return ans;
}


int main() {

    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        cout << calc(i) << endl;
    }

}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  
  for (int i = 0; i < H; i++) {
    cin >> S.at(i);
  }
  
  // '#'のある行と列をカウントする
  // xは縦方向のカウンタ，yは横方向のカウンタ
  // 0なら白，1なら黒
  string x = "", y = "";
  for (int i = 0; i < H; i++)
    x += '0';
  for (int i = 0; i < W; i++)
    y += '0';
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') {
        x.at(i) = '1';
        y.at(j) = '1';
      }      
    }
  }
  
  for (int i = 0; i < H; i++) {
    // xが'0'の行は飛ばす
    if (x.at(i) == '0')
      continue;
    // yが'1'の時のみTにSを代入する
    else {
      string T = "";
      for (int j = 0; j < W; j++) {
        if (y.at(j) == '1')
          T += S.at(i).at(j);     
      }
      cout << T << endl;
    }
  }

}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

const int N = 100005;
LL a[N];
int pre[N];
LL ans[N];

int main() {
	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%lld", &a[i+1]);
	int prev = 0;
	FOR(i, 1, n+2) {
		pre[i] = prev;
		if (a[i] > a[prev])prev = i;
	}
	priority_queue<PII> q;
	int idx = n+1;
	while (idx>0) {
		int target = pre[idx];
		while (target < idx) {
			q.push(MP(a[idx], 1));
			idx--;
		}
		int cnt = 0;
		LL ret = 0;
		while (!q.empty() && q.top().first >= a[pre[idx]]) {
			ret += ((LL)(q.top().first - a[pre[idx]])) * q.top().second;
			cnt += q.top().second;
			q.pop();
		}
		q.push(MP(a[pre[idx]], cnt));

		ret += a[idx] - a[pre[idx]];
		ans[idx] = ret;
		a[idx] = a[pre[idx]];
	}
	FOR(i, 1, n + 1)printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	int ts=0,xs=0,ys=0;
	REP(i,N){
		int tg=in(),xg=in(),yg=in();
		int xl=xg-xs,yl=yg-ys,tl=tg-ts;
		int dl=abs(xl)+abs(yl);
		if(dl>tg){
			out("No");
			return 0;
		}
		if((tl-dl)%2){
			out("No");
			return 0;
		}
	}
	out("Yes");
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

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

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}


int main()
{
    fast;
    ll t;
    
    //~ cin>>t;
    t=1;
    while(t--){
			ll n;
			cin>>n;
			ll a[n];
			for(int i=0;i<n;i++)
				cin>>a[i];
			ll ans=0;
			for(int i=0;i<n;i++){
				if(a[i]==ans+1)
					ans++;
			}
			if(ans==0)
				cout<<-1;
			else
				cout<<n-ans;
			
    }
    return 0;
}


Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	string s;
	cin >> s;
	int ans = 0;
	REP(i, s.length()) {
		if (s[i] != s[s.length() - i - 1])ans++;
	}
	cout << ans/2 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Main
{
    public static class Program
    {

        static void Main(string[] arg)
        {
            string input = Console.ReadLine();
            var answer = 0;
            var char_array = input.ToCharArray();

            int max_length = 0;
            foreach(char c in char_array)
            {
                if (Check_Contain_T(c))
                {
                    max_length++;
                }
                else
                {
                    max_length = 0;
                }
                if (answer < max_length)
                {
                    answer = max_length;
                }

            }

            Console.WriteLine(answer);
            Console.ReadLine();
        
        }
        static bool Check_Contain_T(char c)
        {
            if(c == 'A' || c == 'T' || c == 'C' || c == 'G')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();

        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();

        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s, t;
  cin >> s >> t;
  sort(all(s));
  sort(all(t), greater<char>());
  cout << (s < t ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;

int f(int x) {
	int res = 0;
	while (x % 2 == 0) {
		x /= 2; res++;
	}
	return res;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	VE a(n); rep(i, n)cin >> a[i];
	rep(i, n) {
		if (a[i] % 2 == 1) {
			cout << 0 << endl; return 0;
		}
		a[i] /= 2;
	}
	int t = f(a[0]);
	rep(i, n) {
		if (f(a[i]) != t) {
			cout << 0 << endl; return 0;
		}
		a[i] >>= t;
	}
	m >>= t;
	int l = 1;
	rep(i, n) {
		l = lcm(l, a[i]);
		if (l > m) {
			cout << 0 << endl; return 0;
		}
	}
	m /= l;
	cout << (m + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int n,K;
int a[100010],ans;
std::vector<int>G[100010];
int dfs(int x){
	int r=1;
	for(int i:G[x])r=std::max(r,1+dfs(i));
	if(r==K)r=0,ans+=a[x]!=1;
	return r;
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi(),K=gi();int cnt=0;
	for(int i=1;i<=n;++i)a[i]=gi(),cnt+=a[i]!=1;
	if(K==1)return printf("%d\n",cnt),0;
	ans=a[1]!=1;a[1]=1;
	for(int i=2;i<=n;++i)G[a[i]].push_back(i);
	for(int i:G[1])dfs(i);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
  int n;
  cin >> n;
  while(n>0){
    int x = n%10;
    if(x==7){
      cout << "Yes" << endl;
      return 0;
    }
    n = n/10;
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3624
def main():
    X = int(input())
    if X < 4:
        print(X)
        return
    d = [3]
    end = int(X / 2) if X > 11 else 12
    for a in range(5, end, 2):
        # print(a, flush=True)
        flag = False
        for m in d:
            if a % m == 0:
                flag = True
                break
        if flag:
            continue
        # ループから抜けている = 素数
        if a >= X:
            print(a)
            return
        else:
            d.append(a)

    if X % 2 == 0:
        X += 1

    for a in range(X, 100004, 2):
        flag = False
        for m in d:
            if a % m == 0:
                flag = True
                break
        if flag:
            continue
        # ループから抜けている = 素数
        print(a)
        return

if __name__ == "__main__":
    main()
    

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

int main() {
  int n;
  cin >> n;
  string state = "neutral";
  vector<int> a(n);
  cin >> a[0];

  int ans = 0;
  for(int i=1;i<n;i++) {
    cin >> a[i];
    if(state == "neutral") {
      if(a[i] - a[i-1] > 0) state = "up";
      else if(a[i] - a[i-1] < 0) state = "down";
    } else {
      if(state == "up" && a[i] < a[i-1]) {
        ans++;
        state = "neutral";
      }
      else if(state == "down" && a[i] > a[i-1]) {
        ans++;
        state = "neutral";
      }
    }
  }

  cout << ans + 1 << endl;
}

Measured memory_bytes: 640
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>

#define int uint64_t

using namespace std;

signed main()
{
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    
    vector<int> v;
    v.resize(x);
    for (auto &n: v) {
        cin >> n;
    }
    
    vector<int> vv;
    vv.reserve(x * y);
    while (y--) {
        int n;
        cin >> n;
        for (auto p : v) {
            vv.push_back(p + n);
        }
    }
    
    sort(vv.begin(), vv.end(), std::greater<int>());
    
    vv.resize(k);
    
    vector<int> vvv;
    vvv.reserve(k * z);
    while (z--) {
        int n;
        cin >> n;
        for (auto p : vv) {
            vvv.push_back(p + n);
        }
    }
    
    sort(vvv.begin(), vvv.end(), std::greater<int>());
    
    for (int i = 0; i < k; i++) {
        std::cout << vvv[i] << endl;
    }
    return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 31488
#include<bits/stdc++.h>
using namespace std;
char ch[250010];
int main()
{
	int N;
	scanf("%d",&N);
	scanf("%s",ch);
	int Len=strlen(ch);
	for(int i=0;i<Len;i++)
	{
		ch[i]=ch[i]+N;
		if(ch[i]>'Z') ch[i]-=26;
	}
	printf("%s",ch);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string c1,c2;cin>>c1>>c2;
  if(c1[0]==c2[2] && c1[1]==c2[1] && c1[2]==c2[0]){
    P("YES");
    return 0;
  }
  P("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,a,s=0,b=0;
    cin>>n;
    
    for(int i=1;i<=n;i++){
		cin>>a;
        if(a==1){s=s+1;}
        if(b<s)b=s;
        else if(a==0){s=0;}
                     
    }
    b=b+1;
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 3088