akhauriyash/Code-Regression huggingface dataset:
/*****Enigma_27*****/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<ll,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios        	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,i,j,k,l,t=1,ans=0,flag=0;
int main()
{   ios
    string s ,p="YAKI";
    cin>>s;
    if(s.size()<4) {cout<<"No\n";return 0;}
    for(i=0;i<4;i++)
    {
        if(s[i]==p[ans]) ans++;
        if(ans==4) {cout<<"Yes\n";return 0;}

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


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
    int m, f, r;
    while(true) {
        cin >> m >> f >> r;
        if(m==-1 && f==-1 && r==-1) {
            break;
        }
        if(m==-1 || f==-1) {
            cout << "F" << endl;
            continue;
        }
        if(m+f < 30) {
            cout << "F" << endl;
        }
        else if(m+f < 50) {
            if(r >= 50) {
                cout << "C" << endl;
            }
            else{
                cout << "D" << endl;
            }
        }
        else if(m+f < 65) {
            cout << "C" << endl;
        }
        else if(m+f < 80) {
            cout << "B" << endl;
        }
        else {
            cout << "A" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3008
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int C[3][3];
int main(){
  int i, j, k;
  for(i=0;i<3;i++){
    {
      int Lj4PdHRW;
      for(Lj4PdHRW=0;Lj4PdHRW<3;Lj4PdHRW++){
        rd(C[i][Lj4PdHRW]);
      }
    }
  }
  k = C[0][0];
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      C[i][j] -= k;
    }
  }
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(C[i][j] != C[0][j]+C[i][0]){
        wt_L("No");
        putchar_unlocked('\n');
        return 0;
      }
    }
  }
  wt_L("Yes");
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180208-1

// --- original code ---
// int C[3][3];
// {
//   int i, j, k;
//   rep(i,3) rd(C[i](3));
//   k = C[0][0];
//   rep(i,3) rep(j,3) C[i][j] -= k;
//   rep(i,3) rep(j,3) if(C[i][j] != C[0][j]+C[i][0]) {
//     wt("No");
//     return 0;
//   }
//   wt("Yes");
// }

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		String s = fs.next();
		System.out.println(s.replaceAll("\\?", "D"));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 49400
#include <iostream>

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

    if(N > 81 || N < 1){
        std::cout << "No" << std::endl;
        return 0;
    }

    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(N == i * j){
                std::cout << "Yes" << std::endl;
                return 0;
           }
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=200005,INF=1<<30;

int V,cmp[MAX];
vector<int> G[MAX],rG[MAX],vs;//vsがトポソの逆順になってる
bool used[MAX];

void add_edge(int from,int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void DFS(int v){
    used[v]=1;
    for(int i=0;i<G[v].size();i++){
        if(used[G[v][i]]==0) DFS(G[v][i]);
    }
    vs.push_back(v);
}

void rDFS(int v,int k){
    used[v]=1;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++){
        if(used[rG[v][i]]==0) rDFS(rG[v][i],k);
    }
}

int scc(){
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++){
        if(used[v]==0) DFS(v);
    }
    
    memset(used,0,sizeof(used));
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        if(used[vs[i]]==0) rDFS(vs[i],k++);
    }
    return k;
}
int num;

int mex[MAX],mex2[MAX];

void DFS(int u,int p,int root,int d){
    set<int> SE;
    if(G[u].size()==0){
        return;
    }
    for(int to:G[u]){
        if(cmp[to]==num) continue;
        
        DFS(to,u,root,d+1);
        
        SE.insert(mex[to]);
    }
    
    for(int i=0;;i++){
        if(SE.count(i)==0){
            mex[u]=i;
            if(u==root){
                i++;
                while(SE.count(i)) i++;
                mex2[u]=i;
            }
            break;
        }
    }
}

int S[MAX];

bool ans=false;

void solve(int u,int p,int root,bool c){
    if(u==root){
        if(S[u]==-1){
            if(!c) S[u]=mex[u];
            else S[u]=mex2[u];
            
            for(int to:rG[u]){
                if(cmp[to]==num) solve(to,u,root,0);
            }
        }else{
            int a;
            if(mex[u]==S[p]) a=mex2[u];
            else a=mex[u];
            
            if(a==S[u]) ans=true;
        }
    }else{
        if(mex[u]==S[p]) S[u]=mex2[u];
        else S[u]=mex[u];
        
        for(int to:rG[u]){
            if(cmp[to]==num) solve(to,u,root,0);
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    V=N;
    for(int i=0;i<N;i++){
        int a;cin>>a;
        a--;
        add_edge(a,i);
    }
    int k=scc();
    
    vector<int> cnt(k);
    for(int i=0;i<N;i++){
        cnt[cmp[i]]++;
    }
    for(int i=0;i<k;i++) if(cnt[i]>=2) num=i;
    
    for(int i=0;i<N;i++){
        if(cmp[i]==num) DFS(i,-1,i,0);
    }
    
    for(int i=0;i<N;i++){
        if(cmp[i]==num){
            memset(S,-1,sizeof(S));
            solve(i,-1,i,0);
            
            memset(S,-1,sizeof(S));
            solve(i,-1,i,1);
            
            break;
        }
    }
    
    if(ans) cout<<"POSSIBLE\n";
    else cout<<"IMPOSSIBLE\n";
}



Measured memory_bytes: 33016
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 123450
#endif

int A,B;

void solve() {
    cin>>A>>B;
    
    cout << A*B << endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
    int k,t; cin >> k >> t;
    vector<pair<int,int>> a(t,make_pair(0,0));
    rep(i,t) cin >> a.at(i).first, a.at(i).second = i;
    sort(a.rbegin(),a.rend());
    int ID = INF;
    if(t == 1){
        cout << k-1 << endl;
        return 0;
    }
    while(true){
        if(a.at(0).second == ID){
            ID = a.at(1).second;
            if(a.at(1).first == 0) break;
            a.at(1).first--;
            for(int i=1;i<t-1;i++){
                if(a.at(i).first<a.at(i+1).first) swap(a.at(i),a.at(i+1)); else break;
            }
        }else{
            ID = a.at(0).second;
            a.at(0).first--;
            for(int i=0;i<t-1;i++){
                if(a.at(i).first<a.at(i+1).first) swap(a.at(i),a.at(i+1)); else break;
            }
        }
    }
    cout << a.at(0).first << endl;
    //rep(i,t) cout << a.at(i).first << " ";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 main() {
	int n,q,a[100500],l,r,x;
	long long sum=0;
	cin >> n;
	for(int i=0; i<n; i++) 
	{
		cin>>x;
		sum+=x;
		a[x]++;
	}
	cin >> q;
	for(int i=0; i<q; i++)
	{
		cin >> l>>r;
		int v = a[l];
		sum = sum - (1ll*v*l) + (1ll*v*r);
		a[l]=0;
		a[r]+=v;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

bool IsPrime(int num){
    if(num<2) return false;
    else if(num==2) return true;
    else if(num%2==0) return false;

    double sqrtNum=sqrt(num);
    for(int i=3;i<=sqrtNum;i+=2){
        if(num%i==0) return false;
    }
    return true;
}
int main(){
    int x;
    cin>>x;
    if(x==2){
        cout<<2<<endl;
        return 0;
    }
    int ans;
    bool flag;
    for(int i=x;i<INT_MAX;i++){
        flag=IsPrime(i);
        if(flag) {
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);++(i))
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);--(i))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    cout << min(min(a * b, b * c), a * c) << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    ll n,k;
    cin>>n>>k;

    if(k==1||n==k)
        cout<<"0\n";
    else if(n<k)
      cout<<min(n,abs(n-k))<<"\n";
    else
        cout<<min(n%k,k-(n%k))<<"\n";
return 0;
}


Measured memory_bytes: 3556
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function root(uf::Array{Int,1},x)
	s=x
	while uf[s]>0
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l!=r
		if uf[l] < uf[r]
			uf[l] += uf[r]
			uf[r] = l
		else
			uf[r] += uf[l]
			uf[l] = r
		end
	end
end

function main()
	n = readline() |> parseInt
	e = zeros(Int,2*10^5)
	uf = -ones(Int,2*10^5)
	for i in 1:n
		x,y = readline() |> split |> parseMap
		e[x]+=1
		e[10^5+y]+=1
		unite(uf,x,10^5+y)
	end
	dx = Dict{Int,Int}()
	dy = Dict{Int,Int}()
	rt = [root(uf,i) for i in 1:2*10^5]
	for i in 1:10^5
		r = rt[i]
		if uf[r]<-1
			if haskey(dx,r)
				dx[r]+=1
			else
				dx[r]=1
			end
		end
		r = root(uf,10^5+i)
		if uf[r]<-1
			if haskey(dy,r)
				dy[r]+=1
			else
				dy[r]=1
			end
		end
	end
	t = 0
	for i in 1:10^5
		if haskey(dy,rt[i])
			t += dy[rt[i]]-e[i]
		end
		if haskey(dx,rt[10^5+i])
			t += dx[rt[10^5+i]]-e[10^5+i]
		end
	end
	println(t>>1)
end

main()

Measured memory_bytes: 156408
[H, W] = [int(i) for i in input().split()]
l = [input() for i in range(H)]

l1 = [x for x in l if x != '.'*W]

l2 = [''.join(x) for x in zip(*l1)]

l3 = [x for x in l2 if any([y if y != '.' else False for y in x])]

print("\n".join([''.join(x) for x in zip(*l3)]))


Measured memory_bytes: 3064
local double_check = function(t1)
  if not t1 then
    return false
  end
  local len = #t1
  for i=1, len do
    for j=i+1, len do
      -- print('checking: ' .. i .. ", " .. j)
      if t1[i] == t1[j] then
        return true
      end
    end
  end
  return false
end

local shiritori = function(s1, s2)
  local first = string.sub(s2, 1, 1)
  local last = string.sub(s1, -1)
  --print(first)
  --print(last)
  if first == last then
    return true
  else
    return false
  end
end

local num = io.read("*n")
local data = {}
for i=1, num+1 do
  local str = io.read("*l")
  data[i] = str
end
if double_check(data) then
  print('No')
  os.exit(0)
end

for i=2, #data-1 do
  if not shiritori(data[i], data[i+1]) then
    -- print('checking: ' .. i .. ", " .. i+1)
    print('No')
    os.exit(0)
  end
end
print('Yes')
os.exit(0)

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<pair<long, long>> data(N);
  for(int i = 0; i < N; i++){
    cin >> data.at(i).first;
  }
  for(int i = 0; i < N; i++){
    cin >> data.at(i).second;
  }
  long count = 0;
  for(int i = 0; i < N; i++){
    if(data.at(i).first > data.at(i).second){
      count -= data.at(i).first - data.at(i).second;
    } else if(data.at(i).first < data.at(i).second){
      count += (data.at(i).second - data.at(i).first) / 2;
    }
  }
  if(count >= 0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
using System;

public class hello
{
    public static void Main()
    {
        var s1 = Console.ReadLine().Trim();
        var s2 = Console.ReadLine().Trim();
        var findex = s1.IndexOf(s2);
        if (findex >= 0) Console.WriteLine(findex);
        while (0 <= findex)
        {
            var nIndex = findex +1;
            if (nIndex < s1.Length)
            {
                findex = s1.IndexOf(s2, nIndex);
                if (findex>0)  Console.WriteLine(findex);
            }
            else   break;
        }
    }
}

Measured memory_bytes: 9856
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;
typedef pair<int, int> P;
class Data
{
public:
	string station;
	P start;
	P arrival;
};
class Ans
{
public:
	string station;
	int time;
	Ans(string station, int time) : station(station), time(time){}
};

void solve()
{
	int N, T;
	cin >> N >> T;
	vector<Data> data(N);
	for (int i = 0; i < N; ++i)
	{
		string station2;
		scanf("%d:%d", &data[i].start.first, &data[i].start.second);
		cin >> data[i].station;
		scanf("%d:%d", &data[i].arrival.first, &data[i].arrival.second);
		cin >> station2;
	}
	vector<Ans> ans;
	for (int i = 0; i < N - 1; ++i)
	{
		int startTime = data[i + 1].start.first * 60 + data[i + 1].start.second;
		int arrivalTime = data[i].arrival.first * 60 + data[i].arrival.second;
		if (startTime - arrivalTime >= T)
		{
			Ans a(data[i+ 1].station, startTime - arrivalTime);
			ans.push_back(a);
		}
	}
	if (ans.empty())
	{
		cout << 0 << endl;
		return;
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); ++i)
	{
		cout << ans[i].station << " " << ans[i].time << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int h, w;
  cin >> h >> w;
  char G[h][w];
  rep(i, h) rep(j, w) cin >> G[i][j];

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

  int x = 0;
  int y = 0;
  bool f = 1;
  while (1) {
    if (G[y][x] != '#') {
      f = 0;
      break;
    }

    G[y][x] = '-';
    if (x == w - 1 && y == h - 1) break;

    rep(i, 2) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue;
      if (G[ny][nx] == '#') {
        x = nx;
        y = ny;
        break;
      }
    }
  }

  rep(i, h) rep(j, w) if (G[i][j] == '#') f = 0;

  cout << (f ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
void main()
{
    long x = rdElem;

    long now = 100;
    long year;
    while (now < x)
    {
        now += now / 100;
        ++year;
    }

    year.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}
int main(){
  
  ll N;
  cin>>N;
  
  vector<ll>A(N);
  
  rep(i,N){
cin>>A[i];
      }
  
  sort(all(A));
  ll ans=1;
  ll num=A[0];
  for(ll i=1;i<N;i++){
  if(A[i]==num){
ans--;
      num=INF;
    }
    else{
    num=A[i];
      ans++;
  }
  }
  cout<<ans<<endl;
}

    

Measured memory_bytes: 1152
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
f = list(map(int, input().split()))
a.sort()
f.sort()

import numpy as np

a = np.array(a)
f = np.array(f)
f_ = f[::-1]

left = -1
right = np.max(a*f_)

while left + 1 < right:
    mid = (left + right)//2
    x = np.maximum(0, a - (mid//f_) ).sum() <= k
    if x:
        right = mid
    else:
        left = mid

print(right)

Measured memory_bytes: 33940
from math import log2,ceil

N,K=map(int,input().split())
SUM=0
for i in range(1,N+1):
  if i<K:
    n_trial = ceil(log2(K/i))
    tmp = 1/(2**n_trial)
  else:
    tmp = 1
  SUM += tmp
print(SUM/N)

Measured memory_bytes: 9300
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    x <- getInt
    print . length . takeWhile (< x) $ iterate (\p -> p + (p `div` 100)) 100

Measured memory_bytes: 3692
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main { 

	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int countMaterial = Integer.parseInt(sc.nextLine());
    	String[] inputValue = sc.nextLine().split(" ");
    	
    	PriorityQueue<Double> Que = new PriorityQueue();
    	for(int i = 0;i<countMaterial;i++) {
    		double eachValue = Double.parseDouble(inputValue[i]);
    		Que.add(eachValue);
    	}
    	for(int i = 1;i<=countMaterial-1;i++) {
    		double tmp1 = Que.poll();
    		double tmp2 = Que.poll();
    		double tmp = (tmp1+tmp2)/2;
    		Que.add(tmp);
    	}
    	

    	
    	System.out.println(Que.peek());
    }
}

Measured memory_bytes: 21844
def main():
    n = int(input())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    cnt = 0
    for i in reversed(range(n)):
        now = b[i]
        if now>a[i+1]:
            cnt += a[i+1]
            now -= a[i+1]
            if now>=a[i]:
                cnt +=a[i]
                a[i]=0
            else:
                cnt +=now
                a[i] -=now
        else:
            cnt += now

    print(cnt)
if __name__ == '__main__':
    main()

Measured memory_bytes: 81892
/**
*    author:  boutarou
*    created: 15.08.2020 22:06:03
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define fcout cout << fixed << setprecision(15)
using ll = long long;
using P = pair<ll, ll>;

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

const double PI = 3.1415926535897932;
const ll INF  = 3e18;

ll solver(ll n, ll k, vector<ll> p, vector<ll> c) {
    rep(i, n) p[i]--;
    ll ans = -INF;
    ll k2 = k;
    rep(i, n) { // i : 開始マス
        // 一回の回帰について考える
        k = k2;
        ll kaiki_sum = 0, cnt_sum = 0;
        {
            ll now = i;
            while(1) {
                now = p[now];
                kaiki_sum += c[now];
                cnt_sum++;
                if (cnt_sum <= k2) chmax(ans, kaiki_sum); 
                if (now == i) break;
            }
        }
        ll sum = 0;
        // 最後
        ll search_time;
        if (kaiki_sum <= 0) search_time = min(k, cnt_sum);
        else {
            if (k <= cnt_sum) {
                search_time = k;
            }
            else {
                sum += kaiki_sum * (k / cnt_sum - 1);
                chmax(ans, sum);
                k -= cnt_sum * (k / cnt_sum - 1);
                search_time = k;
            }
        }

        {
            ll now = i;
            rep(j, search_time) {
                now = p[now];
                sum += c[now];
                chmax(ans, sum);
            }
        }
    }
    return ans;
}

ll solver2(ll n, ll k, vector<ll> p, vector<ll> c) {
    rep(i, n) p[i]--;
    ll ans = -INF;
    rep(i, n) {
        ll now_score = 0, now_point = i;
        rep(j, k) {
            now_point = p[now_point];
            now_score += c[now_point];
            chmax(ans, now_score);
        }
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, k; cin >> n >> k;
    vector<ll> p(n), c(n);
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> c[i];
    cout << solver(n,k,p,c) << endl;
    // cout << "Solver1" << " " << solver(n, k, p, c) << endl;
    // cout << "Solver2" << " " << solver2(n, k, p, c) << endl;
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
using namespace std;
typedef long long LL;

LL gcd(LL a, LL b)
{
	if (!b)
      return a;
  	return gcd(b, a % b);
}

int main()
{
	int n;
  	LL t, res;
  	cin >> n >> res;
  	for (int i = 1; i < n; ++i)
    {
    	cin >> t;
      	res = res / gcd(res, t) * t;
    }
  	cout << res;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int k, n;
	cin >> k >> n;
	vector<int> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		s.push_back(a);
	}
	int ans = 0;
	for (int i = 1; i < n; i++) {
		ans = max(ans, s[i] - s[i-1]);
	}
	ans = max(ans, k - s[n - 1] + s[0]);
	cout << k - ans;
 }


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int ff;
int n,m,col[500100],blo,tot,le,ri,ans[500100],cnt[500100];
pair<pair<int,int>,int> que[500100];
bool pp(pair<pair<int,int>,int> x,pair<pair<int,int>,int> y){
	return x.first.second<y.first.second;
}
inline void inser(int val){cnt[val]++;if(cnt[val]==1) ff++;}
inline void eras(int val){cnt[val]--;if(cnt[val]==0) ff--;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&col[i]);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&que[i].first.first,&que[i].first.second);
		que[i].second=i;
	}
	sort(que+1,que+m+1);
	blo=max(1,(int)(sqrt(m)));
	tot=(m+blo-1)/blo;
	for(int i=1;i<=tot;i++){
		le=blo*(i-1)+1;
		ri=min(blo*i,m);
		sort(que+le,que+ri+1,pp); 
		for(int j=1;j<=n;j++) cnt[j]=0;
		ff=0;
		for(int j=que[le].first.first;j<=que[le].first.second;j++)
			inser(col[j]);
		ans[que[le].second]=ff;
		for(int j=le+1;j<=ri;j++){
			for(int kk=que[j-1].first.first;kk<que[j].first.first;kk++)
				eras(col[kk]);
			for(int kk=que[j].first.first;kk<que[j-1].first.first;kk++)
				inser(col[kk]);
			for(int kk=que[j-1].first.second+1;kk<=que[j].first.second;kk++)
				inser(col[kk]);
			ans[que[j].second]=ff;
		}
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 15484
A,B=input().split()
tap=0
plug=1


for i in range(int(B)*3):
    if plug >= int(B):
       break
    plug+=int(A)-1
    tap+=1
#if int(B)%int(A) != 0:
#    tap=int(B)/int(A)+1
#else:
#    tap=int(B)/int(A)

print(int(tap))


Measured memory_bytes: 2940
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut apexes = 1;
    let mut max_level = 0;

    while apexes < n {
        apexes *= 2;
        max_level += 1;
    }
    debug!(max_level);
    let mut levels = vec![vec![false; max_level]; n];

    for i in 0..n {
        for j in 0..max_level {
            if i >> j & 1 == 0 {
                levels[i][j] = true;
            }
        }
    }

    let mut graph = vec![vec![0; n]; n]; // level
    for i1 in 0..n {
        for i2 in i1 + 1..n {
            for j in 0..max_level {
                if levels[i1][j] != levels[i2][j] {
                    graph[i1][i2] = j;
                }
            }
        }
    }
    debug!(graph);
    for i in 0..n - 1 {
        let ans = graph[i][i + 1..n]
            .iter()
            .map(|&x| x + 1)
            .collect::<Vec<_>>();
        print_array(&ans);
    }
}

fn print_array<T: std::string::ToString>(array: &Vec<T>) {
    println!(
        "{}",
        array
            .iter()
            .map(|ref x| x.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 6652
#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef struct{
    double x;
    double y;
}vec;
vec makeVec(vec p,vec q){
    vec r;
    r.x=q.x-p.x;
    r.y=q.y-p.y;
    return r;
}

double crossZe(vec p,vec q){
    if(p.x*q.y-p.y*q.x==0.0) return 0.0;
    return (p.x*q.y-p.y*q.x)/fabs(p.x*q.y-p.y*q.x);
}

bool Tri(vec p[3],vec q[3]){
    double c,d;
    c = crossZe(p[0],q[0]);
    if(c==0) return false;
    for(int i=1;i<3;i++){
        d=crossZe(p[i],q[i]);
        if(c!=d||d==0.0) return false;
    }
    return true;
}
int main(int argc, const char * argv[]) {
    vec p[3],q,r[3],rq[3];
    while(cin >> p[0].x >> p[0].y >> p[1].x >> p[1].y >> p[2].x >> p[2].y){
        cin >> q.x >> q.y;
        r[0]=makeVec(p[0],p[1]);
        r[1]=makeVec(p[1],p[2]);
        r[2]=makeVec(p[2],p[0]);
        rq[0]=makeVec(q,p[1]);
        rq[1]=makeVec(q,p[2]);
        rq[2]=makeVec(q,p[0]);
        if(Tri(r,rq)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(){
	int n,x;
	while(true){
		scanf("%d",&n);
		x=0;
		if(n==0)
			break;
		for(int i=2;i<=n;i++){
			for(int j=1;j<n;j++){
				int count=0;
				for(int k=j;k<j+i;k++)
					count+=k;
				if(count==n)
					x++;
			}
		}
		printf("%d\n",x);
	}
	return 0;
}

Measured memory_bytes: 1188
n = 10**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=sorted(list(primes))
checker0=[0]*(n+1)
checker=[0]*(n+1)
for p in primes:
    checker0[p]=1
    if p%2==1 and checker0[(p+1)//2]==1:
        checker[p]=1

import numpy as np
cumcheck=np.cumsum(checker)
#print(cumcheck[0:100])
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(cumcheck[r]-cumcheck[l-1])

Measured memory_bytes: 21228
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1277
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;

int N, T, L, B;
bool Lose[110];
bool Back[110];
double A[110][110]; // (マス目、ターン数)。確率を直接代入。
// long long six[110]; // 6^i。
// int は10桁、long long でも20桁を超すともうダメです。
// 確率を求める際に分母に6^100が必要ならば、最初から割っておく！！

int main() {
  /* six[0] = 1;
  for (int i=1; i<110; i++) {
    six[i] = 6 * six[i-1];
    cerr << "i = " << i << ", six[i] = " << six[i] << endl;
    } */
  while (scanf("%d%d%d%d", &N, &T, &L, &B) != EOF && N) {
    fill(&A[0][0], &A[0][0]+110*110, 0);
    fill(Lose, Lose+110, false);
    fill(Back, Back+110, false);
    A[0][0] = 1;
    for (int i=0; i<L; i++) {
      int l;
      scanf("%d", &l);
      Lose[l] = true;
    }
    for (int i=0; i<B; i++) {
      int b;
      scanf("%d", &b);
      Back[b] = true;
    }
    for (int t=0; t<T; t++) {
      for (int n=0; n<N; n++) {
	for (int i=1; i<=6; i++) {
	  int stop = n+i;
	  if (stop > N) stop = N - (stop - N);
	  if (Lose[stop]) {
	    A[stop][t+2] += A[n][t]/6; // ここに注意！
	  } else if (Back[stop]) {
	    A[0][t+1] += A[n][t]/6;
	  } else {
	    A[stop][t+1] += A[n][t]/6;
	  }
	}
      }
      /*for (int i=0; i<=N; i++) {
	cerr << A[i][t] << " ";
      }
	cerr << endl;*/
    }
    double ans = 0;
    for (int t=1; t<=T; t++) {
      ans += A[N][t];
    }
    printf("%.6f\n", ans);
  }
}

Measured memory_bytes: 1300
import java.util.Scanner;

public class Main {

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

        if(n < 10 && s < 10){
            System.out.println(n * s);
        } else {
            System.out.println(-1);
        }

        scanner.close();
    }



}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    int a,b,c;
    cin >> a >> b;
    if (a*b % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
N = int(input())
A = [int(x) for x in input().split()]
S = sum(A)
min_res = S * N
ans = -1
for i, a in enumerate(A):
    if abs(N * a - S) < min_res:
        ans = i
        min_res = abs(N * a - S)
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n; cin>>n;
    vector<ll> a(n+1), b(n);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    ll res=0;
    rep(i,n){
        if(a[i]<b[i]){
            res+=a[i];
            b[i]-=a[i];
            if(a[i+1]<b[i]){
                res+=a[i+1];
                a[i+1]=0;
            }else{
                res+=b[i];
                a[i+1]-=b[i];
            }
        }else{
            res+=b[i];
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, k, a[100100], res = 1<<30;

signed main() {
	cin >> n >> k;
	rep(i,n) cin >> a[i];
	sort(a,a+n);
	rep(i,n-k+1) chmin(res, a[i+k-1]-a[i]);
	cout << res << endl;
}

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

int main() {

    int n; cin >> n;

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

    int ans;
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = i;
        int tmpCnt = 0;
        while (true) {
            if (tmp % 2 == 0) {
                tmpCnt++;
            }
            else {
                break;
            }            
            tmp /= 2;
        }
        if (cnt < tmpCnt) {
            cnt = tmpCnt;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> v0(n);
    std::vector<int> v1(n);
    for (int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        v0[i] = a;
        v1[i] = a;
    }
    int q;
    std::cin >> q;
    while(q--){
        int b, e;
        std::cin >> b >> e;
        for (int i = b; i < e; i++){
            int tmp = v0[i];
            v0[i] = v1[b + e - i - 1];
            v1[b + e - i - 1] = tmp;
        }
    }
    for (int i = 0; i < n; i++){
        std::cout << v0[i];
        if (i < n - 1) std::cout << " ";
    }
    std::cout << std::endl;
}


Measured memory_bytes: 3112
#include <stdio.h>

int main(void){
  long long N;
  scanf("%lld",&N);

  long long ans = 0;
  if(N != 1)
  if(N/(N-1) == N%(N-1)) ans += N-1;
  for (long long i = 2; i*i <= N; i++) {
    if(N%i == 0){
      if(N/(i-1) == N%(i-1)) ans += i-1;
      long long cur = N/i-1;
      if(N/cur == N%cur) ans += cur;
    }
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> a(N);

    for (int i = 0; i < N; ++i) {
        cin >> a[i].first;
        a[i].first *= N;
        a[i].second = i;
    }

    sort(a.begin(), a.end());
    int acc = 0;
    for (auto &&e: a) acc += e.first;
    int mean = acc / N;

    auto it = lower_bound(a.begin(), a.end(), make_pair(mean, 0));

    int ans;
    if (it == a.begin()) {
        ans = it->second;
    } else {
        int ud = it->first - mean, dd = mean - (it - 1)->first;
        if (ud >= dd) {
            auto itt = lower_bound(a.begin(), a.end(), make_pair((it-1)->first, 0));
            if (ud == dd) {
                ans = it->second > itt->second ? itt->second : it->second;
            } else {
                ans = itt->second;
            }
        } else {
            ans = it->second;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int MOD = 1e9 + 7;

int a[200005];
long long ps[200005];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	for (int i = 0; i < n; i++) {
		ps[i] = a[i];
		if (i - 1 >= 0) ps[i] = (ps[i] + ps[i - 1]) % MOD;
	}
	
	long long res = 0;
	
	for (int i = n - 1; i > 0; i--) {
		res = (res + 1LL * a[i] * ps[i - 1]) % MOD;
	}
	
	printf("%lld\n", res);
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    while (cin >> s) {
        const int n = s.size();
        int i = 0; VI ans(n);
        while (i < n) {
            int j = i;
            while (j < n && s[j] == 'R')
                j++;
            int k = j;
            while (k < n && s[k] == 'L')
                k++;
            const int x = j-i;
            const int y = k-j;
            int a = (x+y)/2;
            int b = x+y-a;
            if (a > b)
                swap(a,b);
            if (x > y) {
                if (x&1)
                    ans[j-1] = b, ans[j] = a;
                else
                    ans[j-1] = a, ans[j] = b;
            }
            else {
                if (y&1)
                    ans[j-1] = a, ans[j] = b;
                else
                    ans[j-1] = b, ans[j] = a;
            }
            i = k;
        }
        FOR(i,0,n)
            cout << ans[i] << ' ';
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Heuristics
{
    class Introduction
    {
        private static int GeneN = 50;

        private static int DayN;

        private static int ContestN = 26;

        private static int[] c;

        private static int[][] s;

        private static int sumC;

        class Gene
        {
            public int[] Contest;
            public int[] Score;
            public Gene()
            {
                Contest = new int[DayN + 1];
                Score = new int[DayN + 1];
            }
        }

        public static void Score(int[] t, int[] v)
        {
            var last = new int[DayN + 1];
            var sum = c.Sum();
            var dec = 0;
            v[0] = 0;
            for (int i = 1; i <= DayN; i++)
            {
                dec += sum - (c[t[i]] * (i - last[t[i]]));
                last[t[i]] = i;
                v[i] = v[i-1] - dec + s[i][t[i]];
            }
        }

        public static void Main()
        {
            DayN = int.Parse(Console.ReadLine());
            c = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            c.Select((index, x) => (index: index, c: x)).OrderByDescending(x => x.c);

            sumC = c.Sum();

            s = new int[DayN + 1][];

            List<int[]> gene = new List<int[]>();

            var random = new Random();

            var seed = Enumerable.Range(0, 26);

            
            seed.OrderBy(x => random.Next());


            var t = new int[DayN + 1];
            for (int i = 1; i <= DayN; i++)
                s[i] = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            t = InitByGreedy();
            for (int i = 1; i <= DayN; i++)
                Console.WriteLine(t[i] + 1);
        }


        private static int[] InitByGreedy()
        {
            var gene = new int[DayN + 1];
            var last = new int[ContestN];
            for (int i = 1; i <= DayN; i++)
            {
                int max = int.MinValue;
                int maxIndex = 0;
                for (int j = 0; j < ContestN; j++)
                {
                    var temp = s[i][j] - c[j] * (i - last[j]);
                    if (max < temp)
                    {
                        max = temp;
                        maxIndex = j;
                    }
                }
                last[maxIndex] = i;
                gene[i] = maxIndex;
            }
            return gene;
        }
    }
}


Measured memory_bytes: 28928
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

constexpr auto INF = 1000;

int H, W;
vector<vector<bool>>maze;


int main()
{


	cin >> H;
	cin >> W;

	maze = vector<vector<bool>>(H, vector<bool>(W,false));

	auto cost = vector<vector<int>>(H*W, vector<int>(H*W,INF));


	for (int i = 0; i <  H; i++) {
		string tmp;
		cin >> tmp;
		for (int j = 0; j < W; j++) {
			maze[i][j] = (tmp[j] == '.');
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {

			cost[i*W + j][i*W + j] = 0;
			if (!maze[i][j]) { continue; }

			if (i < H - 1 && maze[i + 1][j]) {
				cost[i*W + j][(i+1)*W + j] = 1;
				cost[(i + 1)*W + j][i*W + j] = 1;
			}


			if (j < W - 1 && maze[i][j+1]) {
				cost[i*W + j][i*W + j+1] = 1;
				cost[i*W + j+1][i*W + j] = 1;
			}
		}
	}


	for (int k = 0; k < W*H; k++) {
		for (int j = 0; j < W*H; j++) {
			for (int i = 0; i < W*H; i++) {
				if (cost[i][j] > cost[i][k] + cost[k][j]) {
					cost[i][j] = cost[i][k] + cost[k][j];
				}
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < W*H; i++) {
		for (int j = 0; j < W*H; j++) {
			if (cost[i][j] < INF) {
				ans = max(ans, cost[i][j]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 896
import numpy as np


def count_pair(x):
    # A内のペアで積がxより小さいものの個数
    # まず(i,j)と(j,i)を重複して数える
    cnt = 0
    # A[i]<0なる各iに対してA[j]>x/A[i]なるjの個数
    cnt += (N-np.searchsorted(A, x//A_nega, side='right')).sum()
    if x > 0:
        # 各iに対してA[j]=0なるjの個数
        cnt += len(A_zero)*N
    # A[i]>0なる各iに対してA[j]<x/A[i]なるjの個数
    cnt += np.searchsorted(A, -(-x//A_posi), side='left').sum()
    # i=jを除いてから2で割る
    cnt = (cnt-(A**2 < x).sum())//2
    return cnt


# count_pair(x)<Kをみたすxの最大値を二分探索で求める
N, K = map(int, input().split())
* A, = map(int, input().split())
A = np.array(A)
A = np.sort(A)
A_posi = A[A > 0]
A_zero = A[A == 0]
A_nega = A[A < 0]
inf = 10**18+1
l, r = -inf, inf
while r - l > 1:
    c = (l + r) // 2
    if count_pair(c) < K:
        l = c
    else:
        r = c
print(l)


Measured memory_bytes: 32312