akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
10 39
7 2
7 1
5 6
5 8
9 10
2 8
8 7
3 10
10 1
8 10
2 3
7 4
3 9
4 10
3 4
6 1
6 7
9 5
9 7
6 9
9 4
4 6
7 5
8 3
2 5
9 2
10 7
8 6
8 9
7 3
5 3
4 5
6 3
2 10
5 10
4 2
6 2
8 4
10 6
)");
#define cin input
#endif

bool visit(int idx, int x, vector<int>& col, unordered_map<int, unordered_set<int>>& e, array<int, 2>& a)
{
	col[idx] = x;
	++a[x & 1];
	for (auto i : e[idx])
	{
		if (col[i] == (x ^ 1))
			continue;
		
		if (col[i] == -1)
		{
			if (!visit(i, x ^ 1, col, e, a))
				return false;
			continue;
		}
		return false;
	}
	return true;
}

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> col(n, -1);

	unordered_map<int, unordered_set<int>> e;
	REP (i, n)
		REP (j, n)
			if (i != j)
				e[i].insert(j);

	REP (i, m)
	{
		int a, b;
		cin >> a >> b;
		--a, --b;
		e[a].erase(b);
		e[b].erase(a);
	}

	int x = 0;

	set<int> s;
	s.insert(0);

	auto it = find(col.begin(), col.end(), -1);
	while (it != col.end())
	{
		array<int, 2> a{0, 0};
		if (!visit(it - col.begin(), x, col, e, a))
		{
			cout << -1 << endl;

			return 0;
		}
		set<int> n;
		for (auto i : s)
		{
			n.insert(i + a[0] - a[1]);
			n.insert(i + a[1] - a[0]);
		}
		swap(s, n);
		it = find(col.begin(), col.end(), -1);
		x += 2;
	}

	auto r = (n - *s.lower_bound(0)) / 2;
	auto t = n - r;

	cout << r * (r - 1) / 2 + t * (t - 1) / 2 << endl;

	return 0;
}


Measured memory_bytes: 20096
#include <iostream>

using namespace std;

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

  int ans = 0;

  for (int i = 0; i < N; i++){
    int tmp = 0;
    while ((tmp + 1) <= D){
      tmp += A[i];
      ans++;
    }
  }
  printf("%d\n", ans + X);
  
}


Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int sx = sc.nextInt();
		int sy = sc.nextInt();
		int tx = sc.nextInt();
		int ty = sc.nextInt();
		sc.close();

		StringBuilder sb = new StringBuilder();

		// 1回目行き
		int cnt = ty - sy;
		for (int i = 0; i < cnt; i++) {
			sb.append('U');
		}
		cnt = tx - sx;
		for (int i = 0; i < cnt; i++) {
			sb.append('R');
		}

		// 1回目戻り
		cnt = ty - sy;
		for (int i = 0; i < cnt; i++) {
			sb.append('D');
		}
		cnt = tx - sx;
		for (int i = 0; i < cnt; i++) {
			sb.append('L');
		}

		// 2回目行き
		sb.append('L');
		cnt = ty - sy + 1;
		for (int i = 0; i < cnt; i++) {
			sb.append('U');
		}
		cnt = tx - sx + 1;
		for (int i = 0; i < cnt; i++) {
			sb.append('R');
		}
		sb.append('D');

		// 2回目戻り
		sb.append('R');
		cnt = ty - sy + 1;
		for (int i = 0; i < cnt; i++) {
			sb.append('D');
		}
		cnt = tx - sx + 1;
		for (int i = 0; i < cnt; i++) {
			sb.append('L');
		}
		sb.append('U');

		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 25172
from collections import defaultdict
import math

n = int(input())
a_list = list(map(int, input().split()))
d = defaultdict(int)

for a in a_list:
  d[a] += 1

a_list = reversed(sorted(list(set(a_list))))
c = 0
for a in a_list:
  m = int(math.log(a, 2))
  x = 2 ** (m+1) - a
  if x == a:
    c += d[a] // 2
    d[a] -= d[a] // 2
  else:
    c += min(d[x], d[a])
    d[x] -= min(d[x], d[a])

print(c)
    

Measured memory_bytes: 60660
#include<algorithm>
#include<cstdio>
#include<cstring>
#define M 125001
#define N 52
using namespace std;
int a[N],c[N],d[N],e[M],f[M],i,j,k,l,m,n,o,p,q,r,x;long long b[N],g[M],y,z;
inline bool cmp(int u,int v){return a[u]*b[v]<a[v]*b[u];}
int main()
{
	scanf("%d%d%d%lld",&n,&x,&j,b+1),c[1]=1000000000;
	for(i=2;i<=n;i++)scanf("%lld%d",b+i,f+i),c[i]=j;
	for(i=n;i;i--)a[f[i]]+=++a[i],b[f[i]]+=b[d[i]=i];
	for(sort(d+1,d+n+1,cmp),i=1;i<=n;i++)e[i]=min((long long)c[d[i]],x/b[d[i]]),f[i]=a[d[i]],g[i]=b[d[i]];
	for(i=1;i<=n;i++)a[i]=f[i],b[i]=g[i],c[i]=e[i];
	for(memset(g,0x3f,M<<3),*g=0,i=1;i<=n;i++)for(p=c[i]<n?c[i]:n,c[i]-=p,m+=q=p*a[i],j=0;j<a[i];j++)if(p)
	{
		for(l=k=(m-j)/a[i]*a[i]+j,o=r=0;k-l<q;e[r]=o++,f[r++]=l,l-=a[i])while(r&&g[l]+(o-e[r-1])*b[i]<=g[f[r-1]])r--;
		for(l=o=0;k>0;g[k]=g[f[l]]+(e[l]-o++)*b[i],k-=a[i])
		{
			if(f[l]>k)l++;
			if(k>=q)
			{
				while(l<r&&g[k-q]+(o+p-e[r-1])*b[i]<=g[f[r-1]])r--;
				e[r]=o+p,f[r++]=k-q;
			}
		}
	}
	for(i=0;i<=m;y=max(y,z),z=0,i++)if(x>=g[i])for(o=x-g[i],z=i,j=n;j;j--)p=b[j]*c[j]<=o?c[j]:o/b[j],o-=b[j]*p,z+=a[j]*p;
	return 0*printf("%lld\n",y);
}

Measured memory_bytes: 1152
n = gets.to_i
h = {}
as = []
n.times do |i|
  a = gets.to_i
  h[i+1] = []
  a.times do
    x,y = gets.split.map(&:to_i)
    h[i+1].push([x, y])
  end
end

ans = 0
(0..('1'*n).to_i(2)).each do |i|
  bit = i.to_s(2).rjust(n, '0').chars

  ok = true
  bit.each.with_index(1) do |b, j|
    next if b == '0'
    h[j].each do |xy|
      x = xy[0]
      y = xy[1]
      if bit[x-1].to_i != y.to_i
        ok = false
      end
    end
  end
  next unless ok

  ans = [ans, bit.count('1')].max
end

puts ans


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

const int N = 1e5 + 10;

int a[N];

int main(){
	int n, cnt, p, flag;
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	if (n <= 2){
		printf("1\n");
		return 0;
	}
	cnt = 1; p = 2; flag = 0;
	if (a[p] > a[p - 1]) flag = 1;
	else if (a[p] < a[p - 1]) flag = -1;
	p++;
	while (p <= n){
		if ((a[p] > a[p - 1] && flag == -1) || (a[p] < a[p - 1] && flag == 1)){
			cnt++;
			if (n - p <= 1) break;
			p++;
			flag = 0;
			if (a[p] > a[p - 1]) flag = 1;
			else if (a[p] < a[p - 1]) flag = -1;
			p++;
		}
		else{
			if (a[p] > a[p - 1]) flag = 1;
			else if (a[p] < a[p - 1]) flag = -1;
			p++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int N, Q;
using Tree = vector<vector<int>>;
map<int, long> score;
vector<long> answer;

// 深さ優先探索
void depthFirstSearch(Tree &T, int next, int prev)
{
	answer[next] = answer[prev] + score[next];
	
	for (auto node:T[next])
	{
		if (node == prev)
		{
			continue;
		}
		depthFirstSearch(T, node, next);
	}
}

int main()
{
	cin >> N >> Q;
	
	Tree T(N + 1);
	
	for (int i = 0; i < N - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		
		T[b].push_back(a);
		T[a].push_back(b);
	}
	T[1].push_back(0);
	
	for (int i = 0; i < Q; i++)
	{
		int p;
		long x;
		cin >> p >> x;
		score[p] += x;
	}
	
	// 答えの配列をN + 1個用意し、0初期化します。
	answer.assign(N + 1, 0);
	
	depthFirstSearch(T, 1, 0);
	
	// i = 0はanswer[0] = 0になるので、1から開始する
	for (int i = 1; i <= N; i++)
	{
		cout << answer[i] << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 46080
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n;

	cin>>n;

	vi a(n), b;

	rep(i, n) cin>>a[i];

	b=a;

	sort(all(a));

	rep(i, n){
		if(b[i]<=a[n/2-1]){
			cout<<a[n/2]<<endl;
		}else{
			cout<<a[n/2-1]<<endl;
		}
	}
}

Measured memory_bytes: 3712
N = int(raw_input())

flag = False

Ai = []
xij = []
yij = []


for i in range(N):
    Ai_temp=int(raw_input())
    Ai.append(Ai_temp)
    x_temp = []
    y_temp = []
    for j in range(Ai_temp):
        x, y = map(int, raw_input().split())
        x_temp.append(x)
        y_temp.append(y)
    xij.append(x_temp)
    yij.append(y_temp)

ans_max = 0
for l in reversed(range(2**N)):
    flag = True
    for i in range(N):
        Ai_temp = Ai[i]
        if (l>>i)&0b1 == 1:
            for j in range(Ai_temp):
                xij_temp = xij[i][j]
                yij_temp = yij[i][j]
                if (l>>(xij_temp-1))&0b1 != yij_temp:
#                    print l, xij_temp, yij_temp                                                       
                    flag = False
                    break

        if flag == False:
            break

    if flag == True:
#        print "--"                                                                                    
#        print l                                                                                       
        ans = 0
        for i in bin(l)[2:]:
            ans = ans + int(i)
        if ans > ans_max:
            ans_max = ans

print ans_max


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
    int x, a, b;
    cin >> x >> a >> b;
    auto aa = abs(x - a);
    auto bb = abs(x - b);
    auto ans = aa < bb ? "A" : "B";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include <climits>
#include <cstring>
#include <ctime>
#include <list>
#include <iomanip>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <complex>
#include <limits>
#include <random>

#define int64 long long int

const int M = 1e9 + 7;

void MultL(int64 &a, int64 b) {
    a = (a * b) % M;
}
void AddL(int64 &a, int64 b) {
    a = (a + (b + M)) % M;
}

int64 Mult(int64 a, int64 b) {
    return (a * b) % M;
}
int64 Add(int64 a, int64 b) {
    return (a + (b + M)) % M;
}

using namespace std;



int main() {
    std::ios::sync_with_stdio(false);

    int64 n;
    cin >> n;
    string str;
    stringstream stream;
    stream << n;
    stream >> str;
    int r = 0;
    for (int i =0 ; i < str.size(); ++i) {
        r += str[i] - '0';
    }
    if (n % r == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}








Measured memory_bytes: 256
N=int(input())
L=list(map(int,input().split()))

import itertools
if N<3:
  print(0)
else:
  count=0
  h = itertools.combinations(L, 3)
  for v in h:
    lst=sorted(list(v))
    if lst[0]+lst[1]>lst[2]:
      if lst.count(lst[0])==1:
        if lst.count(lst[1])==1:
          if lst.count(lst[2])==1:
            count+=1
  print(count)

Measured memory_bytes: 9196
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]
b=list(map(int,input().split()))
ans=0
for i in range(2**n):
  c=[]
  q=True
  for j in range(n):
    c.append((i>>j)&1)
  for k in range(m):
    p=0
    for l in range(1,a[k][0]+1):
      if c[a[k][l]-1]==1:
        p+=1
    if p%2!=b[k]:
      q=False
  if q:
    ans+=1
print(ans)

Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func contains(target string, list []string) bool {
	for _, r := range list {
		if target == r {
			return true
		}
	}
	return false
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()

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

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func isInteger(x float64) bool {
	return math.Floor(x) == x
}

func Ave(s []int) int {
	val := 0
	for _, i := range s {
		val += i
	}
	return int(val / len(s))
}
func cal(i int) (sum int) {
	for i != 0 {
		sum += i % 10
		i /= 10
	}
	return
}
func max(a []int) (idx int, val int) {
	max := a[0]
	idx = 0
	for j, i := range a {
		if max < i {
			max = i
			idx = j
		}
	}
	return idx, max
}

func draw(i int, a []int) (l []int) {
	// p = a[i]
	for j := i; j < len(a); j++ {
		if j != len(a)-1 {
			a[j] = a[j+1]
		} else if j == len(a)-1 {
			a = a[:len(a)-1]
		}
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
	n := nextInt()
	a := nextInt()
	b := nextInt()

	s := nextLine()
	var pass int
	var bpass int

	for i := 0; i < n; i++ {
		switch string(s[i]) {
		case "a":
			if pass < a+b {
				pass++
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		case "b":
			bpass++
			if pass < a+b && bpass <= b {
				pass++
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		case "c":
			fmt.Println("No")
		}
	}

}


Measured memory_bytes: 2228
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    a += b;
    uint64_t n = stoll(a);
    for(uint64_t i=0; i*i <= n; ++i) {
        if(i*i == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}
int sa(int a,int b){return (a%b==0?b:sa(b,a%b));}

signed main(void){
    int n,m;cin>>n>>m;
    int a[m];
    rep(i,m)cin>>a[i];
    sort(a,a+m);
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
        
    int b[m-1];
    rep(i,m-1){
        b[i]=a[i+1]-a[i];
    }
    sort(b,b+m-1,greater<>());
    
    int lenth=a[m-1]-a[0];
    rep(i,n-1){
        lenth-=b[i];
    }
    cout<<lenth<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int n, y;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int osatsu[3] = {1000, 5000, 10000};
    cin >> n >> y;
    int nokori;
    int sum;
    for(int i = n;i >= 0;--i){
        nokori = n - i;
        rep(j, (n - i) + 1){
            sum = (osatsu[0] * i);
            sum += (osatsu[1] * ((n - i) - j));
            sum += (osatsu[2] * j);
            if(sum == y) {
                cout << j << ' ' << n - i - j << ' ' << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;

    return 0;
}

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

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cerr << C << endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define EB emplace_back
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, n) (s.find(n) != s.end())

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, K;
    cin >> N >> K;
    VI a(26, 0);
    string s;
    REP(i, N) {
	cin >> s;
	a[s.front() - 'A']++;
    }
    int ans = 0;
    while (true) {
	SORT(a);REVERSE(a);
	bool f = true;
	int cnt = 0;
	REP(i, K) {
	    if (a[i] == 0) {
		f = false;
		break;
	    }
	    a[i]--;
	}
	if (!f) break;
	ans++;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M; ll L;
ll Dist[305][305], cnt[305][305];

int main(){
  cin >> N >> M >> L;
  fill((ll*)Dist, (ll*)(Dist + N + 1), 1e18);
  fill((ll*)cnt, (ll*)(cnt+N+1), 1e18);

  for (int i = 1; i <= N; i++) Dist[i][i] = 0;
  for (int i = 0; i < M; i++){
    int A, B; ll C; cin >> A >> B >> C;
    Dist[A][B] = C;
    Dist[B][A] = C;
  }

  for (int k = 1; k <= N; k++){
    for (int i = 1; i <= N; i++){
      for (int j = 1; j <= N; j++){
        Dist[i][j] = min(Dist[i][k] + Dist[k][j], Dist[i][j]);
      }
    }
  }

  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= N; j++){
      if (Dist[i][j] == 0) cnt[i][j] = 0;
      else if (Dist[i][j] <= L) cnt[i][j] = 1;
    }
  }


  for (int k = 1; k <= N; k++){
    for (int i = 1; i <= N; i++){
      for (int j = 1; j <= N; j++){
        cnt[i][j] = min(cnt[i][j], cnt[i][k] + cnt[k][j]);
      }
    }
  }

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++){
    int S, T; cin >> S >> T;
    if (cnt[S][T] == 1e18) cout << -1 << endl;
    else cout << cnt[S][T] - 1 << endl;
  }


  return 0;
}


Measured memory_bytes: 5076
import itertools, math

def dist(way, n):
    dist = 0
    for i in range(n-1):
        x = (way[i][0] - way[i+1][0]) ** 2
        y = (way[i][1] - way[i+1][1]) ** 2
        dist += math.sqrt(x+y)
    return dist

n = int(input())
point = []

for _ in range(n):
    point.append(list(map(int, input().split())))

mean_dist = 0
cnt = 0
for v in itertools.permutations(point, n):
    mean_dist += dist(v, n)
    cnt += 1

print(mean_dist/cnt)

Measured memory_bytes: 3064
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

s = input()

ans = "YES"
while True:
    if len(s) < 5:
        ans = "NO"
        break
    elif len(s) == 5:
        if (s != "dream" and s != "erase"):
            ans = "NO"
        break
    elif len(s) == 6:
        if (s != "eraser"):
            ans ="NO"
        break
    elif len(s) == 7:
        if (s != "dreamer"):
            ans ="NO"
        break
    else:
        if s[-5:] == "dream" or s[-5:] == "erase":
            s = s[:-5]
        elif s[-6:] == "eraser":
            s = s[:-6]
        elif s[-7:] == "dreamer":
            s = s[:-7]
        else:
            ans = "NO"
            break
print(ans)




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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  if(n==2){
    ll a,b; cin>>a>>b;
    cout<<a+b<<endl;
  }else{
    cout<<"Hello World"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll a[510][510];
int main(){
  ll h,w;cin>>h>>w;
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
    }
  }

  vector<string> ans;
    

  rep(i,h){
  	rep(j,w-1){
  		if(a[i][j]%2){
  		  a[i][j]--;
  		  a[i][j+1]++;
  		  ans.pb(to_string(i+1)+" "+to_string(j+1)+" "+to_string(i+1)+" "+to_string(j+2));
  		}
  	}
  }
  rep(i,h-1){
  	if(a[i][w-1]%2){
  		a[i][w-1]--;
  		a[i+1][w-1]++;
  		ans.pb(to_string(i+1)+" "+to_string(w)+" "+to_string(i+2)+" "+to_string(w));
  	}
  }

  cout<<ans.size()<<endl;
  rep(i,ans.size()){
  	cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 12916
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
    int N, M; cin >> N >> M;
    vector<int> divisor;
    divisor.push_back(1); divisor.push_back(M);
    for (int i = 2; i * i <= M; i++) {
        if (M % i == 0) {
            divisor.push_back(i); 
            if (i*i < M) divisor.push_back(M/i);
        }
    }
    sort(divisor.begin(), divisor.end());
    cout << M / divisor[lower_bound(divisor.begin(), divisor.end(), N) - divisor.begin()] << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 H, W, h, w;
  std::cin >> H >> W >> h >> w;
  std::cout << (H - h) * (W - w) << std::endl;
  return 0;
}

Measured memory_bytes: 256
//
// Created by kash on 16/05/20.
//

#include <bits/stdc++.h>

using namespace std;
int mod = 1e9 + 7;
#define ll long long
#define rev_rep(it, last, first) for(int it=last-1;it>=first;--it)
#define out(x) cout << x;
#define pln(x) cout << x << "\n";
#define debug(x) cout << "Debug: " << x << "\n";
#define in(x) cin >> x;
#define rep(it, start, end) for(int it=start;it<end;++it)
#define x first
#define y second


void set_io(int inp) {
#ifndef ONLINE_JUDGE
    string folder = string(getenv("HOME")) + "/CLionProjects/CompetitiveProgramming/inputs/";
    string input_file = folder + "input-" + to_string(inp) + ".txt";
    string output_file = folder + "output-" + to_string(inp) + ".txt";
    freopen(input_file.c_str(), "r", stdin);
    freopen(output_file.c_str(), "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

}


int main() {
    set_io(1);
    int n, k;
    in(n >> k);
    ll int arr[n];
    rep(i, 0, n)in(arr[i]);
    sort(arr, arr + n);
    long long start = 0, end = n - 1, ans = 1, val = 0;
    if (arr[n - 1] < 0 && k % 2) {
        for (int i = 0; i < k; i++) {
            ans = (ans * arr[n - 1 - i]) % mod;
        }
    } else {
        while (k) {
            if (k > 1) {
                if (arr[start] * arr[start + 1] > arr[end] * arr[end - 1]) {
                    ans = (((arr[start] * arr[start + 1]) % mod) * ans) % mod;
                    start += 2;
                    k -= 2;
                } else {
                    ans = (ans * arr[end]) % mod;
                    end--;
                    k--;
                }
            } else {
                ans = (ans * arr[end]) % mod;
                end--;
                k--;
            }
        }
    }
    ans = (ans + mod) % mod;
    out(ans)

    return 0;
}


Measured memory_bytes: 5180
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;
vector<int> to[MAXV];
int id[MAXN][MAXN];
int toId(int i, int j){
	if(i > j) swap(i,j);
	return id[i][j];
}

bool visited[MAXV];
bool calculated[MAXV];
int dp[MAXV];
int dfs(int v){
	if(visited[v]){
		if(!calculated[v]) return -1;
		return dp[v];
	}
	visited[v] = true;
	dp[v] = 1;
	for(int u : to[v]){
		int res = dfs(u);
		if(res == -1) return -1;
		chmax(dp[v], res+1);
	}
	calculated[v] = true;
	return dp[v];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n)rep(j,n-1){
    	cin >> a[i][j];
    	a[i][j]--;
    }
    int V = 0;
    rep(i,n)rep(j,n){
    	if(i < j) id[i][j] = V++;
    }
    rep(i,n){
    	rep(j,n-1) a[i][j] = toId(i, a[i][j]);
    	rep(j,n-2) to[a[i][j+1]].push_back(a[i][j]);
    }
    int ans = 0;
    rep(i,V){
    	int res = dfs(i);
    	if(res == -1){
    		cout << -1 << endl;
    		return 0;
    	}
    	chmax(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 38528
#include<cstdio>
#include<algorithm>
int main()
{
	char st[10];
	scanf("%s",st);
	int ans=700;
	if (st[0]=='o') ans+=100;
	if (st[1]=='o') ans+=100;
	if (st[2]=='o') ans+=100;
	printf("%d\n",ans);
	return 0;
 } 

Measured memory_bytes: 128
/*************************************
>>> Author:  xiaofan
>>> Blog:    https://xiaofan7.cn
>>> Date:    2020-01-17 23:20:23
**************************************/

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;
#define ls ro<<1
#define fi first
#define se second
#define rs ro<<1|1
#define ll long long
#define pb push_back
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define lson ro<<1,l,mid
#define rson ro<<1|1,mid+1,r
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int INF = 0x3f3f3f3f;


signed main() {
	double a,b;
	cin>>a>>b;
	cout<<b*2-a<<endl;



	return 0;
}



Measured memory_bytes: 256
while True:
    a,op,b = input().split()
    a =int(a)
    b = int(b)
    
    if op == "?":
        break
    
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)


Measured memory_bytes: 5596
// B - Trained?
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi A(N); rp(i, 0, N){cin>>A[i]; --A[i];}
	int a = 0;
	rp(t, 1, N+1){
		a = A[a];
		if(a == 1){
			cout<< t <<endl;
			return 0;
		}
	}
	cout<< -1 <<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;



int main(){
	map<string,int> m;
	int a;
	char b;
	string c;
	while(cin>>a>>b>>c){
		m[c]++;
	}
	cout<<m["A"]<<endl;
	cout<<m["B"]<<endl;
	cout<<m["AB"]<<endl;
	cout<<m["O"]<<endl;
}

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

using ull = unsigned long long;
using ll = long long;
using ld = long double;

const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int N = 2e5 + 5;

class UnionFind {
public:
    int n;
    vector<int> p, r;

    UnionFind(): n(), p(), r() {}
    UnionFind(int n): n(n), p(n), r(n, 1) {
        iota(p.begin(), p.end(), 0);
    }
    int size() const {
        return n;
    }
    int find(int x) {
        return x == p[x] ? x : p[x] = find(p[x]);
    }
    bool merge(int x, int y) {
        int l1 = find(x);
        int l2 = find(y);

        if (l1 == l2)
            return false;
        if (r[l1] >= r[l2]) {
            p[l2] = l1;
            r[l1] += r[l2];
        }
        else {
            p[l1] = l2;
            r[l2] += r[l1];
        }
        n--;
        return true;
    }
};

struct point {
    int x, y, i;
    point(): x(), y(), i() {}
};

int n;
point a[N];

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

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

    UnionFind uf(n);

    sort(a, a + n, [&] (const point& a, const point& b) {
        return a.x < b.x;
    });

    vector<int> st;
    for (int i = 0; i < n; i++) {
        while (!st.empty() and a[st.back()].y >= a[i].y) {
            st.pop_back();
        }
        if (!st.empty()) {
            uf.merge(a[st.back()].i, a[i].i);
        }
        st.push_back(i);
    }

    st.clear();
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() and a[st.back()].y <= a[i].y) {
            st.pop_back();
        }
        if (!st.empty()) {
            uf.merge(a[st.back()].i, a[i].i);
        }
        st.push_back(i);
    }

    sort(a, a + n, [&] (const point& a, const point& b) {
        return a.y < b.y;
    });

    st.clear();
    for (int i = 0; i < n; i++) {
        while (!st.empty() and a[st.back()].x >= a[i].x) {
            st.pop_back();
        }
        if (!st.empty()) {
            uf.merge(a[st.back()].i, a[i].i);
        }
        st.push_back(i);
    }

    st.clear();
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty() and a[st.back()].x <= a[i].x) {
            st.pop_back();
        }
        if (!st.empty()) {
            uf.merge(a[st.back()].i, a[i].i);
        }
        st.push_back(i);
    }

    for (int i = 0; i < n; i++) cout << uf.r[uf.find(i)] << '\n';
    return 0;
}

Measured memory_bytes: 7808
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	string s;
	cin >> s;
	s = s.substr(0, SIZE(s) - 1);
	int len = SIZE(s);
	if (len % 2 == 1)
		s = s.substr(0, SIZE(s) - 1);

	while (SIZE(s) > 1)
	{
		len = SIZE(s);
		if (s.substr(0, len / 2) == s.substr(len / 2, len))
		{
			print(len);
			return 0;
		}
		s = s.substr(0, SIZE(s) - 2);
	}
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

using ll = long long;

int main() {
	ios :: sync_with_stdio(0);
	int n; ll a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	n --;
	bool f = 0;
	for(int i = 0; i <= n; i ++) {
		ll al = a + i * c, ar = a + i * d;
		ll bl = b + (n - i) * c, br = b + (n - i) * d;
		ll l = max(al, bl), r = min(ar, br);
		if(l <= r) f = 1;
	}
	cout << (f ? "YES" : "NO") << '\n';
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

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

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {
          String[] s = in.readLine().split(" ");
          int n = Integer.parseInt(s[0]);
          int k = Integer.parseInt(s[1]);

          String line = in.readLine();
          int[] a = new int[n];
          char regex = ' ';
          boolean isContinue = true;
          for(int i=0, offset=0,next=0; isContinue; i++, offset = ++next) {
            if((next = line.indexOf(regex,offset)) == -1) {
              next = line.length();
              isContinue = false;
            }
            a[i] = Integer.parseInt(line.substring(offset,next));
          }

          List<Long> list = new ArrayList<>();
          for(int i=0; i<n; i++) {
            long sum = 0;
            for(int j=i; j<n; j++) {
              sum += (long)a[j];
              list.add(sum);
            }
          }

          long ans = 0;
          for(int i=62;i>=0;--i) {
            long b = 1L << i;
            int cnt = 0;
            for(long v: list) {
              if( (v&b) > 0 )
                ++cnt;
              if(cnt == k) {
                ans |= b;
                list.removeIf(e -> (e&b) == 0);
                break;
              }
            }
          }

          System.out.println(ans);
      }
      catch(IOException e) {
        System.err.println(e);
      }
  }
}

Measured memory_bytes: 49412
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

ll rui(ll a,ll b){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a%MOD;
        a=a*a%MOD;
        b/=2;
    }
     return ans;
}

int main(){
    int n, k;
    cin >> n >> k;
    double ans = 0;
    
    for(int i = 1; i <= n; i++){
        double win = 1.0 / n;
        int num = i;
        int cnt = 0;
        while(num < k){
            num *= 2;
            cnt++;
        }
        ll ruijo = rui(2, cnt);
        win /= ruijo;
        ans += win;
    }
    cout << fixed << setprecision(10);
    cout << ans << ln;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

long long count(long long A, long long B, long long C) {
  long long min;
  long long max;
  if (A % C == 0) {
    min = A;
  } else {
    min = (A / C + 1) * C;
  }

  if (B % C == 0) {
    max = B;
  } else {
    max = (B / C) * C;
  }

  if (min > max) return 0;
  return (max - min) / C + 1;
}

long long gcd(long long A, long long B) {
  if (B == 0) return A;
  return gcd(B, A % B);
}

int main() {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;

  cout << (B - A + 1) -
              (count(A, B, C) + count(A, B, D) - count(A, B, C * D / gcd(C, D)))
       << endl;

  return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;

    int count = 0;
    if (A > B) {
        count += A;
        A--;
    }
    else {
        count += B;
        B--;
    }

    count += max(A, B);
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define PI 3.14159265358979323846264338327950L

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m;

    long double theta_m=((long double)m/60.0);
    long double theta_h=((long double)h/12.0+((long double)m/60.0)/12.0);
    long double rad=2*PI*(theta_h-theta_m);

    long double rsq=(long double)(a*a+b*b)-(long double)(2*a*b)*cos(rad);

    cout << fixed << setprecision(20) << sqrt(rsq) << endl;
}

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll = pair<ll, ll>;


int main(){
    
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(ll &i:A)cin >> i;
    sort(A.begin(), A.end(), [](ll a,ll b){return a>b;});
    ll count=A[0];
   
    for(ll i=1;i<N/2;i++){
        count+=A[i]*2;
    }
    if(N%2==1)count+=A[N/2];
        
    cout << count << endl;
}


Measured memory_bytes: 4840
#include <stdio.h>

int main(void)
{
 int n,m,x,i,j,a[200];
 int cost1=0,cost2=0;
 scanf("%d %d %d",&n,&m,&x);
 for(i=0;i<m;i++)
  scanf("%d",&a[i]);

 for(i=0;i<m;i++){
  if(a[i]<x)
   cost1++;
 }

 cost2 = m - cost1;

 if(cost1<cost2)
  printf("%d",cost1);
 else
  printf("%d",cost2);

 return 0;
}

Measured memory_bytes: 128
// Problem : F - LCS
// Contest : Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
int main()
{
        string s,t;
        cin >> s >> t;
        int slen=s.length(),tlen=t.length();
        int arr[slen+1][tlen+1][2];
	for(int i=0;i<=slen;++i)
	{
		for(int j=0;j<=tlen;++j)
		{
			arr[i][j][0]=0;
		}
	}
	for(int i=0;i<slen;i++)
	{
		for(int j=0;j<tlen;j++)
		{
			if(s[i]==t[j] && arr[i][j][0]+1>arr[i+1][j+1][0])
			{
				arr[i+1][j+1][0]=arr[i][j][0]+1;
				arr[i+1][j+1][1]=3;
			}
			if(arr[i][j][0]>arr[i+1][j][0])
			{
				arr[i+1][j][0]=arr[i][j][0];
				arr[i+1][j][1]=2;
			}
			if(arr[i][j][0]>arr[i][j+1][0])
			{
				arr[i][j+1][0]=arr[i][j][0];
				arr[i][j+1][1]=1;
			}
		}
	}
	int ans=0;
	pair<int,int> here;
	for(int i=0;i<=slen;++i)
	{
		for(int j=0;j<=tlen;++j)
		{
			if(ans<arr[i][j][0])
			{ans=arr[i][j][0];here={i,j};}
		}
	}
	int count=0;
	string sans="";
	while(count<ans)
	{
		if(arr[here.first][here.second][1]==3)
		{
			++count;
			sans.push_back(s[here.first-1]);
			--here.first;
			--here.second;
		}
		else
		{
			if(arr[here.first][here.second][1]==2)
			{
				--here.first;
			}
			else
			{
				--here.second;
			}
		}
	}
	reverse(sans.begin(),sans.end());
	cout << sans << endl;
	return 0;
}

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

int main(){
    int d;
    cin >> d;
    if (d == 25)
        cout << "Christmas" << endl;
    else if (d == 24)
        cout << "Christmas Eve" << endl;
    else if (d == 23)
        cout << "Christmas Eve Eve" << endl;
    else
        cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

unsigned getDigit(unsigned num)
{
    unsigned digit = 0;
    while (num != 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
    int N;
    cin >> N;
    int ans = 0;
    repX(i,N+1,1){
        if(i<=9||100<=i&&i<1000||10000<=i&&i<100000)ans ++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll X;
    cin >>X;
    ll ans = 8-(X-400)/200;

    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#include "string"
#define int long long

const int M = 1e9 + 7;

int mod(int n){
	n %= M;
	return (n + M) % M;
}

int power(int a,int b){
	int ans = 1;
	while(b>0){
		if(b&1)
			ans = mod(ans * a);
		a = mod(a * a);
		b /= 2;
	}
	return ans;
}

pi get(pi a){
	if(a.ff == 0 && a.ss == 0)
		return {0,0};
	int g = __gcd(a.ff,a.ss);
	a.ff /= g;
	a.ss /= g;
	
	if(a.ss<0) {
		a.ff *= -1;
		a.ss *= -1;
	}
	
	if(a.ff == 0)
		a.ss = 1;
	if(a.ss == 0)
		a.ff = 1;
	return a;
}

pi rev(pi a) {
	if(a.ff == 0 && a.ss == 0)
		return a;
	a.ff *= -1;
	if(a.ff < 0){
		a.ff *= -1;
		a.ss *= -1;
	}
	if(a.ff == 0)
		a.ss = 1;
	if(a.ss == 0)
		a.ff = 1;
	return {a.ss,a.ff};
}

int32_t main(){
   boost;
   int n;
   cin>>n;
   pi a[n];
   map<pi,int>mp;
   for(int i=0;i<n;i++){
   	cin>>a[i].ff>>a[i].ss;
   	a[i] = get(a[i]);
   	mp[a[i]]++;
   }

   int ans = 1;
   for( auto & p:mp){
   	if(mp[p.ff] == -1)
   		continue;
   	if(p.ff == make_pair(0ll,0ll))
   		continue;
   	pi p1 = rev(p.ff);
   	if(mp.count(p1)){
   		int tt = mod( power(2,p.ss) + power(2,mp[p1]) - 1);
   		ans = mod(ans * tt);
   		mp[p1] = -1;
   	}
   	else
   		ans = mod(ans*power(2,p.ss));
   }
   ans = mod(ans  + mp[{0,0}] - 1);
   cout<<ans<<endl;
}

Measured memory_bytes: 19212