akhauriyash/Code-Regression huggingface dataset:
N, D = map(int, input().split())
X=[]
f=0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(N-1):
    for j in range(i+1, N):
        ans=0
        for k in range(D):
            ans = ans + (X[i][k] - X[j][k])**2
        ans = (ans)**0.5
        if ans==int(ans):
            f+=1
print(f)

Measured memory_bytes: 3064
/*input
0 0 1 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	REP(i,c-a) cout<<'R';
	REP(i,d-b) cout<<'U';

	REP(i,c-a) cout<<'L';
	REP(i,d-b) cout<<'D';

	cout<<'D';
	REP(i,c-a+1) cout<<'R';
	REP(i,d-b+1) cout<<'U';
	cout<<'L';

	cout<<'U';

	REP(i,c-a+1) cout<<'L';
	REP(i,d-b+1) cout<<'D';
	cout<<'R';
	return 0;
}


Measured memory_bytes: 256
import math
n=int(input())
l=math.floor(math.sqrt(n))

for i in range(l+1,0,-1):
    if n%i==0:
        a,b=i,n//i
        k=max(math.floor(math.log10(a))+1,math.floor(math.log10(b))+1)
        break
print(k)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define N 500001
using namespace std;
#define int long long
int n,X[N];

int ans;
void update(int a,int i){
  int len = X[n-1];  
  int la = X[a]-X[i];
  int b = lower_bound(X+a,X+3*n,X[a]+(len-la)/2)-X;
  int lb = X[b] - X[a];
  int lc = len-la-lb;
  ans = max(ans,min(la,min(lb,lc)));
}

signed main(){
  cin>>n;
  int A[N];
  for(int i=0;i<n;i++)cin>>A[i];
    
  X[0] = A[0];
  for(int i=1;i<3*n;i++) X[i] += A[i%n] + X[i-1];

  int len = X[n-1];
  for(int i=0;i<=n;i++){
    int au = upper_bound(X+i,X+3*n,X[i]+len/3) - X;
    update(au,i),update(au-1,i);
 }
 cout<< ans << endl;
  return 0;
}

Measured memory_bytes: 6216
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 2000
using namespace std;

int n,k,ans;
int a[MAXN+5][MAXN+5];

void Add(int x,int y,int ex,int ey)
{
	++a[x][y];
	++a[ex][ey];
	--a[x][ey];
	--a[ex][y];
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		int x,y;char c;
		scanf("%d %d %c",&x,&y,&c);
		x %= 2*k;y %= 2*k;
		if(((x<k&&y<k)||(x>=k&&y>=k))==(c=='B'))
		{
			int nx=x % k,ny=y % k;
			Add(0,0,nx+1,ny+1);
			Add(nx+k+1,0,2*k,ny+1);
			Add(0,ny+k+1,nx+1,2*k);
			Add(nx+k+1,ny+k+1,2*k,2*k);
			Add(nx+1,ny+1,nx+k+1,ny+k+1);
		}
		else
		{
			int nx=x % k,ny=y % k;
			Add(nx+1,0,nx+k+1,ny+1);
			Add(nx+1,ny+k+1,nx+k+1,2*k);
			Add(0,ny+1,nx+1,ny+k+1);
			Add(nx+k+1,ny+1,2*k,ny+k+1);
		}
	}
	for(int i=1;i<MAXN;i++)
        a[0][i]+=a[0][i-1];
	for(int i=1;i<MAXN;i++)
    {
        a[i][0]+=a[i-1][0];
		for(int j=1;j<MAXN;j++)
            a[i][j]+=a[i-1][j]-a[i-1][j-1]+a[i][j-1];
    }
	for(int i=0;i<2*k;i++)
		for(int j=0;j<2*k;j++)
			ans=max(ans,a[i][j]);
	printf("%d",ans);
}


Measured memory_bytes: 15872
#include <iostream>
using namespace std;
#define FOR(i,s,e) for(int i = (s);i <= (e);i++)
const int A_MAX = 1e5;

int cou[A_MAX + 10];

int N;

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

	FOR(i,0,N - 1)
	{
		cin >> a;
		if(a > 0) cou[a - 1]++;
		cou[a]++;
		cou[a+1]++;
	}

	int max_ = 0;
	FOR(i,0,A_MAX)
	{
		max_ = max(max_,cou[i]);
	}

	cout << max_ << endl;
	return 0;
}


Measured memory_bytes: 640
const fs = require('fs');
const stdin = fs.readFileSync('/dev/stdin', 'utf-8');
const lines = stdin.split("\n");

const line = lines[0].split(" ");
const n = Number(line[0]);
const a = Number(line[1]);
const b = Number(line[2]);

console.log(Math.min(n*a, b));

Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    unsigned long long int n,i,sum=0;
    cin>>n;
    for(i=1;i<=n;i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        sum=sum+i;
    }
     cout<<sum<<endl;
     return 0;


}


Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <math.h>

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

using namespace std;

typedef long long ll;

#define MAX_H   (2001)
#define MAX_W   (2001)


ll h, w;
char s[MAX_H][MAX_W];
ll l[MAX_H][MAX_W], r[MAX_H][MAX_W], d[MAX_H][MAX_W], u[MAX_H][MAX_W];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> h >> w;
    REP(i, h) {
        REP(j, w) {
            cin >> s[i][j];
        }
    }
    
    /* 左 */
    REP(i, h) {
        REP(j, w) {
            if ('#' == s[i][j]) {
                l[i][j] = 0;
            } else {
                if (0 == j) {
                    l[i][j] = 1;
                } else {
                    l[i][j] = l[i][j - 1] + 1;
                }
            }
        }
    }
    
    /* 右 */
    REP(i, h) {
        REP(j, w) {
            if ('#' == s[i][w - 1 - j]) {
                r[i][w - 1 - j] = 0;
            } else {
                if (0 == j) {
                    r[i][w - 1 - j] = 1;
                } else {
                    r[i][w - 1 - j] = r[i][w - j] + 1;
                }
            }
        }
    }
    
    /* 下 */
    REP(i, h) {
        REP(j, w) {
            if ('#' == s[i][j]) {
                d[i][j] = 0;
            } else {
                if (0 == i) {
                    d[i][j] = 1;
                } else {
                    d[i][j] = d[i - 1][j] + 1;
                }
            }
        }
    }
    
    /* 上 */
    REP(i, h) {
        REP(j, w) {
            if ('#' == s[h - 1 - i][j]) {
                u[h - 1 - i][j] = 0;
            } else {
                if (0 == i) {
                    u[h - 1 - i][j] = 1;
                } else {
                    u[h - 1 - i][j] = u[h - i][j] + 1;
                }
            }
        }
    }
    
    ll tmp = 0;
    ll result = 0;
    REP(i, h) {
        REP(j, w) {
            tmp = l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3;
            if (result < tmp) {
                result = tmp;
            }
        }
    }
    
    cout << result << endl;
    
    return 0;
}



Measured memory_bytes: 129280
#include <cstdio>
#include <cstring>
int main()
{
    char s[15];
    scanf("%s", s);
    int len = strlen(s);
    int yes = 1;
    for (int i = 0; i + i < len; i++) if (s[i] != s[len - i - 1]) {yes = 0; break;}
    if (yes) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define endl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using P = pair<ll, ll>;

/*追加部分*/



/*main関数*/

int main() {
FASTIO;
    int a, b, c, d; cin >> a >> b >> c >> d;

    cout << ((a + b) > (c + d) ? "Left" : (a + b) == (c + d) ? "Balanced" :  "Right") << endl;
return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define int          long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define pi           pair<int,int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define FIO         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}


void solve()
{
     string s;
     cin>>s;
     int sum=0;
     rep(i,0,sz(s))sum+=s[i]-'0';
     if(sum%9==0)cout<<"Yes\n";
     else
      cout<<"No";

}

signed main()
{
        // FIO
        // #ifndef ONLINE_JUDGE
        //   freopen("input.txt","r",stdin);
        //   freopen("output.txt","w",stdout);
        // #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        solve();
        cerr<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;

        return 0;
}

Measured memory_bytes: 3900
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

constexpr long long MOD = 1000000007;

int main()
{
  int N, K;
  std::cin >> N >> K;
  std::cout << (K == 1 ? 0 : N - K) << std::endl;
  return 0;
}



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

int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  for (char c: s) {
    char d = c + n;
    if (d > 'Z') {
      d = d - 'Z' + 'A' - 1;
    }
    cout<<d;
  }
  cout<<endl;
}

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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<long>;
using vll = vector<ll>;
using vb  = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vector<int> >;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

int main()
{
    FASTIO;
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int cnt = 0;

    rep(i, 0, n-1) cnt += (s[i] != t[i]);
    cout << cnt << nl;
    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int a,b,c,d;
cin >> a >> b >> c >> d;
int ab = abs(a-b), bc = abs(b-c), ca = abs(c-a);
if((ab <= d && bc <= d) || ca <= d) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const ll INF = 2e18;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    int r[R];
    rep(i, 0, R) {
        cin >> r[i];
        r[i]--;
    }

    ll dist[N][N];
    rep(i, 0, N) {
        rep(j, 0, N) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0;
    }

    rep(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    rep(k, 0, N) {
        rep(i, 0, N) {
            rep(j, 0, N) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    sort(r, r + R);
    ll ans = INF;
    do {
        ll d = 0;
        rep(i, 0, R - 1) {
            d += dist[r[i]][r[i + 1]];
        }
        ans = min(ans, d);
    } while (next_permutation(r, r + R));

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


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    A,B=mis()
    print(max(A-B*2,0))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,w[101];
	int min;
	int sum[101];
	int i;
	sum[0]=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&w[i]);
		sum[i+1]=sum[i]+w[i];
	}
	min=abs(2*sum[1]-sum[n]);
	for(i=0;i<n+1;i++){
		if(min>abs(2*sum[i]-sum[n])){
			min=abs(2*sum[i]-sum[n]);
		}
	}
	printf("%d",min);
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2 - h1) * 60 + m2 - m1 - k << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include<bits/stdc++.h>
#include<cmath>
#include <algorithm> 
#include <unordered_map>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string n;
	cin >> n;
	vector<long long>ans(10000001);
	int ct = 0;
	int f = 0;
	for (int i = 0; i < 3; i++) {
		if (n[i] == 'R') {
			if (f == 0) {
				ct++;
			}
			else {
				ct++;
				f = 0;
			}
		}
		else {
			f = 1;
			
			ans.push_back(ct);
			ct = 0;
		}
	}
	ans.push_back(ct);
	sort(ans.begin(), ans.end());
	cout << ans[ans.size()-1];
	return 0;
}

Measured memory_bytes: 159484
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

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

int main() {
    int N;
    lint K;
    cin >> N >> K;
    vector<int> K2(50, 0);
    rep(i, 50) K2[49 - i] = (K >> i) & 1;
    vector<lint> A(N);
    rep(i, N) cin >> A[i];
    vector<vector<lint>> dp(51, vector<lint>(2, -1));
    dp[0][0] = 0;
    rep(i, 50) rep(j, 2) {
        if (dp[i][j] == -1) continue;
        for (int x = 0; x <= (j ? 1 : K2[i]); ++x) {
            lint res = 0;
            rep(k, N) {
                if ((A[k] >> (49 - i) & 1) ^ x) ++res;
            }
            res = res << (49 - i);
            chmax(dp[i + 1][j || x < K2[i]], dp[i][j] + res);
        }
    }
    cout << max(dp[50][0], dp[50][1]) << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

bool isPrime(int n){
	bool flg = true;

	for (int i = 2; i*i <= n; i++){
		if (n%i == 0){
			flg = false;
			break;
		}
	}
	return flg;
}

int main(){

	int n, cnt = 0;
	std::cin >> n;

	for (int i = 0,a; i < n; i++){
		std::cin >> a;
		if (isPrime(a))cnt++;
	}
	std::cout << cnt << std::endl;

	return 0;
}

Measured memory_bytes: 1160
s = list(input())
t = list(input())

n = len(s)
ans = "No"
for i in range(n):
    cnt = 0
    for j in range(n):
        if s[j] == t[(i + j) % n]:
            cnt += 1
    if cnt == n:
        ans = "Yes"
        break
print(ans)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
constexpr long N = 300000;
constexpr long mod = 998244353;

long mpow(long a, long p){
    long x=a;
    long y=1;
    while(p>0){
        if((p&1)==1){
            y=x*y%mod;
        }
        x=x*x%mod;
        p>>=1;
    }
    return y;
}

long minv(long a){
    return mpow(a, mod-2);
}

long fact[N+1];
void init_fact(){
    long t=1;
    fact[0]=1;
    for(long i=1; i<=N; i++){
        t=t*i%mod;
        fact[i]=t;
    }
}
long ncr[N+1];
void init_ncr(long n){
    for(long r=0; r<n; r++){
        ncr[r] = fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
    }
}

long mcomb(long n, long r){
    return fact[n]*minv(fact[n-r]*fact[r]%mod)%mod;
    //return ncr[r];
}

int main(void){
    long n, a, b, k;
    scanf("%ld %ld %ld %ld", &n, &a, &b, &k);
    init_fact();
    init_ncr(n);
    long sum = 0;
    long s = max(0l, (k-n*b)/a);
    long e = min(n, k/a);
    for(long i=s; i<=e; i++){
        long q=(k-a*i)/b;
        long m=(k-a*i)%b;
        if(m==0){
            sum = (sum+mcomb(n,i)*mcomb(n,q))%mod;
        }
    }
    if(sum==0)sum++;
    printf("%ld\n", sum);
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define eb          emplace_back
#define mp          make_pair
#define F           first
#define S           second
#define endl        "\n"
#define rep(i,a,b)  for(i=a;i<b;i++)
#define all(v)      v.begin(),v.end()
#define allr(v)     v.rbegin(),v.rend()
#define mod         1e9+7
#define CIN(V,s,n)  for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n) for(int i=s;i<n;i++){cout <<  V[i] << " ";}
#define SbS         sortbysec
#define fast        ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);   for(ll i=0;i<V.size();i++) V[i] = 0;

// map<ll,vector<ll> > M;
// map<ll,vector<ll> >:: iterator it;
// it = M.begin();
// it.F will be ll
// it.S will be vector<ll>

using namespace std;

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
}

ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}

int main()
{
ll t=1;
//cin >> t;
while(t--)
{
    ll a,b,c,d,n,m,i,j,k,h,l,l2,w,q=1,u,v,temp=0,cn=0,cp=0,c0=0,max1=0;
    cin >> a >> b >> c >> d;
    l = (c*d)/__gcd(c,d);

    ll ans = (b-a)-( b/c - (a-1)/c + b/d - (a-1)/d - b/l + ((a-1))/l)+1;

    cout << ans;

}
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#pragma GCC optimize ("trapv")
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,a,b) for(lli i = (lli)(a); i < (lli)(b);i++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()
#define wis cout<<endl<<"I already speak english, bitch"<<endl;
 
typedef long long int lli;
typedef vector<lli> vi;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef pair<ii,lli> iii;
typedef long double C;
 
#define trace(args...) { string  _s =#args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);}
 
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args){
    cerr <<  *it  << " : " << a << endl;
    err(++it, args...);
}


int main(){
	fastio;
	vector<int> v;
	string s; cin>>s;
	rep(i,0,sz(s)){
		v.pb(int(s[i]-'0'));
	}

	int foo1=v[0]*10+v[1];
	int foo2=v[2]*10+v[3];
	//trace(foo1,foo2);
	if((foo1>=13 and foo2>=13)) cout<<"NA";
	else if((foo1>=13 and foo2==0) or (foo2>=13 and foo1==0) or (foo1==0 and foo2==0)) cout<<"NA";
	else if(foo1>=13 or (foo2<=12 and foo2>0 and foo1==0)) cout<<"YYMM";
	else if(foo2>=13 or (foo1<=12 and foo1>0 and foo2==0)) cout<<"MMYY";
	else /*if(foo1<=12 nad foo2<=12) */cout<<"AMBIGUOUS";
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5 + 10;
int n, a[N], d[N], k;
int main()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        d[i] = 1e9 + 1;
    }
    d[1] = 0;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= k; j++)
        {
            d[i + j] = min(d[i + j], abs(a[i + j] - a[i]) + d[i]);
        }
    }
    cout << d[n];
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <queue>

int main()
{
	int x;
	std::cin >> x;
	if (x == 1) {
		std::cout << 0 << std::endl;
	}
	else {
		std::cout << 1 << std::endl;

	}
	return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

class Main{
	public static void main(String[] main) {
		Scanner sc=new Scanner(System.in);
		String a=sc.next();

		boolean isA=false;
		if(a.charAt(0)=='A') {
			isA=true;
		}
		char[] mjs=new char[a.length()];
		for(int i=0; i<a.length(); i++) {
			mjs[i]=a.charAt(i);
		}

		mjs[0]='a';

		int C_cnt=0;
		for(int i=2 ;i<=a.length()-2; i++) {
			if(mjs[i]=='C') {
				C_cnt++;
				mjs[i]='c';
			}
		}

		boolean caps=true;

		for(int i=0; i<a.length(); i++) {
			if((mjs[i]+"").equals((mjs[i]+"").toLowerCase())) {
				//
			}
			else {
				caps=false;
			}
		}

		if(C_cnt==1 && caps==true && isA==true) {
			System.out.println("AC");
		}
		else {
			System.out.println("WA");
		}
	}
}

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

int main(){
  int N, a;
  bool is_odd = false;
  cin >> N;
  for(int i = 0; i < N; i++){
  	cin >> a;
    if(a % 2 == 1) is_odd = true;
  }
  cout << (is_odd ? "first" : "second") << endl;
  return 0;
}


Measured memory_bytes: 256
import math

def resolve():
    X = int(input())

    if X == 2:
        print(2)
        return

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

    while True:
        isPrime = True
        for j in range(3, int(math.sqrt(i)), 2):
            if i % j == 0:
                isPrime = False
                break        
        if isPrime:
            print(i)
            return
        i += 2


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n;
  cin>>n;
  vi v(1<<n);
  rep(i,1<<n){
    cin>>v[i];
  }
  sort(all(v));
  multiset<int> s;
  rep(i,(1<<n)-1){
    s.insert(v[i]);
  }

  vi a;
  a.PB(v[(1<<n)-1]);

  rep(i,n){
    vi w=a;
    for(auto x:a){
      auto it=s.lower_bound(x);
      if(it==s.begin()){
        Yes(false);
        return 0;
      }
      it--;
      w.PB(*it);
      s.erase(it);
    }
    sort(all(w));
    reverse(all(w));
    swap(a,w);
  }

  Yes(true);


}

Measured memory_bytes: 17780
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

ll N, A, B;
vector<ll> X;
int main() {
  cin >> N >> A >> B;
  X.resize(N);

  rep(i, N) cin >> X[i];

  int M = N - 1;
  ll ans = 0;
  rep(i, N - 1) {
    ll c = (X[i + 1] - X[i]) * A;
    if (c <= B) {
      --M;
      ans += c;
    }
  }
  ans += M * B;

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


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

using namespace std;

int main(){
 int n;
  cin >> n;
 
  long res=0;
  
  long a;
  
  for(int i=0;i<n;i++){
    cin >> a;
   while(a%2==0){
    res++;
    a/=2; 
   }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {

task3();

    }

    public static void task1(){
    	Scanner s = new Scanner(System.in);
	    int n = s.nextInt(), m = s.nextInt() - 1;
	    char[] cs = s.next().toCharArray();
	    //A - a = -32
	    cs[m] += ('a' - 'A');
	    System.out.println(cs);
	}

	public static void task2(){
		Scanner s = new Scanner((System.in));
		int n = s.nextInt();
		int fh = n / 100;
		int sh = n % 100;
		System.out.println(isMonth(fh) ? (isMonth(sh) ? "AMBIGUOUS " : "MMYY") : (isMonth(sh) ? "YYMM" : "NA"));
	}

    public static Boolean isMonth(int i){
    	return (1 <= i) && (i <= 12);
	}

	public static void task3(){
    	Scanner s = new Scanner(System.in);
    	int n = s.nextInt(), k = s.nextInt();
		double ans = 0;
		for (int i = 1; i <= n; i ++){
			double tmp = i;
			while (tmp < k){
				tmp *= 2;
			}
			ans += (1/(tmp/(i * 1.0))) * (1/ (1.0 * n));
		}

		System.out.println(ans);

	}




}


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

public class Main {
	
	int a,b;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();

	}
	
	void run() {
		FastReader sc = new FastReader();
		a = sc.nextInt();
		b = sc.nextInt();
		
		solve();
	}
	
	void solve() {
		if (a<=8 && b<=8) {
			System.out.println("Yay!");
		}else {
			System.out.println(":(");
		}
	}
	
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		
		public FastReader() {
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}
	
		
		String next() {
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		int nextInt()
		{
			return Integer.parseInt(next());
		}
		
		long nextLong()
		{
			return Long.parseLong(next());
		}
		
		double nextDouble()
		{
			return Double.parseDouble(next());
		}
		
		String nextLine() {
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch(IOException e) {
				e.printStackTrace();
			}
			
			return str;
		}
	
	}
}

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

using namespace std;

#define task "cf"
#define ff(i, a, b) for(int i=a; i<=b; ++i)
#define fd(i, a, b) for(int i=a; i>=b; --i)
#define ll long long

const int N = 262149;
int f_max[N], g_max[N];
int k, n, a[N];

void enter()
{
	cin >> k;
	n = 1 << k;
	for(int i = 0; i < n; ++i)
		cin >> a[i];
}

int getBit(int x, int i)
{
	return (x >> i ) & 1;
}

void solve()
{
	f_max[0] = 0;
	int cur_best = 0;
	for(int x = 1; x < n; ++x)
	{
		f_max[x] = x;
		g_max[x] = -1;
		int testMax = cur_best;
		vector<int> v;
		while(!v.empty())
			v.pop_back();
		for(int i = 0; i <= 18; ++i)
			if(getBit(x, i) == 1)
			{
				int y = x & ~ (1 << i);
				testMax = max(testMax, a[f_max[y]] + a[x]);
				v.push_back(y);
				if(a[f_max[x]] < a[f_max[y]])
					f_max[x] = f_max[y];
			}
		for(int i = 0; i <= 18; ++i)
			if(getBit(x, i) == 1)
			{
				int y = x & ~ (1 << i);
				if(f_max[x] != f_max[y] && a[g_max[x]] < a[f_max[y]] )
				g_max[x] = f_max[y];
			}
		for(int i = 0; i < v.size(); ++ i)
			for(int j = i + 1; j < v.size(); ++j)
			{
				int pos1 = f_max[v[i]];
				int pos2 = f_max[v[j]];
				if(pos1 != pos2) testMax = max(testMax, a[pos1] + a[pos2]); else
					{
						int subPos1 = g_max[v[i]];
						int subPos2 = g_max[v[j]];
						if(subPos1 != -1) testMax = max(testMax, a[subPos1] + a[pos2]);
						if(subPos2 != -1) testMax = max(testMax, a[pos1] + a[subPos2]);
					}
			}	
		cur_best = max(cur_best, testMax);
		cout << testMax << endl;
	}
	//cout<<endl << " " << f_max[14] << " " << f_max[13] << endl;
}

int main() {
		enter();
		solve();
	return 0;
}

Measured memory_bytes: 6144
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]float64, n)

	d := float64(0)
	for i := 0; i < n; i++ {
		a[i] = 1 / float64(nextInt())
		d += a[i]
	}

	fmt.Printf("%f", 1/d)
}

Measured memory_bytes: 640
n = int(input())
w = [input() for i in range(n)]
v = []
for i in range(n - 1):
    if w[i] not in v and w[i + 1] not in v and w[i][- 1] == w[i + 1][0]:
        v.append(w[i])
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(4e3 + 5);
const int LOG = (int)(20);
const lli mod = (lli)(924844033);

lli n, k, ind, mark[N][2], ar[N], dp[N][N][2], fac[N], ans, ch[N];

lli dfs(int x, int pos) {
	if(x <= 0 || x > n)
		return 0;
	if(mark[x][pos])
		return 0;
	mark[x][pos] = 1;
	lli re = 1;
	re += dfs(x + k, !pos) + dfs(x - k, !pos);
	return re;
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n >> k;

	fac[0] = 1;
	for(lli i = 1; i < N; i++)
		fac[i] = fac[i - 1] * i % mod;
	for(int i = 1; i <= min(2 * k, n); i++) {
		lli sz = dfs(i, 0);
		if(sz == 0)
			continue;
		sz--;
		while(sz--)
			ar[++ind] = i;
	}
	for(int i = 0; i <= ind; i++)
		dp[i][0][0] = 1;
	for(int i = 1; i <= ind; i++)
		for(int j = 1; j <= n; j++) {
			dp[i][j][0] += dp[i - 1][j][1] + dp[i - 1][j][0];
			if(ar[i] != ar[i - 1])
				dp[i][j][1] += dp[i - 1][j - 1][1] + dp[i - 1][j - 1][0];
			else
				dp[i][j][1] += dp[i - 1][j - 1][0];
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
		}
	for(int i = 0; i <= n; i++)
		ch[i] = (dp[ind][i][0] + dp[ind][i][1]) % mod;
	for(int i = 0; i <= n; i++) {
		lli val = fac[n - i] * ch[i] % mod;
		if(i % 2 == 0)
			ans += val;
		else
			ans += mod - val;
		ans %= mod;
	}
	cout << ans;
}

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

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    rep(i,0,sz(s)-3){
        if(s[i]=='A' && s[i+1]=='B'  && s[i+2]=='C') ans++;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if (sc.nextInt() == 1) {
            System.out.println("Hello World");
        } else {
            int a = sc.nextInt() + sc.nextInt();
            System.out.println(a);
        }
    }
}

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

const int MAX_V = 200010;
vector<int> G[MAX_V];
// 2部グラフ判定
struct BipartiteGraph{
    int n;    
    vector<int> color;
    BipartiteGraph(int _n){
        n = _n;
        color.resize(n, 0);
    }
    bool dfs(int v, int c){
        color[v] = c;
        bool res = true;
        for(int i = 0; i < G[v].size(); i++){
            if(color[G[v][i]] == c) res &= false;
            if(color[G[v][i]] == 0) res &= dfs(G[v][i], -c);
        }
        return res;
    }
    bool isBipartiteGraph(){
        bool res = true;
        for(int i = 0; i < n; i++){
            if(color[i] == 0){
                res &= dfs(i, 1);
            }
        }
        return res;
    }
};

int main(){
    long long n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    BipartiteGraph bg(n);
    bool f = bg.isBipartiteGraph();
    long long all = n * (n - 1) / 2, ans = 0;
    if(!f){
        ans = all - m;
    }else{
        long long odd = 0, even = 0;
        for(int i = 0; i < n; i++){
            if(bg.color[i] == -1) odd++;
            else even++;
        }
        ans = odd * even - m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8832
N,M,K = gets.split.map(&:to_i)
Mod = 998244353

D,U = [1,N-1],[1,1]
[K,N/2].min.times{|i| i+=2
	D << D[-1] *(N-i) % Mod
	U << Mod - U[Mod%i] * (Mod/i) % Mod # 謎
}
1.upto(U.size-1){|i|
	U[i] = U[i-1] * U[i] % Mod # 謎
}
Com = lambda{|r| r = [N-1-r,r].min
	D[r] * U[r] % Mod
}

p K.downto(0).inject([0,M*(M-1).pow(N-1-K,Mod)]){|(a,m),k|
	next (a + Com[k] * m) % Mod, m*(M-1)%Mod
}[0]


Measured memory_bytes: 16180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef string str;
typedef vector<ll>  vl;
typedef vector< vector<ll> > vvl;
typedef vector<ii> vii;
typedef vector< vector<ii> > vvii;
typedef vector<iii> viii;
typedef vector< vector<iii> > vviii;
typedef vector<str>  vs;
typedef vector< vector<str> > vvs;
typedef long double ld;

//typelower_bounddef priority_queue<long long> pq;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef set<int>::iterator sit;
//typedef map<int,int>::iterator mit;
//typedef vector<int>::iterator vit;


#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repn(i,a,b) for(int i=(a);i<=(b);i++)
#define repin(i,a,b,x) for(int i=(a);i<(b);i+=x)
#define repnin(i,a,b,x) for(int i=(a);i<=(b);i+=x)
#define MAX(a,blower_bound) a=max(a,b)
#define MIN(a,b) a=min(a,b)
//#define fbo find_by_order
//#define ook order_of_key

// if else int i = (number <0) ? 1:0 -  if (number <0) i=1 else 0

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    double d;
    cin >> n >> d;
    int cnt=0;
    int x,y;
    rep(i,0,n){
        cin >> x >> y;
        double dist= sqrt(pow(x,2)+pow(y,2));
        if(dist<=d)
            cnt+=1;
        
    }
    cout << cnt;
	return 0;
}


Measured memory_bytes: 3756
n = int(input())
A = input().split()

B = {}
for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

sum = 0
for b in B:
    sum += B[b] * (B[b] - 1) // 2

for a in A:
    print(sum - (B[a] - 1))

Measured memory_bytes: 26496
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Set         std::set
#define PQueue      std::priority_queue
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        for ( int i = 0; i < n; i++ ) {
            int t, x, y;
            read t >> x >> y;
            t -= (x+y);
            if ( t < 0 || t & 1 ) {
                echo "No" fin;
                return 0;
            }
        }

        echo "Yes" fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
int n,k,h[100010];
int dp[100010];
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>h[i];
	fill(dp,dp+n,INF);
	dp[0]=0;
	for(int i=1;i<n;i++){
		for(int j=i-1;j>=0&&j>i-1-k;j--){
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  double ans = 0;
  long int kaisu;
  for(int i=1; i<=N; i++){
    kaisu  = max(0.0, ceil(log2(K) - log2(i)));
    ans += pow(0.5, kaisu);
  }
  ans /= N;
  cout << setprecision(20) << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        new Thread(null, () -> {
            int n;
            int k;
            List<Integer> as = new ArrayList<>();
            try (Scanner sc = new Scanner(System.in)) {
                n = sc.nextInt();
                k = sc.nextInt();
                for (int i = 0; i < n; i++) {
                    as.add(sc.nextInt() - 1);
                }
            }
            System.out.println(new Calculator(n, k, as).calculate());
        }, "", 1 << 27).start();
    }
}

class Calculator {
    private int k;
    private int answer = 0;
    private boolean isCalculate = false;
    private List<List<Integer>> lists = new ArrayList<>();

    Calculator(int n, int k, List<Integer> as) {
        this.k = k;
        for (int i = 0; i < n; i++) {
            this.lists.add(new ArrayList<>());
        }
        for (int i = 0; i < n; i++) {
            int j = as.get(i);
            if (0 < i) {
                this.lists.get(j).add(i);
            } else if (0 < j) {
                this.answer++;
            }
        }
    }

    int calculate() {
        if (!this.isCalculate) {
            this.dfs(0, 0);
            this.isCalculate = true;
        }
        return this.answer;
    }

    private int dfs(int a, int pre) {
        int h = 0;
        for (int i : this.lists.get(a)) {
            h = Math.max(h, this.dfs(i, a));
        }
        if (0 < pre && h == this.k - 1) {
            h = 0;
            this.answer++;
        } else {
            h++;
        }
        return h;
    }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

#define INF 1000000

int main(){
  int n,ma,mb;
  cin >> n >> ma >> mb;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  vector<vector<int>> zenhan(201,vector<int>(201,INF));
  int ta,tb,tc;
  for(int i=0;i<(1<<(n/2));i++){
    ta=tb=tc=0;
    for(int j=0;j<n/2;j++){
      if(i&(1<<j)) ta+=a[j],tb+=b[j],tc+=c[j];
    }
    zenhan[ta][tb]=min(zenhan[ta][tb],tc);
  }
  int ans=INF;
  for(int i=0;i<(1<<((n+1)/2));i++){
    ta=tb=tc=0;
    for(int j=0;j<(n+1)/2;j++){
      if(i&(1<<j)) ta+=a[j+n/2],tb+=b[j+n/2],tc+=c[j+n/2];
    }
    for(int k=0;k<=200;k++){
      if((ta+k)%ma==0){
        if(0<=(ta+k)/ma*mb-tb&&(ta+k)/ma*mb-tb<=200){
          if(tc+zenhan[k][(ta+k)/ma*mb-tb]!=0)
          ans=min(ans,tc+zenhan[k][(ta+k)/ma*mb-tb]);
        }
      }
    }
  }
  if(ans==INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
  map<string, vector<int> > m;
  set<string> name;
  string str;
  int ind;
  while (cin >> str >> ind) {
    m[str].push_back(ind);
    name.insert(str);
  }
  
  for (set<string>::iterator it = name.begin(); it != name.end(); it++) {
    cout << *it << endl;;

    sort(m[*it].begin(), m[*it].end());

    for (int j = 0; j < m[*it].size(); j++) {
      cout << m[*it][j];
      if (j != m[*it].size() - 1) {
	cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
from bisect import bisect_right

n = int(input())
l = list(map(int,input().split()))
l.sort() # 昇順にソート

count = 0
for i in range(0,n-2):
    a = l[i]
    for j in range(i+1, n-1):
        ab = a+l[j]
        # bisect_left(a, x): x を a に挿入できる点を返す
        # cの最大値は a+b-1
        k = bisect_right(l, ab-1, j+1, n)
        count += k-(j+1)
print(count)


Measured memory_bytes: 3188
import java.util.*;
import java.math.*;

public class Main{
    public static void main(String[] args){
	Scanner in = new Scanner(System.in);
	int a = in.nextInt();
	long b = 1;

	for(int i = 1 ; i <= a ; i++){
	    b = b*i;
	}
	System.out.println(b);
    }
}

Measured memory_bytes: 17156
using System;
namespace csharptest
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            long[] a = new long[n];
            long ans1=0, ans2=0, ans3=0;
            a[0] = long.Parse(str[0]);
            ans3 += a[0];ans2 = a[0];ans1 = a[0];
            for (long b = 1; b < n; b++)
            {
                a[b] = long.Parse(str[b]);
                ans3 += a[b];
                if (a[b] > ans2)
                    ans2 = a[b];
                if (a[b] < ans1)
                    ans1 = a[b];
            }
            Console.WriteLine(ans1 + " " + ans2 + " " + ans3);
        }
    }
}

Measured memory_bytes: 19932
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	string S;
	cin >> S;
	VLL sv(N);
	for (LL n = 0; n < N; n++) {
		if (S[n] == 'R')sv[n] = 0;
		else if (S[n] == 'G')sv[n] = 1;
		else sv[n] = 2;
	}
	VLL csum[3];   //csum[i][k] := S_k以降の数字iの数
	for (LL i = 0; i < 3; i++) {
		csum[i].resize(N + 1);
		csum[i].back() = 0;
		for (LL k = N - 1; k >= 0; k--) {
			if (sv[k] == i)csum[i][k] = csum[i][k + 1] + 1;
			else csum[i][k] = csum[i][k + 1];
		}
	}
	LL ans = 0;
	for (LL i = 0; i < N; i++) {
		for (LL j = i + 1; j < N; j++) {
			if (sv[i] == sv[j])continue;
			LL str;
			if (sv[i] + sv[j] == 1)str = 2;
			else if (sv[i] + sv[j] == 2)str = 1;
			else str = 0;
			ans += csum[str][j+1];
		}
	}
	for (LL i = 0; i < N; i++) {
		for (LL k = i + 1; k < N; k++) {
			if ((i + k) & 1)continue;
			if (sv[i] == sv[k])continue;
			LL j = (i + k) / 2;
			if (sv[j] != sv[i] && sv[j] != sv[k])ans--;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3292