akhauriyash/Code-Regression huggingface dataset:
import sys
inputs = sys.stdin.readlines()

S = inputs[0].strip()
K = int(inputs[1])

if len(set(S)) == 1:
    print(len(S)*K // 2)
else:
    counts = []
    count = 1
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            count += 1
        else:
            counts.append(count)
            count = 1
    counts.append(count)
    if S[0] != S[-1]:
        print(K*sum(map(lambda x: x//2, counts)))
    else:
        if counts[0] % 2 == 1 and counts[-1] % 2 == 1:
            t = 1
        else:
            t = 0
        counts[0] += counts.pop()
        print(K*sum(map(lambda x: x//2, counts)) - t)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int32_t main() {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	int n; cin >> n;
	int k; cin >> k;
	vector<int> h(n); for (int o = 0; o < n; o++) { cin >> h[o]; }
	std::vector<int> c(n, 1000000001);
	c[0] = 0;
	for (int i = 1; i < n; ++i)
		for (int j = i - 1; j >= max(0, i - k); --j)
			c[i] = min(c[i], c[j] + abs(h[i] - h[j]));
	cout << c[n - 1];
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int flag=scan.nextInt();
    int num=scan.nextInt();
    int[] stk=new int[num];
    for(int a=0; a<num; a++){
      stk[a]=scan.nextInt();
    }
    boolean tmp=true;
    int ans=0;
    int count=0;
    boolean cap=true;
    boolean capplus=true;
    boolean capminus=true;
    while(tmp){
      capplus=true;
      capminus=true;
      cap=true;
      if(flag-count>0){
        for(int a=0; a<num; a++){
          if(flag-count==stk[a]){
            cap=false;
            capminus=false;
          }
        }
      }
      if(!cap){
        cap=true;
        for(int a=0; a<num; a++){
          if(flag+count==stk[a]){
            cap=false;
            capplus=false;
          }
        }
      }
      if(cap){
        if(capminus){
           ans=flag-count;
        }
        else if(capplus){
           ans=flag+count;
        }
        tmp=false;
      }
      count++;
    }
    System.out.println(ans);
  }
}


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

int bubbleSort(int A[], int N){
    //cはchange 交換回数
    int c = 0;
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = N-1 ; j > 0 ; j--){
            if(A[j] < A[j-1]){
                int b = A[j];
                A[j] = A[j-1];
                A[j-1] = b;
                flag = 1;
                c += 1;
            }
        }
    }
    return c;
}
int main(){
    int A[100];
    int N,c,k;
    cin >> N;
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
    }

    c = bubbleSort(A , N);

    for(k = 0 ; k < N ; k++){
        if(k != N-1){
            cout << A[k] << " ";
        }
        else{
            cout << A[k];
        }
    }

    cout << endl;
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3108
// START OF TEMPLATE CODE
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int) (v).size()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define funoredered_map __fast_unordered_map

template<class Key, class Value, class Hash = std::hash<Key>>
using funordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdb = pair< double, double >;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vvi = vector<vi>;

constexpr int inf = 0x3f3f3f3f;
constexpr double eps = 1e-8;
constexpr ll MOD = 1000000007LL;

template <typename T>
using ordered_set = 
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll powmod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// END OF TEMPLATE CODE

int main()
{
    buff(); 
    int n, k;
    cin >> n >> k;
    long long cost = 0;
    vector<int> v(n);
    for(int& x : v) cin >> x;
    sort( all(v) );
    reverse(all(v));
    for(int i = k; i < n; ++i) cost += v[i];
    cout << cost << endl;
    return 0;
}



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

int main(void){
    int N;cin>>N;
    int A[N];
    int ans=0;
    int tmp=0;
    vector<int>X(9,0);
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]/400<=7){
            X[A[i]/400]++;
        }
        else{
            X[8]++;
        }
    }
    for(int i=0;i<8;i++){
        if(X[i]>=1){
            ans++;
        }
    }
    if(ans==0){
        cout<<1<<" "<<X[8]<<endl;
        return 0;
    }
    cout<<ans<<" "<<ans+X[8]<<endl;
    return 0;
}


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

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    rep(i, n) p[i]++;
    int mx = 0;
    int s = 0;
    queue<int> q;
    rep(i, n) {
        s += p[i];
        q.push(p[i]);
        if (q.size() > k) {
            s -= q.front();
            q.pop();
        }
        if (q.size() == k) {
            chmax(mx, s);
        }
    }
    double ans = mx;
    ans /= 2;
    printf("%.10f\n", ans);

    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int32 a, b;
  cin >> a >> b;
  int32 res = 0;
  int32 c = 1;
  int32 cnt = 0;
  REP(i, a) c *= 100;
  while(1){
    res += c;
    if(res%c == 0 && res%(c*100) != 0) cnt++;
    if(cnt == b) break;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
# problem C
n, x0 = (int(i) for i in input().split(' '))
x = (int(i) for i in input().split(' '))
d = list(map(lambda t: abs(t-x0), x))

def mygcd(a, b):
    r = a%b
    while r != 0:
        a, b = b, r
        r = a%b
    return b

g = d[0]
for i in range(1,n):
    g = mygcd(g, d[i])

print(g)


Measured memory_bytes: 14252
#include <cstdio>
#include <algorithm>

using namespace std;

const int mod=1e9+7;
int fact[100010];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(abs(n-m)>=2) {printf("0");return 0;}
    fact[0]=1;
    for(int i=1;i<=max(n,m);i++) fact[i]=(1LL*fact[i-1]*i)%mod;
    int sol=(1LL*fact[n]*fact[m])%mod;
    if(n==m) sol=(1LL*sol*2)%mod;
    printf("%d",sol);
    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main()
{
	int a,b,c,d,x;
	while(scanf("%d",&x)!=EOF)
	{
	
	a=x/1000;
	b=(x-1000*a)/100;
	c=x%100/10;
	d=x%10;
	
	if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
	else if(a+b+c-d==7)printf("%d+%d+%d-%d=7\n",a,b,c,d);
	else if(a+b-c-d==7) 
	printf("%d+%d-%d-%d=7\n",a,b,c,d);
	else if(a-b+c-d==7) 
	printf("%d-%d+%d-%d=7\n",a,b,c,d);
	else if(a-b+c+d==7) 
	printf("%d-%d+%d+%d=7\n",a,b,c,d);
	else if(a-b-c+d==7) 
	printf("%d-%d-%d+%d=7\n",a,b,c,d);
	else if(a-b-c-d==7) 
	printf("%d-%d-%d-%d=7\n",a,b,c,d);
	else if(a+b-c+d==7) 
	printf("%d+%d-%d+%d=7\n",a,b,c,d);
    }
    return 0;
}

Measured memory_bytes: 128
import collections

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

N,P = (int(i) for i in input().split())

tmp = prime_factors(P)
c = collections.Counter(tmp)

num = 1
for index in c.items():
    if index[1] >= N:
        num = num * (index[0] ** (index[1] // N))

print(num)


Measured memory_bytes: 3572
#include <iostream>
#include <string.h>
using namespace std;

int main()
{
  int a;
  cin >> a;

  string s;
  cin >> s;

  int b;
  cin >> b;

  if (s == "+")
  {
    cout << a + b << endl;
  }

  if (s == "-")
  {
    cout << a - b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    if wv[i][0]==w0:
        k=wv[i][1]+x[0][-1]
        l=len(x[0])
        if l*w0<=w:x[0].append(k)
    elif wv[i][0]==w0+1:
        k=wv[i][1]+x[1][-1]
        l=len(x[1])
        if l*(w0+1)<=w:x[1].append(k)
    elif wv[i][0]==w0+2:
        k=wv[i][1]+x[2][-1]
        l=len(x[2])
        if l*(w0+2)<=w:x[2].append(k)
    else:
        k=wv[i][1]+x[3][-1]
        l=len(x[3])
        if l*(w0+3)<=w:x[3].append(k)
#print(x)
ma=0
for i in range(len(x[0])):
    for j in range(len(x[1])):
        for k in range(len(x[2])):
            for l in range(len(x[3])):
                ma_sub=0
                if i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=w:
                    ma_sub+=x[0][i]
                    ma_sub+=x[1][j]
                    ma_sub+=x[2][k]
                    ma_sub+=x[3][l]
                ma=max(ma,ma_sub)
print(ma)


Measured memory_bytes: 3192
using System;
using System.Reflection.Metadata.Ecma335;
using System.Xml.Schema;

namespace AtCoderBeginnerContest169
{
    class Multiplication2_2
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] a = Console.ReadLine().Split();
            int check0 = Array.IndexOf(a, "0");
            //Console.WriteLine(check0);
            decimal total = 1;
            for (int i = 0; i < n; i++)
            {
                if(check0 >= 0)
                {
                    total = 0;
                    break;
                }
               
                if (total.ToString().Length + (a[i].Length) > 20)
                {
                    total = -1;
                    break;
                }
                total *= decimal.Parse(a[i]);

                if (total > 1000000000000000000)
                {
                    total = -1;
                    break;
                }
            }
            Console.WriteLine(total);
            
        }
    }
}

Measured memory_bytes: 39984
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	int n;
	while(cin >> n)
	{
		stringstream stream;
		for(int i = 0; n; i++)
		{
			if(n & 1)
				stream << (1 << i) << ' ';
			n >>= 1;
		}

		string str = stream.str();
		str.erase(str.length() - 1);
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a==b&&b!=c)||(a==c&&c!=b)||(b==c&&c!=a))
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int n, k;
int ans;
int main() {
	ans = 1;
	scanf("%d%d", &n, &k);
	while(n--) {
		if(ans < k)ans *= 2;
		else ans += k;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e7 + 5;
const ll MOD = 1e9 + 7;
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pis pair<ll,string>
#define F first
#define S second
#define LCM(a,b) ((a*b)/__gcd(a,b))
#define inf 1e10
#define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const double EPS = 1E-9;
typedef vector< vector<double> > matrix;
typedef vector<int> vi;


int prime[N];
ll solve(ll num){

    unordered_map< int, int> mapp;
    while(num > 1){
        mapp[prime[num]]++;
        num /= prime[num];
    }
    // number of factors
    ll res = 1;
    for(auto ele: mapp) res *= (ele.S + 1);

    // sum of divisors/factors
    // ll ans = 1;
    // for(auto ele: mapp){
    //     ll ai = ele.F;
    //     ll pi = ele.S;

    //     ans *= (Exp(ai,pi+1)-1)/(ai-1);
    // }
    return res;
}

void sieve(int n){
    memset(prime,0,sizeof(prime));
    prime[0] = prime[1] = 1;

    for(int i = 2; i <= n; i++){
        if(prime[i]==0){
            for(int j=i; j <= N;j+=i) prime[j] = i;
        }
    }
}


ll inv2;
ll modexp(ll x,ll n){
    ll res=1LL;
    while(n > 0){
        if(n&1) res = (res*x) % MOD;
        x = (x*x) % MOD;    n >>= 1;
    }
    return res;
}

int main() {
    fast;

    ll n, d; cin >> n >> d;
    double x, y;
    int ans = 0;

    for(int i = 0; i < n; i++) {
        cin >> x >> y;

        double dist = sqrt(x*x + y*y);

        if(dist <= d) ans++;
    }

    cout << ans << "\n";
    return 0;
}

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

int main(){
  int tate, yoko;
  cin >> tate >> yoko;
  string picture;
  for(int y = 0;y < yoko + 2;y++){
    cout << "#";
  }
  cout << endl;
  for(int t = 0;t < tate;t++){
    cout << "#";
    cin >> picture;
    cout << picture << "#" << endl;
  }
  for(int y = 0;y < yoko + 2;y++){
    cout << "#";
  }
}



Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 998244353
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 3005
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
ll cache[MAX_INT][MAX_INT];
vector<ll> V;

ll modSum(ll A, ll B) {
	return(A + B) % MOD;
}

ll rec(ll ind, ll sum) {
	// cout << ind << " " << sum <<" \n";
	if(sum == 0) {
		return N - ind + 1;	
	}
	if(sum < 0) {
		return 0;
	}
	if(ind >= N) {
		return 0;
	}
	ll &ans = cache[ind][sum];
	if(ans != -1) {
		return ans;
	}
	ans = modSum(rec(ind + 1, sum), rec(ind + 1, sum - arr[ind])); 
	return ans;
}	


int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}	
	ll finalAns = 0;
	memset(cache, -1, sizeof(cache));
	for(int i = 0; i < N; i++) {
		finalAns = modSum(finalAns, rec(i, M));
	}
	printf("%lld\n", finalAns);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 71040
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void swap (i32 *p, i32 n, i32 k) {
  for (i32 i = k; i < n; ++i) {
    i32 s = p[i];
    p[i] = p[i - k];
    p[i - k] = s;
  }
}

int is_sorted (i32 *p, i32 n) {
  for (i32 i = 1; i < n; ++i) {
    if (p[i - 1] > p[i]) return 0;
  }
  return 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *p = (i32 *) calloc (n, sizeof (i32));
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, p + i);
  }
  i32 *ans = (i32 *) calloc (100000, sizeof (i32));
  i32 len = 0;
  while (!is_sorted (p, n)) {
    swap (p, n, 1);
    ans[len++] = 1;
    for (i32 i = 1; i < n; ++i) {
      if (p[0] < p[n - 1]) {
        swap (p, n, n - 1);
        ans[len++] = n - 1;
      }
      swap (p, n, 1);
      ans[len++] = 1;
    }
  }
  printf ("%" PRIi32 "\n", len);
  for (i32 i = 0; i < len; ++i) {
    printf ("%" PRIi32 "\n", ans[i]);
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
import sys

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(N: int, A: "List[int]"):
    print(YES if len(set(A))==len(A) else NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 40240
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////

int main() {
	ll x, k, d; cin >> x >> k >> d;
	ll now = abs(x);
	ll cnt = now / d;
	if (cnt >= k) {
		cout << now - k * d << endl;
	}
	else {
		ll ya = k - cnt;
		now -= cnt * d;
		if (ya % 2 == 0) {
			cout << now << endl;
		}
		else {
			cout << abs(now - d) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3716
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
// using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define bug2(v1,v2)               cerr<<#v1<<" = "<<(v1)<< ' ' << #v2<<" = "<<(v2)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
//const ll mod = 998244353;
const ll mod = 1000000007;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return (((a+mod)%mod)*(b+mod)%mod)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline ll modInverse(ll n, ll p){ return power(n, p-2)%p; }

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 
void stArt()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
}
void eNd()
{
	#ifndef ONLINE_JUDGE
  	cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
  	#endif
}

//////////////////// start /////////////////////////////////
 

ll i,j,k,l,m,r,n;
//ll a[MAX],b[MAX];


int main()
{
 
stArt();
fast
//cout << setprecision(15) << fixed;

	cin >> n;
    vector<ll> d, d2;
    fr(i,0,n)
    {
        ll x, y;
        cin >> x >> y;
        d.pb(x+y);
        d2.pb(x-y);
    }
    sort(ALL(d));
    sort(ALL(d2));
    ll ans = d[n-1] - d[0];
    ans = max(ans, d2[n-1] - d2[0]);
    cout << ans;
  
 eNd();
  return 0;
 
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

 
int main() {

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

    vector<ll> k(n+1);
    rep(i,n+1) {
        k[i]=0;
    }
    rep(i,n+1) {
        k[a[i]]++;
    }
    vector<ll> p(n+1);
    rep(i,n+1) {
        p[i]=0;
    }
    ll ans=0;
    rep(i,n+1) {
        if(k[i]>1)  p[i]=((k[i]*(k[i]-1))/2)-(((k[i]-1)*(k[i]-2))/2);
        ans+=((k[i]*(k[i]-1))/2);
    }

    rep(i,n) {
        cout<<ans-p[a[i]]<<endl;
    }

 return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int h,w;
bool inside(int x,int y)
{
    return x>=0&&x<h&&y>=0&&y<w;
}
vector<int> dx={1,-1,0,0},dy={0,0,1,-1};
int main()
{
	scanf("%i %i",&h,&w);
	vector<vector<int> > visited(h,vector<int>(w));
	queue<pair<int,int> > q;
	for(int i=0;i<h;i++)
    {
        string s;
        cin >> s;
        for(int j=0;j<w;j++)
        {
            if(s[j]=='#')
                q.push({i,j}),visited[i][j]=1;
        }
    }
    int sol=0;
    while(q.size())
    {
        int x=q.front().f,y=q.front().s;
        q.pop();
        sol=visited[x][y]-1;
        for(int k=0;k<4;k++)
        {
            int xx=x+dx[k];
            int yy=y+dy[k];
            if(!inside(xx,yy)||visited[xx][yy])
                continue;
            visited[xx][yy]=visited[x][y]+1;
            q.push({xx,yy});
        }
    }
    printf("%i\n",sol);
    return 0;
}


Measured memory_bytes: 12432
#include<iostream>
#include<vector>
int main(){
	int w;
	int weight[10]={1,2,4,8,16,32,64,128,256,512};
	while(1){
		std::vector<int> vec;
		int a=0;
		std::cin>>w;
		if(std::cin.eof())break;
		//if(w==0)break;
		while(w>0){
			if(w%2!=0)vec.push_back(weight[a]);
			w/=2;
			a++;
		}
		for(int i=0;i<vec.size()-1;i++)std::cout<<vec[i]<<" ";
		std::cout<<vec[vec.size()-1]<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    string S;
    cin >> N >> S;
    REP(i,S.size()){
        char k = S[i];
        k-='A';
        k+=N;k%=26;
        k+='A';
        S[i]=k;
    }
    cout << S << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;
int main(int argc, char const *argv[]) {
  int A, B, C;
  std::cin >> A >> B >> C;
  if(!((B)%2==0&&(A)%2==0&&(C)%2==0)) {
    std::cout << 0 << '\n';
    return 0;
  }
  if(A == B && B == C) std::cout << -1 << '\n';
  else{
    std::vector<ll> v(3);
    v[0]=0,v[1]=v[2]=1;
    if(!((B+A)%2==0&&(A+C)%2==0&&(B+C)%2==0)) {
      std::cout << 1 << '\n';
      return 0;
    }
    ll waru = 2;
    for(int i = 2;;i++){
      waru*=2;
      v[2] = v[0] + v[1];
      v[0] = 2 * v[1];
      v[1] = v[2];
      ll a = v[0]*A+v[1]*B+v[2]*C;
      ll b = v[1]*A+v[0]*B+v[2]*C;
      ll c = v[1]*A+v[2]*B+v[0]*C;
      if(!(a%waru==0&&b%waru==0&&c%waru==0)){
        std::cout << i - 1<< '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int K; cin >> K;
    int ans = 0;

    FOR(i, 1, K + 1) FOR(j, 1, K + 1) FOR(k, 1, K + 1){
        int g = gcd(gcd(i, j), k);
        ans += g;
    } 
    Out(ans);

    return 0;
}


Measured memory_bytes: 3648
M, D = map(int, input().split())
count = 0
for i in range(1, M+1):
    for j in range(20, D+1):
        d = str(j)
        d10 = int(d[0])
        d1 = int(d[1])
        if i == d10 * d1 and d1 >= 2 and d10 >= 2:
            count = count + 1

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
long long cnt;
int l;
int A[1000000];
vector<int> G;
int n;
void insertionSort(int A[],int N,int g){
	for(int i=g ; i<N ; i++){
		int v = A[i];
		int j = i-g;
		while(j>=0 && A[j]>v){
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}
void shellSort(int A[], int N){
	for(int h=1 ; ;){
		if(h>N) break;
		G.push_back(h);
		h = 3*h + 1;
	}
	for(int i=G.size()-1 ; i>=0 ; i--){
		insertionSort(A,N,G[i]);
	}
}
int main(){
	cin>>n;
	for(int i=0 ; i<n ; i++) cin>>A[i];
	cnt = 0;
	shellSort(A, n);
	cout<<G.size()<<endl;
	for(int i=G.size()-1 ; i>=0 ; i--)
	{
		cout<<G[i];
		if(i) cout<<" ";
	}
	cout<<endl<<cnt<<endl;
	for(int i=0 ; i<n ; i++) cout<<A[i]<<endl;
	return 0;
}


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

int main(){
	int n,a;
	a = 100000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		a=a*1.05;
		a = ((a + 999) / 1000) * 1000;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << endl)

using namespace std;
using ll = unsigned long long;

int main() {
	int A, B;
	string S;
	IN(A);
	IN(B);
	IN(S);
	size_t S_size = S.size();
	REP(i, A) {
		if(S[i] == '-') {
			OUT("No");
			return 0;
		}
	}
	if(S[A] != '-') {
		OUT("No");
		return 0;
	}
	FOR(i, A+1, S_size) {
		if(S[i] == '-') {
			OUT("No");
			return 0;
		}
	}
	OUT("Yes");
}

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

struct data {
  string unit;
  int type;
};

int n;
string s, mom = "aiueo", chil = "kstnhmyrwgzdbp",
          non = "ksthp";
vector<data> v;

string solve();

int main() {
  while(1) {
    cin >> s;
    if(s == "#") break;
    n = s.size();
    cout << solve() << endl;
  }
  return 0;
}

string solve() {
  string res;
  v.clear();
  for(int i = 0; i < n;) {
    data now = {"", -1};
    now.unit += s[i++];
    if(mom.find(now.unit) < mom.size()) {
      if(v.empty() || now.unit == "e" || now.unit == "o")
        now.type = 1;
      else
        now.type = 6;
      v.push_back(now);
      continue;
    }
    if(now.unit == "n") {
      if(i == n || s[i] == '\'' ||
         chil.find(s[i]) < chil.size()) {
        if(s[i] == '\'') now.unit += s[i++];
        now.type = 5;
        v.push_back(now);
        continue;
      }
    }
    if(chil.find(now.unit) < chil.size() &&
       now.unit != "n" && now.unit != "y" &&
       now.unit != "w" && now.unit[0] == s[i]) {
      now.type = 4;
      v.push_back(now);
      continue;
    }
    now.unit += s[i++];
    if(now.unit[1] == 'y') {
      now.unit += s[i++];
      now.type = 3;
    }
    else
      now.type = 2;
    v.push_back(now);
  }
  n = v.size();
  bool ch = 1;
  for(int i = 0; i < n; ++i) {
    res += v[i].unit;
    if(v[i].type == 1 || v[i].type >= 4 ||
       non.find(v[i].unit[0]) >= non.size() ||
       v[i].unit[(int)(v[i].unit.size()) - 1] == 'e' ||
       !ch) {
      if(v[i].type < 4) ch = 1;
      continue;
    }
    if(v[i].unit[(int)(v[i].unit.size()) - 1] == 'i' ||
       v[i].unit[(int)(v[i].unit.size()) - 1] == 'u') {
      if(i == n - 1 ||
         non.find(v[i + 1].unit[0]) < non.size()) {
        res.pop_back();
        res += '(';
        res += v[i].unit[(int)(v[i].unit.size()) - 1];
        res += ')';
        ch = 0;
      }
    }
    else {
      if(i + 1 < n &&
         v[i].unit[(int)(v[i].unit.size()) - 1] ==
             v[i + 1]
                 .unit[(int)(v[i + 1].unit.size()) - 1] &&
         non.find(v[i + 1].unit[0]) < non.size()) {
        res.pop_back();
        res += '(';
        res += v[i].unit[(int)(v[i].unit.size()) - 1];
        res += ')';
        ch = 0;
      }
    }
  }
  return res;
}


Measured memory_bytes: 3192
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        String s;
        int flag;
        flag=0;
        s=scan.next();
        for(int i=0;i<s.length()-1;i+=2){
            if(s.charAt(i)=='h'&&s.charAt(i+1)=='i'){
                flag=1;
            }
            else{
                flag=0;
                break;
            }
        }
        if(s.equals("h")||s.equals("i")) System.out.println("No");
        else if(s.length()%2==1) System.out.println("No");
        else if(flag==1) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){ 
   int su,n,k,a[105]={0},i,maxn,minn;    cin>>su>>n;    i=n;    while(su--)    {        a[i]++;        if(i==1)           i=n;        else            i--;    }    maxn=a[1];    minn=a[1];    for(int i=1;i<=n;i++)    {        if(maxn<a[i])             maxn=a[i];        if(minn>a[i])            minn=a[i];    }    cout<<maxn-minn<<endl;}

Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

typedef long long ll;

int main(){
	const int Np=1000000;
	static int phi[Np+1];
	rep(i,Np+1) phi[i]=i;
	for(int i=2;i<=Np;i++) if(phi[i]==i) {
		for(int j=i;j<=Np;j+=i) phi[j]=phi[j]/i*(i-1);
	}

	static ll dp[Np+1];
	rep(i,Np) dp[i+1]=dp[i]+phi[i+1];

	int T; scanf("%d",&T);
	while(T--){
		int n; scanf("%d",&n);
		printf("%lld\n",dp[n]+1);
	}

	return 0;
}

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


ll H,h0,m0,s0;
int main(){
  while( cin >> H >> h0 >> m0 >> s0 && (H||h0||m0||s0) ){
    ll d = 119*H - 1, n = s0 * d;
    //    cout << d << endl;
    while(1){
      ll h = 3600 * h0 * d + 60 * m0 * d + n;
      ll m = 60 * H * d * m0 + n * H;
      ll s = 60*H*n;
      ll one = 3600 * H * d;
      if( h == m && m == s ) {}
      else {
        ll x1 = (h+m)/2;
        ll x2 = (h+m+one)/2;
        if( x2 >= one ) x2 -= one;
        //if( n == 0 )        cout <<h << " "<< m << " "<< s << " " << x1 << " "<< x2 << endl;
        
        if( x1 == s || x2 == s ){
          ll gcd = __gcd(n,d);
          cout << h0 << " " << m0 << " " << n/gcd << " "<< d/gcd <<endl;
          break;
        }
      }
      n++;
      //      cout << n << " " << d*60 << endl;
      if( n == d*60 ){ n = 0; m0++; }
      if( m0 == 60 ){ m0=0; h0++; }
      if( h0 == H ) { h0 = 0; }
    }
  } 
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
string s;
int a[301][301];
int n;
ll ans=0;
int main(void)
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{	
		int flag=0;
		for(int k=1;k<=n;k++)
			{
				if(k==i||k==j) continue;
				if(a[i][k]+a[k][j]==a[i][j]) 
				{
					flag=1;
				}
				if(a[i][k]+a[k][j]<a[i][j])
				{
					printf("-1\n");	return 0;
				}
			}
			if(!flag) ans+=a[i][j];	
		}
	}
		cout<<ans<<endl;
 return 0;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define dump(x) cerr << #x << "=" << x <<endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);

void solve()
{
	/*--------------------------*/

	int N, K; cin >> N >> K;
	double ans = 0;
	repi(i, 1, N + 1) {
		ans += pow(0.5, ceil(max(log2(K) - log2(i), 0.0))) / N;
	}
	cout << ans << endl;
	/*--------------------------*/
}

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

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;

int ord_n(int n, int m) {
	int res = 0;
	for(ll a = n; m / a != 0; a *= n) res += m / a;
	return res;
}

int main() {
	for(int n; cin >> n, n != 0; ) {
		cout << ord_n(5, n) << endl;
	}
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isPrime(int n){
    if(n==1)return false;
    if(n==2)return true;
    
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0)return false;
    }
    return true;
}


int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        if( isPrime(n) )cout<<"0"<<endl;
        else{
            int down,up;
            for(int i=n-1;i>=0;i--){
                if( isPrime(i) ){
                    down=i;
                    break;
                }
            }
            for(int i=n+1;;i++){
                if( isPrime(i) ){
                    up=i;
                    break;
                }
            }
            cout<<up-down<<endl;
        }
    }
}

Measured memory_bytes: 1160
import math
a = int(input())
t = [list(map(int, input().split())) for i in range(a)]
x = 0
for i in range(a):
    for j in range(a):
        x = x + ((t[i][0]-t[j][0])**2 +(t[i][1]-t[j][1])**2)**0.5
print(x*math.factorial(a-1)/(math.factorial(a)))   

Measured memory_bytes: 38384
#include<bits/stdc++.h>//万能库
using namespace std;
int n;
unsigned long long int f[9999];
int main()
{
    cin>>n;
    f[1]=2;
    f[2]=1;
    for(int i=3;i<=n+1;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n+1];
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"

vector<int>dices;
struct masu {
	int num;
	int type;
	int a;
};
map<int, masu>mp;
int X, Y, Z;
vector<vector<ld>>memo;

ld getans(const int nowplace,const int nowmoney) {
	if (memo[nowplace][nowmoney] < -0.5) {
		ld ans = 0;
		
		for (auto di : dices) {
			int nextmoney(nowmoney);
			int next = nowplace + di;
			if (next<Y) {
				if (mp.find(next) != mp.end()) {
					auto it = mp.find(next);
					masu action(it->second);
					if (action.type == 1) {
						next += action.a;
					}
					else if (action.type == 2) {
						nextmoney += action.a;
					}
					else {
						nextmoney -= action.a;
						nextmoney = max(nextmoney, 0);
					}
				}
			}
			if (next < Y) {
				ans += getans(next,nextmoney);
			}
			else {
				ans += nextmoney;
			}
		}
		memo[nowplace][nowmoney] = ans / dices.size();
	}
	return memo[nowplace][nowmoney];
}
int main() {
	while (1) {
		cin >> X >> Y >> Z;
		if (!X)break;
		memo = vector<vector<ld>>(Y, vector<ld>(10000, -1));
		dices.clear();
		for (int i = 0; i < X; ++i) {
			int v; cin >> v;
			dices.emplace_back(v);
		}
		mp.clear();
		for (int i = 0; i < Z; ++i) {
			int n, e, a; cin >> n >> e >> a;
			mp[n] = masu{ n,e,a };
		}
		ld ans = getans(0,0);
		cout << int(ans) << endl;
	}
	return 0; 
}

Measured memory_bytes: 19164
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
	int M,D;
	cin >> M >> D;

	int ans = 0;
	for(int m = 1; m <= M; m++){
		for(int d = 22; d <= D; d++){
			if(d % 10 < 2) continue;
			if(m == (d%10)*(d/10)) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a.at(a.size()-1)-a.at(0);
}

Measured memory_bytes: 256
// ABC166D - I hate Factorization

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

#define N 120

int main() {
	unsigned long long int X;
	cin >> X;
	unsigned long long int A[200];

	for (long long int i = 0; i <= N; i++) {
		A[i] = i * i * i * i * i;
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (A[i] - A[j] == X) {
				cout << i << " " << j << endl;
				return 0;
			}
			if (-1 * A[i] - A[j] == X) {
				cout << -1 * i << " " << j << endl;
				return 0;
			}
			if (A[i] + A[j] == X) {
				cout << i << " " << -1 * j << endl;
				return 0;
			}
			if (-1 * A[i] + A[j] == X) {
				cout << -1 * i << " " << -1 * j << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3608
import math
cookT = {}
lastOrder = 0

for i in range(5):
  cookT[i] = int(input())
  
lastOrder = max(cookT.items(), key=lambda x:(10-x[1]%10)%10)[0]

totalT = 0
for i in range(5):
  if i == lastOrder:
    totalT += cookT[lastOrder]
  else:
    tempX = cookT[i]
    tempY = math.ceil(tempX%10 / 10)*10
    totalT += tempX//10 *10 + tempY
print(totalT)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <string>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
typedef long long ll;
#define min(a, b) ((a) < (b) ? (a) : (b))
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数
long long gcd(long long a, long long b)
{
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

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

	int N;
	cin >> N;
	set<int>st;
	int tmp;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		st.insert(tmp);
	}
	if (st.size() == N) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 9600
/**
* Author: Luis Alberto Herrera Gomez
* Tags: 
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ii;

int main()
{
    int N, X, D, L, count;

    cin >> N >> X;

    count = 1;
    D = 0;
    for (int i = 0; i < N; ++i) {
        cin >> L;
        D += L;
        if (D <= X)
            count++;
    }

    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 256