akhauriyash/Code-Regression huggingface dataset:
a,b,c=map(int,input().split())
if c<(7*a+b):
    if c<=6*a:
        if c%a==0:
            print(c//a)
        else:
            print(c//a+1)
    else:
        print(7)
else:
    if c%(7*a+b)==0:
        print(int(7*c/(7*a+b)))
    else:
        if (c%(7*a+b))<=6*a:
            if c%(7*a+b)%a==0:
                print(int(c//(7*a+b)*7+(c%(7*a+b))//a))
            else:
                print(int(c//(7*a+b)*7+(c%(7*a+b))//a)+1)
        else:
            print(int(c//(7*a+b)*7+7))


Measured memory_bytes: 5600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main
{
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[])
    {
        FastReader obj = new FastReader();
        int n = obj.nextInt(),arr[] = new int[n+1];
        for(int i=0;i<n-1;i++)
        {
            int k = obj.nextInt();
            arr[k]++;
        }
        for(int i=1;i<=n;i++)System.out.println(arr[i]);
    }
}


Measured memory_bytes: 57032
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readIntegerList()
    val allXor = aList.reduce { a, b -> a xor b }
    val ans = aList
        .map { it xor allXor }
        .joinToString(" ")
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

using namespace std;

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

    sort(A, A + N);

    cout << A[N-1] - A[0] << endl;




    return 0;
}


Measured memory_bytes: 256
// AOJ 2879 Gochiusa-Number
// 2018.4.15 bal4u

#include <stdio.h>

long long dp[20][1002][2][2];
char n[20]; int w;

int main()
{
	int i, j, k, m, t, f, d;
	char *p;
	long long ans;

	fgets(p=n, 20, stdin);
	while (*p >= '0') p++;
	*p = 0, w = p-n;

	dp[0][0][0][0] = 1;
	for (i = 0; i < w; i++) for (j = 0; j < 1000; j++) for (k = 0; k < 2; k++) {
		for (m = 0; m < 2; m++) {
			d = k ? 9: (n[i]&0xf);
			for (t = 0; t <= d; t++) {
				f = m || (j/100 == 5 && (j/10)%10 == 1 && t == 3);
				dp[i+1][j%100*10+t][k||t<d][f] += dp[i][j][k][m];
			}
		}
	}

	ans = 0;
	for (i = 0; i < 1000; i++) for (j = 0; j < 2; j++) ans += dp[w][i][j][1];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2408
import java.util.Scanner;

public class Main {
     public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			
		int a = sc.nextInt();
		String op = sc.next();
		int b = sc.nextInt();
		
		if (op.equals("?"))break;
		
		int ans = 0;
		
		switch(op) {
		case "+":
			ans = a + b;
			break;
		case "-":
			ans = a - b;
			break;
		case "*":
			ans = a * b;
			break;
		case "/":
			ans = a / b;
			break;
			
		}
		  System.out.println(ans);

	}
   }
}



Measured memory_bytes: 26240
using System;
using static System.Console;
using System.Collections.Generic;

namespace _20200322
{
    class Program
    {
        static void Main()
        {
            var hwk = ReadLine().Split(' ');
            var h = int.Parse(hwk[0]);
            var w = int.Parse(hwk[1]);
            var k = int.Parse(hwk[2]);
            var s = new string[h];
            for (var i = 0; i < h; ++i)
            {
                s[i] = ReadLine();
            }
            WriteLine(DC(k, s));
        }
        static int DC(int k, string[] s)
        {
            var min = int.MaxValue;
            var bitMax = (int)Math.Pow(2, s.Length - 1);
            for (var bit = 0; bit < bitMax; ++bit)
            {
                min = Math.Min(min, MinCut(k, s, bit));
            }
            return min;
        }
        static int MinCut(int k, string[] s, int bit)
        {
            var horizCut = 0;
            var tmp = bit;
            while (tmp > 0)
            {
                horizCut += (tmp & 1);
                tmp >>= 1;
            }
            var map = new int[horizCut + 1][];
            for (var i = 0; i < map.Length; ++i)
            {
                map[i] = new int[s[0].Length];
            }
            tmp = bit;
            var mapV = 0;
            for (var i = 0; i < s.Length; ++i)
            {
                for (var c = 0; c < s[0].Length; ++c)
                {
                    if (s[i][c] == '1')
                    {
                        ++map[mapV][c];
                    }
                }
                if ((tmp & 1) == 1)
                {
                    ++mapV;
                }
                tmp >>= 1;
            }

            var whiteCount = new int[horizCut + 1];
            var cutCount = horizCut;
            for (var c = 0; c < s[0].Length; ++c)
            {
                // check if impossible
                for (var i = 0; i < horizCut + 1; ++i)
                {
                    if (map[i][c] > k)
                    {
                        return int.MaxValue;
                    }
                }
                var cutFlag = false;
                for (var i = 0; i < horizCut + 1; ++i)
                {
                    if (whiteCount[i] + map[i][c] > k)
                    {
                        cutFlag = true;
                        break;
                    }
                }
                if (cutFlag)
                {
                    ++cutCount;
                    for (var i = 0; i < horizCut + 1; ++i)
                    {
                        whiteCount[i] = map[i][c];
                    }
                }
                else
                {
                    for (var i = 0; i < horizCut + 1; ++i)
                    {
                        whiteCount[i] += map[i][c];
                    }
                }
            }
            return cutCount;
        }
    }
}


Measured memory_bytes: 38912
/**
 * auther: kuroma0616
 */

// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_)

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
#define ll long long
#define pll pair<ll,ll>
#define pq priority_queue
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける

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

//無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main() {
  
  int N;
  int A;
  
  cin >> N >> A;
  
  if ( N % 500 <= A ) {
    
    cout << "Yes" << endl;
  }
  
  else {
    
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
const long long MOD=998244353;
int A,B,C,D;
long long dp[3003][3003];
int main(){
	cin>>A>>B>>C>>D;
	dp[A][B]=1;
	for(int i=B+1;i<=D;i++)dp[A][i]=dp[A][i-1]*A%MOD;
	for(int i=A+1;i<=C;i++)dp[i][B]=dp[i-1][B]*B%MOD;
	for(int i=A+1;i<=C;i++)
		for(int j=B+1;j<=D;j++){
			dp[i][j]=(dp[i][j-1]*i%MOD+dp[i-1][j]*j%MOD-dp[i-1][j-1]*(i-1)*(j-1)%MOD+MOD*20)%MOD;
	//		cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
		}
	//for(int i=1;i<=C;i++,puts(""))for(int j=1;j<=D;j++)cout<<dp[i][j]<<" ";
	cout<<dp[C][D];
}

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

int main () {
    string check[4] = {"dream", "dreamer", "erase", "eraser"};
    string s, x; cin >> s;
    reverse(s.begin(), s.end());
    rep (i, 4) reverse(check[i].begin(), check[i].end());

    for (int i = 0; i < s.size(); i++) {
        x += s[i];
        if (x == check[0] ||x == check[1] ||x == check[2] ||x == check[3]) x = "";
    }

    if (x == "") cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
mod=10**9+7
dic={}
def ADD(x):
	if x in dic:
		dic[x]+=1
	else:
		dic[x]=1
n,m=map(int,input().split())
for i in range(2,int(m**0.5+2)):
	while m%i==0:
		ADD(i)
		m//=i
if m>1:
	ADD(m)
dic=tuple(dic.values())
ans=1
fac=[1]
for i in range(10**6):
	fac.append(fac[-1]*(i+1)%mod)
def c(a,b):
	r=pow(fac[b]*fac[a-b]%mod,mod-2,mod)
	return fac[a]*r%mod
for x in dic:
	ans*=c(x+n-1,x)
	ans%=mod
print(ans)


Measured memory_bytes: 48960
#include "iostream"
#include <array>

uint32_t toSum(uint32_t number) {
    uint32_t sum = 0;
    while(number > 0) {
        sum += (number % 10);
        number /= 10;
    }

    return sum;
}

int main()
{
    uint32_t N, A, B;
    std::cin >> N >> A >> B;

    uint32_t ans = 0;
    for (uint32_t number = 1; number <= N; number++) {
        const uint32_t sum = toSum(number);

        if ((sum >= A) && (sum <= B)) {
            ans += number;
        }
    }

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

    return 0;
}



Measured memory_bytes: 888
import java.util.*;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int reg =0;
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for(int i=a;i<b+1;i++){
            if(c%i==0){
                reg++;
            }
        }
        System.out.println(reg);
    }
}


Measured memory_bytes: 26236
// Aggressive Play

#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const int N = 3e5 + 5;
ll a[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    double n;
    cin >> n;
    cout << fixed << setprecision(10) << 2.0 * acos(-1) * n;
return 0;
}


Measured memory_bytes: 3804
import math
N = int(input())
cands = [list(map(int, input().split())) for i in range(N)]
def calc_dis(x, y):
  return math.sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

sums = [[0 for i in range(N)] for i in range(N)]
for i in range(N):
  for j in range(i+1, N):
    sums[i][j] = calc_dis(cands[i], cands[j])

print(sum([sum(s) for s in sums])*2/N)


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

int main() {
    int X, Y;
    std::cin >> X >> Y;

    for (int i = 0; i <= X; ++i) {
        const int j = X - i;
        if ((i * 2 + j * 4) == Y) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#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 REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int w, a, b; cin >> w >> a >> b;
	int min = a - w, max = a + w;

	if(b >= min && b <= max) cout << '0' << endl;
	elif(b < min) cout << min - b << endl;
	else cout << b - max << endl;

	rtn 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

class Combination {
private:
    const int64_t mod = 1e16;
    vector<vector<int64_t>> comb;

    void init(int64_t max_size) {
        comb.assign(max_size, vector<int64_t>(max_size, 0));
        comb[0][0] = 1;
        for (auto i = 1; i < max_size; i++) {
            // 0個選ぶ組み合わせは1つしかない
            comb[i][0] = 1;
            for (auto j = 1; j < max_size; j++) {
                comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % mod;
            }
        }
    };
public:;
    explicit Combination(int64_t max_size) {
        assert(max_size <= 2000);
        // テーブル生成
        init(max_size + 1);
    };
    virtual ~Combination() = default;

    int64_t combination(int64_t n, int64_t k) {
        if (n < k) return 0;
        if (n < 0 or k < 0) return 0;
        return comb[n][k];
    };
};

int main(){
    int n, p; cin >> n >> p;
    Combination c = Combination(50);

    vector<int> a(n);
    int odd = 0;
    for (auto i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] % 2) odd++;
    }

    int64_t all_comb = 0, odd_comb = 0, even_comb = 0;
    for (auto i = 0; i <= n; i++) {
        all_comb += c.combination(n, i);
        if(odd >= i and i % 2) odd_comb += c.combination(odd, i);
        if(n - odd >= i) even_comb += c.combination(n - odd, i);
//        cout << i << " " << all_comb << " " << odd_comb << " " << even_comb << endl;
    }

    if(p == 0) {
        cout << all_comb - odd_comb * even_comb << endl;
    } else {
        cout << odd_comb * even_comb << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場

int n, d, a;
vector<vector<int>> dat;
vector<i64> boom;
deque<pair<int, i64>> logue;

//inputします
void input() {
	cin >> n >> d >> a;
	dat.resize(n);
	ff(i, 0, n) {
		int a, b;
		cin >> a >> b;
		dat[i] = { a,b };
	}
	srt(dat);
}

//ライブラリ置き場



//main
int main() {
	input();
	i64 ans = 0;
	i64 dealt = 0;
	map<int, i64> boom;
	ff(i, 0, n) {
		int x = dat[i][0];
		while (1) {
			if (logue.empty())break;
			if (logue[0].first >= x - 2 * d)break;
			dealt -= logue[0].second;
			logue.pop_front();
		}
		int rem = dat[i][1] - dealt;
		if (rem < 0)rem = 0;
		boom[x] = cup(rem, a) * a;
		ans += cup(rem, a);
		dealt += boom[x];
		logue.push_back({ x,boom[x] });
		//cout << x << " " << boom[x] << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27008
n, m = map(int, input().split())


root = list(range(n + 1))


# from collections import defaultdict
# d = defaultdict(set)
cnt = [1] * (n + 1)


def find(i):
    if i == root[i]:
        return i
    root[i] = find(root[i])
    return root[i]

def union(u, v):
    fu, fv = find(u), find(v)
    if fu == fv:
        return
    cnt[min(fu, fv)] += cnt[max(fu, fv)]
    root[max(fu, fv)] = min(fu, fv)



for i in range(m):
    u, v = map(int, input().split())
    union(u, v)



# print(d)
print(max(cnt))


Measured memory_bytes: 24500
from operator import itemgetter

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

mod = 998244353

N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
xy.sort(key=itemgetter(1))
for i in range(N):
    xy[i][1] = i+1
xy.sort(key=itemgetter(0))

pow2 = [1]*(N+1)
for i in range(N):
    pow2[i+1] = 2*pow2[i]%mod

ans = pow2[N-1]*N%mod

bit = BIT(N)
for i in range(N):
    l1 = bit.sum(xy[i][1])
    l2 = i-l1
    r1 = xy[i][1]-l1-1
    r2 = N-xy[i][1]-l2
    bit.add(xy[i][1],1)
    ans += (pow2[l2]-1)*(pow2[r1]-1)*pow2[r2]*pow2[l1]
    ans += (pow2[r2]-1)*(pow2[l1]-1)*(pow2[l2]+pow2[r1]-1)
    ans %= mod

print(ans)

Measured memory_bytes: 99544
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

#if __has_include("debugger.cpp")
  #include "debugger.cpp"
#else
void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) > 0) cout << " ";
  print(std::forward<Tail>(tail)...);
}
# endif

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n, m);
  vector<pair<ll, ll>> ab(m);
  REP(i, m) {
    ll input(a, b);
    ab[i] = {a, b};
  }
  sort(ab.begin(), ab.end(), [](auto &v1, auto &v2){
      return v1.first < v2.first;
      });
  ll right = -1;
  ll cnt = 0;
  REP(i, m) {
    if (ab[i].first < right) {
      right = min(ab[i].second, right);
    } else {
      right = ab[i].second;
      cnt++;
    }
  }
  print(cnt);
}


Measured memory_bytes: 4460
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();

		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);
		long l = 0;
		long r = 100000 * 2 + 1;
		while (r - l > 1) {
			long mid = (l + r) / 2;
			long count = 0;

			for (int i = a.length - 1; i >= 0; i--) {
				int index = lowerBound(a, mid - a[i]);
				count += (a.length - index);
				//System.out.println(mid + " " + i + " " + index + " " + count);
				if (count > m) break;
			}

			if (count >= m) {
				l = mid;
			} else {
				r = mid;
			}
		}

		//System.out.println("l: " + l);

		long[] s = new long[n + 1];
		s[n - 1] = a[n - 1];
		for (int i = n - 2; i >= 0; i--) {
			s[i] = s[i + 1] + a[i];
		}

		long answer = 0;
		long c = 0;
		for (int i = a.length - 1; i >= 0; i--) {

			int index = lowerBound(a, l - a[i]);

			//System.out.println(i + " " + index);
			//System.out.println(s[n] + " " + s[index]);

			answer += s[index];
			answer += (n - index) * a[i];
			c += (n - index);
		}

		//System.out.println(m);

		if (m < c) {
			answer -= (c - m) * l;
		}

		System.out.println(answer);
	}

	//private static int upperBound(int[] a, int x) {
	//	int l = -1;
	//	int r = a.length;
	//	while (r - l > 1) {
	//		int m = (l + r) / 2;
	//		if (a[m] > x) {
	//			r = m;
	//		} else {
	//			l = m;
	//		}
	//	}
	//	return r;
	//}

	private static int lowerBound(long[] a, long x) {
		int l = -1;
		int r = a.length;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (a[m] >= x) {
				r = m;
			} else {
				l = m;
			}
		}
		return r;
	}
}


Measured memory_bytes: 60924
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 高さ・幅取得
	int liH, liW;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liH, &liW);

	// 高さ方向 - 奇数回裏返しの行数
	if (liH > 1) {
		liH -= 2;
	}

	// 幅方向 - 奇数回裏返しの行数
	if (liW > 1) {
		liW -= 2;
	}

	// 合計
	long long llSum = (long long)liH * (long long)liW;

	// 結果セット
	sprintf(lc1Out, "%lld\n", llSum);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int unsigned long long
//#define double long double

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

    bool fail = false;
    int n, t, mx = 1, now = 1;
    cin >> n;
    while (n--)
    {
        cin >> t;
        if (t == 0)
            cout << "0\n", exit(0);
        now *= t;

        if (now < mx)
            fail = true;
        else
            mx = now;
    }

    if (fail || mx > 1000000000000000000)
        cout << "-1\n";
    else
        cout << now << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

	sort(S.begin(), S.end());
	string ans = "No";
	if (S[0] == S[1] && S[2] == S[3] && S[1] != S[2])
		ans = "Yes";

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


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

using namespace std;

int solve(int A, int B, int C)
{
    vector<int> ns { A, B, C };
    int ans = 0;

    sort(ns.begin(), ns.end());

    // Faz com que todos tenham mesma paridade
    if (ns[0] % 2 == ns[1] % 2 and ns[1] % 2 != ns[2] % 2)
    {
        ++ans;
        ++ns[0];
        ++ns[1];
    } else if (ns[1] % 2 == ns[2] % 2 and ns[2] % 2 != ns[0] % 2)
    {
        ++ans;
        ++ns[1];
        ++ns[2];
    } else 
    if (ns[0] % 2 == ns[2] % 2 and ns[2] % 2 != ns[1] % 2)
    {
        ++ans;
        ++ns[0];
        ++ns[2];
    }
    
    for (auto x : ns)
        ans += (ns[2] - x)/2;

    return ans;
}

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

    int A, B, C;
    cin >> A >> B >> C;

    auto ans = solve(A, B, C);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int aa(int a)
{
	int x = 1;
	for(int i =0; i < a; i++)
	{
		x *= 10;
	}
	return x;
}

int main()
{
	int a, b;
	cin >> a >> b;
	
	int cnt = 0;
	int tmp = b;
	while(tmp != 0)
	{
		tmp /= 10;
		cnt++;
	}
	
	int x = a*aa(cnt) + b;
	
	for(int i = 1; i <= 1000; i++)
	{
		if(i*i == x)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
# inp.readline()
# int(inp.readline())
# out.write()
# raw_input()
# map(int,raw_input().split())
# map(int,inp.readline().split())
# for _ in xrange(input()):
# print "Case #"+str(_+1)+": "+ 
if __name__ == "__main__":
    from sys import stdin as inp, stdout as out,setrecursionlimit as srl
    from collections import Counter,defaultdict,deque
    from heapq import *
    for _ in xrange(1):
        n=input()
        t=int(pow(n,0.5))+1
        c=Counter()
        for i in xrange(1,t+1):
          for j in xrange(i*i,n+1,i):
            c[j]+=1
        print 2*sum(c[i] for i in xrange(1,n))-int(pow(n-1,0.5))

Measured memory_bytes: 197984
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef unsigned int uint;
typedef pair<int,int> pii;
//-------------------------------------------------------------------LYYY↓
namespace LYYY{
	int rd()
	{
		int s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	LL rdl()
	{
		LL s=0;char c=getchar();int f=1;
		while(c<48||c>57)
		{
			if(c==45) f=-1;
			c=getchar();
		}
		while(c>=48&&c<=57) s=(s<<3)+(s<<1)+(c^48),c=getchar();
		return s*f;
	}
	void wt(int x)
	{
		if(x>=10) wt(x/10);
		putchar(x%10+48);
	}
	void WT(int x)
	{
		if(x<0) x=-x,putchar(45);
		wt(x);
	}
	void wtl(LL x)
	{
		if(x>=10) wtl(x/10);
		putchar(x%10+48);
	}
	void WTL(LL x)
	{
		if(x<0) x=-x,putchar(45);
		wtl(x);
	}
}using namespace LYYY;
//-------------------------------------------------------------------bianliang↓
//-------------------------------------------------------------------hanshu↓
//-------------------------------------------------------------------main()↓
int main()
{
	int a,b;scanf("%d%d",&a,&b);
	if(a<=b*2) puts("0");
	else printf("%d",a-b*2);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<int, PI> PII;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int Par[100000];
int Rank[100000];
void init(int n) {
	rep(i, n) {
		Par[i] = i;
		Rank[i] = 0;
	}
}
int find(int x) {
	if (Par[x] == x) {
		return x;
	}
	else {
		return Par[x] = find(Par[x]);
	}
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (Rank[x] < Rank[y]) {
		Par[x] = y;
	}
	else {
		Par[y] = x;
		if (Rank[x] == Rank[y]) Rank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int x[100000], y[100000];
int main() {
	int N;
	cin >> N;
	vector<PI> vx, vy;
	rep(i, N) {
		cin >> x[i] >> y[i];
		vx.push_back(MP(x[i], i));
		vy.push_back(MP(y[i], i));
	}
	sort(ALL(vx));
	sort(ALL(vy));
	priority_queue<PII, vector<PII>, greater<PII>> Q;
	rep(i, N - 1) {
		Q.push(MP(abs(vx[i].first - vx[i + 1].first), MP(vx[i].second, vx[i + 1].second)));
		Q.push(MP(abs(vy[i].first - vy[i + 1].first), MP(vy[i].second, vy[i + 1].second)));
	}
	init(N);
	LL ans = 0;
	while (!Q.empty()) {
		PII p = Q.top(); Q.pop();
		int a = p.second.first, b = p.second.second;
		if (!same(a, b)) {
			unite(a, b);
			ans += p.first;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7912
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()
ans = 0
word = ""
Slist = list(S.split("W"))
for s in Slist[:-1]:
    ans += len(word + s)
    word = word + s
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if(x==3 || x==5 || x==7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
r = N - K
mod = 10 ** 9 + 7
dp1 = [[0] * (K) for _ in range(K)]
dp2 = [[0] * (r + 2) for _ in range(K + 1)]

for i in range(K):
	for j in range(K):
		if i == 0:
			dp1[i][j] = 1
		elif j == 0:
			dp1[i][j] = 0
		else:
			dp1[i][j] = (dp1[i - 1][j - 1] + dp1[i][j - 1]) % mod

for i in range(K + 1):
	for j in range(r + 2):
		if i == 0:
			dp2[i][j] = 1
		elif j == 0:
			dp2[i][j] = 0
		else:
			dp2[i][j] = (dp2[i - 1][j - 1] + dp2[i][j - 1]) % mod
			
for i in range(K):
	print((dp1[i][-1] * dp2[i + 1][-1]) % mod)


Measured memory_bytes: 76380
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<u64> = procon_read();
	let n = v[0];
	let m = v[1];
	let mut ai = 0;
	let a:Vec<u64> = procon_read();
	let mut flag = true;
	for i in 0..m {
		ai += a[i as usize];
		if ai > n {
			flag = false;
			break;
		}
	}
	if flag {
		println!("{}", n - ai);
	}else{
		println!("-1");
	}
}

Measured memory_bytes: 2252
#include <bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vint vector<int> 
#define for(i,a,n) for(i=a;i<n;i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int i,int n,vint &a){
    for(i,0,n){
        cin>>a.at(i);
    } 
} 

int gcm(int a,int b){ //a>b
    int amari=-1;
    while(amari!=0){
        amari=a%b;
        if(amari!=0){
            a=b;
            b=amari;
        }
    }
    return b;
}

signed main() {
    int N,K;
    cin>>N>>K;
    int i;
    vint A(N);
    fin(i,N,A);

    sort(A.begin(),A.end());
    int agcm=A.at(0);
    for(i,1,N){
        agcm=gcm(max(agcm,A.at(i)),min(agcm,A.at(i)));
    }

    if(K%agcm==0 && K<=A.at(N-1)){
        cout<<"POSSIBLE"<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }
    
return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
	static final long MOD = 1000000007L;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		
		String s = sc.next();
		int ans = 0;
		int cur = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i)=='R') {
				cur++;
			} else {
				ans = Math.max(ans, cur);
				cur = 0;
			}
		}
		ans = Math.max(ans, cur);
		pw.println(ans);
		
		pw.close();
	}
	
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        }
        
        int ni() { 
            return Integer.parseInt(next()); 
        }
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() {
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 32876
#include<stdio.h>
int dp[50];
int fib(int n){
    if(n==0 || n==1)return dp[n]=1;
    if(dp[n]!=-1) return dp[n];
    return dp[n] = fib(n-1)+ fib(n-2);
}
int main(){
    int n,i;
    for(i=0;i<50;i++)dp[i]=-1;
    scanf("%d",&n);
    printf("%d\n",fib(n));
    return 0;
}


Measured memory_bytes: 2108
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]
c = 0.006


def solve_temp(h):
    return T-h*c


minimum = abs(A - solve_temp(H[0]))
minIndex = 0
for i in range(N):
    if minimum > abs(A - solve_temp(H[i])):
        minimum = abs(A - solve_temp(H[i]))
        minIndex = i
print(minIndex+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double pi=acos(-1);


 
int main() {
  int n;
  cin >> n;
  
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << a.at(n-1) << endl;
}


Measured memory_bytes: 256
arg = list(map(int, input().split()))
A = arg[0]
B = arg[1]
C = arg[2]
D = arg[3]

while True:
  C = C - B
  if C <= 0:
    break
  A = A - D
  if A <= 0:
    break
if A <= 0:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 61792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

struct edge{int from,to,cost;};

edge es[5000]; //MAX_E
int d[2500]; //S→Gのcost //MAX_V
int N,M,C;

//最短経路を求める
void bellman_ford(int s){
	for(int i=0;i<N;i++) d[i]=-INF; //
	d[s]=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=es[j];
			if(d[e.from]!=-INF && d[e.to]<d[e.from]+e.cost){ //
				d[e.to]=d[e.from]+e.cost;
                if(i==N-1) return;
			}
		}
	}
    return;
}

//ゴールまで負の閉路に巻き込まれずに到達可能か　bellman_fordの直後に使用
bool negative[2500]; 
void bellman_ford_sec(){
	for(int i=0;i<N;i++) negative[i]=true;
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=es[j];
			if(d[e.from]!=-INF && d[e.to]<d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				negative[e.to]=false; //到達不能
			}
		}
	}
    return;
}

//グラフ全体を対象に負の閉路を探す
bool find_negative_roop(){
	memset(d,0,sizeof(d));
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			edge e=es[j];
			if(d[e.to]>d[e.from]+e.cost){
				d[e.to]=d[e.from]+e.cost;
				if(i==N-1) return true; //負の閉路あり
			}
		}
	}
	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M>>C;
	for(int i=0;i<M;i++){
		int x,y,z;
		cin>>x>>y>>z;
		x--; y--; z-=C;
		es[i].from=x;
		es[i].to=y;
		es[i].cost=z;
	}
	bellman_ford(0);
	bellman_ford_sec();
	if(!negative[N-1]) cout<<-1<<endl;
	else cout<<max(0,d[N-1])<<endl;
	return 0;
}

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

using namespace std;

constexpr int N = 200000;

int p[N + 1];

int main() {
	int n, k, ans, cur, i;

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

	for (i = 1; i <= n; i++) {
		scanf("%d", p + i);
	}

	cur = 0;

	for (i = 1; i <= k; i++) {
		cur += p[i];
	}

	ans = cur;

	for (i = 2; i + k - 1 <= n; i++) {
		cur -= p[i - 1];
		cur += p[i + k - 1];
		ans = max(ans, cur);
	}

	printf("%d.%d\n", (ans + k) / 2, (ans + k) % 2 == 0 ? 0 : 5);

	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define maxs 2020202
#define mme(i,j) memset(i,j,sizeof(i))
#define ll long long
using namespace std;
bool vis[11];

bool check(int n)
{
    while(n){
        if(vis[n%10]) return 0;
        n/=10;
    }
    return 1;
}

int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        int num = n;
        int xx;
        mme(vis,0);
        for(int i=1;i<=k;i++){
            scanf("%d",&xx);
            vis[xx]=1;
        }
        while(!check(num))
            num++;

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

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


const int MOD = 1000000007;

int64_t modpow(int64_t x, int64_t n) {
  x = x%MOD;
  if(n==0) return 1;  //再帰の終了条件

  else if(n%2==1) {
    return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
  }
  else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}


int main() {
  int n;
  cin>>n;
  int64_t a[n];
  for(int i=0; i<n; i++) cin>>a[i];

  const int keta = 60;

  int64_t bitc[keta];
  for(int i=0; i<keta; i++) bitc[i]=0;
  for(int i=0; i<keta; i++) {
    for(int j=0; j<n; j++) {
      if((a[j]>>i)&1) bitc[i]++;
    }
  }

  int64_t ansc[keta];
  for(int i=0; i<keta; i++) ansc[i] = bitc[i]*(n-bitc[i]);

  int64_t ans = 0;
  for(int i=0; i<keta; i++) {
    int64_t mp = modpow(2,i);
    ans += (mp*(ansc[i]%MOD))%MOD;
    ans = ans%MOD;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2560
a = [int(input()) for _ in range(6)]
la = len(a)
cnt= 0
for i in range(la-1):
    for j in range(i+1,la):
        if a[j]-a[i]<=a[5]:
            cnt+=1
        else:
            print(':(')
            break
    else:
        continue
    break
else:
    print('Yay!')

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline
write = sys.stdout.write
H, W = map(int, readline().split())
S = [readline().strip() for i in range(H)]

ans = 0
D = [0]*W
for i in range(H-1, -1, -1):
    Si = S[i]
    cur = 0
    for j in range(W-1, -1, -1):
        c = Si[j]
        if c == 'J':
            ans += D[j]*cur
        elif c == 'O':
            cur += 1
        else:
            D[j] += 1
write("%d\n" % ans)


Measured memory_bytes: 14796
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//
vector<ll>adj[300005];
ll vis[300005]={0};
vector<ll>con;
ll cnt= 0;
ll app[300005]={0};
void dfs(ll u)
{


	vis[u]=1;
	cnt++;
	for(auto v : adj[u])
	{
		if(vis[v]==0)
		{
			dfs(v);
		}
	}
}


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	
	ll n,m;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		ll a,b;
		cin>>a>>b;
		
		adj[a].pb(b);
		adj[b].pb(a);
		
		app[a] = 1;
		app[b] = 1;
	}
	ll g= 0;
	for(i=1;i<=n;i++)
	{
		if(vis[i]==0 && app[i]==1)
		{
			dfs(i);
			con.pb(cnt);
			cnt = 0;

		}

	}
	if(con.size()>0)
	sort(con.begin(),con.end());
	if(con.size()>0)
	cout<<con[con.size()-1]<<endl;
else
	cout<<1<<endl;

	
	


	
	return 0;
}

Measured memory_bytes: 26144
from collections import Counter


def solve(n, a_list, b_list):
    count_a = Counter(a_list)
    count_b = Counter(b_list)
    count_ab = dict()
    for k in count_a.keys():
        if k in count_b.keys():
            if count_a[k] + count_b[k] > n:
                return ["No"]
            count_ab[k] = min(count_a[k], count_b[k])

    # move a
    a_list_1 = []
    a_list_2 = []
    a = 0
    for i in range(n):
        if a != a_list[i]:
            if a_list[i] in count_ab.keys():
                c = count_ab[a_list[i]]
            else:
                c = 0
        a = a_list[i]
        if c > 0:
            a_list_1.append(a)
            c -= 1
        else:
            a_list_2.append(a)
    # move b
    b_list_1 = []
    b_list_2 = []
    b = 0
    for i in range(n):
        if b != b_list[i]:
            if b_list[i] in count_ab.keys():
                c = count_ab[b_list[i]]
            else:
                c = 0
        b = b_list[i]
        if c > 0:
            b_list_1.append(b)
            c -= 1
        else:
            b_list_2.append(b)
    # print(a_list_1, a_list_2, b_list_1, b_list_2)
    k_max = -1
    if len(count_ab.values()) == 0:
        return ["Yes", " ".join([str(b) for b in b_list])]
    d = max(count_ab.values())
    for k in count_ab.keys():
        if count_ab[k] == d:
            k_max = k
            break
    a_list_moved = a_list_1 + a_list_2
    b_list_moved = b_list_1[d:] + b_list_1[:d] + b_list_2

    # need to modify
    if d * 2 > len(a_list_1):
        # a includes many k_max
        if count_a[k_max] >= count_b[k_max]:
            # swap a
            j = len(a_list_1)
            for i in range(len(a_list_1)):
                if a_list_moved[i] == b_list_moved[i] == k_max:
                    while a_list_moved[j] == k_max:
                        j += 1
                    a_list_moved[i], a_list_moved[j] = a_list_moved[j], a_list_moved[i]
        else:
            # swap b
            j = len(a_list_1)
            for i in range(len(a_list_1)):
                if a_list_moved[i] == b_list_moved[i] == k_max:
                    while b_list_moved[j] == k_max:
                        j += 1
                    b_list_moved[i], b_list_moved[j] = b_list_moved[j], b_list_moved[i]
    # print(a_list_moved, b_list_moved)
    res_ab = list(sorted([(a, b) for a, b in zip(a_list_moved, b_list_moved)], key=lambda x: x[0]))
    res_b = " ".join([str(ab[1]) for ab in res_ab])
    # print(res_b)
    return ["Yes", res_b]


def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    res = solve(n, a_list, b_list)
    for r in res:
        print(r)


def test():
    assert solve(6, [1, 1, 1, 2, 2, 3], [1, 1, 1, 2, 2, 3]) == ["Yes", "2 2 3 1 1 1"]
    assert solve(3, [1, 1, 2], [1, 1, 3]) == ["No"]
    assert solve(4, [1, 1, 2, 3], [1, 2, 3, 3]) == ["Yes", "2 3 3 1"]


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


Measured memory_bytes: 94928
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<math.h>
#include<time.h>
#include<vector>
#include<bitset>
#include<memory>
#include<utility>
#include<fstream>
#include<stdio.h>
#include<sstream>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
int fa[100005];
int findroot(int x)
{
    int root;
    for (root=x;fa[root]!=-1;root=fa[root]) ;
    int temp;
    for (;fa[x]!=-1;)
    {
        temp=fa[x];
        fa[x]=root;
        x=temp;
    }
    return root;
}
void u(int x,int y)
{
    x=findroot(x);
    y=findroot(y);
    if (x==y) return;
    fa[x]=y;
}
vector<int> v1[100005];
vector<int> v2[100005];
int a[100005];
int main()
{
    #ifdef absi2011
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,m;
    scanf("%d%d",&n,&m);
    int i;
    for (i=0;i<n;i++)
    {
        fa[i]=-1;
        scanf("%d",&a[i]);
        a[i]--;
    }
    for (i=0;i<m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        x--;
        y--;
        u(x,y);
    }
    for (i=0;i<n;i++)
    {
        v1[findroot(i)].push_back(i);
        v2[findroot(i)].push_back(a[i]);
    }
    int ans=0;
    for (i=0;i<n;i++)
    {
        if (v1[i].size()!=0)
        {
            sort(v1[i].begin(),v1[i].end());
            sort(v2[i].begin(),v2[i].end());
            int k1=0,k2=0;
            for (;;)
            {
                if ((k1>=v1[i].size())||(k2>=v2[i].size())) break;
                if (v1[i][k1]==v2[i][k2])
                {
                    ans++;
                    k1++;
                    k2++;
                }
                else if (v1[i][k1]<v2[i][k2])
                {
                    k1++;
                }
                else
                {
                    k2++;
                }
            }
        }
    }
    printf("%d\n",ans);
    return 0;
} 


Measured memory_bytes: 12032
#include <stdio.h>
#define MAX 100000

int partition(int *,int ,int);

int main(){

  int i=0;
  int A[MAX];
  int n=0;
  int border_n=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  border_n=partition(A,0,n);
  for(i=0;i<n;i++){
    if(i!=0)printf(" ");
    if(i==border_n)printf("[");
    printf("%d",A[i]);
     if(i==border_n)printf("]");
  }
  printf("\n");
  
  return 0;
}

int partition(int *A, int p, int r){
  int judge=0;
  int i=0;
  int j=0;
  int swap=0;
  judge=A[r-1];
  i=p-1;
  for(j=p;j<r-1;j++){
    if(A[j]<=judge){
      i++;
      swap=A[j];
      A[j]=A[i];
      A[i]=swap;
    }
  }
  swap=A[r-1];
  A[r-1]=A[i+1];
  A[i+1]=swap;
  return i+1;
}



Measured memory_bytes: 2136
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
using namespace std;
//
const int inf=1e9+7;//0x3f
//
int N;
int A[100000];
int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	int now=1;
	long long ans=0;
	for(int i=0;i<N;i++){
		if(A[i]<now){
			continue;
		}else if(A[i]==now){
			now++;
		}else{
			ans+=(A[i]-1)/now;
			if(now==1){
				now++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640