akhauriyash/Code-Regression huggingface dataset:
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int, rdr *bufio.Reader) []string {
	var strSlice []string

	//rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

//DivideConvertInt is to divide and convert
func DivideConvertInt(line string, num int) []int {
	tmp := strings.Split(line, " ")

	intSlice := make([]int, num)

	for i := 0; i < num; i++ {
		intTmp, _ := strconv.Atoi(tmp[i])
		intSlice[i] = intTmp
	}

	return intSlice
}

func main() {
	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)
	line0 := inputs(1, rdr)

	N := DivideConvertInt(line0[0], 1)[0]

	line1 := inputs(1, rdr)

	A := DivideConvertInt(line1[0], N)

	max := A[0]

	for i := 1; i < N; i++ {
		if max < A[i] {
			max = A[i]
		}
	}

	cntArray := make([]int, max+1)

	for i := 0; i < N; i++ {
		if cntArray[A[i]] == 0 {
			for j := 1; j < (max/A[i] + 1); j++ {
				B := A[i] * j
				cntArray[B]++
			}
		} else if cntArray[A[i]] == 1 {
			cntArray[A[i]]++
		}
	}

	cnt := 0
	for i := 0; i < N; i++ {
		if cntArray[A[i]] <= 1 {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 19440
s = list(input())

next = None
pre = s[0:1]
result = 1
def search(i):
    global pre
    global result
    n = 1
    while i+n < len(s)+1:
        next = s[i:i+n]
        if pre != next:
            pre = next
            result += 1
            return i+n
        else:
            n += 1

r = search(1)
while r < len(s):
    r = search(r)
    if r == None:
        break
print(result)

Measured memory_bytes: 4840
#include <iostream>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define PI 3.14159265358979323846
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const int mod = inf+7;

int n, a[110];

int main(){

	scanf("%d", &n);
	int sum = 0;
	for(int i=0;i<n;i++){
		int x;
		scanf("%d", &x);
		sum+=x;
		a[i] = x;
	}

	if(sum%10!=0){
		printf("%d\n", sum);
		return 0;
	}

	int maxX = 0;
	for(int i=0;i<n;i++){
		int c = sum-a[i];
		if(c%10!=0){
			maxX = max(maxX, c);
		}
	}

	printf("%d\n", maxX);


	return 0;
}

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

int main(void){
  int a,b;
  
  /*足し算　引き算　掛け算*/
  int addition=0,subtraction=0,multiplied=0;
  
  cin >> a >> b;
  
  addition=a+b;
  subtraction=a-b;
  multiplied=a*b;
  
  cout << max(max(addition,subtraction),multiplied) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a=0;
  int W,H,x,y,
  r=0;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if(x-r>=0&&x+r<=W){
    if(y-r>=0&&y+r<=H){
      a=1;
    }
  }
  else{
    a=0;
  }
  if(a==1){
    printf("Yes\n");
  }
  else if(a==0){
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 584
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する
ll mod = 1000000007;


int main() {
    string s;
    int N,A,B;
    cin >> N >> A >> B >> s;
    int a,b;
    vector<bool> pass(N);
    a = b = 0;
    REP(i,0,N){
        if(s[i] == 'a'){
            if(a + b < A + B){
                pass[i] = true;
                a++;
            }else{
                pass[i] = false;
            }


        }else if(s[i] == 'b'){

            if(b + 1 <= B && a + b < A + B){
                pass[i] = true;
                b++;
            }else{
                pass[i] = false;
            }
        }else{
            pass[i] = false;
        }
    }

    REP(i,0,N){
        if(pass[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

    return 0;

}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,l,r,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>l>>r;
		ans+=r-l;
	}
	cout<<ans+n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char s[MAXN];
int n, a[MAXN], sMin[MAXN], sMax[MAXN]; bool b[MAXN];
void init() {
	for (int i = 1; i <= n; i++) {
		if (s[i] == '0') a[i] = a[i - 1] - 1;
		else a[i] = a[i - 1] + 1;
		if (s[i] == '?') b[i] = true;
	}
	sMin[n + 1] = n + 5;
	for (int i = n; i >= 0; i--)
		sMin[i] = min(sMin[i + 1], a[i]);
}
int work(int limit) {
	int mns = 0;
	for (int i = 1; i <= n; i++) {
		if (s[i] == '?' && sMin[i] - mns - 2 >= limit) {
			b[i] = false;
			mns += 2;
		} 
		a[i] -= mns;
	}
	sMin[n + 1] = n + 5;
	sMax[n + 1] = -n - 5;
	for (int i = n; i >= 0; i--) {
		sMin[i] = min(sMin[i + 1], a[i]);
		sMax[i] = max(sMax[i + 1], a[i]);
	}
	int ans = sMax[0] - sMin[0];
	int Max = 0, Min = 0, pls = 0; mns = 0;
	for (int i = 1; i <= n; i++) {
		if (b[i]) {
			mns += 2;
			int tmp = max(Max, sMax[i] - mns) - min(Min, sMin[i] - mns);
			if (tmp < ans) ans = tmp;
		}
		a[i] -= mns;
		chkmax(Max, a[i]);
		chkmin(Min, a[i]);
	}
	return ans;
}
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	int ans = n + 5, tmp = 0;
	init(); chkmin(ans, work(sMin[0]));
	init(); chkmin(ans, work(sMin[0] - 1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 17360
#include<bits/stdc++.h>
using namespace std;
const long long INF = 123456789;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

int main() {
    cin >> n >> m >> k;
    cout << min(n*m,k) << endl;
    
}

Measured memory_bytes: 256
x = int(input())

m = 2*10**9
l = []

a = 0
b = 0
p = 0
#while b <= m:
while p < 1000:
  b = a**5
  l.append(b)
  a += 1
  p += 1


flg = 0
for i in range(len(l)):
  
  if flg == 1:
    break
  for j in range(i+1,len(l)):
    if l[i] + l[j] == x:
      res = [i,-j]
      flg = 1
      break
    elif l[i] - l[j] == x:
      res = [i,j]
      flg = 1
      break
    elif -l[i] + l[j] == x:
      res = [-i,-j]
      flg = 1
      break
    elif -l[i] - l[j] == x:
      res = [-i,j]
      flg = 1
      break
      
      
print(res[0],res[1])
    

Measured memory_bytes: 9248
#include<bits/stdc++.h>
    #define ll          long long int
    #define ld          long double
    #define pb          push_back
    #define mp          make_pair
    #define ff          first
    #define se          second
    #define endl        '\n'
    #define fd(n)       fixed<<setprecision(n)
    #define MAX         1000000000000000000
    #define MAXN        200000005
    #define mod         1000000007
    using namespace std;
     
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        ll n,i,count=0,ans,j,mx;
        ll a,b,p;
        p=0;
        cin>>a>>b;
        mx=max(p,a-2*b);
        cout<<mx;
    }

Measured memory_bytes: 256
module Main where

import           Control.Monad
import           Data.List
import           Data.List.Split
import           Data.Array.IO
import qualified Data.Vector as V

main :: IO ()
main = do
  as <- map read . words <$> getLine :: IO [Int]
  if (length . group) as == 1
    then putStr "Yes"
    else putStr "No"

Measured memory_bytes: 508
#include <stdio.h>

int main()
{
    int n[4],i,j,hold;
    for(i=0;i<4;i++){
        scanf("%d",&n[i]);
    }
    for(i=3;i>0;i--){
        for(j=0;j<i;j++){
            if(n[j]>n[j+1]){
                hold = n[j];
                n[j] = n[j+1];
                n[j+1] = hold;
            }
        }
    }
    if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9 ) printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

int main(){
    int x, n;

    cin >> x >> n;
    int p[n];

    if (n == 0){
        cout << x << endl;
        return 0;
    }

    bool flag = 1;

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

    int i = 0;

    while(i != 1000){
        int y = x - i;
        int z = x + i;

        if (x >= 0){
            flag = 1;
            for (int j = 0; j < n; j++){
                if (y == p[j]){
                    flag = 0;
                }
            }

            if(flag) {
                cout << y << endl;
                return 0;
            }

            flag = 1;

            for (int k = 0; k < n; k++){
                if(z == p[k]){
                    flag = 0;
                }
            }

            if (flag) {
                cout << z << endl;
                return 0;
            }
        } 
        i++;

    }

    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const* argv[])
{

    int a,b,c;
    cin >> a >> b >> c;
    
    if((a<c && c<b) || (b<c && c<a)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
string s,t;
ll n,m;
ll dp[3001][3001];
ll func(ll i,ll j)
{
    if(i==n or j==m)
        return dp[i][j]=0;
    ll &ret = dp[i][j];
    if(ret!=-1)
        return ret;
    ret = max(func(i+1,j),func(i,j+1));
    if(s[i]==t[j])
        ret = max(ret,func(i+1,j+1)+1);
    return ret;
}
void print(ll i,ll j,ll ans)
{
    if(i==n or j==m)
        return;
    if(s[i]==t[j] and func(i+1,j+1)==ans-1)
    {
        cout<<s[i];
        return print(i+1,j+1,ans-1);
    }
    if(func(i+1,j)==ans)
        return print(i+1,j,ans);
    if(func(i,j+1)==ans)
        return print(i,j+1,ans);
}
signed main()
{
    fast;
    mem(dp,-1);
    cin>>s>>t;
    n = s.length();
    m = t.length();
    ll ans = func(0,0);
    print(0,0,ans);
}

Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	int cnt1=0;
	int cnt2=0;
	if(a<b){
		cnt1=a*c;
	}else{
		cnt1=b*c;
		cnt2=(a-b)*d;
	}
	cout << cnt1+cnt2 << endl;
	return 0;
}


Measured memory_bytes: 256
N=str(input())
a=[]
a=list(N)
b=[["2"],["4"],["5"],["7"],["9"]]
c=[["0"],["1"],["6"],["8"]]
if a[-1:]in b:
    print("hon")
elif a[-1:]in c:
    print("pon")
else :
    print("bon")


Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=1e5+1;
ll dp[N][3],n;
vector<vector<ll>> a(N,vector<ll>(3));


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    cin>>n;
    for(ll i=0;i<n;i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    memset(dp,-1,sizeof(dp));
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(k==j) continue;
                dp[i+1][j]=max(dp[i][k]+a[i][k],dp[i+1][j]);
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));


    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

Measured memory_bytes: 11088
n = int(input())
x = input()
remain = [None]*(n)
ans = [1]*(n)
one = x.count("1")+1
if one == 2:
    for i in range(n):
        if x[i] == "1":
            ans[i] = 0
            remain[i] = 0

num = 0
for i in range(n-1, -1, -1):
    if x[i] == "1":
        num += pow(2, n-1-i, one)

for i in range(n):
    if x[i] == "0":
        num_temp = num+pow(2, n-1-i, one)
        num_temp %= one
        remain[i] = num_temp


one -= 2
if one == 0:
    pass

else:
    num = 0
    for i in range(n-1, -1, -1):
        if x[i] == "1":
            num += pow(2, n-1-i, one)

    for i in range(n):
        if x[i] == "1":
            num_temp = num-pow(2, n-1-i, one)
            num_temp %= one
            remain[i] = num_temp

for i in range(n):
    if remain[i] != 0:
        rem = remain[i]
        while rem != 0:
            ans[i] += 1
            popcount = format(rem, "b").count("1")
            rem %= popcount

for i in ans:
    print(i)


Measured memory_bytes: 84116
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

using ll = long long;

ll N, Q;
std::vector<ll> A;
ll S[100010], eS[100010];
ll X, xi;

bool C( ll t )
{
  ll a = N-(t+1)/2;
  ll b = N-t;
  ll d1 = llabs(X-A[a]);
  ll d2 = llabs(A[b]-X);

  if( d1 < d2 )
    return true;
  else if( d1 == d2 )
    return a < b;

  return false;
}

int main()
{
  std::cin >> N >> Q;

  rep( i, N )
  {
    ll a;
    std::cin >> a;

    A.emplace_back( a );

    S[i+1] = S[i]+a;
  }

  rep( i, N )
    eS[i+1] = eS[i]+(i&1?0:A[i]);

  rep( q, Q )
  {
    std::cin >> X;

    ll ng = 0, ok = N+1;

    while( ok-ng > 1 )
    {
      ll mid = (ng+ok)/2;

      (C(mid)?ok:ng) = mid;
    }

    ll t = ng;
    ll ans = S[N]-S[N-(t+1)/2];
    ll lt = N-t;

    ans += ((lt%2==0)^(t%2==0) ? eS[lt] : S[lt]-eS[lt]);

    std::cout << ans << std::endl;
  }

  return 0;
}

Measured memory_bytes: 4212
//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

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

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}
int lcm(int x, int y) {
    return (x * y) / __gcd(x, y);
}
int32_t main() {
#ifndef ONLINE_JUDGE
    //for getting input from input.txt
    freopen("input.txt", "r", stdin);
    //for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        int a[n + 1];
        loop(1, n + 1)
        cin >> a[i];
        int c = 0;
        for (int i = 1; i <= n; i++) {
            if ((i & 1) && (a[i] & 1))
                c++;
        }
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0120

"""
import sys
from sys import stdin
input = stdin.readline


def calc_width(cakes):
    # ??±????????????????????????(?????????)????????????????????????????????????????¨??????????
    if len(cakes) == 1:
        return cakes[0]*2

    prev_r = cakes[0]
    width = prev_r              #  ??±?????????(???????????±???????????????)
    for r in cakes[1:]:         #  ???????????±?????????????????????????°´????????¢
        h_diff = abs(prev_r - r)
        w = ((prev_r + r)**2 - h_diff**2)**0.5
        width += w
        prev_r = r
    width += cakes[-1]          #  ??±?????????(???????????±???????????????)

    return width


def main(args):
    for line in sys.stdin:
        data = [int(x) for x in line.strip().split()]
        box_size = data[0]
        temp = data[1:]
        temp.sort()

        # ??±??????????????????????????????????????????????????????????????????????????????
        # ????°??????±??????????????????????????§????????´??¨?°?????????´??????????????????????????¢??????????????£????????±????????¨???????????§????????????????????????
        cakes = [temp[0]]
        temp = temp[1:]
        pick_large = True
        pick = 0
        while temp:
            if pick_large:
                pick = temp[-1]
                temp = temp[:-1]
                pick_large = False
            else:
                pick = temp[0]
                temp = temp[1:]
                pick_large = True

            diff_front = abs(pick - cakes[0])
            diff_rear = abs(pick - cakes[-1])
            if diff_front > diff_rear:
                cakes.insert(0, pick)
            else:
                cakes.append(pick)

        # ??±????????¨???????¨????????¨????????????±?????\???????¢??????????
        result = calc_width(cakes)
        if result <= box_size:
            print('OK')
        else:
            print('NA')


if __name__ == '__main__':
    main(sys.argv[1:])
    

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int a[303][303];
int R[303 * 303];
int C[303 * 303];
ll cost[18][303 * 303];

int main2() {
  CLR(cost, 0);

  int H = nextInt();
  int W = nextInt();
  int D = nextInt();
  REP(i, H) REP(j, W) {
    int x = nextInt();
    a[i][j] = x;
    R[x] = i;
    C[x] = j;
  }
  for (int i = 1; i <= H*W; i++) {
    if (i + D <= H*W) {
      cost[0][i] = abs(R[i] - R[i+D]) + abs(C[i] - C[i+D]);
    }
  }

  int d = D;
  for (int t = 1; t < 18; t++) {
    if (1 + d + d > H*W) break;
    for (int i = 1; i <= H*W; i++) {
      if (i + d + d <= H * W)
        cost[t][i] = cost[t-1][i] + cost[t-1][i + d];
    }
    d = 2 * d;
  }

  // for (int t = 0; t < 3; t++) {
    // for (int i = 1; i <= H*W; i++) {
      // cout << cost[t][i] << " " ;
    // }
    // cout << endl;
  // }

  for (int Q = nextInt(); Q-->0; ) {
    int L = nextInt();
    int R = nextInt();
    int s = (R - L) / D;
    ll ans = 0;
    for (int i = 0; i < 18; i++) {
      if (s >> i & 1) {
        ans += cost[i][L];
        L += (1 << i) * D;
      }
    }
    printf("%lld\n", ans);
  }

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
	long long int x, y;
	while (cin >> x >> y) {
		long long int a, b, c;
		a = max(x, y);
		b = min(x, y);
		c = a % b;
		while (c) {
			a = b;
			b = c;
			c = a % b;
		}
		cout << b << ' ' << x * y / b << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>


class LCA{
	int log,n;
	std::vector<int> depth,par;
	int dfs(const int parent[],int u){
		if(parent[u]==-1)return depth[u]=1;
		if(depth[u]!=0)return depth[u];
		return depth[u]=dfs(parent,parent[u])+1;
	}
public:
	LCA(const int parent[],int n):n(n),depth(n,0){
		log=1;
		while((1<<log)<n)log++;
		log++;
		for(int i=0;i<n;i++)dfs(parent,i);
		par.resize(n*log);	
		for(int i=0;i<n;i++)par[i]=parent[i];
		for(int i=1;i<log;i++)
			for(int v=0;v<n;v++)
				par[i*n+v]=par[(i-1)*n+par[(i-1)*n+v]];
	}
	int query(int u,int v)const{
		if(depth[u] > depth[v])std::swap(u,v);
		for(int i=log-1;i>=0;i--)
			if(depth[u] <= depth[v]-(1<<i))
				v=par[i*n+v];
		if(u==v)return u;
		for(int i=log-1;i>=0;i--){
			if(par[i*n+u]!=par[i*n+v]){
				u=par[i*n+u];
				v=par[i*n+v];
			}
		}
		return par[u];
	}
};

using namespace std;

int par[100000];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)par[i]=-1;
	for(int i=0;i<n;i++){
		int k,v;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			par[v]=i;
		}
	}
	LCA lca(par,n);
	int q,u,v;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>u>>v;
		cout<<lca.query(u,v)<<endl;
	}
	return 0;
}

Measured memory_bytes: 8788
#include <stdio.h>
#include <iostream>

int main()
{
	int r, s;

	//scanf("%d %d %d", &a, &b,&c);
	int K;
	scanf("%d", &K);

	int sum = 0;
	for (int i = 1; i <= K; i++)
	{
		for (int j = 1; j <= K; j++)
		{
			for (int k = 1; k <= K; k++)
			{
				int a = i, b = j, c = k;
				if (b > a) {
					int tmp;
					tmp = a;
					a = b;
					b = tmp;
				}

				while (a % b)
				{
					r = a % b;
					a = b;
					b = r;
				}
				if (b < c) {
					int tmp = c;
					c = b;
					b = tmp;
				}

				while (b % c)
				{
					r = b % c;
					b = c;
					c = r;
				}
				sum += c;

			}

		}
	}
	

	


	std::cout << sum << std::endl;

	
	return 0;
}



Measured memory_bytes: 3192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");
		int a[] = new int[100005];

		for (int i = 0; i < n; i++) {
			int value = Integer.parseInt(str[i]) + 1;

			a[value]++;
			a[value + 1]++;
			a[value - 1]++;
		}

		SegmentTree st = new SegmentTree(a);
		int ans = st.query(0, 100005);
		System.out.println(ans);
	}
}

class SegmentTree {

	// 元の配列もMAX_VALUEで初期化
	// MIN_VALUE,Math.maxで最大値を得られる

	int N;
	int[] origin;
	int[] tree;

	int INT_MAX = Integer.MIN_VALUE;

	SegmentTree(int[] original) {
		this.origin = Arrays.copyOf(original, original.length);
		int n = origin.length;
		this.N = 1;
		while (N < n)
			N *= 2;
		this.tree = new int[N * 2];
		for (int i = 0; i < N * 2; i++) {
			tree[i] = INT_MAX;
		}
		build();
	}

	// O(N)
	void build() {
		for (int i = 0; i < origin.length; i++) {
			update(i, origin[i]);
		}
	}

	// i番目の値をxに更新 O(log N)
	void update(int i, int x) {
		i += N - 1;
		tree[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			tree[i] = marge(tree[i * 2 + 1], tree[i * 2 + 2]);
		}
	}

	// O(log N);
	int query(int start, int end) {
		return query(start, end, 0, 0, N);
	}

	// [a, b)の最小値、l, rにはノードkに対応する区間を与える
	private int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)
			return INT_MAX;

		if (a <= l && r <= b) {
			return tree[k];
		} else {
			int lv = query(a, b, 2 * k + 1, l, (l + r) / 2);
			int rb = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return marge(lv, rb);
		}
	}

	private int marge(int l, int r) {
		return Math.max(l, r);
	}

}


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

std::string S;
bool used[26]{};

std::string solve();
void add(std::string&, char);
void remove(std::string&);
bool isUpper(std::string&, char);

int main()
{
	std::cout << solve() << std::endl;

	return 0;
}

std::string solve()
{
	std::cin >> S;
	if (S >= "zyxwvutsrqponmlkjihgfedcba")
		return "-1";
	std::string ans;
	for (int i{}; i < 26; i++)
	{
		for (char c{'a'}; c <= 'z'; c++)
			if (!used[c - 'a'] && isUpper(ans, c))
			{
				add(ans, c);
				break;
			}
		if (ans > S) return ans;
	}
	return "-1";
}

void add(std::string& ans, char c)
{
	ans.push_back(c);
	used[c - 'a'] = true;
}

void remove(std::string& ans)
{
	used[ans.back() - 'a'] = false;
	ans.pop_back();
}

bool isUpper(std::string& ans, char back)
{
	int size{(int)ans.size()};
	add(ans, back);
	for (int i{25}; i >= 0; i--)
		if (!used[i])
			add(ans, 'a' + i);
	bool ret{ans > S};
	while ((int)ans.size() > size)
		remove(ans);
	return ret;
}

Measured memory_bytes: 256
#include<stdio.h>
int search(int[],int,int);
int main(){
  int n,q,r,count=0;
  int S[100000];
  int T;
  int i,j,s;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T);

    s=search(S,n,T);
    if(s==-1){
    }else{
      count++;
    }
  }
  
  printf("%d\n",count);
  return 0;
}

int search(int x[],int n,int key){
  int l=0;
  int r,m;
  r=n;

  while(l<r){
    m = (l+r)/2;
    if(key == x[m]){
      return m;
    } else if(key >x[m]){
      l=m+1;
    } else { 
      r=m;
    }
  } 
  return -1;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
int main(){
    int n,m; cin >> n >> m;
    int left = 1 , right = m + 1;
    while(left < right){
        cout << left << " " << right << endl;
        left++; right--;
    }
    left = m + 2, right = 2*m + 1;
    while(left<right){
        cout << left << " " << right << endl;
        left++; right--;
    }
}

Measured memory_bytes: 3612
#include <iostream>
using namespace std;
#define MAX 1000000
typedef long long llong;
int n,k;
llong T[MAX];

int check(llong p){
    int i=0;
    for(int j=0;j<k;j++){
        llong s=0;
        while(s+T[i]<=p){
            s+=T[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}

int solve(){
    llong left=0;
    llong right=100000*10000;
    llong mid;
    while(right-left>1){
        mid=(right+left)/2;
        int v=check(mid);
        if(v>=n) right=mid;
        else left=mid;
    }
    return right;
}


int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>T[i];
    llong ans=solve();
    cout<<ans<<endl;
}



Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int change[35][35];
int c[505][505];
map<int,int> mem[3];
int main(){
    int n,c; cin >> n >> c;
    REP(i,c){
        REP(j,c){
            cin >> change[i][j];
        }
    }
    REP(i,n){
        REP(j,n){
            int c;cin >> c; c--;
            mem[(i+j)%3][c]++;
        }
    }
    ll ans = LINF;
    REP(i,c){
        REP(j,c){
            REP(k,c){
                if(i!=j&&j!=k&&k!=i){
                    ll anstmp = 0;
                    REP(l,3){
                        auto it = mem[l].begin();
                        while(it!=mem[l].end()){
                            int from    = it->first;
                            int count = it->second;
                            int to;
                            if(l==0){
                                to = i;
                            }else if(l==1){
                                to = j;
                            }else{
                                to = k;
                            }
                            anstmp += change[from][to] * count;
                            it++;
                        }
                    }
                    ans = min(ans, anstmp);
                }
            }
        }
    }
    cout << ans << endl;




}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

void pakuri_sort(int N, int A[]) {
	const int b = 8;
	int tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	int N = getint();
	int A[100000];
	rep(i, N) A[i] = getint();

	pakuri_sort(N, A);

	int L1 = 0, L2 = 0;
	int i = N - 1;
	for (; i >= 1; i--) {
		if (A[i - 1] == A[i]) {
			L1 = A[i];
			break;
		}
	}
	i -= 2;
	for (; i >= 1; i--) {
		if (A[i - 1] == A[i]) {
			L2 = A[i];
			break;
		}
	}

	printf("%lld", (ll)L1 * L2);

	Would you please return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>
#include <iomanip>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int X, p;
  std::cin >> X >> p;
  double P = p / 100.0L;
  std::cout << std::fixed << std::setprecision(30) << ((X + 1) / 2) / P << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  REP(i, N) cin >> A[i];
  vl DP1(N, 0);
  vl DP2(N, 0);

  REP(i, N) {
    if (i - A[i] >= 0)
      DP1[i - A[i]]++;
    if (i + A[i] <= N)
      DP2[i + A[i]]++;
  }
  ll ans = 0;
  REP(i, N) ans += DP1[i] * DP2[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7952
#include <stdio.h>
#define N 100000

int A[N];
void Swap(int *,int *);
int Partition(int);

int main(){
  int n,i,index;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&A[i]);
  index=Partition(n-1);

  for(i=0;i<n-1;i++){
    if(i==index){
      printf("[%d] ",A[i]);
      continue;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  return 0;
}

int Partition(int l){
  int x,i,j,base;

  base=A[l];
  i=-1;
  for(j=0;j<=l-1;j++){
    if(A[j]<=base){
      i+=1;
      Swap(&A[i],&A[j]);
    }
  }
   Swap(&A[i+1],&A[l]);

  return i+1;
}

void Swap(int *a, int *b){
  int temp;

  temp = *a;
  *a = *b;
  *b = temp;
}

Measured memory_bytes: 988
N, M = gets.split.map(&:to_i)
a = Array.new(N,Array.new(2,0))
ans = 0
bought = 0
N.times do |i|
  a[i] = gets.split.map(&:to_i)
end

a = a.sort
i = 0
#B本買うまで一個ずつ買う
while bought < M do
  #n件目の本数がゼロでなければ一本買う
  if a[i][1]>0 then
    ans = ans+ a[i][0]
    a[i][1] = a[i][1]-1
    bought = bought+1
  else
  #n件目の本数がゼロならば店を移る
    i = i+1
  end
end

puts ans

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

using namespace std;

typedef long long ll;

int main() {
    int k, a, b; cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string str[4] = { "dream","dreamer","erase","eraser" };

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i++) {
        reverse(str[i].begin(), str[i].end());
    }

    bool divcan = false;
    for (int i = 0; i < S.size();) {
        for (int j = 0; j < 4; j++) {
            if (S.substr(i, str[j].size()) == str[j]) {
                divcan = true;
                i += str[j].size();
                break;
            }
            divcan = false;
        }
        if (!divcan) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

typedef long long ll;

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

    vector<int> a(n), b(n), c(n);

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll accum = 0;
    for(int i = 0; i < n; i++){
        accum += (lower_bound(a.begin(), a.end(), b[i]) - a.begin())* 
                    (c.end() - upper_bound(c.begin(), c.end(), b[i]));
    }

    cout << accum << endl;
    return 0;
}

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

int main(){
	int n; cin>>n;
	int k=n%1000;
	if(k){
		cout<<1000-k<<endl;
	}else{
		cout<<0<<endl;
	}
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int inf = (1 << 30) - 1;
ll gcd(ll a, ll b) {
  // if (a == 0) return b;    : 終了条件
  // return gcd(b%a, a);      : a<b を仮定
  // これは a>=b のときも成立する. 1行にまとめると
  return a ? gcd(b%a, a) : b;
}

ll lcm(ll a, ll b) {
  // a,b の 最大公約数 g, 最小公倍数 l とすると
  // a*b = g*l <=> l = a*b/g
  return a * b / gcd(a, b);
}

ll cnt(ll x, ll C, ll D) {
  // 条件を満たす x 以下の整数の個数
  // Cで割り切れない かつ Dで割り切れない 整数の個数
  // 否定をとると
  // Cで割り切れる または Dで割り切れる 整数の個数
  // = Cの倍数の個数 + Dの倍数の個数 - lcm(C,D)の倍数の個数
  // = x/C + x/D - x/lcm(C,D)
  // = x/C + x/D - x*gcd(C,D)/(C*D) でもok
  return x - ( x/C + x/D - x/lcm(C,D) );
}

int main()
{
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  
  cout << cnt(B,C,D) - cnt(A-1,C,D) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String x = scan.nextLine();
		String ux = x.toUpperCase();
		String lx = x.toLowerCase();
		String w[] = x.split("");
		String uw[] = ux.split("");
		String lw[] = lx.split("");
		String[] q;
		q = new String[1200];
		int i;
		for(i = 0; i < x.length(); i++){
			if(w[i].equals(uw[i]))
				q[i] = lw[i];
			else
				q[i] = uw[i];
		}
		for(i = 0; i < x.length(); i++){
			System.out.print(q[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 27380
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int x;
	cin >> x;
	int a,b=0;
	a = x / 500;
	x = x - (a * 500);
	b += a * 1000;
	a = x / 5;
	b += a * 5;
	cout << b << endl;
} 

Measured memory_bytes: 3600
// AOJ 0371: Electronic Metronome
// 2017.11.14 bal4u@uu

#include <stdio.h>

int t[100002];
int a[100000], sz;

char buf[10], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int bsch(int x)
{
	int m, l = 0, r = sz;

    while (l < r) {
        m = (l + r) >> 1;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return a[l]-x;
}

int main()
{
	int n, i, max, ans;

	fgets(p=buf, 10, stdin), n = getint();
	for (max = 0, i = 0; i < n; i++) {
		fgets(p=buf, 10, stdin);
		t[i] = getint();
		if (t[i] > max) max = t[i];
	}

	for (sz = 0, i = 1; i <= max; i++) if (max % i == 0) a[sz++] = i;

	for (ans = 0, i = 0; i < n; i++) ans += bsch(t[i]);

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2076
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
using namespace std;



int main()
{
	set<string> strSet;
	int n;
	cin >> n;
	string commandStr,str;
	for( int i = 0; i < n; i++){
		cin >> commandStr >> str;
		if( commandStr == "insert"){
			strSet.insert(str);
		}else if(commandStr == "find"){
			if(strSet.find(str) != strSet.end()){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}
	}
	return 0;
}





Measured memory_bytes: 32580
#include<cstdio>
int isPrime(int x){
int i;
if(x<2)return 0;
else if(x==2)return 1;
if(x%2==0)return 0;
for(i=3;i*i<=x;i+=2){
if(x%i==0)return 0;
}
return 1;
}
int main(){
int n,x,i;
int cnt=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&x);
if(isPrime(x))cnt++;
}
printf("%d\n",cnt);
return 0;
}


Measured memory_bytes: 2724
#include <stdio.h>          // printf(), scanf()
#define MAX_N 10000

int
main(int argc, char** argv)
{
	int s[MAX_N];
	int t;
	int n = 0;
	int q = 0;
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &s[i]);

	scanf("%d", &q);
	int count = 0;
	for (i = 0; i < q; ++i)
	{
		scanf("%d", &t);
		for (j = 0; j < n; ++j)
		{
			if (s[j] == t)
			{
				count++;
				break;
			}
		}
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 500010;
char s[N];
int n, a[N];
bool check(int mx) {
	int l = n;
	rep(i,1,l) a[i] = s[i] - '0', a[i] *= 9;
	a[1] += 9 * mx;
	int j = 0;
	rep(i,1,l) a[i] = a[i] + j, j = a[i] / 10, a[i] %= 10;
	while (j) a[++l] = j % 10, j /= 10;

	int s = 0;
	rep(i,1,l) s += a[i];
	return s <= 9 * mx;
}

int main() {
//	freopen("e.in","r",stdin);
	scanf("%s",s + 1); n = strlen(s + 1);
	int l = 0, r = n;
	reverse(s + 1, s + n + 1);
	while (l + 1 < r) {
		int mid = (l + r) >> 1; 
		if (check(mid)) r = mid; else l = mid;
	}
	cout <<r<<endl;
	return 0;
}


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

using namespace std;

const long long MOD = 1000000007;

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

    vector<long long> A(N);
    vector<long long> tmp(3, 0);
    long long count = 1, tmp_count = 0;

    for (int i = 0; i < N; i++) {
        cin >> A[i];

        tmp_count = 0;
        
        for (int k = 0; k < 3; k++) {
            if (tmp[k] == A[i]) {
                if (tmp_count == 0) {
                    tmp_count += 1;
                    tmp[k] += 1;
                } else {
                    tmp_count += 1;
                }
            }
        }

        count = (count * tmp_count) % MOD;
    }

    cout << count << endl;
	return 0;
}

Measured memory_bytes: 3944
N,K=gets.split.map &:to_i
# 期待値の前計算
p=gets.split.map{|i|(i.to_f+1)/2.0}
# 累積和の計算
a=[0]
N.times do |i|
  a<<a[i]+p[i]
end
# 隣接するK項の和の計算
s=0
(N-K+1).times do |i|
  r=a[i+K]-a[i]
  s=[s,r].max
end
puts s


Measured memory_bytes: 20284
n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] == l[j] or l[j] == l[k]:
                continue
            if l[i] + l[j] > l[k]:
                ans += 1

print(ans)


Measured memory_bytes: 73740
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = new int[100];
		
		int n = sc.nextInt();
		for (int i = 0; i < n; i++)
			array[i] = sc.nextInt();
		
		doInsertionSort(array, n);
		
		printArray(array, n);
	
	}
	public static void doInsertionSort(int[] array, int n) {
		for (int i = 1; i < n; i++) {
			printArray(array, n);
			int val = array[i];
			int j = i - 1;
			while (j >= 0 && array[j] > val) {
				array[j + 1] = array[j];
				j--;
			}
			array[j + 1] = val;
		}
	}
	public static void printArray(int[] array, int n) {
		for (int i = 0; i < n; i++) {
			if (i != 0) 
				System.out.print(" ");
			System.out.print(array[i]);
		}
		System.out.print("\n");
	}
}

Measured memory_bytes: 33948
#include <bits/stdc++.h>
#define ll long long
#define uint unsigned int
#define inf 0x3f3f3f3f
#define db double
using namespace std;
const int maxn=2e5+10;
struct node{
	ll num;
	ll pos1,pos2;
	ll value;
};
int k,n,m;
int ma[2][maxn];
ll cal[2][maxn];
int ans=0;
int main() {
	std::ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	ll tmp=0,x=0,y=0;
	for(int i=1;i<=n;i++){
		cin>>ma[0][i];
		if(tmp>k) continue;
		tmp+=ma[0][i];
		if(tmp<=k) {
			cal[0][i]=tmp;
			x=i;
		}
	}
	tmp=0;
	for(int i=1;i<=m;i++){
		cin>>ma[1][i];
		if(tmp>k) continue;
		tmp+=ma[1][i];
		if(tmp<=k) {
			cal[1][i]=tmp;
			y=i;
		}
	}
	if(x>y){
		int j=0;
		for(int i=x;i>=0;i--){
			while(j<=y){
				if(cal[0][i]+cal[1][j]>k) break;
				ans=max(i+j,ans);
				j++;
			}
		} 
	}
	else {
		int j=0;
		for(int i=y;i>=0;i--){
			while(j<=x){
				if(cal[1][i]+cal[0][j]>k) break;
				ans=max(i+j,ans);
				j++;
			}
		} 
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 8204