akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    int ans = 0;
    int pos = 0;
    int count = 0;
    while(pos < n)
    {
        while(pos < n-1 && s[pos] == s[pos+1])
        {
            pos++;
            ans++;
        }
        if(pos == n-1) break;
        count++;
        pos++;
    }
    int num = count / 2;
    ans += min(k, num) * 2;
    if(k > num && count % 2 == 1) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
int n;
int t[1000];
int main(){
	cin>>n;
	rep(i,n)cin>>t[i];
	sort(t,t+n,greater<int>());
	int ans=0,now=2000000;

	rep(i,n){
		if(now>t[i]){
			now=t[i];
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll hoge[200005];
int main()
{
  ll n, k, a, b, c;
  ll ans = 0;
  scanf("%lld%lld", &n, &k);
  for (int i = 1; i <= n; i++)
  {
    hoge[i % k]++;
  }
  for (a = 0; a < k; a++)
  {
    b = (k - a) % k;
    c = (k - a) % k;
    if ((b + c) % k != 0)
      continue;
    ans += hoge[a] * hoge[b] * hoge[c];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue> 
#include <map>
#include <cmath> 
#include <stack>
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
struct node{
	int id,w;
	bool operator<(const node &n1)const{
		return w>n1.w;
	}
	node(int id=0,int w=0):id(id),w(w){}
};
priority_queue<node> q;
int n;
int d[maxn];
bool vis[maxn];
vector<pair<int,int> > adj[maxn];
int main(){
	cin>>n;
	for (int i=1;i<n;i++){
		adj[i].push_back(make_pair((i+1)%n,1));
		adj[i].push_back(make_pair(i*10%n,0));
	}
	memset(d,0x3f,sizeof(d));
	d[1]=1;
	q.push(node(1,1));
	while(!q.empty()){
		int u=q.top().id;
		q.pop();
		if (vis[u]) continue;
		vis[u]=1;
		for (int i=0;i<adj[u].size();i++){
			int v=adj[u][i].first;
			int w=adj[u][i].second;
			if (d[v]>d[u]+w){
				d[v]=d[u]+w;
				q.push(node(v,d[v]));
			}
		}
	}
	cout<<d[0]<<endl;
}

Measured memory_bytes: 6904
#include <stdio.h>

int main()
{
    int contests, displayRating, innerRating = 0;
    
    scanf("%d %d", &contests, &displayRating);
    
    if(contests < 10)
    {
        innerRating = displayRating + (100 * (10 - contests));
    }
    else
    {
        innerRating = displayRating;
    }
    
    printf("%d", innerRating);
    
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long i = 1;
		for (; i * i <= n; i++) {
		}
		System.out.println((i - 1) * (i - 1));
	}
}


Measured memory_bytes: 21844
from sys import stdin


def main():
    _ = int(stdin.readline().rstrip())
    S, T = [x for x in stdin.readline().rstrip().split()]
    ans = ''
    for s, t in zip(S, T):
        ans += '{}{}'.format(s, t)
    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n){
    for(int j = i+1;j<n;++j){
      if(s[i] == 'C' && s[j] == 'F'){
        puts("Yes");
        return 0;
      }
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int main() {
  int n;
  string s;
  cin >> n >> s;

  int ecount = count(s.begin() + 1, s.end(), 'E');
  int wcount = count(s.begin() + 1, s.end(), 'W');
  //先頭除外

  vector<int> ans;
  ans.push_back(ecount);

  for (int i = 1; i < n; i++) {
    int temp = ans.back();
    if (s[i - 1] == 'E') {
    } else {
      temp++;
    }

    if (s[i] == 'E') {
      temp--;
    } else {
    }

    ans.push_back(temp);
  }

  cout << *min_element(ans.begin(), ans.end()) << endl;

  //  EEEEEEEEEEEE reader WWWWWWWWWWW となればよい。
}

Measured memory_bytes: 5780
#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a <= 12 and a >= 6)
        cout << b/2 << endl;
    else if(a < 6)
        cout << 0 << endl;
    else
        cout << b << endl;
}

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

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

const int MOD=1e9+7;
const int INF=1<<30;
const int MAX=1e5;

template<class T>
inline void xmin(T &a, T b){a=(a<b)?a:b;}
template<class T>
inline void xmax(T &a, T b){a=(a>b)?a:b;}

int n;
int h[100000];

void solve(){
    cin>>n;
    int temp;
    int maxi=1<<31;
    int cnt=0;
    cin>>h[0];
    temp=h[0];
    for(int i=1; i<n; i++){
        cin>>h[i];
        if(h[i]<=temp){
            cnt++;
            temp=h[i];
        }else{
            xmax(maxi, cnt);
            cnt=0;
            temp=h[i];
        }
        //cout<<cnt<<endl;
    }
    xmax(maxi, cnt);
    cout<<maxi<<endl;
}

signed main(){
    //while(1)
    solve();
}


Measured memory_bytes: 640
N,A=map(int,input().split())
x = list(map(int,input().split()))
y = [val-A for val in x]

# dp[i][j] : i枚目まで見て合計がj-2500のもの
dp = [[0]*5001 for _ in range(N+1)]
dp[0][y[0]+2500] = 1
dp[0][2500] += 1
for i in range(N-1):
    new = y[i+1]
    for j in range(5001):
        dp[i+1][j] += dp[i][j]
        if 0 <= j+new <= 5000:
            dp[i+1][j+new] += dp[i][j]
print(dp[N-1][2500]-1)


Measured memory_bytes: 41200
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int compare(const void*a,const void *b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int l=0,r=0,d,k,a,b,c = 0, n, e[100] = { 0 }, ans = 0;
	char s[3], cas[4][4] = {"AC","WA","TLE","RE"};
	scanf("%d", &a);
	if (a>=30)printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 1692
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int m = sc.nextInt();
        int d = sc.nextInt();
        int ans = 0;
        
        if(m<=d){
            ans = m;
        }else{
            ans = m-1;
        }
        
		System.out.println(ans);
    }
}


Measured memory_bytes: 35640
N, A, B, C = map(int, input().split())
ll = [int(input()) for _ in range(N)]

def dfs(now, a, b, c):
    if now == N:
        if a == 0 or b == 0 or c == 0:
            return 100000
        return abs(A-a) + abs(B-b) + abs(C-c)
    d1 = dfs(now+1, a+ll[now], b, c) + min(10, a*10)
    d2 = dfs(now+1, a, b+ll[now], c) + min(10, b*10)
    d3 = dfs(now+1, a, b, c+ll[now]) + min(10,c*10)
    d4 = dfs(now+1, a, b, c)
    return min(d1, d2, d3, d4)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  bool ans = true;
  int buf;
  rep(i,n){
    int x;
    cin >> x;
    if(i==0){
      buf = x;
      continue;
    }
    if(x < buf) ans = false;
    else buf = min(max(x-1,buf),x);
  }
  cout << (ans ? "Yes" : "No") << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

#define cmax 35
#define INFTY 1000000000

int Color_1[cmax] = { 0 };
int Color_2[cmax] = { 0 };
int Color_3[cmax] = { 0 };

int sum1[cmax] = { 0 };
int sum2[cmax] = { 0 };
int sum3[cmax] = { 0 };

int D[cmax][cmax];
int CIJ[510][510];

int main() {
	int N, C;
	int inp_int;
	int ans = INFTY;

	scanf("%d %d", &N, &C);
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			scanf("%d", &inp_int);
			D[i][j] = inp_int;
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			scanf("%d", &inp_int);
			CIJ[i][j] = inp_int;
		}
	}

	for (int i = 1; i <= 2*N; i+=3) {
		for (int j = 1; j <= i; j++) {
			if (j > N || i - j + 1 > N)continue;
			Color_1[CIJ[j][i - j + 1]]++;
		}
	}
	for (int i = 2; i <= 2*N; i += 3) {
		for (int j = 1; j <= i; j++) {
			if (j > N || i - j + 1 > N)continue;
			Color_2[CIJ[j][i - j + 1]]++;
		}
	}
	for (int i = 3; i <= 2*N; i += 3) {
		for (int j = 1; j <= i; j++) {
			if (j > N || i - j + 1 > N)continue;
			Color_3[CIJ[j][i - j + 1]]++;
		}
	}
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			sum1[i] += D[j][i] * Color_1[j];
			sum2[i] += D[j][i] * Color_2[j];
			sum3[i] += D[j][i] * Color_3[j];
		}
	}
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			for (int k = 1; k <= C; k++) {
				if (i == j || j == k || k == i)continue;
				else if (ans > sum1[i] + sum2[j] + sum3[k])ans = sum1[i] + sum2[j] + sum3[k];
			}
		}
	}
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 1152
import sys
N, K = map(int, input().split())
rousoku = [int(i) for i in input().split()]
if N == 1:
    print(abs(rousoku[0]))
    sys.exit()
if K == 1:
    rousoku = [abs(i) for i in rousoku]
    print(min(rousoku))
    sys.exit()

dislist = []
for i in range(N - K + 1):
    dislist.append(abs(rousoku[i] - rousoku[i + K - 1]) +
                   min(abs(rousoku[i]), abs(rousoku[i + K - 1])))


print(min(dislist))

Measured memory_bytes: 14224
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	char str[N];int nxt[N][30],dp[N],go[N];
	void main()
	{
		scanf("%s",str+1);int n=strlen(str+1);fo(c,0,25) nxt[n+1][c]=n+1;
		fd(i,n,1){memcpy(nxt[i],nxt[i+1],sizeof nxt[i]);nxt[i][str[i]-'a']=i;}
		mem(dp,0x3f);dp[n+2]=0;
		fd(i,n,1) fo(c,0,25) if(chmin(dp[i],dp[nxt[i][c]+1]+1)) go[i]=c;
		fo(i,1,n) debug("dp[%d]=%d\n",i,dp[i]);
		for(int now=1;now<=n;now=nxt[now][go[now]]+1) putchar('a'+go[now]);
 	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 33920
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	char str[1030];
	int chr;
	int i=0;
	bool fir=true;
	while(chr=getchar(),chr!=EOF){
		if(chr==' '||chr=='.'||chr==','){
			if(3<=i&&i<=6){
				str[i]=0;
				if(!fir)cout<<" ";
				else fir=false;
				cout<<str;
			}
			i=0;
		}else{
			str[i++]=chr;
		}
	}
cout<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int N,K,ANS=1;
	cin >> N >> K;
	fore(i,0,N){
		ANS=min(2*ANS,ANS+K);
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
N = int(input())
A_list = list(map(int,input().split()))
money = 1000
stock = 0
Frag = False
for i in range(N):
    if Frag == True:
        if i == N-1:
            money = money + stock * A_list[i]
        else:
            if A_list[i] > A_list[i+1]:
                money = money + stock * A_list[i]
                stock = 0
                Frag = False
    if Frag == False:
        if i == N-1:
            break
        else:
            if A_list[i] < A_list[i+1]:
                stock = money // A_list[i]
                money = money - A_list[i] * stock
                Frag = True
print(money)



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

int main(){
  int n;
  cin >> n;
  vector<long long> L(87);
  L.at(0)=2;
  L.at(1) = 1;
    for(int i=0; i< 87; i++){
    if(i == 0 || i == 1) continue;
    else{
      L.at(i) = L.at(i-1)+L.at(i-2);
    }
  }
 cout << L.at(n) << endl;
  

}


Measured memory_bytes: 3612
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool p[1000000];

void prime() {
  fill(p, p+1000000, true);
  p[0] = false;
  p[1] = false;
  FOR(i, 2, 1000000) {
    if(p[i]) {
      for(int j = 2; i*j < 1000000; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n;

  prime();

  while(1) {
    cin >> n;
    if(!n) break;

    int cnt = 0;
    for(int i = n+1; i <= 2*n; i++) {
      if(p[i])cnt++;
    }
    cout << cnt << endl;
  }
}

Measured memory_bytes: 2136
s=list(input())
t=list(input())
ans=[]

for i in range(len(s)-len(t)+1):
    u=s[i:len(t)+i]
    a=0
    for j in range(len(t)):
        if not t[j-1]==u[j-1]:
            a=a+1
    ans.append(a)
print(min(ans))

Measured memory_bytes: 67484
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <iostream>
#include <limits>
#include <climits>
#include <functional>
#include <numeric>

using namespace std;

#define alloc(type,n) (type*)calloc(sizeof(type),(n));
typedef long long lli;

lli c,s;

int main(){
    cin >> s >> c;
    if(c-2*s < 0) cout << c/2 << endl;
    else cout << s + (c-2*s)/4 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d,l,r;
  cin >> a >> b >> c >> d;
  l = a + b;
  r = c + d;
  if(l>r){
    cout << "Left" << endl;
  }else if(r>l){
    cout << "Right" << endl;
  }else{
	cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
static const int mod = 2019;

int main() {
  long long l, r;
  cin >> l >> r;
  long long cnt = 0;
  long long ans = 2018;
  r = min(r, l + mod);
  for (long long i = l; i <= r-1; i++) {
    for (long long j = l+1; j <= r; j++) {
      long long x = i*j%mod;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	var total, wtotal int
	fmt.Scanf("%s\n", &s)

	for i := 0; i < len(s); i++ {

		if string(s[i]) == "W" {
			total += i - wtotal
			wtotal++
		}
	}
	fmt.Println(total)

}


Measured memory_bytes: 3272
#![allow(non_snake_case, unused_imports)]

// Input
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        A: chars,
        B: chars,
        C: chars,
    }
    println!("{}", if A[A.len()-1]==B[0] && B[B.len()-1]==C[0]{"YES"}else{"NO"});
}

Measured memory_bytes: 4352
#include <iostream>
#include "bits/stdc++.h"
#include <vector>

using namespace std;

int main() {
	int c;
	int r;
	cin >> c >> r;

	vector<int> h;

	for (int i = 0; i < c * r;++i) {
		int hin;
		cin >> hin;
		h.push_back(hin);
	}

	int sum = 0;

	for (int j = 0; j < c;++j) {
		for (int k = 0; k < r;++k) {
			cout << h[j * r + k] << " ";
			sum += h[j * r + k];
			if (k == r - 1) {
				cout << sum;
			}
		}
		cout << endl;
		sum = 0;
	}

	int all = 0;
	for (int m = 0; m < r; ++m) {
		for (int n = 0; n < c; ++n) {
			sum += h[n * r + m];
			if (n == c - 1) {
				cout << sum;
				all += sum;
			}
		}
		cout << " ";
		sum = 0;
	}

	cout << all << endl;

	return 0;
}


Measured memory_bytes: 3212
X, Y = map(int, input().split())
p = {1: 300000, 2: 200000, 3: 100000}
sum = 0
if X == 1 and Y == 1:
  sum += 400000
if X <= 3:
  sum += p[X]
if Y <= 3:
  sum += p[Y]
print(sum)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	ll a[100005];
	ll ans=0;
	cin >> n;
	REP(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	int ptr = 0;
	while(ptr<n) {
		int cc = a[ptr], f = 0;
		while (ptr < n&&a[ptr] == cc) { f++, ptr++; }
		ans += f % 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)
	dp1 := map[int]struct{}{}
	dp2 := map[int]struct{}{}
	ans := map[int]struct{}{}
	for i := 0; i < N; i++ {
		c := int(S[i]) - '0'
		for i := range dp2 {
			ans[i*10+c] = struct{}{}
		}
		for i := range dp1 {
			dp2[i*10+c] = struct{}{}
		}
		dp1[c] = struct{}{}
	}
	fmt.Println(len(ans))
}


Measured memory_bytes: 896
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

calc [] _ = 0
calc (a : as) i
  | odd i && odd a = 1 + calc as (i + 1)
  | otherwise = calc as (i + 1)

main = do
  n <- getInt
  as <- getIntList
  print $ calc as 1


Measured memory_bytes: 3756
import java.io.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
//        int t = in.nextInt();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException {
            int n = in.nextInt();
            int[][] arr = new int[n][2];
            for (int i = 0; i < n; i++) {
                arr[i][0] = in.nextInt();
                arr[i][1] = in.nextInt();
            }
            double sum = 0;
            for (int i = 0; i < n; i++) {
                double dis = 0;
                for (int j = i+1; j < n; j++) {
                    dis += Math.sqrt(Math.pow(arr[i][0] - arr[j][0], 2) + Math.pow(arr[i][1] - arr[j][1], 2));
                }
                sum += dis;
            }
            long times = (n-1) * fact(n) / (n * (n-1) / 2);
            sum *= times;
            sum = sum / fact(n);
            DecimalFormat df = new DecimalFormat("0.0000000000");
            out.println(df.format(sum));
        }

        private long fact(int n) {
            long f = 1;
            while (n > 0){
                f *= n;
                n--;
            }
            return f;
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

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

        public char nextChar() {
            return next().charAt(0);
        }

        public String nextLine() throws IOException {
            return reader.readLine().trim();
        }
    }
}


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

int f(int n){
  if(n == n/2*2){
  	return n/2;
  }
  else{
  	return 3*n+1;
  }
}

int main(){
  int s;
  cin >> s;
  vector<int> a;
  a.push_back(s);
  
  bool flag = true;
  int i = 0;
  
  while(flag){
  	a.push_back(f(a.at(i)));
  	for(int j = 0; j <= i; j++){
    	if(a.at(i+1) == a.at(j)){
        	flag = false;
        }
    }
  	i++;
  }
  cout << i+1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int ans=1,n,k;
int main()
{
 cin>>n>>k;
 for(int i=1;i<=n;i++) ans+=min(ans,k);
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

// dp[c3][c2][c1][i]
// 3つ前がc3、2つ前がc2、1つ前がc1。i番目。
int dp[4][4][4][101];

int main(){
  int N;
  cin >> N;
  rep(c3, 4) rep(c2, 4) rep(c1, 4) dp[c3][c2][c1][3] = 1;
  dp[0][1][2][3] = 0;
  dp[1][0][2][3] = 0;
  dp[0][2][1][3] = 0;

  rep(i, 3, N) rep(c3, 4) rep(c2, 4) rep(c1, 4){
    int vv = c2 * 10 + c1;
    int vvv = c3 * 100 + vv;
    if(vv == 1 || vv == 10 || vvv == 11 || vvv == 13 || vvv == 31){
      dp[c2][c1][2][i + 1] -= dp[c3][c2][c1][i];
    }else if(vv == 2){
      dp[c2][c1][1][i + 1] -= dp[c3][c2][c1][i];
    }
    rep(x, 4){
      dp[c2][c1][x][i + 1] += dp[c3][c2][c1][i];
      dp[c2][c1][x][i + 1] %= mod;
    }
  }

  ll ans = 0;
  rep(c3, 4) rep(c2, 4) rep(c1, 4) ans = (ans + dp[c3][c2][c1][N]) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

struct Edge {int to; int idx;};

int main() {
    int n;
    cin >> n;
    vector<vector<Edge>> G(n);
    REP(i, n - 1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        G[a].push_back({b, i});
        G[b].push_back({a, i});
    }
    
    vector<vector<int>> a(n, vector<int>(n, -1)), b(n, vector<int>(n, -1));
    REP(i, n) {
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto e: G[v]) {
                if (b[i][v] == e.to) continue;
                a[i][e.to] = e.idx;
                b[i][e.to] = v;
                q.push(e.to);
            }
        }
    }
    
    vector<vector<ll>> s(n, vector<ll>(n, 0LL));
    REP(i, n) REP(j, n) {
        int u = i, v = j;
        while (v != u) {
            s[i][j] += (1LL << a[u][v]);
            v = b[u][v];
        }
    }
    
    int m;
    cin >> m;
    vector<int> u(m), v(m);
    REP(i, m) {
        cin >> u[i] >> v[i];
        --u[i]; --v[i];
    }
    ll ans = 0;
    REP(bit, 1 << m) {
        ll x = 0;
        int cnt = 0;
        REP(i, m) {
            if ((bit >> i) & 1) {
                ++cnt;
                x |= s[u[i]][v[i]];
            }
        }
        ll y = 1;
        REP(i, n - 1) {
            if (!((x >> i) & 1)) y <<= 1;
        }
        if (cnt & 1) ans -= y;
        else ans += y;
    }
    cout << ans << "\n";
    return 0;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

const long long MOD = 1000000007;

ll fastpow(ll _x,ll _n){
   int ret = 1;
   while(0<_n){
       if((_n%2) == 0){
           _x = (_x*_x)%MOD;
           _n >>= 1;
       }else{
           ret = (ret*_x)%MOD;
           --_n;
       }
   }
   return ret;
}

void solve(long long n, std::vector<long long> c){
    Vi a(n);
    REP(i,0,n){
        if(i==0) a[i]=1;
        else{
            a[i]=((i+2)*fastpow(2,i-1))%MOD;
        }
    }
    sort(ALL(c));
    reverse(ALL(c));

    int ans=0;
    REP(i,0,n){
        // cout<<a[i]<<" "<<fastpow(2,n-i-1)<<" "<<c[i]<<" ";
        // cout<<(((a[i]*fastpow(2,n-1-i))%MOD)*c[i]%MOD)%MOD<<endl;
        ans=(ans+(((a[i]*fastpow(2,n-1-i))%MOD)*c[i]%MOD)%MOD)%MOD;
    }
    ans = (ans*fastpow(2,n))%MOD;
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(C));
    return 0;
}


Measured memory_bytes: 3328
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.print(a / b);
        System.out.print(" " + a % b);
        System.out.printf(" %f\n", ((a * 1.0) / b));
        
        sc.close();
    }
}


Measured memory_bytes: 26592
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        double d = l / (double) 3;
        System.out.println(d * d * d);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 21460
#include<iostream>
#include<queue>

using namespace std;

static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s) {
  queue<int> q;

  q.push(s);

  for (int i = 0; i < n; i++) {
    d[i] = INFTY; 
  }
  d[s] = 0;

  int u;
  while (!q.empty()) {
    u = q.front(); q.pop();
    for (int v = 0; v < n; v++) {
      if (M[u][v] == 0) {
        continue;
      }
      if (d[v] != INFTY) {
        continue;
      }
      d[v] = d[u] + 1;
      q.push(v);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
  }
}

int main() {

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

  int u, k, v;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--; // to 0 origin
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--; // to 0 origin
      M[u][v] = 1;
    }
  }

  bfs(0);

  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;
vector <pair<long long,long long>> dp;
vector <vector <int>> vec;
void dfs(int i,int p){
    //if(vec[i].size()==0){dp[i].first=1;dp[i].second=1;}
    for(auto v:vec[i]){
        if(v!=p){dfs(v,i);
        dp[i].first=(dp[i].first*(dp[v].first+dp[v].second))%mod;
        dp[i].second=(dp[i].second*dp[v].first)%mod;}
        }
}

int main() {
    int n;
    cin>>n;
    vec.assign(n,vector <int>(0));
    dp.assign(n,make_pair(1,1));
    for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
    }
    dfs(0,-1);
    cout<<(dp[0].first+dp[0].second)%mod;
}

Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  map<int, int> m;
  sort(a, a + n, greater<int>());
  rep(i,n) {
    m[a[i]]++;
  }
  ll mx1 = -1, mx2 = -1;
  bool first = false;
  rep(i,n) {
    if(m[a[i]] >= 2 && !first) {
      mx1 = a[i];
      m[a[i]] -= 2;
      first = true;
    } else if(m[a[i]] >= 2) {
      mx2 = a[i];
      break;
    }
  }
  if(mx2 != -1) {
    cout << mx1 * mx2 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
#define ed(V) V&-V
using namespace std;
int n,k;
int T[200005];
int a[100005],srt[100005];
void m_Tree(int x,int t){
	for(int i=x;i<=2*n;i+=ed(i))T[i]+=t;
}
int g_Tree(int e){
	int ret=0;
	for(int i=e;i>0;i-=ed(i))ret+=T[i];
	return ret;
}
bool check(int x){
	for(int i=2*n;i>0;i--)T[i]=0;
	int t=n+1;
	ll cnt=0;
	m_Tree(t,1);
	for(int i=0;i<n;i++){
		t+=a[i]>=x?1:-1;
		cnt+=g_Tree(t);
		m_Tree(t,1);
	}
	return cnt>=(ll)n*(n+1)/2-cnt;
}
int BS(int s,int e){
	if(s==e)return s;
	int m=s+e>>1;
	if(check(m+1))return BS(m+1,e);
	return BS(s,m);
}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i),srt[i]=a[i];
	sort(srt,srt+n);
	k=unique(srt,srt+n)-srt;
	for(int i=0;i<n;i++)a[i]=lower_bound(srt,srt+k,a[i])-srt;
	printf("%d",srt[BS(0,k-1)]);
}

Measured memory_bytes: 1792
import sys
fastinput=sys.stdin.readline
N,K=map(int,fastinput().split())
data=[[int(j) for j in fastinput().split()] for k in range(N)]
ab=sorted(data,key=lambda x:x[0])
number=0
for a,b in ab:
    number+=b
    if number>=K:
        print(a)
        break

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,b) for(int i = 0; i < (int)(n); i++)
bool isPrime(const ll &n){
    if(n == 2) return true;
    if(n < 2 || n%2 == 0) return false;
    const ll m = n-1, d = m / (m & -m);
    auto modmul = [&](ll a, ll b){
        ll res = 0;
        while(b){
            if(b&1) res = (res+a)%n;
            a = (a+a)%n;
            b >>= 1;
        }
        return res;
    };
    auto modpow = [&](ll a, ll b){
        ll res = 1;
        while(b){
            if(b&1) res = modmul(res,a);
            a = modmul(a,a);
            b >>= 1;
        }
        return res;
    };
    auto suspect = [&](ll a, int t){
        a = modpow(a,t);
        while(t != -1+n && a != 1 && a != -1+n){
            a = modmul(a,a);
            t *= 2;
        }
        return a == n-1 || t%2 == 1;
    };
    const int witness[] = {2,7,61,0}; // n <= 2^32
    // const int witness[] = {2,325,9375,28178,450775,9780504,1795265022,0}; // n <= 2^64
    for(const int *w = witness; *w < n && *w; w++){
        if(!suspect(*w,d)) return false;
    }
    return true;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        ll x;
        cin >> x;
        ans += isPrime(x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1200
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
//#define repitr(itr, st) for(auto itr = st.begin(); itr != st.end(); ++itr)
#define P_B push_back
#define PO_B pop_back
#define E_B emplace_back
#define M_P make_pair
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << endl
//#define print(x) printf("%d\n", x)

using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Pll = pair<ll,ll>;
using VI = vector<int>;
using VL = vector<ll>;
using VVI = vector<vector<int> >;
using VVL = vector<vector<ll> >;
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};
//const ll LINF = (ll)1e18 - 1;
//const int INF = 1e9 - 1;
//int:±2*10^9くらい　ll:±9*10^18くらい



void Main(){
	int N, n, K;
	long double x, y, ans=0;
	cin >> N >> K;
	n = N;

	y = 1;
	while(true){
		if(N >= K){
			ans += (N-K+1)/(long double)n/y;
			N = K-1;
		}
		if(K == 1) break;
		K = (K-1)/2 +1;
		y *= 2;
	}

	cout << ans << endl;



}

int main()
{
	cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();

  return 0;
}


Measured memory_bytes: 256
from math import floor

def solve(s, k):
    counts = [0] * len(s)
    prev = ''
    index = -1
    for l in s:
        if prev == l:
            counts[index] += 1
        else:
            index += 1
            counts[index] = 1
        prev = l
    if index == 0:
        return floor(len(s) * k / 2)
    total = 0
    for i in range(index + 1):
        if counts[i] > 1:
            total += floor(counts[i] / 2) * k
    if s[0] == s[-1] and counts[0] % 2 == 1 and counts[index] % 2 == 1:
        if (counts[0] + counts[index]) % 2 == 0:
            total += k - 1
    return total

_s = input()
_k = int(input())
print(solve(_s, _k))


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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

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

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

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

    int N, M;
    cin >> N >> M;
    dsu d(N);
    int c = N;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        if (!d.same(a, b)) {
            --c;
            d.merge(a, b);
        }
    }
    cout << c - 1 << endl;
    return 0;
}

Measured memory_bytes: 3772
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	cMax := a + b + 1

	var r int
	if c > cMax {
		r += cMax
	} else {
		r += c
	}

	r += b
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
// 入力
int n;
int a[10010];  // 最大10000個ですが、少しだけ多めにとる

// DP テーブル
int dp[10010];


int main()
{
  string s;
  cin >> s;
  int max = (int)s.size();
  cout << s[0] << max-2<< s[max-1] << endl;
}

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

using namespace std;

int partition(int A[], int p, int r) {
  int x = A[r];
  int i = p - 1;
  int tmp;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      tmp = A[i]; A[i] = A[j]; A[j] = tmp;
    }
  }
  tmp= A[i + 1]; A[i + 1] = A[r]; A[r] = tmp;
  return i + 1;
}

int main() {
  int n; cin >> n;
  int A[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int base_index = partition(A, 0, n - 1);
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (i == base_index) {
      cout << "[" << A[i] << "]";
    } else {
      cout << A[i];
    }
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 3480
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}




int main(void){
    const ll INF = 1000000007;
    ll n, d;
    cin >> n >> d;
    ll ans = 0;
    if(n%(d*2+1)==0)ans = n/(d*2+1);
    else ans = n/(d*2+1)+1;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
A1 = gets.split.map(&:to_i)
A2 = gets.split.map(&:to_i)

ans = 0
(0..N-1).each do |down_index|
  candy_count1 = 0
  candy_count2 = 0
  
  (0..down_index).each do |c1_i|
    candy_count1 += A1[c1_i]
  end
    
  (down_index..N-1).each do |c2_i|
    candy_count2 += A2[c2_i]
  end
  
  candy_sum = candy_count1 + candy_count2
  if candy_sum > ans then
    ans = candy_sum
  end
    
end
  
p ans

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int ans = 0;
    for(int i=0; i< N;i++)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.end(),greater<int>());
    for(int i = 0; i < N-2; i++)
    {
        for(int j = i+1;j< N-1;j++)
        {
            for(int k = j+1; k < N; k++)
            {
                if(a[i] < a[j]+ a[k] && a[j] < a[i]+ a[k]  )
                {
                    if( a[k] < a[j]+ a[i])
                    {
                        if(a[i] != a[j] && a[i] != a[j])
                        {
                            if(a[j] != a[k])
                            {
                                ans++;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3228
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,s,x,a[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(;++i<n;)
	{
		cin>>x;
		a[x]++;
	}
	for(i=0;i++<n;)cout<<a[i]<<endl;
}

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

int x1,x2,x3,x4,y1,y2,y3,y4;

int main(){
    cin >> x1 >> y1 >> x2 >> y2;
    x3 = x2+y1-y2;
    y3 = y2+x2-x1;
    x4 = x3+x1-x2;
    y4 = y3+y1-y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}


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

char s1[11];

int getkind() {
	scanf("%s", s1);
	if(s1[0] == 'V')
		exit(0);
	return s1[0] == 'F';
}

int n;
int a[101010];

int main() {
	scanf("%d", &n);
	int st = 1, ed = n - 1;
	printf("0\n");
	fflush(stdout);
	int key = getkind();
	while(st <= ed) {
		int mid = st + ed;
		mid >>= 1;
		printf("%d\n", mid);
		fflush(stdout);
		int cur = getkind();
		if(cur ^ ((mid) & 1) ^ key) {
			ed = mid - 1;
		}
		else {
			st = mid + 1;
		}
	}

	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
    cin>>v[i];
    }
    sort(v.begin(),v.end());
    int fi = v[n/2];
    int se = v[n/2-1];

    se++;
   // cout<<fi<< " "<<se<<endl;
    if(se > fi){
        cout<<0<<endl;
    }else cout<<fi-se+1<<endl;
    return 0;
}


Measured memory_bytes: 640