akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
//#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------

//tle
//O(N)ではあうと

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


int main(void)
{
  double a,b,n;
  LL A,B;
  LL work1, work2;
  LL ans = 0;
  LL sum;
  scanf("%lf %lf %lf", &a, &b, &n);

  if (n < b) {
    printf("%lld\n", (LL)(a*((double)n)/b));
    return 0;
  }else{
    printf("%lld\n", (LL)((a*(double)(b-1))/b) - ((LL)a)*(LL)(((double)(b-1))/b));
  }
  /*

  if ((LL)n % (LL)b == 0) {
    printf("%lld\n", (LL)((a*(double)(n-1))/b) - ((LL)a)*(LL)(((double)(n-1))/b));
  }else{
    printf("%lld\n", (LL)((a*((double)n))/b) - ((LL)a)*(LL)(((double)(n))/b) );
  }
  */
  /*

  for (LL x = b; x <= n; x+=b) {
    work1 = (LL)(a*((double)x)/b);
    work2 = (LL)(((double)x)/b);
    sum = work1 - ((LL)a) *work2;
    ans = max(ans,sum);
  }
  printf("%lld\n", ans);
  */
  return 0;
}


Measured memory_bytes: 1696
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

ll MAX = 1000000000000;

ll sol(ll i,ll m,ll cind,vector<ll> &cost,vector<ll> &indices,ll fval,vector<vector<ll> > &dp)
{
    if(i==m)
    {
        if(fval == cind)
        {
            return 0;
        }
        return MAX;
    }
    if(fval == cind)
    {
        return 0;
    }
    if(dp[i][cind]!=-1)
    {
        return dp[i][cind];
    }
    ll ans1 = cost[i] + sol(i+1,m,(cind|indices[i]),cost,indices,fval,dp);
    ll ans2 = sol(i+1,m,cind,cost,indices,fval,dp);
    ll ans = min(ans1,ans2);
    return dp[i][cind] = ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll> cost(m);
    vector<ll> indices(m);
    for(ll i=0;i<m;i++)
    {
        ll a,b;
        cin>>a>>b;
        cost[i]=a;
        for(ll j=0;j<b;j++)
        {
            ll x;
            cin>>x;
            x--;
            ll p = 1<<x;
            indices[i] = (indices[i]|p);
        }
    }
    ll maxv = 1<<n;
    maxv--;
    ll p = 0;
    for(auto x:indices)
    {
        p = (p|x);
    }
    if(p!=maxv)
    {
        cout<<-1<<endl;
        return 0;
    }
    vector<vector<ll> > dp(m,vector<ll>(maxv+1,-1));
    ll ans = sol(0,m,0,cost,indices,maxv,dp);
    cout<<ans;
    return 0;
}



Measured memory_bytes: 32512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    string s;
    cin>>s;
    ll i,j,k,l,d,p,q,r,y,ans=999999999;
    l=s.size();
    for(i=0; i<l-2; i++)
    {

        p=s[i]-'0';
        q=s[i+1]-'0';
        r=s[i+2]-'0';
        y=(p*100)+(q*10)+r;
        d=y-753;
        if(d<0)
            d=-d;
        //cout<<y<<" "<<d<<endl;
        if(ans>d)
            ans=d;

    }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <stdio.h>
int a[111111];
int main(void)
{
	int n, cnt4 = 0, cnt2 = 0, cnt1=0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		a[i] = x;
		if (x % 4 == 0) cnt4++;
		else if (x % 2==0) cnt2++;
		else if (x % 2 != 0) cnt1++;
	}
	if (cnt2 == 0)
	{
		if (cnt4 + (n & 1) >= cnt1) puts("Yes");
		else puts("No");
	}
	else
	{
		if (cnt4 >= cnt1) puts("Yes");
		else puts("No");
	}
	return false;
}

Measured memory_bytes: 512
count = 1

def number(h,count):
    if h<= 1:
        return count
    else:
        return number(h//2,count+1)
h = int(input())
#print(keisan(h,count))
key = number(h//2,count)
ans = 0
if h == 1:
    print(1)
else:
    for i in range(1,key+1):
        ans += 2**i
    print(ans+1)


Measured memory_bytes: 2940
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    println(problem111a(n))
}

fun problem111a(n: Int): String {
    return n.toString().map { if (it == '9') 1 else 9 }.joinToString("")
}

Measured memory_bytes: 31392
fun main(args: Array<String>) {
    val (n, m, c) = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    val b = readLine()!!.split(" ").map { it.toInt() }
    for(i in 0 until n){
        var now = 0
        val a = readLine()!!.split(" ").map { it.toInt() }
        for(j in 0 until m) {
            now += b[j] * a[j]
        }
        if(now + c > 0)ans++
    }
    println(ans)
}

Measured memory_bytes: 38128
n=parse(Int,readline())
dp=zeros(Int,62,3)
dp[61,1]=1
for i=60:-1:1
	b=(n>>(i-1))&1
	for j=0:2
		for k=0:2
			if j*2+b>=k
				dp[i,min(j*2+b-k,2)+1]+=dp[i+1,j+1]
				dp[i,min(j*2+b-k,2)+1]%=10^9+7
			end
		end
	end
end
println((dp[1,1]+dp[1,2]+dp[1,3])%(10^9+7))


Measured memory_bytes: 165800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


void factorize(ll n, unordered_map<ll, ll>& out){
    // out.clear();
    while(n % 2 == 0){
        out[2]++;
        n /= 2;
    }
    for(ll p = 3; p * p <= n; p += 2){
        while(n % p == 0){
            out[p]++;
            n /= p;
        }
    }
    if(n > 2){
        out[n]++;
    }
}


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

    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    unordered_map<ll, ll> f;
    factorize(n, f);

    ll ans = 0;
    for(auto it = f.begin(); it != f.end(); ++it){
        ll m = it->second;
        for(ll i = 1; i <= m; ++i){
            ans++;
            m -= i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
ll a[100005];
void solve()
{
	int n;
	ll sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum = sum + abs(a[i]);
	}
	sort(a, a + n);
	if (a[0] < 0 && a[n - 1] < 0)
	{
		ll x = a[n-1];
		cout << sum + 2*a[n - 1]<<endl;
		for (int i = n-2; i>=0; i--)
		{
			cout << x << " " << a[i] << endl;
			x = x - a[i];
		}
		return;
	}
	if (a[0] >= 0 && a[n - 1] >= 0)
	{
		ll x = a[0];
		cout << sum - 2 * a[0] << endl;
		for (int i = 1; i < n -1; i++)
		{
			cout << x << " " << a[i]<<endl;
			x = x - a[i];
		}
		cout << a[n-1] << " " << x;
		return;
	}
	cout << sum << endl;
	int i = n - 2,x=a[0];
	while (a[i] >=0)
	{
		cout << x << " " << a[i]<<endl;
		x = x - a[i];
		i--;
	}
	cout << a[n - 1] << " " << x << endl;
	x = a[n - 1] - x;
	 i = 1;
	while (a[i] < 0)
	{
		cout << x << " " << a[i] << endl;
		x = x - a[i];
		i++;
	}
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

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

const ll INF = 1LL << 60;

ll N;
struct edge { ll u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}
vector<edge> es;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B) {
			return false;
		}
 
		if (size(A) < size(B)) swap(A, B);
 
		Parent[A] += Parent[B];

		Parent[B] = A;
 
		return true;
	}
};

ll kruscal() {
    sort(es.begin(), es.end(), comp);
    UnionFind uf = UnionFind(N);

    ll cost = 0;
    for (int i = 0; i < es.size(); i++) {
        if (uf.root(es[i].u) != uf.root(es[i].v)) {
            uf.connect(es[i].u, es[i].v);
            cost += es[i].cost;
        }
    }

    return cost;
}

int main() {
    cin >> N;
    vector<P> v_x, v_y;
    rep(i, N) {
        ll x, y;
        cin >> x >> y;

        v_x.push_back(P(x, i));
        v_y.push_back(P(y, i));
    }
    sort(v_x.begin(), v_x.end());
    sort(v_y.begin(), v_y.end());

    // x方向
    rep(i, N) {
        if (i - 1 >= 0) {
            // v_x[i].first - 
            edge e = { v_x[i].second, v_x[i - 1].second, v_x[i].first - v_x[i - 1].first};
            es.push_back(e);
        }

        if (i + 1 <= N - 1) {
            edge e = { v_x[i].second, v_x[i + 1].second, v_x[i + 1].first - v_x[i].first};
            es.push_back(e);
        }
    }

    // y方向
    rep(i, N) {
        if (i - 1 >= 0) {
            edge e = { v_y[i].second, v_y[i - 1].second, v_y[i].first - v_y[i - 1].first};
            es.push_back(e);
        }

        if (i + 1 <= N - 1) {
            edge e = { v_y[i].second, v_y[i + 1].second, v_y[i + 1].first - v_y[i].first};
            es.push_back(e);
        }
    }

    ll ans = kruscal();
    cout << ans << endl;
}

Measured memory_bytes: 16864
#include<iostream>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1c(i, n) for (ll i = 1; i <= (ll)(n); i++)

typedef long long ll;

string S;

int main() {
  cin >> S;
  int hi = 0;
  int nohi = 0;
  if(S.size()%2) {
    nohi = 1;
  } else {
    for(int i = 0; i < S.size()-1; i+=2) {
      if(S[i] == 'h' && S[i+1] == 'i') {
        hi = 1;
      } else {
        nohi = 1;
      }
    }
  }
  if(hi && !nohi) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pll pair<long long, long long>
#define f first
#define s second
#define debug cout<<"here\n" 
#define MOD 1000000007
 
using namespace std;

ll modexp(ll a, ll p, ll mod){
	if(p == 0) return 1;
	ll ans = modexp(a,p/2,mod);
	ans = (ans*ans)%mod;
	if(p%2) return (ans*a)%mod;
	else return ans;
}

void solve(){	
	int n; 
	string s; cin>>s;
	n = s.length();
	ll x=0,y=0,z=0,xx,yy,zz,k=0;
	for(int i=0; i<n; i++){
		if(s[i] == '?'){
			k++;
			xx = (3*x + modexp(3,k-1,MOD))%MOD;	
			yy = (3*y + x)%MOD;
			zz = (3*z + y)%MOD;
			x = xx; y = yy; z = zz;
		}
		else if(s[i] == 'A') x = (x+modexp(3,k,MOD))%MOD;
		else if(s[i] == 'B') y = (x+y)%MOD;
		else z = (z+y)%MOD;
	}
	cout<<z;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cout.tie(0); cin.tie(0);	
	cout<<fixed<<setprecision(12);

	int t =1; //cin>>t;
	for(int i=1; i<= t; i++){
		solve();
		cout<<"\n";
	}
	
	return 0;
}

Measured memory_bytes: 3748
def ra(a): #圧縮された要素を非保持
    ll,l=[],1
    for i in range(len(a)-1):
        if a[i]==a[i+1]:
            l+=1
        else:
            ll.append(l)
            l=1
    ll.append(l)
    return ll
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=sorted(ra(sorted(a)))
print(sum(b)-sum(b[-k:]))

Measured memory_bytes: 32316
package main

import "fmt"

var (
	n    int
	l, r int
)

func main() {
	fmt.Scan(&n)

	count := 0
	for i := 0; i < n; i++ {
		fmt.Scanln(&l, &r)
		count += r - l + 1
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1277
#define ll long long
#define ESP 1e-10
using namespace std;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	//dp[i][j] = ???????????????i????????£?????¨???, line_j?????°?????????????¢????
	int N, T, L, B;
	while (cin >> N >> T >> L >> B) {
		if (N == 0 && T == 0 && L == 0 && B == 0)break;
		vector<vector<double>> dp(T + 2, vector<double>(N + 1, 0));
		vector<int> Lose(N + 1, 0), Back(N + 1, 0);

		for (int i = 0; i < L;i++) {
			int Lose_i; cin >> Lose_i;
			Lose[Lose_i] = 1;
		}
		for (int i = 0; i < B;i++) {
			int Back_i; cin >> Back_i;
			Back[Back_i] = 1;
		}

		/* ????????¶??? */
		dp[0][0] = 1;

		for (int i = 0; i < T;i++) {
			dp[i + 1][N] += dp[i][N];
			for (int j = 0; j < N;j++) {
				if (dp[i][j] < ESP)continue;
				for (int k = 1; k <= 6;k++) {
					int next = j + k;
					if (next > N) next = N - (next%N);
					if (Lose[next] == 1) { dp[i + 2][next] += dp[i][j] / 6.0; }
					else if (Back[next] == 1) { dp[i + 1][0] += dp[i][j] / 6.0; }
					else {dp[i + 1][next] += dp[i][j] / 6.0; }
				}
			}
		}


		cout << fixed << setw(8) << dp[T][N] << endl;
	}
}

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

int main(){
	long long int N, M, count;
	cin >> N >> M;
	
	if(N<=M/2){
		count = N;
		M-=2*N;
		count+=M/4;
	}
	else{
		count=M/2;
	}
	
	cout << count << endl;
	return 0;
}

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

#define ll long long int
const ll sz=1e4+100;;
const ll mod=1e9+7;

ll dp[sz][100][3];
string str;
ll len,kick;

ll cholo(ll id,ll rem, bool bl)
{
    if(id>=len){
        if(rem==0) return 1ll;
        else return 0ll;
    }

    ll &ret=dp[id][rem][bl];
    if(~ret) return ret;

    ll last=(bl) ? (str[id]-'0') : 9;
    ll sum=0;

    for(ll i=0;i<=last;i++){
        if(i==last) sum=(sum + cholo(id+1,(rem + i)%kick,bl))%mod;
        else sum=(sum + cholo(id+1,(rem+ i)%kick,false))%mod;
    }

    return (ret=sum);
}

int main()
{
    ll n,m,p,q,x,y,i,j,k,l;

    cin>>str>>kick;
    memset(dp,-1,sizeof dp);
    len=str.length();

    ll ans=cholo(0,0,true);
    ans=(((ans-1ll)%mod)+mod)%mod;

    cout<<ans<<'\n';

}


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

int main(void) {
	
	int n;
	int ans = 0;
	scanf("%d",&n);
	
	int a[2][n];
	
	for (int i=0;i <= n-1;i++) {
		scanf("%d",&a[0][i]);
	}
	
	for (int j=0;j <= n-1;j++) {
		scanf("%d",&a[1][j]);
	}
	
	for (int k=0;k<=n-1;k++){
		int s = 0;
		for (int l=0;l<=k;l++){
			s = s + a[0][l];
		}
		
		for (int m=k;m<=n-1;m++){
			s = s + a[1][m];
		}
		ans = max(s,ans);
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

cnt = 0
for n in range(A, B+1):
    n_s = str(n)
    n_s_len = len(n_s)
    for i in range(n_s_len//2):
        if n_s[i] != n_s[n_s_len-i-1]:
            break
    else:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
from operator import mul
from functools import reduce
 
def cmb(n,r):
    r = min(n-r,r)
    if r==0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

inf = input().split()
N = int(inf[0])
K = int(inf[1])
M = N-K
for i in range(1,K+1):
  if M+1<i:
    red = 0
  else:
    red = cmb(M+1,i)
  blue = cmb(K-1,i-1)
  print(red*blue%(10**9+7))

Measured memory_bytes: 3944
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();

		int one = N % 10;

		int hundered = N / 100;

		if (one == hundered) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


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

int main()
{
  int n;
  cin>>n;
  
  int a[n+1]={0};
  
  for(int i=1;i<=n;i++)
  {
    int q;
    cin>>q;
    a[q]=i;
  }
  for(int i=1;i<=n;i++)
    cout<<a[i]<<" ";
  cout<<"\n";
  return 0;
}

Measured memory_bytes: 3944
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <list>

using namespace std;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	cout << s.substr(0,s.length()-strlen("FESTIVAL")) << endl;
	return 0;
}


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

int main()
{
  // 入力受け取り
  int N, K;
  cin >> N >> K;
  
  // 出目の数だけ確認
  double probability = 0;
  for (int i=1; i < N+1; i++) {
    int point=i;
    double denominator = N;
    int denotemp=1;
    while( point < K) {
      point *= 2;
      denotemp++;
    }
    denominator*=pow(2,denotemp-1);
    probability += 1/denominator;
  }
  
  printf("%.10lf\n", probability); 
  return 0;
}


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

public class Main
{
	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
                solve();
            }
        }, "1", 1 << 26).start();
	}
	static void solve () {
		FastReader fr =new FastReader();	PrintWriter op =new PrintWriter(System.out);
 
 		double r =(double)fr.nextInt() ;	r *= Math.PI ;	r *= 2.0 ;
 		op.println(r) ;	
		op.flush();	op.close();
	}
	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();
		}

		String nextLine() {
			String str ="";

			try
			{
				str =br.readLine();
			}
			catch(IOException e)
			{
				e.printStackTrace();
			}

			return str;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next()) ;
		}
	}
}


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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }


    sort(A,A + N,greater<int>());
    int Alice=0,Bob=0;
    for (int j = 0; j < N;j += 2){

        Alice = Alice + A[j];
    }
    for (int k = 1; k < N;k += 2){
        Bob = Bob + A[k];
    }

    int result;
    result = Alice - Bob;
    cout << result <<endl;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (r, d, mut x) = (v[0], v[1], v[2]);
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2152
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int> pii32;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 5e3+10;
const int64 MO = 1e9+7;
const int64 IN = 1e9;

vector <int> g[maxn];
int dp[2][maxn][maxn], tmp[2][maxn], G[maxn];
int n;

int dfs (int v, int parent = -1) {
	int sz = 1;
	dp[0][v][1] = 1;
	for (auto u : g[v]) {
		if (u == parent)
			continue;
		int k = dfs(u, v);
		sz += k;
		memset(tmp, 0, sizeof tmp);
		// v u stays
		for (int t = 1; t <= sz - k; t++)
		for (int j = 1; j <= k; j++)
		for (int p = 0; p <= 1; p++) {
			tmp[0][t + j] = (tmp[0][t + j] + 1LL * dp[p][u][j] * dp[p][v][t] % MO) % MO;
			tmp[1][t + j] = (tmp[1][t + j] + 1LL * dp[p][u][j] * dp[1 - p][v][t] % MO) % MO;
		}
		// delete v u
		for (int t = 1; t <= sz - k; t++)
		for (int j = 1; j <= k; j++)
		for (int p = 0; p <= 1; p++) {
			tmp[0][t] = (tmp[0][t] + 1LL * dp[p][u][j] * G[j] % MO * dp[1 - p][v][t] % MO) % MO;
			tmp[1][t] = (tmp[1][t] + 1LL * dp[p][u][j] * G[j] % MO * dp[p][v][t] % MO) % MO;
		}
		for (int t = 1; t <= sz; t++)
		for (int p = 0; p <= 1; p++)
			dp[p][v][t] = tmp[p][t];
	}
	return sz;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	G[0] = 1;
	G[1] = 0;
	for (int i = 2; i < maxn; i++)
		G[i] = 1LL * (i - 1) * G[i - 2] % MO;
	//
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		--v; --u;
		g[v].PB(u);
		g[u].PB(v);
	}
	dfs(0);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = (ans + 1LL * -1 * G[i] * dp[1][0][i] % MO) % MO;
		ans = (ans + 1LL * 1  * G[i] * dp[0][0][i] % MO) % MO;
	}
	cout << (ans + MO) % MO << "\n";
}


Measured memory_bytes: 195840
class UnionFold:
    def __init__(self,n):
        self.par = [i for i in range(n+1)]
        
        #木の高さを格納する（初期状態では０）
        self.rank = [0]*(n+1)
        
    def find(self, x):
        #根ならその番号を返す
        if self.par[x]==x:
            return x
        
        #根でないないなら親の要素で再検索
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])
    
    #同じ木に属するか判定
    def same(self,x,y):
        return self.find(x) == self.find(y)
    
    #併合
    def union(self,x,y):
        #根を探す
        x = self.find(x)
        y = self.find(y)
        
        #木の高さを比較し、低い方から高い方に辺を繋ぐ
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
                
def main():
    N,M = map(int, input().split())
    union_fold = UnionFold(N)
    for _ in range(M):
        x,y,z = map(int, input().split())
        if not(union_fold.same(x,y)):
            union_fold.union(x,y)
    
    n=0
    for i in range(1,N+1):
        if union_fold.par[i]==i:
            n+=1
    print(n)
    
main()

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
void run_case()
{
    int n;
    cin >> n;
    int mx1 = -INF, mx2 = -INF;
    int mn1 = INF, mn2 = INF;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        int z = x + y;
        mx1 = max(z, mx1);
        mn1 = min(z, mn1);
        int w = x - y;
        mx2 = max(w, mx2);
        mn2 = min(w, mn2);
    }
    int ans = max(mx1 - mn1, mx2 - mn2);
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}


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

using namespace std;
using ll=long long;
const int N = 42; 
bool g[N][N];
ll dp[N][N][N][N][2];

void solve() {
    int n; cin >> n;
    n <<= 1;
    for (int i = 1; i <= n; i++) {
        string s; cin >> s;
        for (int j = 1; j <= n; j++) {
            g[i][j] = s[j-1] == '1';
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n+1; j++) {
            dp[i][i-1][j][j-1][0] = dp[i][i-1][j][j-1][1] = 1;
        }
    }

    for (int a = n; a >= 2; a--) {
        for (int b = a; b < n; b++) {
            for (int c = n; c > b; c--) {
                for (int d = c; d <= n; d++) {
                    for (int p = a; p <= b; p++) {
                        for (int q = c; q <= d; q++) {
                            if (g[p][q]) {
                                dp[a][b][c][d][0] += dp[a][p-1][p+1][b][1] * dp[c][q-1][q+1][d][1];
                            }
                        }
                    }
                    for (int p = a; p <= b; p++) {
                        for (int q = c; q <= d; q++) {
                            dp[a][b][c][d][1] += dp[a][p][q][d][0] * dp[p+1][b][c][q-1][1];
                        }
                    }
                }
            }
        }
    }

    ll res = 0;
    for (int a = 2; a <= n; a++) {
        if (g[1][a]) res += dp[2][a-1][a+1][n][1];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 45440
from itertools import permutations

def main():
    N, C = map(int, input().split())
    Dc = [tuple(map(int, input().split())) for _ in [0] * C]
    Cn = [tuple(map(int, input().split())) for _ in [0] * N]

    sum_ = [[0] * C for _ in [0] * 3]
    for i, cn in enumerate(Cn):
        for j, c in enumerate(cn):
            n = (i + j) % 3
            for k in range(C):
                sum_[n][k] += Dc[c-1][k]

    cost = float('inf')
    for i, j, k in permutations(range(C), 3):
        cost = min(cost, sum_[0][i] + sum_[1][j] + sum_[2][k])
    print(cost)

main()


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

int main(){
  while(true){
    int h, w;
    cin >> h >> w;

    if(h==0 && w==0)
      break;

    int d = h*h+w*w;

    int H = 150;
    int W = 150;
    int D = 150*150+150*150;

    for(int y=1; y<=150; y++){
      for(int x=y+1; x<=150; x++){
	int z = y*y+x*x;

	if(z<=d){
	  continue;
	}
	else{
	  if(z<D){
	    H = y;
	    W = x;
	    D = z;
	  }
	  break;
	}
      }
    }

    for(int y=h+1; y<150; y++){
      bool flg = false;

      for(int x=y+1; x<=150; x++){
	int z = y*y+x*x;

	if(z==d){
	  H = y;
	  W = x;
	  D = z;

	  flg = true;
	}

	if(z>=d)
	  break;
      }

      if(flg)
	break;
    }

    cout << H << ' ' << W << endl;

  }
  return 0;
}



Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP1(i, n) for (int i = 1; i < n + 1; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, d;
    cin >> n >> d;
    int cnt = 0;
    ll x, y;
    REP(i, n)
    {
        cin >> x >> y;
        if (d * d >= x * x + y * y)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int> >;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  string s,t;
  std::cin >> s>>t;
  std::cout << t+s << std::endl;
}


Measured memory_bytes: 256
#include<cstdio>
long long gcd(long long a,long long b)
{
	if(b==0LL)
		return a;
	return gcd(b,a%b);
}
int main()
{
	long long a,b;
	while(~scanf("%lld%lld",&a,&b))
	{
		long long d=gcd(a,b);
		printf("%lld %lld\n",d,a/d*b);
	}
	return 0;
}

Measured memory_bytes: 2664
import math

a,b,c = map(int,input().split())
S = a*b*math.sin(math.radians(c))/2
L = a + b + math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(c)))
h = b*math.sin(math.radians(c))
print(S)
print(L)
print(h)


Measured memory_bytes: 5704
#include <bits/stdc++.h>
#include <cstring> 
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define For2(i, st, en) for(ll i=st; i<en; i+=2)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define int long long int
#define F first
#define mem(a,b) memset(a,b,sizeof(a))
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 500008

 
signed main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
 
    char ch;
    cin>>ch;
    int x = ch;
    x++;
    cout<<(char)(x)<<endl;
}

Measured memory_bytes: 256
//--- pA ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		// int N = Integer.parseInt(line.split("\\s+")[0]);
		// int M = Integer.parseInt(line.split("\\s+")[1]);
		String str_a = line.split("\\s+")[0];
		String str_b = line.split("\\s+")[1];

		line = scanner.nextLine();
		int a = Integer.parseInt(line.split("\\s+")[0]);
		int b = Integer.parseInt(line.split("\\s+")[1]);

		line = scanner.nextLine();
		String throw_str = line;

		if (throw_str.equals(str_a)) {
			a --;
		} else {
			b --;
		}

		System.out.println(a + " " + b);
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int>P;
 
int main() {
  ll a,b,c;
  cin>>a>>b>>c;
  for(int i=0;i<b;i++){
    cout<<c<<" ";
  }
 for(int j=0;j<a-b;j++){
   if(j==(a-b-1)){
     if(c>2){
     cout<<c-1<<endl;
     }
     else{
       cout<<c+1<<endl;
     }
   }
   else {
     if(c>2){
   cout<<c-1<<" ";
     }
     else{
       cout<<c+1<<" ";
     }
   }
 }
}

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

#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

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

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

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<pll> v(n);
	vl mv(n,0);
	rep(i,n){
		ll t,d;
		cin>>t>>d;
		v[i]={t-1,d};
		chmax(mv[t-1],d);
	}
	sort(all(v),[](pll a, pll b){return a.sc>b.sc;});

	vl initVal(1,0),addVal(1,0);
	vb selected(n,false);
	rep(i,n){
		ll t,d; tie(t,d)=v[i];
		if(selected[t]){
			addVal.push_back(d+addVal.back());
		}else{
			selected[t]=true;
			initVal.push_back(d+initVal.back());
		}
	}

	ll ans=0;
	range(i,1,k+1){
		if(initVal.size()-1<i or addVal.size()-1<k-i)continue;
		chmax(ans,i*i+initVal[i]+addVal[k-i]);
	}
	puta(ans);
	return 0;
}

Measured memory_bytes: 3832
import sys
input = sys.stdin.buffer.readline

n = int(input())
li = [list(map(int, input().split()))[1:] for _ in range(n)]


def prepare(n: int, con: list):
	sz = n.bit_length()
	parent = [[0] * n for _ in range(sz)]
	parent[0][0] = -1
	depth = [-1] * n
	depth[0] = 0
	q = [0]
	while q:
		cur = q.pop()
		for nxt in con[cur]:
			if depth[nxt] < 0:
				depth[nxt] = depth[cur] + 1
				parent[0][nxt] = cur
				q.append(nxt)
	for k in range(sz - 1):
		for i in range(n):
			if parent[k][i] < 0:
				parent[k + 1][i] = -1
			else:
				parent[k + 1][i] = parent[k][parent[k][i]]
	return sz, depth, parent


sz, depth, parent = prepare(n, li)


def lca(u, v):
	if depth[u] > depth[v]:
		u, v = v, u
	for k in range(sz):
		if ((depth[v] - depth[u]) >> k & 1):
			v = parent[k][v]
	if u == v:
		return u
	for k in range(sz - 1, -1, -1):
		if parent[k][u] != parent[k][v]:
			u, v = parent[k][u], parent[k][v]
	return parent[0][u]


ans = []
for _ in range(int(input())):
	u, v = map(int, input().split())
	ans.append(lca(u, v))
print("\n".join(map(str, ans)))



Measured memory_bytes: 44828
n = int(input())
a = [0] + list(map(int, input().split())) + [0]

total = sum(abs(a[i] - a[i + 1]) for i in range(0, n + 1))
for i in range(1, n + 1):
    print(total - abs(a[i - 1] - a[i]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]))


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    int h, w;
    cin >> h >> w;
    map<int, int> idma;
    map<int, int> ma;
    REP(i, w) {
        idma.insert(make_pair(i+1,i+1));
        ma[0]++;
    }
    REP(i,h) {
        int a, b;
        cin >> a >> b;
        if (b == w) b = 1000000000;
        auto nowite = idma.lower_bound(a);
        while (true) {
            if (nowite == idma.end()) break;
            auto nextite = next(nowite);
            pint now = *nowite;
            if (now.FI > b) break;
            idma.erase(nowite);
            if (--ma[now.FI-now.SE] == 0) ma.erase(now.FI-now.SE);
            now.FI = b + 1;
            if (idma.find(now.FI) == idma.end()) {
                idma[now.FI] = now.SE;
                ++ma[now.FI-now.SE];
            } else {
                int nowval = idma[now.FI];
                if (nowval < now.SE) {
                    if (--ma[now.FI-nowval] == 0) ma.erase(now.FI-nowval);
                    ++ma[now.FI-now.SE];
                    idma[now.FI] = now.SE;
                }
            }
            nowite = nextite;
        }
        auto ite = ma.begin();
        if (ite->first >= 100000000 ) cout << -1 << endl;
        else cout << i + 1 + ite->first << endl;
    }
}

int main() {
    solve();
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



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

using int64 = long long;

const int64 MOD = 1e9 + 7;

int64 factorialMod(int64 n) {
    int64 res = 1;
    for (int64 x = 1; x <= n; x++) {
        (res *= x) %= MOD;
    }
    return res;
}

int main() {
    int64 N, M;
    cin >> N >> M;

    // N <= Mとする
    if (N > M) swap(N, M);

    int64 factN = factorialMod(N),
          factM = factorialMod(M);
    if (N < M - 1) {
        cout << 0 << endl;
    } else if (N == M - 1) {
        cout << (factN * factM) % MOD << endl;
    } else {    // N = M
        cout << (factN * factM * 2) % MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n, k;
    cin >> n;
    k = n % 10;
    if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9)
        cout << "hon" << endl;
    else if(k == 0 || k == 1 || k == 6 || k == 8)
        cout << "pon" << endl;
    else
        cout << "bon" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=--data.end();it!=l;++it) cout << *it << " ";
  cout << *it << endl;
}



Measured memory_bytes: 34384
#![allow(unused_mut, non_snake_case, unused_macros,unused_imports)]
use std::cmp::{max, min, Ordering};
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn gcd(mut n: u64,mut m:u64) -> u64{
    while m != 0{
        if m < n{
            let t = m;
            m = n;
            n = t;
        }
        m = m % n;
    }
    n
}
fn main(){
    input!{
    N:u64,
    X:u64,
    x:[u64;N]
    }
    let y:Vec<u64> = x.into_iter().map(|v| (max(v,X)-min(v,X))).collect();
    let GCD:u64 = y.iter().fold(y[0].clone(),|now,&v| gcd(now,v));
    println!("{}",GCD);
}

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

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

int main(){
    int N, M;
    while(cin >> N >> M, N|M){
        vector<pair<int, int> > way;
        rep(i, N){
            int D, P;
            cin >> D >> P;
            way.emplace_back(-P, D);
        }
        sort(all(way));
        int exp = 0;
        rep(i, N){
            M -= way[i].second;
            if(0 <= M)continue;
            exp += -way[i].first * min(-M, way[i].second);
        }
        cout << exp << '\n';
    }
    return 0;
}

Measured memory_bytes: 1324
n = int(input())
a = list(map(int, input().split()))
s = [0]
for i in range(n):
    s.append(a[i]+s[i])
m = 100000000000000
for i in range(len(s)):
	m = min(m, abs((s[i] - s[0]) - (s[len(s) - 1] - s[i])))
print(m)

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

using namespace std;

int main() {
    int n,q;
    cin >> n >> q;
    vector<vector<int>>A(n); 
    while (q--) {
        int code;
        cin >> code;
        switch (code) {
            case 0: {
                int t,x;
                cin >> t >> x;
                A[t].push_back(x);
            } break;
            case 1: {
                int t;
                cin >> t;
                if (A[t].size() == 0) cout << endl;
                for (int i=0; i<A[t].size(); i++) 
                    cout << A[t][i] << " \n"[i == A[t].size()-1];
            } break;
            case 2: {
                int t;
                cin >> t;
                A[t].clear();
            }
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 5888
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

int main(void){
  ll n;
  cin >> n;
  n--;
  ll l = 1, work = 26;
  while(n > work-1){
    n -= work;
    l++;
    work *= 26;
  }

  string ans;
  rep(i,l){
    int cnt = 0;
    for(char tmp='a';tmp<='z';tmp++){
      if(cnt == n%26) ans += tmp;
      cnt++;
    }
    n /= 26;
  }

  rep(i,ans.length()) cout << ans[ans.length()-1-i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 3648
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
ans=[0 for i in range(n+1)]

for x in range(1,100):
  for y in range(1,100):
    for z in range(1,100):
        if x**2+y**2+z**2+x*y+y*z+z*x<=n:
          ans[x**2+y**2+z**2+x*y+y*z+z*x]+=1

for i in ans[1:]:
  print(i)

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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  sort(A.begin(),A.end());
  
  ll max = A.at(N-1);
  ll mid=0;
  for(ll i=0;i<N;i++){
    if(abs((max+1)/2 - A.at(i)) < abs((max+1)/2 - mid)){
      mid = A.at(i);
    }
  }
  
  cout << max << " " << mid << endl;
  
  return(0);
}

Measured memory_bytes: 1024