akhauriyash/Code-Regression huggingface dataset:
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.lang.Math.*;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        int total = 0;
        int[] time = new int[n+1];
        for(int i=1;i<=n;i++){
            int t = in.nextInt();
            total+=t;
            time[i]=t;
        }
        int m = in.nextInt();
        for(int i=0;i<m;i++){
            int p = in.nextInt();
            int t = in.nextInt();
            int dif = Math.abs(time[p]-t);
            if (t>time[p])
                out.println(total+dif);
            else
                out.println(total-dif);

        }
        out.close();



    }
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a[10001] = {0};
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long min = 1000000, max = -1000000, sum = 0;
    for(int i = 0; i < n; i++) {
        if(a[i]<min) {
            min = a[i];
        }
        if(a[i]>max){
            max = a[i];
        }
        sum = sum + a[i];
    }
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3164
#include <stdio.h>

int main() {
  int n;
  char s[50];

  int cnt;

  int num = 0;

  scanf("%d", &n);
  scanf("%s", s);

  for(cnt = 0; cnt <= n - 2; cnt++) {
    if(s[cnt] == 'A' && s[cnt + 1] == 'B' && s[cnt + 2] == 'C')
      num++;
  }

  printf("%d", num);

  return 0;
}

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

int main() {
string szo;
cin >> szo;
if (szo[0] == 'A') {
  if (szo[1] == 'A') {
 if (szo[2] == 'A') {
  cout << "No";
} else {
  cout << "Yes";
}
 } else {
 if (szo[2] == 'B') {
  cout << "Yes";
} else {
  if (szo[2] == 'A'){
      cout << "Yes";
  }
}
 }
} else {
  if (szo[1] == 'B') {
 if (szo[2] == 'B') {
  cout << "No";
} else {
  cout << "Yes";
}
  } else {
     if (szo[2] == 'B') {
  cout << "Yes";
} else {
  if (szo[2] == 'A') {
        cout << "Yes";
  }
}
}
}
	return 0;
}


Measured memory_bytes: 3576
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    total = sum(A)
    mod = 10**9 + 7
    ans = 0
    for a in A[:-1]:
        total -= a
        ans += a * total
        ans %= mod

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31484
#include<stdio.h>

int main(){
    int a,b;
    char op;
    while(true){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        switch(op){
            case '+':
                printf("%d\n",a+b);
                break;
            case '-':
                printf("%d\n",a-b);
                break;
            case '*':
                printf("%d\n",a*b);
                break;
            case '/':
                printf("%d\n",a/b);
                break;
        }        
    }
}


Measured memory_bytes: 2724
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;
constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

ll N;
vector<ll> As;

int main() {
    cin >> N;
    As.resize(N);
    rep(i,0,N) {
        cin >> As[i];
    }
    unordered_map<ll, ll> cnt;
    rep(i,0,N) {
        cnt[As[i]]++;
    }
    ll sum = 0;
    rep(n,1,N+1) {
        sum += (cnt[n] * (cnt[n] - 1)) / 2;
    }
    rep(k,0,N) {
        ll n = cnt[As[k]];
        ll ans = sum;
        ans -= (n * (n-1)) / 2;
        ans += ((n-1) * (n-2)) / 2;
        cout << ans << endl;
    }
}


Measured memory_bytes: 15100
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<algorithm>

using namespace std;
//#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 1e13
#define ll long long
const ll mod = 2333;
const int N = 1e5 + 10;
const int M = 2e6 + 1005;
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s == "SUN") puts("7");
    else if(s == "MON") cout<<6;
    else if(s == "TUE") cout<<5;
    else if(s == "WED") cout<<4;
    else if(s =="THU") cout<<3;
    else if(s == "FRI") cout<<2;
    else if(s == "SAT") cout<<1;
}


Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#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>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    cin >> N >> K;
    print(N - K + 1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n);
  vector<ll> c(m), d(m);
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];

  rep(i, n) {
    ll val = INF;
    ll ans = n;
    rep(j, m){
      if (chmin(val, abs(a[i]-c[j]) + abs(b[i]-d[j])))
        ans = j+1;
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3596
n = int(input())
s = [input() for _ in range(2)]

ans = 1
mod = 1000000007
count = 0
flag = True

while count < n:
    if count == 0:
        if s[0][count] == s[1][count]:
            ans *= 3
            count += 1
        else:
            ans *= 3 * 2
            count += 2
            flag = False
    else:
        if flag:
            if s[0][count] == s[1][count]:
                ans *= 2
                count += 1
            else:
                ans *= 2 * 1
                count += 2
                flag = False
        else:
            if s[0][count] == s[1][count]:
                ans *= 1
                count += 1
                flag = True
            else:
                ans *= 3
                count += 2
    ans %= mod

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<"\n";
#define ll long long
int dp[1005][1005];
int arr[1005][1005];
ll N=1000000007;
int main()
{

	int h,w;
	cin>>h>>w;
	memset(dp,0,sizeof(dp));
	for(int i=0; i<=h+1; i++)
	{
		for(int j=0; j<=w+1; j++)
		{
			if(j==0 || i==0 || i==h+1 || j==w+1)
				arr[i][j]=1;
			else
			{
				char temp;
				cin>>temp;
				if(temp=='.')
					arr[i][j]=0;
				else
					arr[i][j]=1;
			}
		}
	}
	dp[1][1]=1;
	for(int i=1; i<=h; i++)
	{
		for(int j=1; j<=w; j++)
		{
			if(i==1 && j==1)
				continue;
			
			if(arr[i][j]==1)
				dp[i][j]=0;
			else
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%N;
			
			
		}
	}
	cout<<dp[h][w];
	// for(int i=0; i<=h+1; i++)
	// {
	// 	for(int j=0; j<=w+1; j++)
	// 	{
	// 		cout<<arr[i][j]<<" ";
	// 	}nl;
	// }

}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
template<class T> inline void chmax(T &a,T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a,T b){if(a>b)a=b;}

ll dp[110][100010];

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,W,V=0;
    cin >> N >> W;
    vector<int> w(N),v(N);
    
    for(int i = 0; i < N; ++i){
        cin >> w[i] >> v[i];
        V += v[i];
    }

    // init
    for(int i = 0;i <= N; ++i) for(int j = 0; j <= V; ++j) dp[i][j] = INF;
    dp[0][0] = 0;

    // calc
    for(int i = 0; i < N; ++i){
        for(int j = 0; j <= V; ++j){
            if(j - v[i] >= 0) chmin(dp[i+1][j],dp[i][j-v[i]] + w[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    
    int ans = 0;
    for(int i = 0; i <= V; ++i) if(dp[N][i] <= W) ans = i;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 80128
def libra(l,r):
    if l>r:
        return "Left"
    elif l == r:
        return "Balanced"
    else:
        return "Right"
def sum(a,b):
    c = a+b
    return c
a,b,c,d=[int(i) for i in input().split()]
print(libra(sum(a,b),sum(c,d)))

Measured memory_bytes: 38256
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
s = list(input() for i in range(n))
t = [0]*5

for i in range(n):
        if s[i][0] == 'M':
                t[0] += 1
        elif s[i][0] == 'A':
                t[1] += 1
        elif s[i][0] == 'R':
                t[2] += 1
        elif s[i][0] == 'C':
                t[3] += 1
        elif s[i][0] == 'H':
                t[4] += 1

c = combinations(range(5),3)
ans = 0   
for x in c:
        ans += t[x[0]] * t[x[1]] * t[x[2]]

print(ans)

Measured memory_bytes: 17140
def binarySearch(arr, key)
    left = -1
    right = arr.size
    while (right-left).abs > 1
        mid = (right+left) / 2
        if arr[mid] > key then
            right = mid
        else
            left = mid
        end
    end
    return left
end

n, m, k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
ruiseki_a = [0]
ruiseki_b = [0]
ans = 0
n.times do |i|
    ruiseki_a << a[i] + ruiseki_a[i]
end
m.times do |i|
    ruiseki_b << b[i] + ruiseki_b[i]
end
(n+1).times do |i|
    j = binarySearch(ruiseki_b, k - ruiseki_a[i])
    break if j == -1
    ans = ans < i+j ? i+j : ans
end
puts ans

Measured memory_bytes: 49240
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long r){
  std::cout << 3 * r * r << std::endl;
}

int main(){
  long long r;
  scanf("%lld",&r);
  solve(r);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool isR(string s)
{
    string t  =s;
    bool is = true;
    for(int i = 0;i < (int)s.size();++i)
    {
        if(s[i] != t[s.size() - 1 -i])
            is = false;
    }
    return is;
}
int main()
{
    int a,b;
    cin >> a >> b;
    int count = 0;
    for(int i = a; i <= b; ++i)
    {
        if(isR(to_string(i)))
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	string s;
	cin >> s;
	auto found = vector<bool>('z' + 1);
	for(auto c : s) found[c] = true;
	char ans = 0;
	for(auto i = (int)'a'; i <= 'z'; ++i){
		if(!found[i]){
			ans = i;
			break;
		}
	}
	if(ans != 0) cout << ans << endl;
	else cout << "None" << endl;
	return 0;
}

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

struct SegmentTree2D {
#define all(x) begin(x), end(x)
    int sz;
    vector<vector<int>> dat;
    SegmentTree2D(int n) : sz(1) {
        while (sz < n) sz <<= 1;
        dat.resize(sz * 2);
    }
    void add_point(int i, int j) { dat[i + sz].emplace_back(j); }
    void build() {
        for (int k = 0; k < sz; k++) sort(all(dat[k + sz]));
        for (int k = sz - 1; k > 0; k--) {
            merge(all(dat[2 * k]), all(dat[2 * k + 1]), back_inserter(dat[k]));
        }
    }
    int get(int si, int ti, int sj, int tj) {   // [si, ti) x [sj, tj)
        int res = 0;
        auto calc = [&](vector<int> &v) {
            return lower_bound(all(v), tj) - lower_bound(all(v), sj);
        };
        for (int l = si + sz, r = ti + sz; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res += calc(dat[l++]);
            if (r & 1) res += calc(dat[--r]);
        }
        return res;
    }
#undef all
};

int main() {
    int n, m; cin >> n >> m;
    int q; cin >> q;
    SegmentTree2D acc(n + 1);
    while (m--) {
        int l, r; cin >> l >> r;
        acc.add_point(l, r);
    }
    acc.build();
    while (q--) {
        int l, r; cin >> l >> r;
        cout << acc.get(l, r + 1, l, r + 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 11316
import sys

s = sys.stdin.read().strip()
words = ["dream", "dreamer", "erase", "eraser"]

stack = [0]
match = False
while not match and stack:
  i = stack.pop()
  for w in words:
    if s.startswith(w, i):
      n = i + len(w)
      if n == len(s):
        match = True
        break
      stack.append(n)
print("YES" if match else "NO")


Measured memory_bytes: 3564
import itertools
N = int(input())
A = tuple(map(int,input().split()))
B = tuple(map(int,input().split()))
p = itertools.permutations(range(1,N+1),N)
hashmap = {}
for i, v in enumerate(p):
    hashmap[v]=i+1
print(abs(hashmap[A]-hashmap[B]))

Measured memory_bytes: 16112
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;

int n,A[5000000];
void maxheapify(int i){
  int l=2*i,r=2*i+1,largest;
  if(l<=n&&A[l]>A[i])largest=l;
  else largest=i;
  if(r<=n&&A[r]>A[largest])largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxheapify(largest);
  }
}
int main(){
  cin>>n;
  FOR(i,1,n+1)cin>>A[i];
  for(int i=n/2;i>=1;i--)maxheapify(i);
  FOR(i,1,n+1)cout<<" "<<A[i];
  cout<<endl;
  return 0;
}


Measured memory_bytes: 5024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#include <atcoder/all>
using namespace atcoder;
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    dsu d(n);
    ll q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        if (a == 0)d.merge(b, c);
        else {
            if (d.same(b, c))cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}

Measured memory_bytes: 3996
#include<stdio.h>
int main(void)
{
	int a,s,d,i,f;
	f=0;
	scanf("%d %d",&a,&s);
	while(a!=0&&s!=0){
	d=0;
	if(f!=0){
		printf("\n");
	}
	for(i=a;i<=s;i++){
		if(i%4==0&&i%100!=0||i%400==0){
			printf("%d\n",i);
			d=1;
		}
	}
	if(d==0){
		printf("NA\n");
	}
	scanf("%d %d",&a,&s);
	f++;
	}
	return 0;
}

Measured memory_bytes: 1044
package main

// Solution for https://atcoder.jp/contests/abc070/tasks/abc070_b

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var a, b, c, d int
	con.Scan(&a, &b, &c, &d)
	if a > c {
		a, b, c, d = c, d, a, b
	}
	if b < d {
		d = b
	}
	x := d - c
	if x < 0 {
		x = 0
	}
	con.Println(x)
	return nil
}


Measured memory_bytes: 1848
# -*- coding: utf-8 -*-
INF=10**10

def main():
    
    lim=10**9+7
    n=int(input())
    ans=1
    for i in range(1,n+1):
        ans*=i
        if ans>lim:
            ans%=lim
    print(ans)
    
    
if __name__=="__main__":
    main()
    

Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>

int main (void)
{
    char S[101];
    int i, len, s = 0, e = 0;

    gets(S);

    if (strstr(S, "keyence") != NULL) {
        puts("YES");
        return 0;
    }

    len = strlen(S);
    if (S[0] == 'k') {
        s = 1;
        if (S[1] == 'e') {
            s = 2;
            if (S[2] == 'y') {
                s = 3;
                if (S[3] == 'e') {
                    s = 4;
                    if (S[4] == 'n') {
                        s = 5;
                        if (S[5] == 'c') {
                            s = 6;
                            if (S[6] == 'e') s = 7;
                        }
                    }
                }
            }
        }
    }
    

    if (S[len - 1] == 'e') {
        e = 1;
        if (S[len - 2] == 'c') {
            e = 2;
            if (S[len - 3] == 'n') {
                e = 3;
                if (S[len - 4] == 'e') {
                    e = 4;
                    if (S[len - 5] == 'y') {
                        e = 5;
                        if (S[len - 6] == 'e') {
                            e = 6;
                            if (S[len - 7] == 'k') e = 7;
                        }
                    }
                }
            }
        }
    }

    if (s + e >= 7) {
        puts("YES");
        return 0;
    }

    puts("NO");
    return 0;
}


Measured memory_bytes: 128
from itertools import permutations
from math import sqrt
n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = map(int, input().split())

p = [i for i in range(n)]
c = 0
d = 0.0
dp = [[0.0 for _ in range(n)] for _ in range(n)]
for a in permutations(p):
    c += 1
    for i in range(n - 1):
        if dp[a[i]][a[i + 1]] == 0.0:
            dp[a[i]][a[i + 1]] = sqrt((x[a[i]] - x[a[i + 1]]) ** 2 + (y[a[i]] - y[a[i + 1]]) ** 2)
            dp[a[i + 1]][a[i]] = dp[a[i]][a[i + 1]]
        d += dp[a[i]][a[i + 1]]
print("{:10f}".format(d / c))


Measured memory_bytes: 3064
/* ex_5-3. nknm */

#include <stdio.h>
#include <math.h>


int main(void){

    int ver, hor, count;
    char imput[100][100];
    int i, j, k, l;

    scanf("%d%d", &hor, &ver);

    for(i = 0; i < hor; i++){
        for(j = 0; j < ver ; j++){
            scanf(" %c", &imput[i][j]);
        }
    }

    
    count = 0;

    for(j = 0; j < ver; j++){
        for(i = 0; i < hor; i++){
            if(imput[i][j] == '.'){
                count += 1;
            }
        }
        if(count == hor){
            for(k = j; k < ver - 1; k++){
                for(i = 0; i < hor; i++){
                    imput[i][k] = imput[i][k + 1];
                }    
            }
            for(l = 0; l < hor; l++){
                imput[l][ver - 1] = ' ';
            }
            ver = ver - 1;
            j = j - 1;
        }
        count = 0;        
    }

     for(i = 0; i < hor; i++){
            for(j = 0; j < ver; j++){
                if(imput[i][j] == '.'){
                    count += 1;
                }
            }
            if(count == ver){
                for(k = i; k < hor - 1; k++){
                    for(j = 0; j < ver; j++){
                        imput[k][j] = imput[k + 1][j];
                    }
                } 
                for(l = 0; l < ver; l++){
                    imput[hor - 1][l] = ' ';
                }
                hor = hor - 1;
                i = i - 1;
            }
            count = 0;        
    }


    for(i = 0; i < hor; i++){
        for(j = 0; j < ver; j++){
            printf("%c", imput[i][j]);

        }
        printf("\n");
    }

    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  lli k;
  while (cin >> n >> k) {
    vector<lli> a(n);
    cin >> a;

    if (k == 0) {
      cout << accumulate(a.begin(), a.end(), 0LL) << endl;
      continue;
    }
    
    map<int, int> cnt;
    each (i, a) {
      for (int j = 0; j < 63; ++j) {
        if (i & (1LL << j)) ++cnt[j];
      }
    }

    const int N = 62;
    lli dp[N][2];
    fill(&dp[0][0], &dp[N - 1][2 - 1] + 1, -(1LL << N));
    dp[0][false] = 0;
    const int M = N - 2;
    for (int i = 0; i <= M; ++i) {
      lli x = 1LL << (M - i);
      lli w = cnt[M - i];
      setmax(dp[i + 1][0], dp[i][0] + x * w);
      if (k < x) continue;
      for (int j = 0; j < 2; ++j) {
        if (j) {
          setmax(dp[i + 1][j], dp[i][j] + x * max(w, n - w));
        } else {
          if (k & x) {
            // 0
            setmax(dp[i + 1][1], dp[i][0] + x * w);
            // 1
            setmax(dp[i + 1][0], dp[i][0] + x * (n - w));
          } else {
            // 0
            setmax(dp[i + 1][0], dp[i][0] + x * w);
            // 1
          }
        }
      }
    }

    cout << *max_element(&dp[0][0], &dp[N - 1][2 - 1] + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll unsigned long long
using namespace std;
class Graph 
{ 
    int V;    
    list<int> *adj;    
public: 
    Graph(int V);  // Constructor 
  
    // function to add an edge to graph 
    void addEdge(int v, int w);  
  
    // prints BFS traversal from a given source s 
    void BFS(int s);   
}; 
  
Graph::Graph(int V) 
{ 
    this->V = V; 
    adj = new list<int>[V]; 
} 
  
void Graph::addEdge(int v, int w) //How to add edge
{ 
    adj[v].push_back(w); 
} 
  
void Graph::BFS(int s) //BFS 
{ 
   
    bool *visited = new bool[V]; 
    for(int i = 0; i < V; i++) 
        visited[i] = false; 
 
    list<int> queue; 
    visited[s] = true; 
    queue.push_back(s); 
    list<int>::iterator i; 
  
    while(!queue.empty()) 
    { 
        s = queue.front(); 
        cout << s << " "; 
        queue.pop_front(); 
  
        for (i = adj[s].begin(); i != adj[s].end(); ++i) 
        { 
            if (!visited[*i]) 
            { 
                visited[*i] = true; 
                queue.push_back(*i); 
            } 
        } 
    } 
} //To create a graph
//Graph g(4); 
    //g.addEdge(0, 1); 
    //g.addEdge(0, 2); 
int gcd(int x, int y) {
        if (x == 0) {
            return y;
        }
        
        return gcd(y % x, x);
    }


int main()
{
  int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin>>k;
  cout<<a[k-1]<<"\n";
   
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

struct compare {
	bool operator()(pair<int, int> const & a,
					pair<int, int> const & b)
	{return a.first < b.first;}
};

int H, W, N;
priority_queue<pair<int, int>, vector<pair<int, int> >, compare > pq;
int main() {
	int color = 1, num_color;
	cin >> H >> W >> N;
	while (cin >> num_color) {
		pair<int, int> p = make_pair(num_color, color);
		pq.push(p);
		color++;
	}
	int board[H][W];
	int index = 0;
	while (!pq.empty()) {
		pair<int, int> color_num = pq.top();
		num_color = color_num.first;
		color = color_num.second;
		for (int i = 0; i < num_color; i++) {
			if ((index / W)%2 == 0) {
				board[index/W][index%W] = color;
			} else {
				board[index/W][W - index%W - 1] = color;
			}
			index++;
		}
		pq.pop();
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			printf("%d", board[i][j]);
			if (j != W-1) printf(" ");
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int N, A[200];
 
int main()
{
	int dmin = 100, N;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		int d = 0;
		while (A % 2 == 0) {
			A /= 2;
			++d;
		}
		dmin = min(dmin, d);
	}
	cout << dmin << endl;
	return 0;
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"

#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;
const long double PI = (acos(-1));
const ull MOD = 1000000007;


struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

void mini_solve(){

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

    int color = 1;
    int cnt = 0;

    vector<vector<int>> Ans(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        if(i % 2 == 0){
            for(int j = 0; j < W; j++){
                Ans[i][j] = color;
                cnt++;
                if(A[color - 1] == cnt){
                    color++;
                    cnt = 0;
                }
            }
        }else{
            for(int j = W - 1; j >= 0; j--){
                Ans[i][j] = color;
                cnt++;
                if(A[color - 1] == cnt){
                    color++;
                    cnt = 0;
                }
            }
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(j == W - 1) cout << Ans[i][j] << endl;
            else cout << Ans[i][j] << ' ';
        }
    }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define endl "\n"
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()
ll maxAbsValExpr(vector<ll>& x, vector<ll>& y) {
        ll res = 0, n = x.size(), smallest, cur;
        for (int p : {1, -1}) {
            for (int q : {1, -1}) {
                smallest = p * x[0] + q * y[0] + 0;
                for (int i = 1; i < n; ++i) {
                    cur = p * x[i] + q * y[i] ;
                    res = max(res, cur - smallest);
                    smallest = min(smallest, cur);
                }
            }
        }
        return res;
    }
ll power(ll x, ll y, ll p) { 
    ll res = 1;    x = x % p;  
    while(y > 0) {
        if(y & 1) res = (res*x) % p; 
        y = y>>1;    x = (x*x) % p; 
    } return res; 
}
int main()
{
    Imposter
    
    int t=1;
    //cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       vll a,b;
       f(n)
       {
           ll x,y;
           cin>>x>>y;
           a.pb(x);
           b.pb(y);
       }
       cout<<maxAbsValExpr(a,b)<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 6624
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,char> P;
int partition(P* A,int p,int r){
  int x=A[r].first;
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j].first<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
void quicksort(P* A,int p,int r){
  if(p<r){
    int q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}
signed main(){
  int n;
  cin>>n;
  P A[n];
  for(int i=0;i<n;i++) cin>>A[i].second>>A[i].first;
  map<int,string> m1,m2;
  for(int i=0;i<n;i++) m1[A[i].first]+=A[i].second;
  quicksort(A,0,n-1);
  for(int i=0;i<n;i++) m2[A[i].first]+=A[i].second;
  bool flag=1;
  for(int i=0;i<n;i++) flag&=m1[A[i].first]==m2[A[i].first];
  if(flag) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  for(int i=0;i<n;i++){
    cout<<A[i].second<<" "<<A[i].first<<endl;
  }
  return 0;
}


Measured memory_bytes: 10120
import itertools
import numpy as np
N, K, *XYC = open(0).read().split()
N = int(N)
K = int(K)
board = np.zeros((4 * K + 1, 4 * K + 1), dtype=np.uint16)
for x, y, c in zip(XYC[::3], XYC[1::3], XYC[2::3]):
    x = int(x)
    y = int(y)
    if c == 'W':
        x += K
    x = x % (2 * K)
    y = y % (2 * K)
    board[x, y] += 1
    board[(x + K) % (2 * K), (y + K) % (2 * K)] += 1
board[1 + 2 * K:, 1 + 2 * K:] = board[:2 * K, :2 * K]
board[1:1 + 2 * K, 1 + 2 * K:] = board[1 + 2 * K:, 1 + 2 * K:]
board[1 + 2 * K:, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[1:1 + 2 * K, 1:1 + 2 * K] = board[1 + 2 * K:, 1 + 2 * K:]
board[0, :] = 0
board[:, 0] = 0
for j in range(1, 1 + 4 * K):
    board[:, j] += board[:, j - 1]
for j in range(1, 1 + 4 * K):
    board[j, :] += board[j - 1, :]
ans = np.max(board[K:3 * K, K:3 * K] + board[:2 * K, :2 * K] -
             board[:2 * K, K:3 * K] - board[K:3 * K, :2 * K])
print(ans)


Measured memory_bytes: 82760
//
// Created by moono on 2018/10/27.
//

#include <iostream>
#include <string>
#include <set>

using namespace std;


int get_num_divisors(int n){
    int primes[]  = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
                     53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103};

    //
    set<int> divisors;
    for(int p: primes){

        if(n % p == 0){
            int q = p;
            while(q <= n){
                if(n % q == 0) divisors.insert(q);
                q += p;
            }
        }
    }

//    cout << "-- -- --" << endl;
//    for(int d: divisors)
//        cout << d << endl;


    return divisors.size();
}

int main() {


    //
    int N;
    cin >> N;

    // 
    int num_answer = 0;
    for(int i = 1; i <= N; i+=2){
        int d = get_num_divisors(i);
        if(d == 7) {
//            cout << i << endl;
            num_answer++;
        }
    }
    cout << num_answer << endl;


    return 0;
}

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

using namespace std;

#define For(a, b, c) for(int a = b; a <= c; ++a)
#define Ford(a, b, c) for(int a = b; a >= c; --a)
#define All(a, b) for(auto &a : b)
#define Rep(a, b, c) for(int a = b; a < c; ++a)

#define int long long
#define ii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))

#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))
#define bitone(i) __builtin_popcount(i)
#define bitl(i) __builtin_clz(i)
#define bitr(i) __builtin_ctz(i)

const int N=2e5+5;
int n, a[N], s[N], k;
double ans, x[N];

main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	For(i, 1, n) cin >> a[i];
	For(i, 1, n) x[i] = x[i - 1] + (double)(a[i] + 1) / 2;
	For(i, k, n) {
		ans = max(ans, (double)(x[i] - x[i - k]));
	} 
	cout << setprecision(12) << fixed << ans;
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    int flag = 1;
    long long int k, m;
    vector<long long int> v;
    for(int i = 0; i < 5; i++){
        cin >> m;
        v.push_back(m);
    }
    
    cin >> k;
    
    if(v[4]-v[0] > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

}


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

int main(){
	  int n;
	  cin >> n;
	  cout << n << ":";
	  for(int i=2; i*i<=n; i++){
			while(n%i == 0){
				  cout << " " << i;
				  n /= i;
			}
	  }
	  if(n!=1)cout << " " << n ;
	  cout << endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
//=============================
void input()
{
    cin>>N;
    A.resize(N);
    rep(i,0,N-1){
        cin>>A[i];
    }
}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    int ans = INF;
    for(auto x : A){
        int i=0;
        for( ; x && (x % 2 == 0)& i<ans ; ++i){
            x /= 2;
        }
        ans = min(i,ans);

    }
    cout<<ans<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int room[120] = {0};
    int n;
    int b,f,r,v;
    int i;
    char part[] = "####################\n";
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        room[30 * (b - 1) + 10 * (f - 1) + r - 1] += v;
    }
    for (i = 0; i < 120; i++)
    {
        putchar(' ');
        printf("%d", room[i]);
        if (i % 10 == 9)
        {
            putchar('\n');
            if (i < 119 && (i / 10) % 3 == 2)
            {
                printf("%s", part);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2052
a = input()
b = input()

max_len = 105

if len(a) < max_len:
    a = '0' * (max_len - len(a)) + a

if len(b) < max_len:
    b = '0' * (max_len - len(b)) + b

if a > b:
    ans = "GREATER"
elif a == b:
    ans = "EQUAL"
else:
    ans = "LESS"

print(ans)


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

int main(){
    int maxv=0;
    int sum=0;
    rep(i,5){
        int t;
        cin>>t;
        int x=t%10;
        if(x!=0){
            t+=(10-x);
            maxv=max(maxv,10-x);
        }
        sum+=t;
    }
    cout<<sum-maxv<<"\n";
    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i< (int) n; i++)
#define PI  3.14159265358979323846264338327950
 
int main () {
    int N , M;
    cin >> N >> M;

    vector<vector<int>>gakusei(N,vector<int>(2));
    rep(i,N){
        rep(j,2){
            cin >> gakusei[i][j];
        }
    }
    vector<vector<int>>check(M,vector<int>(2));
    rep(i,M){
        rep(j,2){
            cin >> check[i][j];
        }
    }

    rep(i,N){
        int man = 1000000000;
        int ans =55;
        rep(j,M){
            int kyori = abs(gakusei[i][0]-check[j][0]) + abs(gakusei[i][1]-check[j][1]);
            if( man > kyori ){
                man = kyori;
                ans = j+1;
            }
            

        }
        cout << ans << endl;
    }


}


Measured memory_bytes: 256
import math

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

def calculate_distance(data1,data2,p):
  if len(data1) != len(data2):
    print("error")
  tmp_sum=0
  for i in range(len(data1)):
    tmp_sum += abs(data2[i]-data1[i]) ** p
  return tmp_sum ** (1/p)

#where p = 1
print("{:.5f}".format(calculate_distance(a_list,b_list,1)))

#where p = 2
print("{:.5f}".format(calculate_distance(a_list,b_list,2)))

#where p = 3
print("{:.5f}".format(calculate_distance(a_list,b_list,3)))

#where p = ∞
tmp_list=[0]*n
for i in range(n):
  tmp_list[i]=abs(a_list[i]-b_list[i])
print("{:.5f}".format(max(tmp_list)))



Measured memory_bytes: 5704
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
      if((a+b+c) == 17){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
	}
}

Measured memory_bytes: 21844
import sys

input = sys.stdin.readline

K = int(input())

arr = [i for i in range(1, 10)]

for i in range(100001):
    one = arr[i]%10
    if one == 0:
        arr.append(arr[i]*10 + 0)
        arr.append(arr[i]*10 + 1)
    elif one == 9:
        arr.append(arr[i]*10 + 8)
        arr.append(arr[i]*10 + 9)
    else:
        arr.append(arr[i]*10 + one - 1)
        arr.append(arr[i]*10 + one)
        arr.append(arr[i]*10 + one + 1)

arr.sort()
print(arr[K-1])

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

pair<ll,ll> sum(pair<ll,ll> a,pair<ll,ll> b){
  pair<ll,ll> c;
  c.first=(a.first*b.second+a.second*b.first)/__gcd(a.second,b.second);
  c.second=a.second*b.second/__gcd(a.second,b.second);
  return c;
}

int main(){
  ll n,k;
  cin >> n >> k;
  pair<ll,ll> s,t;
  if(k>n){
    s.first=0;
    s.second=1;
  }else{
    s.first=(n-k+1)/__gcd(n-k+1,n);
    s.second=n/__gcd(n-k+1,n);
  }
  //cout << s.first << "/" << s.second;
  ll p=2;
  while(k>1){
    t.first=(min(n,k-1)-min(n,(k-1)/2))/__gcd(min(n,k-1)-min(n,(k-1)/2),p*n);
    t.second=p*n/__gcd(min(n,k-1)-min(n,(k-1)/2),p*n);
    //cout << "+" << t.first << "/" << t.second << endl;
    s=sum(s,t);
    k=(k+1)/2;
    p *= 2;
    //cout << s.first << "/" << s.second;
  }
  
  double r=(double)s.first/s.second;
  printf("%.12lf",r);
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  ll h, w;
  cin >> h >> w;
  ll now = h * w;
  if (h == 1 or w == 1) cout << 1 << endl;
  else if (now % 2 == 0) cout << now/2 << endl;
  else cout << now/2 + 1 << endl;
  return 0;
}



Measured memory_bytes: 3672
D = int(input())
listC = list(map(int, input().split()))
answerL = []
for i in range(D):
    listS = list(map(int, input().split()))
    maxi = min(listS)
    target = listS.index(maxi)
    answerL.append(target+1)
for ans in answerL:
    print(ans)

Measured memory_bytes: 9060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int dp[200001][2];
char ans[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    string T;
    cin >> T;
    int N = T.size();
    for(int i = 1; i <= N; i++){
        if(T[i-1] == 'D'){
            dp[i][0] = max(dp[i-1][0], dp[i-1][1]+1)+1;
        }else if(T[i-1] == 'P'){
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]);
        }else{
            dp[i][0] = max(dp[i-1][0], dp[i-1][1]+1)+1;
            dp[i][1] = max(dp[i-1][0], dp[i-1][1]);
        }
    }
    char cur;
    if(dp[N][0] > dp[N][1]){
        cur = 'D';
    }else{
        cur = 'P';
    }
    ans[N-1] = cur;
    // cout << dp[N][0] << ' ' << dp[N][1] << endl;
    for(int i = N-1; i >= 1; i--){
        if(cur == 'D'){
            if(dp[i][0]+1 == dp[i+1][0]) cur = 'D';
            else cur = 'P';
        }else{
            if(dp[i][0] == dp[i+1][1]) cur = 'D';
            else cur = 'P';
        }
        ans[i-1] = cur;
    }
    for(int i = 0; i < N; i++) cout << ans[i];
    cout << endl;
}

Measured memory_bytes: 5532
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, U, V;
vector<int> edge[100005];
int aokiDist[100005];
int chokDist[100005];

void dfs(int u, int dist[]) {
    for(auto&&v:edge[u]) {
        if(dist[v] == -1) {
            dist[v] = dist[u] + 1;
            dfs(v, dist);
        }
    }
}


signed main() {

    cin >> n >> U >> V;

    for(int i = 0; i < n-1; i++) {
        int a, b;
        cin >> a >> b;
        edge[a].bash(b);
        edge[b].bash(a);
    }
    memset(aokiDist, -1, sizeof(aokiDist));
    memset(chokDist, -1, sizeof(chokDist));
    chokDist[U] = 0;
    aokiDist[V] = 0;
    dfs(U, chokDist);
    dfs(V, aokiDist);

    int maxi = 0;
    
    for(int i = 1; i <= n; i++) {
        if(chokDist[i] <= aokiDist[i])
            chmax(maxi, aokiDist[i]-1);
    }

    cout << maxi << endl;
    
    return 0;
}



Measured memory_bytes: 10368
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007

using namespace std;
using ll = long long;
using ldb = long double;
int main(){
 int N;
 ldb ans = 0.0, a;
 cin >> N;
 for(int i = 0; i < N; i++){
 cin >> a;
 ans += 1.0 / a;
 }
 ans = 1.0 / ans;
printf("%.10Lf\n", ans);
 }


Measured memory_bytes: 256
a,b = map(int,input().split())
if abs(a-b)>=2:
    print(0)
elif a!=b:
    mod = 10**9+7
    res = 1
    for i in range(a):
        res *=(i+1)
        res%=mod
    for i in range(b):
        res*=(i+1)
        res%=mod
    print(res)
else:
    res = 1
    mod = 10**9+7
    for i in range(a):
        res*=(i+1)
        res%=mod
    print(((res**2)*2)%mod)


Measured memory_bytes: 3060