akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int N, K; cin >> N >> K;
  vi V(N);
  rep(i,N) cin >> V[i];

  int valmax = 0;
  rep(A,K+1){
    rep(B,K+1){
      if(A+B>min(N,K)) continue;
      int val=0; vi negV;
      rep(i,A){
        val += V[i];
        if(V[i]<0) negV.pb(V[i]);
      }
      rep(i,B){
        val += V[N-i-1];
        if(V[N-i-1]<0) negV.pb(V[N-i-1]);
      }
      sort(all(negV));
      rep(i,min((int)negV.size(),K-A-B)){
        val -= negV[i];
      }
      valmax = max(valmax,val);
    }
  }
  cout << max(valmax,0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
 
using namespace std;
 
int main()
{
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    //std::vector<int> p, q, r;
    std::multimap<int, char> mp;
    
    int tmp;
    for(int i=0; i<a; i++){
        cin >> tmp; //p.push_back(tmp);
        mp.insert(std::multimap<int, char>::value_type(tmp, 'p'));
    }
    for(int i=0; i<b; i++){
        cin >> tmp; //q.push_back(tmp);
        mp.insert(std::multimap<int, char>::value_type(tmp, 'q'));
    }
    for(int i=0; i<c; i++){
        cin >> tmp; //r.push_back(tmp);
        mp.insert(std::multimap<int, char>::value_type(tmp, 'r'));
    }

    std::multimap<int, char>::reverse_iterator itr = mp.rbegin();
    // 無色を赤/緑のどちらを優先して着色するかの配列
    // ex1) rrrrpppqqq…の場合、rrrr=qqqpに着色
    // ex2) prqqqqpp…の場合、r=p
    std::vector<char> v;
    int cntx = 0;
    int cnty = 0;
    int cntr = 0;
    //for(int i=0; i<(x+y); i++){
    while(1){
        if(itr->second == 'p'){
            if(cntx < x){
                cntx++;
                // 無色を着色する候補は赤(p)
                if(cntx+cnty+cntr > (x+y)){
                    v.push_back('p');
                }
            }
        }else if(itr->second == 'q'){
            if(cnty < y){
                cnty++;
                // 無色を着色する候補は緑(q)
                if(cntx+cnty+cntr > (x+y)){
                    v.push_back('q');
                }
            }
        }else{
            cntr++;
        }
        if(cntx == x && cnty == y) break;
        ++itr;
    }
    /*
    std::vector<char>::iterator vitr = v.begin();
    while(vitr != v.end()){
        cout << *vitr << ", ";
        ++vitr;
    }
    cout << endl;
    */

    long long int sum = 0;
    cntx = 0;
    cnty = 0;
    cntr = 0;
    itr = mp.rbegin();
    for(int i=0; i<(x+y); i++){
        //cout << itr->first << ":" << itr->second << endl;
        if(itr->second == 'p'){
            if(cntx < x){
                cntx++;
            }else{
                ++itr; i--; //cout << "next!" << endl;
                continue;
            }
        }else if(itr->second == 'q'){
            if(cnty < y){
                cnty++;
            }else{
                ++itr; i--; //cout << "next!" << endl;
                continue;
            }
        }else if(itr->second == 'r'){
            if(v.front() == 'p'){
                cntx++;
            }else if(v.front() == 'q'){
                cnty++;
            }
            v.erase(v.begin(), v.begin()+1);
        }
        sum += itr->first;
        if(cntx == x && cnty == y) break;
        
        ++itr;
    }
    cout << sum << endl;
}

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


int main(){
	int A,B,C;
	cin >> A >> B >> C;
	int s = 0;
	for(int i = 1; ; i++){
		s+=A;
		if(i % 7 == 0){
			s+=B;
		}
		if(s >= C){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}



Measured memory_bytes: 3116
import java.util.*;

public class Main {
    static Dish[] dishes;
    static int[][] dp;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t = sc.nextInt();
		dishes = new Dish[n];
		dp = new int[n][t + 1];
		for (int i = 0; i < n; i++) {
		    dishes[i] = new Dish(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(dishes);
		System.out.println(dfw(n - 1, t));
   }
   
   static int dfw(int idx, int time) {
       if (idx < 0) {
           return 0;
       }
       if (time <= 0) {
           return 0;
       }
       if (dp[idx][time] == 0) {
           dp[idx][time] = Math.max(dfw(idx - 1, time), dfw(idx - 1, time - dishes[idx].time) + dishes[idx].taste);
       }
       return dp[idx][time];
   }
   
   static class Dish implements Comparable<Dish> {
       int time;
       int taste;
       
       public Dish(int time, int taste) {
           this.time = time;
           this.taste = taste;
       }
       
       public int compareTo(Dish another) {
           return another.time - time;
       }
   }
}


Measured memory_bytes: 82392
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll bg=1234567890123;
#define ff(i,n) for(i=0;i<n;i++)
#define gg1(n1) cin>>n1;
#define gg(n1,n2) cin>>n1>>n2;
#define gg3(n1,n2,n3) cin>>n1>>n2>>n3;
#define hh(n) cout<<n<<endl;
#define t top
#define p push
#define pb push_back
#define mp make_pair
int main()
{
  ll i,n,k,j;
  cin>>n>>k;
  ll arr[n],dp[n];
  
  for(i=0;i<n;i++)
  {cin>>arr[i];dp[i]=bg;}
  dp[0]=0;
  for(i=0;i<n;i++)
  {
    for(j=1;j<=k;j++)
    {
      if(i+j<n)
       dp[i+j]=min(dp[i+j],dp[i]+abs(arr[i+j]-arr[i]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll s; cin>>s;
    set<ll> st;
    ll x=s;
    while(st.count(x)==0){
        st.insert(x);
        if(x%2==0) x/=2;
        else x=3*x+1;
    }
    cout<<st.size()+1<<endl;
    return 0;
}

Measured memory_bytes: 3628
n = int(input())

info = []
for i in range(20):
    v, w = 1, 1 ** i
    info.append((v, w))
    v, w = 1, 6 ** i
    info.append((v, w))
    v, w = 1, 9 ** i
    info.append((v, w))

m = len(info)
INF = 10 ** 8
dp = [[INF] * (n + 1) for i in range(m + 1)]
dp[0][0] = 0

for i in range(m):
    v, w = info[i]
    for j in range(n + 1):
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j])
        if j - w >= 0:
            dp[i + 1][j] = min(dp[i + 1][j - w] + v, dp[i + 1][j])

print(dp[-1][-1])


Measured memory_bytes: 88684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, m, x; cin >> n >> m >> x;
	ll c[n], a[n][m];
	zep(i, 0, n){
		cin >> c[i];
		zep(j, 0, m){
			cin >> a[i][j];
		}
	}
	
	ll ans = INF;
	zep(bit, 0, (1 << n)){
		ll cnt[m]; memset(cnt, 0, sizeof(cnt));
		
		ll res = 0;	
		zep(i, 0, n){
			if(bit & (1 << i)){
				res += c[i];
				zep(j, 0, m){
					cnt[j] += a[i][j];
				}
			}
		}
		
		bool ok = true;
		zep(j, 0, m){
			if(cnt[j] < x)ok = false;
		}
		if(ok)ans = min(ans, res);
	}
	
	print((ans != INF)? ans : -1)
	
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
using namespace std;

signed main(){
	ios_base::sync_with_stdio(0);
	int x;
	cin>>x;
	if(x>=30) cout<<"Yes";
	else cout<<"No";
	re 0;
}

Measured memory_bytes: 3644
import sys

input = sys.stdin.readline

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

x = [0] * N
x[0] = sum(A) - sum(A[i] for i in range(1, N, 2)) * 2

for i in range(1, N):
    x[i] = A[i - 1] * 2 - x[i - 1]

print(*x)


Measured memory_bytes: 14104
#include<stdio.h>

#define N 101

void dfs(int u);

int G=1,n,a[N][N],b[N];
int d[N],f[N];

int main(void){
  int i,j,u,t,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&t);
    for(j=0;j<t;j++){
      scanf("%d",&v);
      a[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    if(b[i]==0){
      dfs(i);
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

void dfs(int id){
  int v;
  d[id]=G++;
  b[id]=1;
  for(v=0;v<n;v++){
    if(a[id][v]==1&&b[v]==0){
      dfs(v);
    }
  }
  f[id]=G++;
}



Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 300010
long long mod = 998244353LL;
long long fac[MAXN], inv[MAXN];
long long power(long a, long x)
{
    long long ans = 1;
    while(x)
    {
        if(x&1)
        {
            ans  = ans * a % mod;
        }
        x >>= 1;
        a = a * a % mod;
    }
    return ans;
}
void init()
{
    fac[0] = 1;
    for(int i = 1; i < MAXN; i++)
        fac[i] = fac[i-1] * i % mod;
    inv[MAXN-1] = power(fac[MAXN-1], mod-2);
    for(int i = MAXN-2; i >= 0; i--)
        inv[i] = inv[i+1] * (i+1) % mod;
}
long long combinator(long long n,long long m)
{
    if(n < m)
        return 0;
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
    init();
    long long n, a, b, k, ans = 0;
    cin >> n >> a >> b >> k;
    for(int i = 0; i <= n; i++)
    {
        if(k - a*i < 0)
            continue;
        if((k-a*i) % b != 0)
            continue;
        long long y = (k-a*i)/b;
        if(y > n)
            continue;
        ans = (ans+combinator(n, i) * combinator(n, y) + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
//DEBUG 
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define all(v) (v).begin(), (v).end()
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define pb push_back
#define fi first
#define se second
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
 
int32_t main()
{
    IOS;
    //go in steps of 99
    int ans=0;
    cin>>n;
    int curr=100;
    int i=0;
    while(true){
      curr=ll(curr*1.01);
      i++;
      if(curr>=n){
        cout<<i<<ln;
        break;
      }
    }
}


Measured memory_bytes: 3612
#include<iostream>
#include<cmath>
#include<cstdio>

using namespace std;

bool func();

int main()
{
	while(func()){};
	
	return false;
}

bool func()
{
	while(true)
	{
		double n = 0.0;

		cin >> n;

		if(n < 0)
		{
			return false;
		}

		double tmpi = 0;
		double d = 0; // 整数部格納
		double doubl_e = modf(n, &d); // 小数部格納
		int in_t = d;

		for(int i = 0; true; i++)
		{
			if(i >= 8)
			{
				cout << "NA" << endl;
				return true;
			}

			tmpi += (in_t % 2) * pow(10, (double)i);
		
			in_t /= 2;


			if(in_t == 0)
			{
				break;
			}
		}

		int spi = 0;

		for(spi = 1; true; spi++)
		{
			if(spi >= 5)
			{
				cout << "NA" << endl;
				return true;
			}

			doubl_e *= 2;

			if(doubl_e >= 1)
			{
				doubl_e -= 1;
				tmpi += 1 * pow(10, (double)-spi);
			}

			if(doubl_e == 0)
			{
				break;
			}
		}

		bool flag = true;

		for(unsigned long int i = 10000000; true; i /= 10)
		{
			if(flag && tmpi <= 0.9)
			{
				flag = false;
				i /= 10; 
			}

			if(tmpi >= i)
			{
				break;
			}

			cout << '0';
		}

		printf("%.4lf\n",  tmpi);

	}
}

Measured memory_bytes: 1324
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, m;
    long long ans = 0;
    vector<int> a;
    vector<P> p;
    cin >> n >> m;
    a.assign(n, 0);
    p.assign(m, P(0, 0));
    
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    
    for(int i=0;i<m;i++){
        int b, c;
        cin >> b >> c;
        p[i] = P(c, b);
    }
    sort(a.begin(), a.end());
    sort(p.begin(), p.end(), greater<P>());
    int q = 0;
    for(int i=0;i<n;i++){
        if(q < m && a[i] < p[q].first){
            a[i] = p[q].first;
            if(--p[q].second <= 0)q++;
        }
        ans += a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double div = (double) n / 111;
		if (div % 1 == 0) {
			System.out.println(((int) div) * 111);
		} else {
			System.out.println(((int) div + 1) * 111);
		}
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define LL long long
#define M 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main()
{
	fastio;
	int n, i, ans=0;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
		cin>>a[i];
	sort(a, a+n);
	for(i=0;i<n-1; i++){
		int j=i+1, k=j+1;
		while(j<n-1){
			if(a[i]+a[j]>a[k]){
				ans++;
				k++;
				if(k>n-1){
					j++;
					k=j+1;
				}
			}
			else{
				j++;
				k=j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
/*
Problem

Category
全探索・全列挙

URL
https://atcoder.jp/contests/abc106/tasks/abc106_b

Date: 2020/03/24
*/

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

/* ==== declarations ====== */
// functions
void solve();

// global variables
int N;

/* ======================== */

int calcDivisor(int n) {
    int numDivisor = 0;
    for (int i = 1; i<=n; ++i) {
        if (n%i == 0) {
            numDivisor++;
        }
    }
    return numDivisor;
}

void solve() {
    int ans = 0;
    for (int i=1; i<=N; ++i) {
        if (i % 2 && calcDivisor(i) == 8) ans++;
    }
    cout<<ans<<endl;
}

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

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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	ll a,b,c;
	cin>>a>>b>>c;
	set<pair<pll,ll>> se;
	int ans = 0;
	while(1){
		if(a&1||b&1||c&1){
			cout<<ans<<endl;
			return;
		}
		if(se.find(mkp(pll(a,b), c)) != se.end()){
			cout<<-1<<endl;
			return;
		}
		se.insert(mkp(pll(a,b), c));
		ll _a = a;
		ll _b = b;
		ll _c = c;
		a = _b/2 + _c/2;
		b = _a/2 + _c/2;
		c = _a/2 + _b/2;
		ans++;
	}
}


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

Measured memory_bytes: 256
num_inputs = int(input())

for i in range(num_inputs):
    current_rate = int(input())
    if i == 0:
        minimum_rate = current_rate
        continue
    
    profit = current_rate - minimum_rate
    if i == 1:
        max_profit = profit
    elif profit > max_profit:
        max_profit = profit
    
    if current_rate < minimum_rate:
        minimum_rate = current_rate

print(max_profit)



Measured memory_bytes: 5608
import sys
input = sys.stdin.readline
from collections import *

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N, K, L = map(int, input().split())
uf1 = Unionfind(N)
uf2 = Unionfind(N)

for _ in range(K):
    p, q = map(int, input().split())
    uf1.unite(p-1, q-1)

for _ in range(L):
    r, s = map(int, input().split())
    uf2.unite(r-1, s-1)

d = defaultdict(int)

for i in range(N):
    a = uf1.root(i)
    b = uf2.root(i)
    d[10**6*a+b] += 1
    
ans = []

for i in range(N):
    a = uf1.root(i)
    b = uf2.root(i)
    ans.append(d[10**6*a+b])

print(*ans)

Measured memory_bytes: 99544
N=int(input())
A=list(map(int, input().split()))
MAXBIT=60
MOD=10**9+7
bits=[[0 for _ in range(MAXBIT)] for _ in range(N)]
for i in range(N):
    tmp=A[i]
    j=0
    while tmp>0:
        bits[i][j]=tmp%2
        tmp=tmp//2
        j+=1
ans=0
for j in range(MAXBIT):
    cnt0=0
    for i in range(N):
        if bits[i][j]==0:
            cnt0+=1
    ans=(((cnt0*(N-cnt0))%MOD*(2**j))%MOD+ans)%MOD
print(ans)


Measured memory_bytes: 232780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll a,b,c,n,ans=0;
void Main(){
    ll t[2],a[2],b[2];
    cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1];
    ll onedist=t[0]*(a[0]-b[0]);
    ll twodist=t[1]*(a[1]-b[1]);
    ll totaldist=onedist+twodist;
    if(totaldist==0){
        cout<<"infinity"<<endl;
        return;
    }
    if(totaldist<0){
        onedist*=(-1);
        twodist*=(-1);
        totaldist*=(-1);         
    }
    if(onedist>=0){
        ans=0;
    }
    else{
        ans=abs(onedist/totaldist)*2+bool(abs(onedist)%abs(totaldist));
    }
    cout<<ans<<endl;
}
main(){
    Main();
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
XYA = [list(map(int, input().split())) for _ in range(N)]

x_min = max([0] + [xya[0] for xya in XYA if xya[2] == 1])
x_max = min([W] + [xya[0] for xya in XYA if xya[2] == 2])
y_min = max([0] + [xya[1] for xya in XYA if xya[2] == 3])
y_max = min([H] + [xya[1] for xya in XYA if xya[2] == 4])
print(max(x_max - x_min, 0) * max(y_max - y_min, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int n;
    int64_t k;
    cin>>n>>k;
    int64_t ans=-1000000000000;
    vector<int64_t> p(n),c(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,n){
        cin>>c[i];
    }
    rep(i,n){//n通りのスタート地点を考える 
        int place=i;
        int64_t score=c[p[place]];
        int64_t tochu=0;
        if(k<=n){
            rep(j,k){
                tochu += c[p[place]];
                place = p[place];
                score = max(score,tochu);
            }
            ans = max(score,ans);
        }
        //cout<<score<<" ";
        else{
            int circle=0;
            rep(j,n){
                tochu += c[p[place]];
                place = p[place];
                score = max(score,tochu);
                if(place==i){
                    circle=j+1;
                    break;
                }
            }
            //cout<<tochu<<endl;
            //tochu=一周した時のスコア
            if(tochu<=0){//これ以上回っても得がない
                ans = max(score,ans);
                //cout<<i<<"minus"<<endl;
            }
            else{
               // if(score >= tochu*(n/k)+n%kまでの最大値)
               //if(k/n>=2){
               tochu *= (k/circle)-1;
               //}
               int64_t k2;
                k2 = k - circle*(k/circle-1);
                score = max(tochu,score);
                place=i;
                //cout<<place<<endl;
                rep(j,k2){
                    tochu += c[p[place]];
                    place = p[place];
                    score = max(score,tochu);
                }
                ans = max(ans,score);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3652
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)

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

count = 0
for i in range(N):
    x, y = list(map(int, input().split()))
    if x**2 + y**2 <= D**2: count += 1

print(count)

Measured memory_bytes: 71428
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int a = 0;
	cin >> a;
	int* arr = new int[a];
	for (int i = 0; i < a; i++)
	{
		cin >> arr[i];
	}
	sort(arr, arr + a);
	int temp = -1;
	bool flag = 0;
	for (int i = 0; i < a; i++)
	{
		if (temp != arr[i])
		{
			temp = arr[i];
		}
		else
		{
			flag = 1;
			break;
		}
	}
	if (flag)
	{
		cout << "NO";
	}
	else
	{
		cout << "YES";
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll d[MAXn];
int main(){
    IOS();
    ll n;
    cin >> n;
    REP (i,n) cin >> d[i];
    for (ll i=n-2;i>=0;i--) {
        if (d[i] > d[i+1]) d[i]--;
    }
    ll cur = 0;
    bool ok = true;
    REP (i,n) {
        if (d[i] < cur) ok = false;
        cur = d[i];
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main(){
	
	int N;
	cin >> N;
	
	string str1, str2;
	
	cin >> str1 >> str2;
	
	long long int ans;
	
	int start, pre;
	
	if(str1[0] == str2[0]){
		ans = 3;
		start = 1;
		pre = 1;
	}else{
		ans = 6;
		start = 2;
		pre = 2;
	}
	
	for(int i = start; i < N; i++){
		if(str1[i] == str2[i]){
			if(pre == 1){
				ans *= 2;
			}else{
				ans *= 1;
			}
			pre = 1;
		}else{
			if(pre == 1){
				ans *= 2;
			}else{
				ans *= 3;
			}
			i++;
			pre = 2;
		}
		ans %= 1000000007;
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18+1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll H, W, K;
	cin >> H >> W >> K;

	ll x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	vector<vector<char>> c(H + 2, vector<char>(W + 2, '@'));
	repn(i, H)repn(j, W)cin >> c[i][j];

	vvll dis(H + 1, vll(W + 1, INF));
	queue<pair<ll,ll>> q;
	dis[x1][y1] = 0;
	q.push({ x1,y1 });

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

	while (!q.empty()) {
		ll xx = q.front().first;
		ll yy = q.front().second;
		q.pop();

		ll t = dis[xx][yy];

		rep(j, 4) {
			ll x = xx;
			ll y = yy;

			rep(k, K) {
				x += dx[j];
				y += dy[j];
				if (c[x][y] == '@') { break; }
				if (dis[x][y] <= t) { break; }

				if(dis[x][y]==INF)q.push({ x,y });
				dis[x][y] = min(dis[x][y], t + 1);
				

				//cout << x << y << dis[x][y] << endl;
			}
		}
	}

	if (dis[x2][y2] == INF) { dis[x2][y2] = -1; }
	cout << dis[x2][y2] << endl;
}

Measured memory_bytes: 29468
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);

	string x;
	cin >> x;
	int n = x.size();
	REP(i, n) cout << 'x';
	cout << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 

typedef long long ll; 
const int mod = 1000000007; 

int prime[MAX]; 
unordered_map<int, int> max_map; 

// Function to return a^n 
int power(int a, int n) 
{ 
	if (n == 0) 
		return 1; 
	int p = power(a, n / 2) % mod; 
	p = (p * p) % mod; 
	if (n & 1) 
		p = (p * a) % mod; 
	return p; 
} 

// Function to find the smallest prime factors 
// of numbers upto MAX 
void sieve() 
{ 
	prime[0] = prime[1] = 1; 
	for (int i = 2; i < MAX; i++) { 
		if (prime[i] == 0) { 
			for (int j = i * 2; j < MAX; j += i) { 
				if (prime[j] == 0) { 
					prime[j] = i; 
				} 
			} 
			prime[i] = i; 
		} 
	} 
} 

// Function to return the LCM modulo M 
ll lcmModuloM(const int* ar, int n) 
{ 

	for (int i = 0; i < n; i++) { 
		int num = ar[i]; 
		unordered_map<int, int> temp; 

		// Temp stores mapping of prime factor to 
		// its power for the current element 
		while (num > 1) { 

			// Factor is the smallest prime factor of num 
			int factor = prime[num]; 

			// Increase count of factor in temp 
			temp[factor]++; 

			// Reduce num by its prime factor 
			num /= factor; 
		} 

		for (auto it : temp) { 

			// Store the highest power of every prime 
			// found till now in a new map max_map 
			max_map[it.first] = max(max_map[it.first], it.second); 
		} 
	} 

	ll ans = 1; 

	for (auto it : max_map) { 

		// LCM is product of primes to their highest powers modulo M 
		ans = (ans * power(it.F, it.S)) % mod; 
	} 

	return ans; 
} 
ll modularExponentiation(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = modularExponentiation(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 
int main(){
	int n;
	cin>>n;
	int a[n];
	sieve();
	for(int i = 0;i<n;i++)
		cin>>a[i];
	ll res = lcmModuloM(a,n);
	ll sum = 0;
	for(int i = 0;i<n;i++){
		sum = sum + res*modularExponentiation(a[i],mod-2,mod);
		sum = sum %mod;
	}
	cout<<sum;
}

Measured memory_bytes: 39808
from bisect import bisect_right as binser
n = int(input())
l = [int(j) for j in raw_input().split()]
l = sorted(l)
ans = 0 
for i in range(1,n):
    for j in range(i):
        a = l[i] - l[j]
        x = binser(l,a, j+1, i)
        # if i-x:
        #     print(x, j+1, i-1)
        if l[x] == a:
            x = x+1
        ans+=(i-x)
        # print(i-x, a, l[x], l[j], l[i])
        # print(l[x], l[i],l[j])
print(ans)

Measured memory_bytes: 33896
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <map>
#include <set>

using namespace std;

int main() {
    int x,t;
    cin >> x >> t;
    if(x-t > 0) {
        cout << x-t;
    }else {
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt();
            }

            int[] counts = new int[(int) (1e5 + 1)];
            for (int i = 0; i < N; i++) {
                counts[a[i]]++;
            }

            int max = 0;
            for (int i = 0; i < counts.length; i++) {
                max = Math.max(max, (i - 1 < 0 ? 0 : counts[i - 1]) + counts[i] + (i + 1 >= counts.length ? 0 : counts[i + 1]));
            }

            System.out.println(max);
        }
    }
}


Measured memory_bytes: 49696
#include <iostream>

using namespace std;

void output(int in[], int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << in[i];
		if (i != n - 1)
			cout << " ";
	}
	cout << endl;
}

int main(void)
{
	int n;
	cin >> n;

	int a[103];

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

	output(a, n);

	for (int i = 1; i < n; i++)
	{
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;

		output(a, n);
	}

	return 0;
}


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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, k, MOD = 1e9+7;
	cin >> n >> k;
	int arr[n], dp[n + 3][k + 3], pfs[n + 3][k + 3];
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	memset(dp, 0, sizeof(dp));
	memset(pfs, 0, sizeof(pfs));
	dp[0][0] = 1;
	for(int i = 0; i <= k; i++) pfs[0][i] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= k; j++){
			dp[i][j] = pfs[i - 1][j];
			if(j - arr[i - 1] - 1 >= 0) dp[i][j] = ((dp[i][j] - pfs[i - 1][j - arr[i - 1] - 1])%MOD + MOD)%MOD; 
			pfs[i][j] = dp[i][j];
			if(j) pfs[i][j] = (pfs[i][j] +  pfs[i][j - 1])%MOD; 
		}
	}
	cout << dp[n][k] << endl;
}

Measured memory_bytes: 80768
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[3001][3001],a[3001],n;
ll f(int i,int j)
{
    if(i>j)
    return 0;
    if(dp[i][j]!=0)return dp[i][j];
    else
    {
        if((j-i)%2==n%2)
            dp[i][j]=max(a[i]+f(i+1,j),a[j]+f(i,j-1));
        else
            dp[i][j]=min(-1*a[i]+f(i+1,j),-1*a[j]+f(i,j-1));
    }
}
int main()
{
    cin>>n;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)cin>>a[i];
    f(0,n-1);
    cout<<-1*dp[0][n-1];
}


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


string S;

int main(){
    cin >> S;

    int ans = 0;
    int cnt = 0;
    for(int i=0;i<S.size();++i){
        char t = S[i];
        if(t=='A' || t=='T' || t=='G' || t=='C'){
            cnt++;
        } else {
            cnt = 0;
        }
        ans = max(ans,cnt);
    }

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


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

using namespace std;

int main()
{
	int n=0;
	string s="";
	cin >> n >> s;
	if (n%2==1)
	{
		cout << "No";
		return 0;
	}
	string s1="", s2="";
	for (int i=0; i<n/2; i++)
	{
		s1+=s[i];
	}
	for (int i=n/2; i<n; i++)
	{
		s2+=s[i];
	}
	(s1==s2) ? cout << "Yes" : cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

#include <deque>

int main(void){
    Cin(int, h, w);
    vc<vc<int>> m(h+2, vc<int>(w+2, -1));
    int k = 0;
    For(i, h) For(j, w){
        Cin(char, c);
        if(c == '.') m[i+1][j+1] = 1e9;
        else k ++;
    }
    m[1][1] = 1;
    deque<pair<int, int>> q {{1, 1}};
    while(!q.empty()){
        int i, j;
        tie(i, j) = q.front();
        q.pop_front();
        
        if(i == h && j == w){
            // For(i, h+2) Couts(m[i]);
            Cout(h*w - m[i][j] - k);
            return 0;
        }
        
        for(int d : {-1, 1}){
            if(m[i+d][j] > m[i][j]+1){
                m[i+d][j] = m[i][j]+1;
                q.emplace_back(i+d, j);
            }
            if(m[i][j+d] > m[i][j]+1){
                m[i][j+d] = m[i][j]+1;
                q.emplace_back(i, j+d);
            }
        }
    }
    Cout(-1);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
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;


//ここから

void solve(){
  int n,k;
  cin>>n>>k;
  double ans=0;
  double p=double(n),q=0.5;
  for(int i=1;i<=n;++i){
    int sum=i,cnt=0;
    while(sum<k){
      sum*=2;
      ++cnt;
    }
    //cerr<<cnt<<endl;
    ans+=pow(q,cnt)/p;
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for _ in range(n)])

d = 0
ans = 0
for _ab in ab:
    diff = m - d
    if _ab[1] - diff < 0:
        ans += _ab[0]*_ab[1]
        d += _ab[1]
    else:
        ans += _ab[0]*diff
        d += diff

print(ans)


Measured memory_bytes: 28652
import java.util.*;

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

        int min1 = sc.nextInt();
        min1 = Math.min(min1, sc.nextInt());

        int min2 = sc.nextInt();
        min2 = Math.min(min2, sc.nextInt());

        System.out.println(min1 + min2);
    } 
}

Measured memory_bytes: 22740
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    for i in range(1, N):
        A[i] += A[i-1]
    cnt1, cnt2 = 0, 0
    ref1, ref2 = 0, 0
    for i, a in enumerate(A):
        if i % 2 == 0:
            if a <= ref1:
                cnt1 += ref1 - a + 1
                ref1 -= ref1 - a + 1
            if a >= ref2:
                cnt2 += a - ref2 + 1
                ref2 += a - ref2 + 1
        if i % 2 == 1:
            if a >= ref1:
                cnt1 += a - ref1 + 1
                ref1 += a - ref1 + 1
            if a <= ref2:
                cnt2 += ref2 - a + 1
                ref2 -= ref2 - a + 1

    print(min(cnt1, cnt2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a,b,c,d,e;
 cin >> a >> b >> c;
 if((a+(b-1))/b<=c)
 {
     cout << "Yes" << endl;
 }
 else{
    cout << "No" << endl;
 }

}


Measured memory_bytes: 3632
import java.io.*;
import java.util.*;

public class Main
{

	static OutputStream outputStream = System.out;
	static PrintWriter out = new PrintWriter(outputStream);

	static class node implements Comparable<node>
		{
			int data;int indx;
	
			node(int i,int o)
			{
				data=i;indx=o;
			}
			public int compareTo(node n)
			{
				if(this.data!=n.data) return this.data-n.data;
				return this.indx-n.indx;
			}
		}
	
	public static void main(String[] Rohan)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		String[] s=br.readLine().split(" ");
		int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1]);


		node[] a=new node[n];


		for(int i=0;i<n;i++)
		{
			s=br.readLine().split(" ");
			a[i]=new node(Integer.parseInt(s[0]),Integer.parseInt(s[1]));
		}

		Arrays.sort(a);


		long ans=0;

		for(int i=0;i<n;i++)
		{
			if(m<=0) break;

			long temp=a[i].data;
			temp*=Math.min(m,a[i].indx);
			m-=Math.min(m,a[i].indx);
			ans+=temp;
		}

		
		out.println(ans);
		out.close();
		

	}
}

Measured memory_bytes: 46888
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    char t;
    t = s[0];
    for(int i = 1; i < 4; i++){
        if (t == s[i]) {
            cout << "Bad" << endl;
            return 0;
        }else{
            t = s[i];
        }
    }
    cout << "Good" << endl;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a(n);
    for (Int i = 0; i < (Int)n; i++) {
        cin >> a[i];
    }
    for (Int i = k; i < n; i++) {
        if (a[i - k] < a[i]) {
            print("Yes");
        } else {
            print("No");
        }
    }
    return 0;
}

Measured memory_bytes: 4788
n=int(input())
cs=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    t=0
    for c,s,f in cs[i:]:
        t=max(t,s)
        if t%f:
            t+=-t%f
        t+=c
    print(t)
print(0)

Measured memory_bytes: 42476