akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def main():
  N = int(input())
  A = [(i, v) for i, v in enumerate(map(int, input().split()))]
  values = [[0] * (N + 1) for _ in range(N + 1)]

  A.sort(key=lambda x:-x[1])

  for i, (p, v) in enumerate(A):
    for j in range(i + 1):
      left = abs((p - j) * v)
      right = abs((N - 1 - (i - j) - p) * v)

      values[i + 1][j + 1] = max(values[i][j] + left, values[i + 1][j + 1])
      values[i + 1][j] = max(values[i][j] + right, values[i + 1][j])

  print(max(values[-1]))


if __name__ == '__main__':
  main()


Measured memory_bytes: 100168
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;
string S;

int main() {

	cin >> N >> S;

	ll ans = 0;

	vector<int> C[3];
	rep(i, N) {
		if (S[i] == 'R') C[0].push_back(i);
		if (S[i] == 'G') C[1].push_back(i);
		if (S[i] == 'B') C[2].push_back(i);
	}

	char c[] = "RGB";
	vector<int> perm = { 0, 1, 2 };

	do {
		for (auto c0 : C[perm[0]]) {
			auto c1 = upper_bound(all(C[perm[1]]), c0);
			while (c1 != C[perm[1]].end()) {
				ans += distance(upper_bound(all(C[perm[2]]), *c1), C[perm[2]].end());
				if (*c1 + *c1 - c0 < N && S[*c1 + *c1 - c0] == c[perm[2]]) --ans;
				++c1;
			}
		}
	} while (next_permutation(all(perm)));


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3672
package main

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

func main() {

	A := oneInt()
	B := oneInt()

	ans := A - B*2
	if ans < 0 {
		fmt.Print(0)
		return
	}
	fmt.Print(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


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

int main(){
  int r,D,x,a,b,c,d,e,f,g,h,i,j;
  cin>>r>>D>>x;
  a=r*x-D;
  b=r*a-D;
  c=r*b-D;
  d=r*c-D;
  e=r*d-D;
  f=r*e-D;
  g=r*f-D;
  h=r*g-D;
  i=r*h-D;
  j=r*i-D;
  
  cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl<<e<<endl<<f<<endl<<g<<endl<<h<<endl<<i<<endl<<j<<endl;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b)
#define mins(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){
   
    int n,t;cin>>n>>t;
    vi a(n+1,0),b(n+1,0);
    rep(i,n)cin>>a[i+1]>>b[i+1];

    vc<vvi> dp(n+1,vvi(t,vi(2,0)));
    
    repa(i,1,n+1){
        rep(j,t){
            //食べない
            maxs(dp[i][j][0],dp[i-1][j][0]);
            maxs(dp[i][j][1],dp[i-1][j][1]);
            //最後でない注文として食べる
            if(j-a[i]>=0 && j-a[i]<t){
                maxs(dp[i][j][0],dp[i-1][j-a[i]][0]+b[i]);
                maxs(dp[i][j][1],dp[i-1][j-a[i]][1]+b[i]);
            }
            //最後の注文として食べる
            maxs(dp[i][j][1],dp[i-1][j][0]+b[i]);
        }
    }

    cout<<dp[n][t-1][1]<<endl;
    
    return 0;
}

Measured memory_bytes: 492928
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long double pi = acos(-1.0); 
typedef long long ll;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s, t;
	cin >> s >> t;
	int x = s.length();
	int y = t.length();
	int dp[x + 1][y + 1];
	for(int i = 0; i < x + 1; i++) {
		for(int j = 0; j < y + 1; j++) {
			dp[i][j] = 0;
		}
	}
	for(int i = 0; i < x; i++) {
		for(int j = 0; j < y; j++) {
			if(s[i] == t[j]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	int len = dp[x][y];
	string ans = "";
	while(len > 0) {
		if(s[x - 1] == t[y - 1]) {
			ans = s[x - 1] + ans;
			x--;
			y--;
			len--;
		}else if(dp[x][y] == dp[x - 1][y]) {
			x--;
		}else if(dp[x][y] == dp[x][y - 1]) {
			y--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n),b(n);
  rep(i,0,n){
    cin>>a[i]>>b[i];
  }
  vector<ll> ks(1);
  ks[0]=k;
  bool f=0;
  rep(i,0,30){
    if(k&(1<<i)){
      if(f){
      	ks.push_back(k^(1<<i)|((1<<i)-1));
      }
    }
    else f=1;
  }
  ll ans=0;
  rep(j,0,ks.size()){
      ll cnt = 0;
    rep(i,0,n){
      if((a[i]|ks[j])==ks[j]) {
        cnt+=b[i];
      }
    }
    if(ans<cnt)ans=cnt;
  }
  cout<<ans;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

#define DEBUG

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	vector<P> a(5, make_pair(0,0));
	rep(i, 5) cin >> a[i].first;

	rep(i, 5){
		a[i].second = a[i].first%10 == 0 ? 10 : a[i].first % 10;
		//a[i].second = a[i].first % 10;
	}
	sort(all(a), [](P &a, P &b){return a.second > b.second; });
	rep(i, 4){
		a[i].first = ((a[i].first+9) / 10) * 10;
	}
	int ans = 0;
	rep(i, 5){
		cerr << a[i].second << endl;
		ans += a[i].first;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=[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]
print(n[int(input())-1])


Measured memory_bytes: 2940
//absのdefineは怖いのでおとなしくstdlib使う
//0の隣接点は必ずしも0じゃないよ！！
//情報の中に、0点じゃないものが存在する⇒それを基準に他の情報と比較する。
#include <iostream>
#include <stdlib.h>
using namespace std;

#define NUMARRAY 101
#define INFONUM 100
long map[NUMARRAY][NUMARRAY] = {0};
int kouho[NUMARRAY][NUMARRAY] = {0};
struct ten
{
    int x;
    int y;
    long h;
};

struct ten info[INFONUM] = {0};

void mapping(struct ten nonzero)
{

    for (int i = 0; i < NUMARRAY; i++)
    {
        for (int j = 0; j < NUMARRAY; j++)
        {
            int base_norm = abs(i - nonzero.x) + abs(j - nonzero.y);
            map[i][j] = base_norm + nonzero.h;
        }
    }
}

struct ten info_map(int infonum)
{
    struct ten ans;
    for (int i = 0; i < NUMARRAY; i++)
    {
        for (int j = 0; j < NUMARRAY; j++)
        {
            int NGflag = 0;
            for (int k = 0; k < infonum; k++)
            {
                int base_norm = abs(i - info[k].x) + abs(j - info[k].y);
                if (info[k].h == 0)
                {
                    if (map[i][j] > (base_norm + info[k].h)) NGflag = 1;
                }
                else
                {
                    if (map[i][j] != (base_norm + info[k].h)) NGflag = 1;
                }
            }
            if (NGflag == 0){
                ans.x = i;
                ans.y = j;
                ans.h = map[i][j];
            }
        }
    }
    return ans;
}

int main()
{
    int N;
    cin >> N;
    int flag;
    for (int i = 0; i < N; i++)
    {
        int x, y, h;
        cin >> x >> y >> h;
        if (h != 0)
            flag = i;
        info[i].x = x;
        info[i].y = y;
        info[i].h = h;
    }

    mapping(info[flag]);
    struct ten ans = info_map(N);
    
    cout << ans.x << " " << ans.y << " " << ans.h << endl;
}

Measured memory_bytes: 384
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize,m:usize,x:isize,y:isize,mut xn:[isize;n],mut ym:[isize;m]);

    xn.sort();
    ym.sort();

    let is_oc = if xn[xn.len() - 1] >= ym[0] {
        true
    } else {
        let count = (xn[xn.len() - 1] + 1..ym[0] + 1)
            .filter(|&xxx| x < xxx && xxx <= y)
            .count();
        count == 0
    };

    println!("{}", if is_oc { "War" } else { "No War" });
}


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

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        long A = long.Parse(input[0]);
        long B = long.Parse(input[1]);
        long N = long.Parse(input[2]);
        long ans = 0;
        if (A == 1 || B == 1) { ans = 0; }
        else
        {
            if (B - 1 > N) { ans = (A * N) / B - A * (N / B); }
            else { ans= ans = (A * (B-1)) / B - A * ((B-1) / B); }
        }
        Console.WriteLine(ans);
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;

  vector<ll> v;
  for (auto e : a) {
    if (v.empty()) {
      v.push_back(e);
    } else if ((v.size() % 2 != 0) == (v.back() < e)) {
      v.push_back(e);
    } else {
      v.back() = e;
    }
  }

  for (auto e : v) cerr << e << ' ';
  cerr << endl;

  ll r = 1000;
  for (int i = 0; i + 1 < v.size(); i += 2) r += (r / v[i]) * (v[i + 1] - v[i]);
  cout << r << endl;
}


Measured memory_bytes: 3624
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0: break
    else:
        for i in range(a):
            if i == 0 or i == a-1:
                print('#' * b)
                
            else:
                print('#' + '.' * (b-2) + '#')
    print()            


Measured memory_bytes: 5608
#include <iostream>

using namespace std;

const int MAX_N = 20;
const int MAX_Q = 2000;

int n, A[MAX_N];

int solve(int i, int m) {
    if (m == 0) {
        return 1;
    }
    else if (i >= n) {
        return 0;
    }
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, M, i;

    cin >> n;

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

    cin >> q;

    for (int i = 0; i < q; i++) {
        cin >> M;
        if (solve(0, M)) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
char str[110][110];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	bool h=false;
	if(a<b){
		h=true;
		swap(a,b);
	}
	b--;
	int H=97;
	int W=97;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++){
		str[i][j]='#';
	}
	for(int i=0;i<H/4;i++){
		for(int j=0;j<W/4;j++){
			int id=i*(W/4)+j;
			if(id<a){
				for(int k=0;k<3;k++)for(int l=0;l<3;l++)str[i*4+1+k][j*4+1+l]='.';
			}
			if(id<b)str[i*4+2][j*4+2]='#';
		}
	}
	printf("%d %d\n",H,W);
	for(int i=0;i<H;i++){
		if(h){
			for(int j=0;j<W;j++){
				if(str[i][j]=='#')str[i][j]='.';
				else str[i][j]='#';
			}
		}
		printf("%s\n",str[i]);
	}
}

Measured memory_bytes: 128
def is_good(mid, key):
    ret = 0
    for i in range(N):
        ret += max(0, A[i] - mid // F[i])
    return ret <= key


def binary_search(key):
    bad, good = -1, 10 ** 18
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)
print(binary_search(K))


Measured memory_bytes: 116152
from itertools import accumulate,zip_longest
from functools import reduce
import bisect
import sys
input = sys.stdin.readline

N,Q = map(int,input().split())
A = list(map(int,input().split()))
X = [int(input()) for i in range(Q)]

B = [2*a+1 for a in A] # right
A = [2*a for a in A] # left
X = [2*x for x in X]

S = list(accumulate(A))
T0 = accumulate(A[::2])
T1 = accumulate(A[1::2])
T = []
for s,t in zip_longest(T0,T1):
    T.append(s)
    T.append(t)
if T[-1] is None:
    T.pop()

maxhigh = 10**16
for x in X:
    if x > (A[-1]+A[-2])//2:
        print(T[-1]//2)
        continue
    NG = maxhigh
    OK = 0
    R = OK
    ans = 0
    while True:
        l = x - R
        r = x + R
        li = bisect.bisect_left(A,l)
        ri = bisect.bisect_right(B,r)
        M = ri-li
        if ri == N-M:
            if li > 0:
                ans += T[li-1]
            break
        if ri == N-M-1:
            li -= 1
            if li > 0:
                ans += T[li-1]
            break
        if ri < N-M:
            OK = R
            R = (R + NG)//2
        if N-M < ri:
            NG = R
            R = (R + OK)//2
    if ri > 0:
        ans += S[N-1] - S[ri-1]
    else:
        ans += S[N-1]
    print(ans//2)



Measured memory_bytes: 101460
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <iomanip>
#include <limits>
#include <sstream>
#include <bitset>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007
#define MOD ((int)1e9+7)
//static const long double pi = 3.1415926535897932;

using namespace std;
using ll = long long int;
using ull = unsigned long long;

char toSmall(char c) { // 大文字を小文字へ
	return (c + 0x20);
}

char toLarge(char c) { // 小文字を大文字へ
	return (c - 0x20);
}

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

struct Combination {
	const int num=51e4;			//要素数
	const int mod=1e9+7;
	vector<ll> fact,inv,finv; //階乗,逆元,逆元の階乗.
	
	Combination():fact(num),inv(num),finv(num){
		fact[0]=fact[1]=1;
		inv[1]=1;
		finv[0]=finv[1]=1;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){
		if(n<k) return 0;
		if(n<0 or k<0) return 0;
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	int big_nCk(int n,int k){ //nが大きいとき
		ll res=1LL;
		for (int i = 0; i < k; i++) {
			res=res*(n-i)%mod;
		}
		res = res*finv[k]%mod;
		return res;
	}
	int nHk(int n,int k){return nCk(n+k-1,n-1);}//重複組み合わせ.
};

vector<string> split(const string& src, const char* delim = ",") { //カンマ区切り
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

bool check_int(string str)
{
	if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch);}))
	{
		return true;
	}
	return false;
}

struct rest {
	string s;
	int p;
	int num;

	/* -------------------------------------
	sort関数を使用したときのソートの定義をする。
	まずは文字列sでソートする。
	文字列sが同じだった場合、pでソートする。
	この条件を参考演算子で表現(ifでもOK)
	-------------------------------------*/
	bool operator<(const rest& right) const {
		return s == right.s ? p > right.p : s < right.s;
	}
};

ll pow_mod(ll n, ll k, ll p) { // n^k(mod p)
	if (k == 0) {
		return 1;
	}
	ll res = pow_mod(n * n % p, k / 2, p);
	if (k & 1) {
		res = res * n % p;
	}
	return res;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	Combination com;
	ll ans = (MOD + pow_mod(2LL, n, MOD) - 1) % MOD;
	ll tempA = com.big_nCk(n, a);
	ll tempB = com.big_nCk(n, b);
	ans = (2 * MOD + ans - tempA - tempB) % MOD;

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14664
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt(); //参加者
		int d = stdIn.nextInt(); //日数
		int x = stdIn.nextInt(); //残ったチョコレートの数
		int [] a = new int[n]; //
		for(int i = 0; i < n; i++) {
			a[i] = stdIn.nextInt();
		}
		int cnt = n;
		for(int i = 0; i < n; i++) {
			int num = 1;
			while(true) {
				if(num+a[i] <= d) {
					num+= a[i];
					cnt++;
				}else {
					break;
				}
				
			}
			
			
		}
		
		System.out.println(cnt+x);
		
		
	}

}


Measured memory_bytes: 23124
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x = int(input())

    import math
    test = math.ceil(math.sqrt(math.sqrt(x)))

    for i in range(-test, test + 1):
        for j in range(-test, test + 1):
            if i ** 5 - j ** 5 == x:
                return " ".join([str(i), str(j)])


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


Measured memory_bytes: 9200
(defun solve (n)
  (let ((a (make-array n))
        (l (make-array n))
        (r (make-array n)))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (setf (aref l 0) (aref a 0))
    (setf (aref r (1- n)) (aref a (1- n)))
    (loop for i from 1 below n
          do (setf (aref l i) (+ (aref a i) (aref l (1- i)))))
    (loop for i from (- n 2) downto 0
          do (setf (aref r i) (+ (aref a i) (aref r (1+ i)))))
    (loop for i below (1- n) 
          minimize (abs (- (aref l i) (aref r (1+ i)))))))

(princ (solve (read)))

Measured memory_bytes: 63944
#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main(){
  int n;
  cin >> n;
  int h[n];
  for(int i = 0; i < n; i++) cin >> h[i];
  
  int ans = 0;
  int max = 0;
  for(int i = 0; i < n; i++){
    if(max <= h[i]){
      ans++;
      max = h[i];
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    static Scanner sc = new Scanner(System.in);
    static StringBuffer sb = new StringBuffer();
    public static void main(String args[]){
        int N=sc.nextInt(),K=sc.nextInt();
        long res=K;
        for(int i=0;i<N-1;i++){
            res*=(K-1);
        }
        System.out.println(res);
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int N;

    cin >> N;
    int a[N + 1], box[N + 1] = {0};

    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
    }

    int M = 0;

    for (int i = N; i >= 1; i--)
    {
        int sum = 0;
        for (int j = 1; j <= N / i; j++)
        {
            if (box[i * j] == 1)
                sum += 1;
        }
        if (sum % 2 != a[i])
        {
            box[i] = 1;
            M += 1;
        }
    }

    OP(M)
    for (int i = 1; i <= N; i++)
    {
        if (box[i] == 1)
            OP(i)
    }

    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N; cin >> N;
    map<int,int> MAP;
    rep(i,N) {
        int a; cin >> a;
        MAP[a]++;
    }
    ll ma = 0;
    ll ma2 = 0;
    map<int,int>::reverse_iterator p = MAP.rbegin();
    for (;p != MAP.rend(); p++) {
        if (p->second >= 4) {
            if (ma == 0) {
                ma = p->first;
                ma2 = p->first;
                break;
            } else {
                ma2 = p->first;
                break;
            }
        } else if (p->second >= 2) {
            if (ma == 0) ma = p->first;
            else {
                ma2 = p->first;
                break;
            }
        }
    }
    
    cout << ma * ma2 << endl;
}


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

int main() {
	int N, t, M, p, x;
	vector<int> P, X, T;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> t;
		T.push_back(t);
	}
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> p >> x;
		P.push_back(p);
		X.push_back(x);
	}
	for (int i = 0; i < M; i++) {
		int sum = 0;
		for (unsigned j = 0; j < T.size(); j++) {
			if (j + 1 == P[i])sum += X[i];
			else sum += T[j];
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1<<29;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 
const int N = 2e5 + 1;
int k, n, m;
vector<int> g[N];
bool visited[N];

void dfs(int s,int k){
   if ( k >= 2) return;
   for ( auto it : g[s]){
	     if (!visited[it]){
			  visited[it] = true;
			  dfs(it,k+1); 
			} 
	  }
}

void solve(){
  	cin >> n >> m;
  	for(int i = 0; i < m; i++){
	    int x, y;
	    cin >> x >> y;
	    g[x].push_back(y);
	    g[y].push_back(x);
	}
	visited[1] = true;
	dfs(1,0);
	if (visited[n]) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 13032
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main()
{
	ll N, x;
	cin >> N >> x;

	ll a[100000];
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	ll count = 0;
	for (int i = 0; i < N - 1; i++)
	{
		if (i == 0)
		{
			if (x < a[i])
			{
				count = a[i] - x;
				a[i] = x;
			}
		}

		if (x < (a[i] + a[i + 1])) {
			count += a[i + 1] - (x - a[i]);
			a[i + 1] = (x - a[i]);
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1152
l = input().split()


N = int(l[0])
M = int(l[1])
X = int(l[2])
Y = int(l[3])

"""
if X < -100:
    X = -100
elif X > 100:
    X = 100

if Y < -100:
    Y = -100
elif Y > 100:
    Y = 100
"""

lx = input().split()
ly = input().split()

lx = [int(z) for z in lx]
ly = [int(z) for z in ly]

lx = sorted(lx)


ly = sorted(ly)

flag = True


if int(ly[0]) - int(lx[N-1]) >= 1:
    for z in range(int(lx[N-1]) + 1, int(ly[0]) + 1):

        if z > X and z <= Y:
            flag = False
            break


if flag:
    print("War")
else:
    print("No War")


Measured memory_bytes: 3064
_ = gets
s = gets.chomp

def remove_valid_parens(s)
  while s.include?('()')
    s.gsub!('()', '')
  end
  s
end

ss = remove_valid_parens(s.dup)
num_opens = ss.count('(')
num_closes = ss.count(')')

puts '(' * num_closes + s + ')' * num_opens

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main()
{
	double a = 0, b = 0, c = 0, ang = 0, pi = 3.141592653589793;

	cin >> a >> b >> ang;

	ang = ang * pi / 180;
	c = sqrt(a * a + b * b - 2 * a * b * cos(ang));

	cout << setprecision(13) << fixed << a * b * sin(ang) / 2 << endl
		<< a + b + c << endl
		<< b * sin(ang) << endl;

    return 0;
}

Measured memory_bytes: 3424
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
# import math
from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n, m = map(int, input().split())
A = list(map(int, input().split()))


def lcm_base(x, y):
    # return (x * y) // math.gcd(x, y)
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    x = 1
    for i in range(n):
        x = lcm_base(x, numbers[i])
        if x > 2*m:
            print(0)
            exit()

    return x


def count_two(x):
    count = 0
    while x%2 == 0:
        count += 1
        x //= 2
    return count


two_count = count_two(A[0])
for a in A[1:]:
    if two_count != count_two(a):
        print(0)
        exit()

LCM = lcm_list(A)
# print(LCM)
print((m - LCM//2)//LCM + 1)


Measured memory_bytes: 89580
#include <stdio.h>

int main(){
  int a[5],mod[5];
  for(int i = 0; i < 5; ++i){
    scanf("%d\n",&a[i]);
    mod[i] = a[i] % 10;
  }
  int modmin = mod[0],var = 0;
  for(int i = 1; i < 5; ++i){
    if(modmin > 0){
      if(mod[i] < modmin && mod[i] != 0){
        modmin = mod[i];
        var = i;
      }
    }else{
      modmin = mod[i];
      var = i;
    }
  }
  int time = 0;
  for(int i = 0; i < 5; ++i){
    time += ((9 + a[i])/10) * 10;
  }
  time -= ((9 + a[var]) / 10) * 10;
  time += a[var];
  printf("%d\n",time);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int

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

    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        if (a%2) {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/apc001/tasks/apc001_c
# C - Vacant Seat
"""
m > n impossible
m = n, possible only when n = 1


"""

N = gi()
K = gi()

ans = 0
for b in range(K + 1, N + 1):
    full = N // b
    ans += full * (b - K)
    p = N % b
    if p:
        if K:
            ans += max(0, p + 1 - K)
        else:
            ans += max(0, p - K)

print(ans)


Measured memory_bytes: 12712
using System;

namespace oasobi
{
    static class MainClass
    {
        public static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int s = a * b;
            if( s % 2 == 1 )
            {
                Console.WriteLine("Odd");
            }
            else if( s % 2 == 0)
            {
                Console.WriteLine("Even");
            }
        }
    }
}

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

using ll = long long;
using P = pair<int, int>;

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

ll b[MAX];

int main() {
  // 入力
  int N, K;
  cin >> N >> K;
  ll a[N+1];
  a[0] = 0;
  for (int i = 1; i <= N; i++) cin >> a[i];

  // 累積和を求める
  for (int i = 1; i <= N; i++) {
    b[i] = b[i-1];
    if (a[i] > 0) b[i] += a[i];
  }
  for (int i = 2; i <= N; i++) a[i] += a[i-1];

  // 連続するK個の区間を全探索
  ll ans = 0;
  for (int i = 1; i <= N - K + 1; i++) {
    ll sum = max(0LL, a[i+K-1] - a[i-1]);
    sum += b[i-1] + b[N] - b[i+K-1];
    ans = max(ans, sum);
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
long long s[1000009],b[1000009];
const long long mod=1e9+7;
int main(){
    int n,m;
	s[1]=0;b[1]=0;
	cin>>n>>m;
	for(int i=2;i<=n+1;i++)
	s[i]=i-1,b[i]=b[i-1]+s[i];
	long long ans=0;
	for(int i=m;i<=n+1;i++){
		if(i==2)
		ans=ans+b[n+1]-b[n-1];
		else ans=b[n+1]-b[n+1-i]-b[i]+1+ans;
		ans=ans%mod;
	}
	cout<<ans<<endl;
}

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

using namespace std;

bool func(pair<int,int> p1, pair<int,int> p2) {
    if(p1.first>p2.first) {
        return 1;
    } else if(p1.first<p2.first) {
        return 0;
    } else {
        if(p1.second<p2.second) return 1;
        else return 0;
    }
}

int main()
{
    int i,n,k,x;
    cin>>n>>k;
    map<int,int> MP;
    for(i=0;i<n;i++) {
        cin>>x;
        MP[x]++;
    }
    vector<pair<int,int> > freqarr;
    map<int,int>::iterator it;
    for(it = MP.begin();it!=MP.end();it++) {
        freqarr.push_back(make_pair(it->second,it->first));
    }
    sort(freqarr.begin(),freqarr.end(),func);
    
    int cnt=0;
    for(i=freqarr.size()-1;i>=k;i--) {
        cnt+=freqarr[i].first;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 11768
// Michael Pfeifer
// Version 04, 2018/02/17

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

const ld  pi   = 4.0*atanl(1.0);
const int iinf = 1e9 + 10;
const ll  inf  = 1e18 + iinf + 10;
const int mod  = 1000000007;
const ld  prec = .000001;

#define enld endl
#define endl '\n'
#define pb push_back
#define debug(x) cout<<#x<<" -> "<<x<<'\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define umap unordered_map
#define uset unordered_set

template<class TIn>
using indexed_set = tree<
        TIn, null_type, less<TIn>,
        rb_tree_tag, tree_order_statistics_node_update>;

void fast() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

void file() {
    auto a = freopen("a.in",  "r", stdin);
    auto b = freopen("a.out", "w", stdout);
    if(!a || !b) cout << "uh oh" << endl;
}





int main() {
    //file();
    //fast();

    ll n, x;
    cin >> n >> x;

    vector<int> v(n);

    for(auto& i : v) {
        cin >> i;
    }

    sort(all(v));

    int t = 0;

    for(int i = 0; i < n; i++) {
        if(x - v[i] >= 0) {
            t++;
            x -= v[i];

            if(i == n-1 && x != 0) {
                t--;
            }
        }
    }

    cout << t << endl;

    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    Rep(i,N+30){
        int c = i+i*8/100;
        if( c==N ){
            printf ("%lld\n", i);
            return 0;
        }
    }

    printf (":(\n");

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, double> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


class SegTree {
public:
	int n, height;
	vector<ll> dat;
	
	ll def = INT32_MAX;
	ll operation(int a, int b) {
		return min(a, b);
	}

	// ????????????_n????????????????´???°???
	SegTree(int _n) {
		n = 1;
		height = 1;
		while (n < _n) {
			n *= 2;
			height++;
		}
		dat = vector<ll>(2 * n - 1, def);
	}

	// ??´???i(0-indexed)???x????¶????
	void add(int i, ll x) {
		i += n - 1;
		dat[i] += x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] += x;
		}
	}

	// ??´???i(0-indexed)?????????x?????´??°
	void change(int i, ll x) {
		i += n - 1;
		dat[i] = x;
		while (i > 0) {
			i = (i - 1) / 2;
			dat[i] = operation(dat[i * 2 + 1], dat[i * 2 + 2]);
		}
	}

	// ??????[a,b)?????????????????????k=[l,r)????????????????????????
	ll _query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l)return def;	// ???????????????
		if (a <= l && r <= b)return dat[k];	// a,l,r,b????????§?????¨???????????????
		else {
			ll c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);	// ?????????
			ll c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);	// ?????????
			return operation(c1, c2);
		}
	}

	// ?????¨?????¨???_query()???????????????
	ll query(int a, int b) {
		return _query(a, b, 0, 0, n);
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	SegTree seg(N);
	rep(i, Q) {
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 1) {
			cout << seg.query(b, c + 1) << endl;
		}
		else {
			seg.change(b, c);
		}
	}

	return 0;
}

Measured memory_bytes: 4924
using System;
using System.Collections.Generic;

public class DateSet
{
    //0?????\????????§??°????????????????????????????????????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int i = 0;
        int k;
        string[] unit_num;
        List<string> list = new List<string>(); //??\???????????????????????????????????????????????????
        int[] sort_set = new int[2];  //???????????????????????????????????????????????????
        /*---??£?¨???¨---*/

        /*[0 0]?????\????????§???????????????????????????*/
        while (true){

            list.Add((Console.ReadLine()));
            if (list[i] == "0 0"){
                break;
            }
            i++;
        }

        /*????????????????????????x??¨y??????????????¨???*/
        for (k = 0; k < i; k++) {
            /*2?????????????????????????????§??????*/
            unit_num = list[k].Split(' ');
            sort_set[0] = int.Parse(unit_num[0]);
            sort_set[1] = int.Parse(unit_num[1]);

            /*??????????????????????????????????????????*/
            Array.Sort(sort_set);

            Console.WriteLine("{0} {1}", sort_set[0], sort_set[1]);
        }
    }
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const ll MOD = 1e9+7;

bool f(ll div, ll n){
	if(div == 1) return false;
	while(n%div == 0){
		n/=div;
	}
	return (n%div == 1);
}

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

	ll n; cin >> n;
	if(n == 2){
		cout << "1\n"; return 0;
	}
	int cnt = 0;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			if(f(i, n))
				cnt++;
			if(i != n/i && f(n/i, n))
				cnt++;
		}
	}
	n--;
	for(ll i = 1; i*i <= n; i++){
		if(n%i == 0){
			cnt+=2;
			if(i == 1 || i*i==n)
				cnt--;
		}
	}
	cout << cnt << '\n';

 	return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int,input().split()))
a.sort()

#b:個数
b = []
cnt = 1
for i in range(1,n):
    if a[i] == a[i-1]:
        cnt += 1
    else:
        b.append(cnt)
        cnt = 1
b.append(cnt)
b.sort()

#p[i]:各々からi個以下取った時の最大個数
p = [0]*(n+1)
for i in range(1,n+1):
    kp = bisect.bisect_left(b,i)
    p[i] = p[i-1]+len(b)-kp


for k in range(1,n+1):
    ok = 0
    ng = n+1
    while abs(ng-ok) > 1:
        mid = (ok+ng)//2
        if p[mid] >= k*mid:
            ok = mid
        else:
            ng = mid
    print(ok)


Measured memory_bytes: 116252
# Contest No.: ABC167
# Problem No.: C
# Solver:      JEMINI
# Date:        20200510

import sys

def main():
    n, m, x = map(int, sys.stdin.readline().split())
    table = []

    for _ in range(n):
        table.append(list(map(int, sys.stdin.readline().split())))
    for i in range(1, m + 1):
        temp = 0
        for j in range(n):
            temp += table[j][i]
        if temp < x:
            print(-1)
            return
    ans = 0
    for i in range(n):
        ans += table[i][0]
    for i in range(1, 2 ** n):
        temp = i
        cnt = 0
        tempList = [0] * (m + 1)
        while temp > 0:
            if temp % 2:
                for j in range(m + 1):
                    tempList[j] += table[cnt][j]
            temp >>= 1
            cnt += 1
        flag = True
        for j in range(1, m + 1):
            if tempList[j] < x:
                flag = False
                break
        if flag:
            ans = min(ans, tempList[0])
    print(ans)    
    return

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string N;
    cin >> N;
    if(N[0] == '9' || N[1] == '9') { printf("Yes\n"); }
    else { printf("No\n"); }
    return 0;
}


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

using namespace std;

using ll=long long;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr int mo = 1e9+7;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    vector<int> ac(n),wa(n);
    
    int acsum=0,wasum=0;
    for(int i=0;i<m;++i){
        int p;string s;
        cin>>p>>s;p--;
        if(s == "AC" and !ac[p])ac[p] = 1,acsum++;
        if(!ac[p] and s == "WA") wa[p]++;
    }
    for(int i=0;i<n;++i){
        if(ac[i]){
            wasum += wa[i];
        }
    }
    cout << acsum << " " << wasum << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> ri, le;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x == 0) {
      k--;
    }
    if (x > 0) {
      ri.push_back(x);
    }
    if (x < 0) {
      x *= -1;
      le.push_back(x);
    }
  }
  if (k == 0) {
    puts("0");
    return 0;
  }
  reverse(le.begin(), le.end());
  const int inf = 2e9;
  int ans = inf;
  int cur = 0;
  for (int i = 0; i < min(k, (int) ri.size()); i++) {
    if (k - i - 2 < (int) le.size()) {
      cur = ri[i];
      if (k - i - 2 >= 0) {
        cur += cur + le[k - i - 2];
      }
      ans = min(ans, cur);
    }
  }
  for (int i = 0; i < min(k, (int) le.size()); i++) {
    if (k - i - 2 < (int) ri.size()) {
      cur = le[i];
      if (k - i - 2 >= 0) {
        cur += cur + ri[k - i - 2];
      }
      ans = min(ans, cur);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1020
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define pb push_back
#define endl '\n';
#define sz(s) int(s.size())
#define Ceil(x,y)  ((x+y-1)/y)
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()), ((v).rend())
#define I64 int
typedef long long ll;
typedef unsigned long long ull;
typedef double dl;
const ll mod = ll(1e9 + 7);
const double PI = acos(-1.0);
const int N = (int)1e7 + 1;
using namespace std;
void Selim()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int dx[8] = { 1, 0, -1, 0, -1, 1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, -1, 1, 1, -1 };
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll LCM(ll a, ll b) { return a / gcd(a, b)*b; }
//ll fact(long long  n) { return !n ? 1 : n * fact(n - 1); }
//transform(s.begin(), s.end(), s.begin(), ::tolower);
//palindrom if(s==string(s.rbegin(),s.rend()));
//memset(arr,0,sizeof arr)

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

If you want something you've never had, you must be willing to do something you've never done

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

int main()
{
	//freopen("mulan.in", "r", stdin);
	Selim();   
	int n, a, ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++){
		cin >> a;
		if ((i & 1) && (a & 1))ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;int main() {
  int N, K, x, i, Sum;
  cin >> N >> K;
  for(i = 0; i < N; i++){
    cin >> x;
      if(x < K -x){
        Sum += 2 * x;
      }
      else{
        Sum += 2 * (K-x);
      }
  }
  cout << Sum;
}

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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N,L; cin >> N>>L;
    vector<string> S(N); cin >> S;
    
    sort(ALL(S));

    for (const string& s : S) cout<<s;
    cout << endl;
}


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

int main() {
  int m = 1000000007;
  int n;
  cin >> n;
  
  vector<int> v(n);
  long long sumN=0;
  for(int i=0; i<n; i++){
    cin >> v.at(i);
    sumN += v.at(i);
  }
  
  long long sum=0;
  for(int i=0; i<n-1; i++){
	sum += (sumN-v.at(i)) % m * (long long)v.at(i) % m;
    sumN -= (long long)v.at(i);
  }
  
  cout << sum % m << endl;
  
  
  
  
}


Measured memory_bytes: 4040
#include <stdio.h>

int kyori(int i, int j)
{
	int total;

	if (i > j)
	{
		total = i - j;
	}
	else if (j > i)
	{
		total = j - i;

	}
	else
	{
		total = 0;
	}
	return total;
}

int main()
{
	int i, j;

	scanf("%d %d", &i, &j);

	printf("%d\n", kyori(i, j));
	return 0;
}



Measured memory_bytes: 2032
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int a, p;
	cin >> a >> p;

	cout << (3*a+p)/2 << endl;
	
}

Measured memory_bytes: 256