akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << endl;}
void no(){cout << "No" << endl;}

int solve(){
    string n; cin >> n;
    rep(i,3){
        if(n[i] == '7'){
            yes();
            return 0;
        }
    }

    no();

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

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

int main(void){
  int n, d;
  cin >> n >> d;

  int cnt = 0;
  int skip = d*2 + 1;

  for (int i = 1; i < n + 1; i += skip) {
    cnt ++;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
 
int main() {
while(1){
int a;
cin >> a;
if(a == 0){break;}
char *b = new char [a];
char *c = new char [a];
for(int i = 0;i < a;i++){
cin >> b[i] >> c[i];
}
int m;
cin >> m;
for(int i = 1;i <= m;i++){
char p;
cin >> p;
int ii = 0;
while(ii < a){
if(p == b[ii]){
p = c[ii];
break;
}
ii++;
}
if(i == m){cout << p << endl;}
else{cout << p;}
}
 
delete[] b;
delete[] c; 
}
	return 0;
}

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

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

    int h, w;
    cin >> h >> w;

    char s[h][w];
    rep(i, h) rep(j, w) cin >> s[i][j];

    rep(i, h) {
        rep(j, w) {
            if(s[i][j] == '#') cout << '#';
            else {
                int cnt = 0;

                if(j+1<w && s[i][j+1]=='#')++cnt;
                if(i+1<h && j+1<w && s[i+1][j+1]=='#')++cnt;
                if(i+1<h && s[i+1][j]=='#')++cnt;
                if(i+1<h && j-1>=0 && s[i+1][j-1]=='#')++cnt;
                if(j-1>=0 && s[i][j-1]=='#')++cnt;
                if(i-1>=0 && j-1>=0 && s[i-1][j-1]=='#')++cnt;
                if(i-1>=0 && s[i-1][j]=='#')++cnt;
                if(i-1>=0 && j+1<w && s[i-1][j+1]=='#')++cnt;

                cout << cnt;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

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

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m),b(m);
    vector<ll> ans(m+1);
    rep(i,m){
        cin >> a[i] >> b[i];
        --a[i],--b[i];
    }
    
    UnionFind uf(n);
    ans[0]=0;
    rep(i,m){
        if(uf.issame(a[m-i-1],b[m-i-1])){

            ans[i+1] = ans[i];
        }else{
            ll p = uf.size(a[m-i-1]);
            ll q = uf.size(b[m-i-1]);
            ans[i+1] = ans[i] + p * q;
            uf.merge(a[m-i-1],b[m-i-1]);
        }
    }
    ll all = (n*(n-1))/2;
    reverse(ans.begin(),ans.end());
    reps(i,1,m+1){
        cout << all-ans[i] << endl;
    }
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll w, h, n;
  cin >> w >> h >> n;
  ll xmin=0, xmax=w, ymin=0, ymax=h;
  ll x, y, a;
  forll(i, 0, n){
	cin >> x >> y >> a;
	if (a == 1)
	  xmin = max(xmin, x);
	if (a == 2)
	  xmax = min(xmax, x);
	if (a == 3)
	  ymin = max(ymin, y);
	if (a == 4)
	  ymax = min(ymax, y);
  }
  if (xmin >= xmax || ymin >= ymax)
	cout << 0 << endl;
  else
	cout << (xmax - xmin) * (ymax - ymin) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	if(a + b > c + d) printf("Left\n");
	if(a + b < c + d) printf("Right\n");
	if(a + b == c + d) printf("Balanced\n");
	return 0;
}

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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a.at(a.size()-1)==b.at(0) && b.at(b.size()-1)==c.at(0))
    cout << "YES" << endl;
    else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int W, H, N;
int bfs(int sx, int sy, int gx, int gy, bool w1[51][51], bool w2[51][51]){
  queue<int> qx, qy;
  qx.push(sx);
  qy.push(sy);
  int d[51][51];
  memset(d, -1, sizeof(d));
  d[sy][sx] = 0;
  while(!qx.empty()){
    int x = qx.front(); qx.pop();
    int y = qy.front(); qy.pop();
    REP(r, 4){
      int nx = x + dx[r];
      int ny = y + dy[r];
      if(valid(nx, ny, W, H) && d[ny][nx] == -1){
        bool wall = false;
        switch(r){
          case 0:
            wall = w1[y][x + 1];
            break;
          case 1:
            wall = w2[y + 1][x];
            break;
          case 2:
            wall = w1[y][x];
            break;
          case 3:
            wall = w2[y][x];
            break;
        }
        if(wall) continue;
        qx.push(nx);
        qy.push(ny);
        d[ny][nx] = d[y][x] + 1;
      }
    }
  }
  return d[gy][gx];
}

int main(){
  while(cin>>W>>H>>N && W){
    bool w1[51][51] = {};
    bool w2[51][51] = {};
    REP(i, N){
      int x1, y1, x2, y2;
      cin>>x1>>y1>>x2>>y2;
      if(x1 == x2){
        int x = x1;
        if(y1 > y2) swap(y1, y2);
        for(int y = y1; y < y2; y++){
          w1[y][x] = true;
        }
      }else if(y1 == y2){
        int y = y1;
        if(x1 > x2) swap(x1, x2);
        for(int x = x1; x < x2; x++){
          w2[y][x] = true;
        }
      }
    }
    int sx, sy, gx, gy;
    cin>>sx>>sy>>gx>>gy;
    int init = bfs(sx, sy, gx, gy, w1, w2);
    int ans = 0;
    REP(i, 51)REP(j, 51){
      if(!w1[i][j]){
        w1[i][j] = true;
        ans = max(ans, bfs(sx, sy, gx, gy, w1, w2) - init);
        w1[i][j] = false;
      }
      if(!w2[i][j]){
        w2[i][j] = true;
        ans = max(ans, bfs(sx, sy, gx, gy, w1, w2) - init);
        w2[i][j] = false;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {
	int x, y;

	cin >> x >> y;

	cout << x + y / 2 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

ll mod_pow(ll x, ll n, ll mod){ // x ^ n % mod
    ll res = 1;
    while(n > 0){
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int ask(int a,int b,int c,int d){
	cout<<"? "<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"<<flush;
	int res;
	cin>>res;
	return res;
}

ll h, w, n, K;
int a[55][55];

int main() {
    cin >> h >> w >> n >> K;
    rep(i,h)rep(j,w)a[i][j] = -1;

    rep(i,h){
        rep(j,w){
            if(i%2==0&&j%2==0){
                int res = ask(i,j,i+1,j+1);
                if(res == 0){
                    a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = 0;
                }
                if(res == 4){
                    a[i][j] = a[i][j+1] = a[i+1][j] = a[i+1][j+1] = 1;
                }
            }
        }
    }



    

    // 愚直
    int cnt = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j] == 1){
                cnt++;
                if(cnt == n)break;
                continue;
            }
            if(a[i][j] == -1){
                cout << "? " << i << " " << j << " " << i << " " << j << endl << flush;
                int res;
                cin >> res;
                a[i][j] = res;
                cnt += a[i][j];
            }
            if(cnt == n)break;
        }
        if(cnt == n)break;
    }

    // ans出力
    ll ans = 0;
    rep(i,h){
        rep(j,w){
            if(a[i][j]==1)ans = (ans + mod_pow(2,i*w+j,K)) % K;
        }
    }
    cout << "! " << ans << endl << flush;
    return 0;
}




Measured memory_bytes: 3792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
signed main() {
	ll a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	ll aa = (10 - a % 10) % 10, bb = (10 - b % 10) % 10, cc = (10 - c % 10) % 10, dd = (10 - d % 10) % 10, ee = (10 - e % 10) % 10;
	cout << a + b + c + d + e + aa + bb + cc + dd + ee - max({ aa,bb,cc,dd,ee }) << endl;
	ggr
}


Measured memory_bytes: 256
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x * y // gcd(x, y)


def solve(a, b):
    return lcm(a, b)


def main():
    a, b = map(int, input().split())
    res = solve(a, b)
    print(res)


def test():
    assert solve(2, 3) == 6
    assert solve(123, 456) == 18696
    assert solve(10000, 99999) == 999990000


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[] c = GetString().Select(x => (int)(x - '0') + 1).ToArray();

		bool[] f = new bool[11];
		bool[] s = new bool[111];
		bool[] t = new bool[1111];
		for(int i = 0; i < N; i++)
		{
			for(int j = 1; j < 111; j++)
				if(s[j])
					t[j * 10 + c[i]] = true;
			
			for(int j = 1; j < 11; j++)
				if(f[j])
					s[j * 10 + c[i]] = true;
			
			f[c[i]] = true;
		}
		WriteLine(t.Count(x => x));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 14036
from collections import Counter as C
n=int(input())
a=list(map(int,input().split()))
l=C([i+a[i]for i in range(n)])
r=C([i-a[i]for i in range(n)])
b=0
for i in l.keys():
    b+=l[i]*r[i]
print(b)

Measured memory_bytes: 61512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int sum,a,b,c,x,cnt=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;++i)
   for(int j=0;j<=b;++j)
    for(int k=0;k<=c;++k){
     sum=500*i+100*j+50*k; 
     if(sum==x)cnt++;
    } 
  cout<<cnt<<endl;
  return 0;
}

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

int cnt[100001];

int main(void) {

	for (int i = 0; i <= 100000; i++) cnt[i] = 0;
	int N, A;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		cnt[A]++;
		if (cnt[A] == 3) cnt[A] = 1; // eat
	}

	int one = 0, two = 0;
	for (int i = 0; i <= 100000; i++) {
		if (cnt[i] == 1) one++;
		if (cnt[i] == 2) two++;
	}

	if ((two & 1) == 1) two--;
	int ans = one + two;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <boost/math/common_factor_rt.hpp>
using namespace std;

int main() {
	int a, b;
	while (cin >> a >> b) {
		int Ngcd = boost::math::gcd(a, b);
		int Nlcm = boost::math::lcm(a, b);
		cout << Ngcd << " " << Nlcm << endl;
	}
	return 0;
}


Measured memory_bytes: 3000
#include <iostream>

using namespace std;
int main(){
	int a,b,w,d;
	cin>>w>>a>>b;
	d=b-(a+w);
	if(b>(a+w)){
		cout<<d;
	}
	else if(a>(b+w)){
	
	cout<<a-(b+w);
	}
	else
	cout<<"0";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);ios::sync_with_stdio(false);

signed main()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    sort(all(v));

    ll dif = v.back() - v[0];

    if (dif > 1)
    {
        puts("No");
    }
    else if (dif == 0)
    {
        if (v[0] == n - 1 || v[0]<= n/2)
        {
            puts("Yes");
        }
        else
        {
            puts("No");
        }
    }
    else
    {
        ll nofa = (lb(all(v), v[n - 1]) - v.begin());
        ll nofgm=n-nofa;
        if (nofgm>=2 && (v[n-1]-nofa)<=nofgm/2 && nofa<v[n-1])
        {
            puts("Yes");
        }
        else
        {
            puts("No");
        }
    }
}

Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve 0 m ps


solve :: Int -> Int -> [Pair] -> Int
solve _ _ [] = 0
solve !n m ((a,b):ps)
    | c >= m    = a*(m-n)
    | otherwise = a*b + solve (n+b) m ps
  where
    c = n+b

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = do
  [x,y] <- readInts
  return (x,y)

Measured memory_bytes: 56700
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int taka = sc.nextInt();
    int flag1 = 0;
    int flag2 = 0;
    
    if(taka < 1200){
      System.out.print("ABC");
      flag1 = 1;
    }else if(taka < 2800){
      System.out.print("ARC");
      flag2 = 1;
    }
    
    if(flag1 == 0 && flag2 == 0){
      System.out.print("AGC");
    }
  }
}

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

typedef long long int ll;

int main(){
	int a,b;cin >> a >> b;
	for(int i = 1;i <= 1300;i++){
		if(int(i * 0.08) == a && int(i * 0.1) == b)return cout << i, 0;
	}
	cout << -1;
}


Measured memory_bytes: 256
using System;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var count = 0;
            if (str[0] == '1')
            {
                count++;
            }
            if (str[1] == '1')
            {
                count++;
            }
            if (str[2] == '1')
            {
                count++;
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 25980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, k;
  cin >> n >> k;

  double ans = 0;

  rep(i, n) {
    if (i+1 >= k) ans += 1;
    else {
//      cerr << 1/pow(2, ceil(log2((double)k/(i+1)))) << endl;
      ans += 1/pow(2, ceil(log2((double)k/(i+1))));
    }
  }

  printf("%.12lf\n", ans/n);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
using namespace std;
signed main()
{
    int n;
    cin>>n;
    if(n%1000==0)
    cout<<0;
    else
    {
        int x=n/1000+1;
        cout<<(x*1000)-n;
    }

}
                 

Measured memory_bytes: 3640
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=600005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int main()
{
	int n=read(),a=read(),b=read();
	if (a+b>n+1||1ll*a*b<n)  { puts("-1"); return 0; }
	while (n)
	{
		int x=min(a,n-(b-1));
		for (int i=n-x+1;i<=n;i++) cout<<i<<" ";
		n-=x,b--;
	}
	return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct BIT //0-indexed
{
	vector<int> node;
	int mn;

	BIT(int mn)
	{
		this->mn = mn;
		node.resize(mn + 1, 0);
	}

	void add(int i, int x)
	{
		i++;
		while (i <= mn)
		{
			node[i] += x;
			i += (i&-i);
		}
	}

	int sum(int i)
	{
		i++;
		int res = 0;
		while (i > 0)
		{
			res += node[i];
			i -= (i&-i);
		}
		return res;
	}
};

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

	int N,M;
	cin>>N>>M;

	vector<int> X(N),Y(M);
	rep(i,0,N)cin>>X[i];
	rep(i,0,M)cin>>Y[i];

	vector<pii> S;
	sort(all(Y));
	rep(i,0,N)
	{
		int idx=lower_bound(all(Y),X[i])-Y.begin();
		if(idx==M||idx==0)continue;
		int l=X[i]-Y[idx-1],r=Y[idx]-X[i];
		S.push_back(mp(l,r));
	}

	sort(all(S),[](pii a,pii b){return a.first!=b.first?a.first<b.first:a.second>b.second;});
	S.erase(unique(all(S)),S.end());

	vector<int> YC;
	for(auto p:S)YC.push_back(p.second);
	YC.push_back(0);
	sort(all(YC));
	YC.erase(unique(all(YC)),YC.end());

	BIT bit(N+M+5);
	bit.add(0,1);

	for(auto p:S)
	{
		int yidx=lower_bound(all(YC),p.second)-YC.begin();
		bit.add(yidx,bit.sum(yidx-1)%MOD);
	}

	int ans=bit.sum(N+M+3)%MOD;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 6768
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());

		double K = (double) k;

		//   double[] wariai = new double[n];

		double p = 0;
		double ans = 0;
		double tmp = 0;

		for (int i = 1; i <= n; i++) {
			p = (int) Math.ceil(Math.log(K / (double)i) / Math.log(2.0));
			//    	wariai[i]= Math.pow(0.5, p);
			if (p > 0) {
				tmp = Math.pow(0.5, p);
				ans += tmp;
			} else {
				//ans += (1 / n)*(n-i+1);
				ans += (n-k+1);
				break;
			}
		}
		BigDecimal Ans = BigDecimal.valueOf(ans/n);

		System.out.println(Ans);

	}

}

Measured memory_bytes: 21716
while True:
    n,k=map(int,input().split())
    if n == 0 and k == 0:break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) cin >> a[i];
  ll ans=inf;
  for(ll i=-100;i<=100;i++) {
    ll tmp=0;
    for(ll j=0;j<n;j++) {
      tmp+=(i-a[j])*(i-a[j]);
    }
    ans=min(ans,tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#include "./Lib/Timer.h"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {
	ll a, b;
	cin >> a >> b;
	if (a < 0 || a >= 10 || b < 0 || b >= 10) {
		cout << -1 << endl;
	} else {
		cout << a * b << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){//愚直にやってみたら
    int n;
    cin>>n;
    vector<int> A(n);
    rep(i,n) cin>>A[i];
    double under=0;
    rep(i,n) under+=(double)1/A[i];
    cout<<fixed<<setprecision(10)<<1/under<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<pair<int,int>> vp(n);
	for(int i = 0;i<n;i++)cin >> vp[i].first >> vp[i].second;
	sort(vp.begin(),vp.end(), [&](auto a,auto b){return  a.first+a.second < b.first + b.second;});
	ll ans = 0;
	ans = abs(vp[0].first-vp[n-1].first)+abs(vp[0].second-vp[n-1].second);
	sort(vp.begin(),vp.end(), [&](auto a,auto b){return  a.first-a.second < b.first - b.second;});
	ll now = abs(vp[0].first-vp[n-1].first)+abs(vp[0].second-vp[n-1].second);
	ans = max(now,ans);
	cout<<ans<<endl;

}


Measured memory_bytes: 4832
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    int n, s, sum = 0, ans = 0;
    cin >> n;
    vector<int> S;
    for (int i = 0; i < n; i++) {
        cin >> s;
        sum += s;
        S.push_back(s);
    }
    if(sum % 10 != 0) ans = sum;
    else{
        for (int i = 0; i < n; i++) {
            int tmp = sum;
            tmp -= S[i];
            if(tmp % 10 != 0) ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
p=10**9+7
def S(x):
    return (x*(x-1))//2
c=n
ans=[c+1]+[0]*n
for i in range(1,n+1):
    c=(c+(n-i))%p
    ans[i]=(c-S(i+1)+1)%p
print(sum(ans[k-1:])%p)

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, x;
	cin >> n >> x;
	int l[n];
	rep(i, n) cin >> l[i];
	
	int cnt = 1;
	int d = 0;
	rep(i, n) {
		d += l[i];
		if (d > x) break;
		cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int x1,x2,c;
	scanf("%d %d",&x1,&x2);
	if(x1<x2){
		c=x2-x1;
	}
	else{
		c=x1-x2;
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2060
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String today = sc.next();
    if(today.equals("Sunny")){
      System.out.println("Cloudy");
    }else if(today.equals("Cloudy")){
      System.out.println("Rainy");
    }else{
      System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >>A>>B>>C>>D;
  
  if(A+B<C+D){
    cout << "Right" <<endl;
  }
  if(A+B==C+D){
    cout << "Balanced" << endl;
  }
  if(A+B>C+D){
    cout << "Left" << endl;
  }}

Measured memory_bytes: 256
#include <set>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <math.h>
#include <map>
using namespace std;

int main() {

	int N;
	cin >> N;
	map<char, set<string>> name_set = { 
		{ 'M',{} },
		{ 'A',{} },
		{ 'R',{} },
		{ 'C',{} },
		{ 'H',{} }};
	for (int i = 0; i < N; i++) {
		string tmp;
		cin >> tmp;
		if (name_set.find(tmp[0]) != name_set.end()) name_set[tmp[0]].insert(tmp);
	}
	unsigned long sum = 0;
	string s = "MARCH";
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			for (int k = j + 1; k < 5; k++) {
				sum += name_set[s[i]].size() * name_set[s[j]].size() * name_set[s[k]].size();
			}
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 9600
/*

*/
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
#define cin1(x) cin >> x
#define cin2(x, y) cin >> x >> y
#define cin3(x, y, z) cin >> x >> y >> z
#define cou(x) cout << x
#define cous(x) cout << x << " "
#define coul(x) cout << x << "\n"
#define ret(x) return x
#define MAX 5000001
#define start int main() {   fastio
#define finish ret(0); }
#define Test ll _t; cin1(_t); while( _t-- )
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;
typedef double db;
//mt19937 mrand(random_device{}());
const ll mod=1000000007;
//ll rnd(ll x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}ret(res);}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll fact[13];
void factorial() {   fact[0]=1;  rep(i, 1, 12) fact[i]=(fact[i-1]*i);  }
vector <ll> sie; //for sieve function
ll spf[MAX+7];  //for sieve function
void sieve() {    rep(i, 2, MAX)  {  if (spf[i] == 0) {  spf[i] = i;   sie.pb(i);  }    for (ll j=0; j<SZ(sie) && i*sie[j] <= MAX && sie[j] <= spf[i]; j++)   spf[i * sie[j]] = sie[j]; }   }
// head collected

string str;
db n, m, ans, an;

start;

    cin1(n);
    an = n/3;
    m = an*an*an;

    printf("%.7lf\n", m);
finish





Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] num = new int[n + 1];
			for (int i = 1; i <= n; i++)
				num[i] = scanner.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i <= n; i++)
				for (int j = i; j <= n; j++)
					if (num[i] + num[j] <= m)
						list.add(num[i] + num[j]);
			Collections.sort(list);
			int ans = list.get(0) + list.get(list.size() - 1);
			int i = 1;
			int j = list.size() - 1;

			boolean flag = true;
			while (i < j) {
				int l = i;
				int r = j;
				while (l <= r) {
					int mid = (l + r) / 2;
					int ret = list.get(flag ? j : i) + list.get(mid);
					if (ret <= m) {
						ans = Math.max(ans, ret);
						l = mid + 1;
					} else {
						r = mid - 1;
					}
				}
				if (flag)
					i = l;
				else
					j = r;
				flag = !flag;

			}
			System.out.println(ans);

		}
	}
}

Measured memory_bytes: 94064
#include <stdio.h>

const int max = 300000;
bool is_Prime[max];

void eratos(){
	is_Prime[0] = is_Prime[1] = false;
	for(int i=2; i<max; i++){
		is_Prime[i] = true;
	}
	for(int i=4; i<max; i+=2)
		is_Prime[i] = false;
	for(int i=3; i*i<max; i+=2){
		if(is_Prime[i])
			for(int j=2*i; j<max; j+=i)
				is_Prime[j] = false;
	}
}

int main(){
	int n,ans;
	
	eratos();
	
	while(1){
		scanf("%d", &n);
		if(!n)
			break;
		ans = 0;
		for(int i=n+1; i<=2*n; i++){
			if(is_Prime[i])
				ans++;
		}
		printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 0
S = input()
ans = 0
is_started = False
is_w = False
for s in S:
    if not is_started:
        is_w = True if s == 'W' else False
        is_started = True
    else:
        if s == 'W':
            if not is_w:
                ans += 1
            is_w = True
        else:
            if is_w:
                ans += 1
            is_w = False
print(ans)


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

typedef unsigned long long  ULL;
typedef long long LL;

#define pb push_back
#define mp make_pair
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
//    cin>>T;
    T=1;
    while(T--){
       
       int n,m;
       cin>>n>>m;
       int sum=0;
       
       int a[n];
       rep(i,n){
           cin>>a[i];
           sum+=a[i];
       }
       
       int x=sum/(4*m);
       int count =0;
       if(sum%(4*m)==0){
           rep(i,n){
               if(a[i]>=x) count++;
           }
       }
       else{
           rep(i,n){
               if(a[i]>x) count++;
           }
       }
       
       if(count>=m) cout<<"Yes";
       else cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;

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

    int ans = 0;
    for(int x=a; x<=b; ++x){
        string s = to_string(x);
        string inv_s;
        for(int i=s.size()-1; i>=0; --i){
            inv_s += s[i];
        }
        if(s==inv_s) ans += 1;
    }
    cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
const int INF = 1<<30;
template<typename T1, typename T2> T1 gcd(T1 a, T2 b) { return (b ? gcd(b, a % b) : a); }
template<class Type> class BinaryTree
{
    struct Node { Type val; Node *left, *right; };
    public:
        Node *root = nullptr;
        Node *insert(Node *p, Type x)
        {
            if(p == nullptr) { Node *q = new Node; q->val = x; q->left = q->right = nullptr; if(root == nullptr) root = q; return q; }
            else { if(x < p->val) p->left = insert(p->left, x); else p->right = insert(p->right, x); return p; }
        }
        bool find(Node *p, Type x)
        {
            if(p == nullptr) return false;
            else if(x == p->val) return true;
            else if(x < p->val) return find(p->left, x);
            else return find(p->right, x);
        }
        Node *remove(Node *p, Type x)
        {
            if(p == nullptr) return nullptr;
            else if(x < p->val) p->left = remove(p->left, x);
            else if(x > p->val) p->right = remove(p->right, x);
            else if(p->left == nullptr && p->right == nullptr) { delete p; return nullptr; }
            else if(p->right == nullptr) { Node *q = p->left; delete p; return q; }
            else if(p->left == nullptr) { Node *q = p->right; delete p; return q; }
            else if(p->right->left == nullptr) { Node *q = p->right; q->left = p->left; delete p; return q; }
            else
            {
                Node *q;
                for(q = p->right; q->left->left != nullptr; q = q->left);
                Node *r = q->left;
                q->left = r->right;
                r->left = p->left, r->right = p->right;
                delete p;
                return r;
            }
            return p;
        }
        void print() { inorder(root); cout << endl; preorder(root); cout << endl; }
        void inorder(Node *p) { if(p->left != nullptr) inorder(p->left); cout << " " << p->val;if(p->right != nullptr) inorder(p->right); }
        void preorder(Node *p) { cout << " " << p->val; if(p->left != nullptr) preorder(p->left); if(p->right != nullptr) preorder(p->right); }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    BinaryTree<int> bt;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;
        if(s == "print") bt.print();
        else
        {
            int x; cin >> x;
            if(s == "insert") bt.insert(bt.root, x);
            if(s == "find") cout << (bt.find(bt.root, x) ? "yes" : "no") << "\n";
            if(s == "delete") bt.remove(bt.root, x);
        }
        
    }
    return 0;
}




Measured memory_bytes: 15712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for (int i = k; i < n; i++) {
    if (a[i] > a[i-k])
      cout << "Yes\n";
    else
      cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 3984
k,n=map(int, input().split())
a=list(map(int, input().split()))
dist=[0]*n

for i in range(n):
    if i==n-1:
        dist[i]=k+a[0]-a[i]
    else:
        dist[i]=a[i+1]-a[i]
print(k-sorted(dist,reverse=True)[0])

Measured memory_bytes: 26420
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		final int MOD = 1000000007;

		//入力
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();
		sc.close();

		//処理
		boolean f = (a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0));

		//出力	
		out.println(f ? "YES" : "NO");
		out.flush();
	}

	static class Pair{
		int a,b;
		public Pair(int a, int b){
			this.a = a;
			this.b = b;
		}
	}
}

Measured memory_bytes: 21972
#include <iostream>
using namespace std;
const int mod = 1000000007;
int main(){
	int n,m;
	cin >> n >> m;
	long long res = 1;
	long long x = n;
	while(m>0){
		if(m&1)res = x * res % mod;
		x = x*x %mod;
		m >>= 1;
	}
	cout << res << endl;
	return 0;
	}

Measured memory_bytes: 3092
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,M;
pair<int,int> ba[100000];

int main(){
    cin>>N>>M;
    rep(i,M) cin>>ba[i].second>>ba[i].first;

    sort(ba,ba+M);

    int ans=1;
    int b=ba[0].first;
    repn(i,M-1){
        if(b<=ba[i].second){
            ans++;
            b=ba[i].first;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int h, w, ans, sy, sx;
char s[21][21] = {};
int d[21][21] = {};
int dy[4] = { 1, -1, 0, 0 };
int dx[4] = { 0, 0, 1, -1 };

void dfs(int y, int x){
	if (y < 0 || h <= y || x < 0 || w <= x || d[y][x]||s[y][x]=='#') return;
	ans++;
	d[y][x] = 1;
	rep(i, 0, 4){
		int ny = y + dy[i], nx = x + dx[i];
		dfs(ny, nx);
	}
	return;
}

int main(){
	while (1){
		cin >> w >> h;
		rep(i, 0, 21){
			rep(j, 0, 21){
				d[i][j] = 0;
			}
		}
		if (h == 0 && w == 0) break;
		rep(i, 0, h){
			rep(j, 0, w){
				cin >> s[i][j];
				if (s[i][j] == '@'){
					sy = i;
					sx = j;
				}
			}
		}
		ans = 0;
		dfs(sy, sx);
		o(ans);
	}

}

Measured memory_bytes: 1164
A,B,C = [int(i) for i in input().split()]

if A==B==C and A%2==0:
  print(-1)
else:
  ans = 0
  while 1:
    if A%2==1 or B%2==1 or C%2 ==1:
      print(ans)
      break
    tempA = A//2
    tempB = B//2
    A = tempB + C//2
    B = tempA + C//2
    C = tempA + tempB
    ans+=1


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7

char A[200], B[200];

int main() {
	scanf("%s%s", A, B);

	if (strlen(A) == strlen(B)) {
		if (strcmp(A, B) > 0) {
			printf("GREATER");
		}
		else if (strcmp(A, B) == 0) {
			printf("EQUAL");
		}
		else {
			printf("LESS");
		}
	}
	else if (strlen(A) > strlen(B)) {
		printf("GREATER");
	}
	else {
		printf("LESS");
	}




}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define DEC(i, a, b) for(int i = a; i >= b; --i)
#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define FI first
#define SE second
#define SZ(x) ((int)(x).size())
#define MP make_pair
#define PB push_back
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pii > VPI;
typedef vector<pll > VPL;
const int mod = 1000000007;

int a, b, c;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> a >> b >> c;
    if(c <= a + b) cout << "No" << endl;
    else{
        int k = c - a - b;
        if(4LL * a * b < 1LL * k * k) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int64
	fmt.Fscan(r, &n)

	pairs := getPairs(n)
	min := math.MaxInt64
	for _, p := range pairs {
		tmp := funcF(p[0], p[1])
		if tmp < min {
			min = tmp
		}
	}

	fmt.Fprintln(w, min)
}

func getPairs(n int64) [][2]int64 {
	result := make([][2]int64, 0)
	var i int64
	max := int64(math.Sqrt(float64(n)))
	for i = 1; i <= max; i++ {
		if n%i == 0 {
			another := n / i
			result = append(result, [2]int64{i, another})
		}
	}

	return result
}

func funcF(a int64, b int64) int {
	var max int64
	if a > b {
		max = a
	} else {
		max = b
	}

	return len(strconv.FormatInt(max, 10))
}


Measured memory_bytes: 1912