akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s[71];
const int dx[]={0,1},dy[]={1,0};
string dp[71][71];
string ans;
int w,h;
bool cmp(const string& a,const string& b){
    if(a.size()!=b.size()) return a.size()<b.size();
    else{
        rep(i,a.size()){
            if(a[i]>b[i]){
                return false;
            }
            else if(a[i]<b[i]) return true;
        }
    }
    return false;
}
string dfs(int x,int y){
    if(dp[y][x]!="."){
        return dp[y][x];
    }
    string ret;
    ret+=s[y][x];
    rep(i,2){
        int tx=x+dx[i],ty=y+dy[i];
        if(tx>=0&&ty>=0&&tx<w&&ty<h&&isdigit(s[ty][tx])){
            ret=max(ret,s[y][x]+dfs(tx,ty),cmp);
        }
    }
    return dp[y][x]=ret;
}
int main(){
    while(cin>>w>>h,w){
        rep(i,h)rep(j,w) dp[i][j]=".";
        rep(i,h) cin>>s[i];
        ans="";
        rep(i,h)rep(j,w)if(isdigit(s[i][j])&&s[i][j]!='0'){
            ans=max(ans,dfs(j,i),cmp);
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3328
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var h     = ulong.Parse(spl[0]);
        var w     = ulong.Parse(spl[1]);

        if (h == 1 || w == 1) return 1;

        var x = (h * w);
        if (x % 2 == 0) return x / 2;
        else return (x / 2) + 1;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0)
    {
        cout<<t*(n/x);
    }
    else
    {
        cout<<t*(n/x+1);
    }
    
}


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

#define PI 3.141592653589
int main(){
        double r;
        cin >> r;
        cout << fixed << setprecision(20) << PI * r * r << " ";
        cout << fixed << setprecision(20) << PI * 2 * r << endl;
        return 0;
}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e5+10;

int main(){
    int n,x,t;
    in>>n>>x>>t;

    out<<(n+x-1)/x*t;
    return 0;
}

Measured memory_bytes: 3568
import sys

MOD = 10 ** 9 + 7

def make_table(size=10**6, p=MOD):
    fac = [None] * (size + 1)
    fac[0] = 1
    for i in range(size):
        fac[i+1] = fac[i] * (i + 1) % p
    ifac = [None] * (size + 1)
    ifac[size] = pow(fac[size], p-2, p)
    for i in range(size, 0, -1):
        ifac[i-1] = ifac[i] * i % p
    return fac, ifac

fac, ifac = make_table(10**5)

def comb(n, r, mod=MOD):
    if r > n or r < 0:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

n, k, *a = map(int, sys.stdin.read().split())
a.sort()

def main():
    if k == 1:
        return 0

    ma = 0
    mi = 0
    for i in range(n):
        ma += a[i] * comb(i, k-1) % MOD
        ma %= MOD
        mi += a[i] * comb(n-1-i, k-1) % MOD
        mi %= MOD
    
    return (ma - mi) % MOD

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

Measured memory_bytes: 21996
import sys
from numba import njit
input = sys.stdin.buffer.readline

K = int(input())

A, B = map(int, input().split())


@njit
def main(K, A, B):
    for i in range(A, B + 1):
        if i % K == 0:
            print('OK')
            return 0
    print('NG')
    return 0


if __name__ == '__main__':
    main(K, A, B)


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

int main(){
    long long N, M;
    cin >> N >> M;
    
    vector<pair<long long, long long>> p(M);
    for(int i = 0; i < M; ++i)cin >> p[i].first >> p[i].second;
    sort(p.begin(), p.end());
    
    long long ans(1), y(100000);
    for(auto t : p){
        if(y <= t.first){
            ++ans;
            y = t.second;
        }
        y = min(y, t.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=100005;
int a[MAXN],n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();sort(a+1,a+1+n);reverse(a+1,a+1+n);
	for(int i=1;i<n;i++)if(a[i+1]<i+1)
	{
		int f1=(a[i]-i)&1,u=i;
		while(u<n&&a[u+1]==i)++u;
		int f2=(u-i)&1;
		return puts((f1|f2)?"First":"Second"),0;
	}
	int f1=(a[n]-n)&1;
	puts(f1?"First":"Second");
	return 0;
}


Measured memory_bytes: 512
one = list(map(int, input().split()))
two = list(map(int, input().split()))
three = list(map(int, input().split()))
n = int(input())
out = [int(input()) for x in range(n)]


def judge(a_list):
    for i in a_list:
        if i not in out:
            return False

    return True


for_judge = [one, two, three]

for i in range(3):
    tmp = [one[i], two[i], three[i]]
    for_judge.append(tmp)


naname1 = [one[0], two[1], three[2]]
naname2 = [one[2], two[1], three[0]]

for_judge.append(naname1)
for_judge.append(naname2)

for a_list in for_judge:
    if judge(a_list):
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1000000000100000000;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, k, x, y; cin >> n >> k >> x >> y;
    if(n <= k)cout << x*n << ln;
    else cout << x*k+y*(n-k) << ln;
}

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


int main(void){
    long long x,k,d;
    cin>>x>>k>>d;
    if(x<0) x=x*-1;
    long long sho=x/d;
    if(sho<=k){
        if(sho%2==k%2) cout<<x%d<<endl;
        else cout<<abs(x%d-d)<<endl;
    }
    else cout<<x-k*d<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
struct Node{
  int key;
  struct Node *left;
  struct Node *right;  
  struct Node *p;
};

typedef struct Node *node; 

void insert(node);
void inorder(node);
void preorder(node);
node root=NULL,n[500000];
int main()
{
  int i,num,a; 
  char s[10];
  root= (node)malloc(sizeof(struct Node));
  scanf("%d",&num);
  for(i=0;i<num;i++){        
    n[i] = (node)malloc(sizeof(struct Node));

scanf("%s",s);    
if(s[0]=='i'){	

scanf("%d",&n[i]->key);		
 n[i]->right=NULL;
      n[i]->left=NULL;

insert(n[i]);

    }
     
 else {

   inorder(n[0]);
   printf("\n");
   preorder(n[0]);
 printf("\n");
}  

}

  return 0; 
}

void insert(node z){
 
 node x,y;     
  y = NULL; 
  x =root;
  

while (x!=NULL){
    y = x ;
    if (z->key < x->key)
      x = x->left; 
    else 
      x = x->right;
  } 
  z->p = y;
  if (y ==NULL) 
    root = z;
  else if (z->key < y->key)
    y->left = z ;
  else 
    y->right = z ;
}

void inorder(node u){
  if (u == NULL)
    return;
  inorder(u->left);
  printf(" %d",u->key);

inorder(u->right);


}

void preorder(node u){
  if (u == NULL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

}

Measured memory_bytes: 27944
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 200010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,wb;
    cin >> n >> wb;
    vector<ll> w(n),v(n);
    rep(i,n){
        cin >> w[i] >> v[i];
    }
    vector<vector<ll>> value(4);
    rep(i,n){
        value[w[i]-w[0]].push_back(v[i]);
    }
    rep(i,4) RSORT(value[i]);
    ll ans = 0;
    rep(a,value[0].size()+1){
        rep(b,value[1].size()+1){
            rep(c,value[2].size()+1){
                rep(d,value[3].size()+1){
                    if (w[0]*(a+b+c+d)+b+2*c+3*d > wb) continue;
                    ll cnt = 0;
                    rep(i,a) cnt += value[0][i];
                    rep(i,b) cnt += value[1][i];
                    rep(i,c) cnt += value[2][i];
                    rep(i,d) cnt += value[3][i];
                    chmax(ans,cnt);
                }
            }
        }
    }
    PRINT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL              long long
#define ll              long long
#define SL(n)           scanf("%lld",&n)
#define LF              double
#define SF(n)           scanf("%lf",&n)

#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define ON(n,i)         (n|(1LL<<i))
#define OFF(n,i)        (n&(~(1LL<<i)))
#define CHK(n,i)        (n&(1LL<<i))

#define SET(arr)        memset( arr , -1 , sizeof arr)
#define RESET(arr)      memset( arr,0,sizeof arr)

#define srt(v)          sort(v.begin(),v.end())
#define uniq(v)			v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define found( s,d )    (s.find(d) != s.end())

#define FOR(i,s,e)      for( LL i = s ; i<=e ; i++ )

#define FILEIN          freopen("in.txt","r",stdin)
#define FILEOUT         freopen("out.txt","w",stdout)

/// DEBUG
#define deb             printf("OKA\n")
/// DEBUG ENDSk

using namespace std;



int main(){
       
     LF L;
     SF(L);
     LF a = L/3.0;
     printf("%.8f\n", a*a*a);

return 0;}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long

string s;
int n;
LL cnt[26];
LL mod = 1000000007;

int main(){
  cin>>n;
  cin>>s;
  REP(i,n){
    cnt[(int)(s[i]-'a')]++;
  }
  LL ret=1LL;
  REP(i,26){
    ret=(ret*(1+cnt[i]))%mod;
  }
  cout<<(ret-1)<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int n, x, k;
  int total = 0;
  scanf("%d %d", &n, &x);

  for(int i = 0; i < n; ++i){
    scanf("%d", &k);
    if(k >= x)
    ++total;
  }

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

  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

m1 = sum(A) - 2 * sum([x for i, x in enumerate(A) if i % 2 == 1])
ans = [m1]
for i in range(N-1):
    ans.append((A[i] - ans[-1] // 2) * 2)
print(*ans, sep=' ')

Measured memory_bytes: 70372
(*q,D,A),*X=$<.map{|l|l.split.map &:to_i}
c=z=l=0
X.sort!.map{|x,h|c+=q[l+=1]while X[l][0]+2*D<x
q<<t=[c+z+-h/A,0].min
z-=t}
p z

Measured memory_bytes: 22376
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s1[1000005];
ll dp[1000005][2];
int main()
{
	scanf("%s",s1);
	int n=strlen(s1);
	ll ans=0;
	dp[n-1][0]=s1[n-1]-'0';
	dp[n-1][1]=10-dp[n-1][0];
	for(int i=n-2;i>=0;i--)
	{
		int k=s1[i]-'0';
		int s=10-k;
		dp[i][0]=min(dp[i+1][0],dp[i+1][1]+1)+k;//因下一位没给钱,且次位给钱,需占一位本位钱,固多 
		dp[i][1]=min(dp[i+1][0],dp[i+1][1]-1)+s; //因下一位没有给钱,且次位不给钱,导致本位获得钱少
//		printf("**%lld**%lld**\n",dp[i][0],dp[i][1]); 
	}
	printf("%lld\n",min(dp[0][0],dp[0][1]+1));//最高位不给钱,需额外一张大钱 
	return 0;
}

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

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.bigin(), a.end())
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Srep(i,a,n) for(int i = (a); i < (n); i++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int n, h, high, ans = 1;
    cin >> n;
    cin >> high;
    rep(i,n-1){
        cin >> h;
        if(h >= high){
            high = h;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3472
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
#define INF 100000000
using namespace std;
typedef pair<int,int> P;
int main()
{
	int n,m,re[500][500],df[500],idf[500];
	while(cin>>n>>m&&(n!=0||m!=0)){
		int ans=0;
		fill(re[0],re[500],-1);
		fill(df,df+500,0);
		fill(idf,idf+500,0);
		for(int i=0;i<n;i++)re[i][i]=0;
		for(int i=0;i<m;i++){
			int a,b;cin>>a>>b;a--;b--;
			re[a][b]=re[b][a]=1;
		}
		for(int i=0;i<n;i++){
			if(re[0][i]==1){df[i]=1;ans++;}
		}
		for(int i=0;i<n;i++){
			if(df[i]!=1)continue;
			for(int j=1;j<n;j++){
				if(df[j]==1||idf[j]==1)continue;
				if(re[i][j]==1){ans++;idf[j]=1;}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 2136
#include <iostream>
using namespace std;
typedef long long ll;
ll N,K;
int main(){
	cin >> N >> K;
	if(K==2){
		cout << ((N+1)/2)*((N+1)/2)*((N+1)/2)+(N/2)*(N/2)*(N/2) << endl;
	}else if(K%2==1){
		cout << (N/K)*(N/K)*(N/K) << endl;
	}else{
		ll t = K/2;
		cout << (N/K)*(N/K)*(N/K) + (N/t-N/K)*(N/t-N/K)*(N/t-N/K) << endl;
	}
}

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

using namespace std;
const int N=1e6+55;
int dp[105][N];
int w[105];
int v[105];
int n,W;

int bt(int i , int j)
{
	if(i==-1)
	{
		if(j==0)
			return 0;
		return (int)1e9+55;
	}
	int &ret=dp[i][j];
	if(dp[i][j]!=-1)
		return ret;
	ret=bt(i-1,j);
	if(j-v[i]>=0)
		ret=min(bt(i-1,j-v[i])+w[i],ret);
	return ret;
}

main()
{
	cin>>n>>W;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
		sum+=v[i];
	}
	memset(dp,+1,sizeof dp);
	for(int i=0;i<=n;i++)
	dp[i][0]=0;
	int ans=0;
	for(int j=1;j<=sum;j++)
	{
		for(int i=1;i<=n;i++)
		{
			dp[i][j]=dp[i-1][j];
			if(j>=v[i])
			{
				dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
			}
			if(dp[i][j]<=W)
				ans=j;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 820608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>
#include<queue>
using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int binary_search2(vector<ll> &l,ll key){
  ll left=0;
  ll right=l.size()-1;
  ll mid;
  if(l[right]<key)return right;
  else{
  while(right-left>1){
    mid=(right+left)/2;
    if(l[mid]>=key)right=mid;
  else left=mid;
  }
  }
return left;
}

bool judge(vector<ll>a,vector<ll>f,ll key,ll k,ll n){
  ll sum=0;
  for(int i=0;i<n;i++){
    if(key<a[i]*f[n-1-i]){
    sum+=a[i]-key/f[n-i-1];
    }
  }
  return sum<=k;
}
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> a(n);
  vector<ll> f(n);
  vector<ll> mul(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>f[i];
  ll max=0;
  ll sum=0;
  queue<int> que;
  rep(i,n){
    if(max<a[i]*f[n-i-1])max=a[i]*f[n-i-1];
    sum+=a[i];
  }
  if(k>=sum){
    cout<<0<<endl;
    return 0;
  }
  sort(a.begin(),a.end());
  sort(f.begin(),f.end());
  
  ll left,right;
  left=0;
  right=max;
  ll mid;
  //  ll mid=(left+right)/2;
  while(right-left>1){
    mid=(left+right)/2;
    if(judge(a,f,mid,k,n))right=mid;
    else left=mid;
  }
  cout<<right<<endl;
  return 0;
}


Measured memory_bytes: 8120
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

bool table[26];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int H,W;cin>>H>>W;
    string s[100];
    REP(i,H) cin >> s[i];
    REP(i,W+2) cout<<'#';
    cout <<'\n';
    REP(i,H){
        cout << "#"+s[i]+"#" << '\n';
    }
    REP(i,W+2) cout<<'#';
    cout << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(int argc, const char * argv[]) {
    
    
    int a,b,c,x,y;
    
    scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
    
    if(a+b>2*c){//c를 먼저 다사
        
        if(x>y){ //추가로 a피자
            int sum = 2*c*y;
            
            if(a<2*c){
                sum+=a*(x-y);
            }else{
                sum+=2*c*(x-y);
            }
            printf("%d\n",sum);
        }else{//추가로 b피자
            //
            int sum = 2*c*x;
            
            if(b<2*c){
                sum+=b*(y-x);
            }
            else{
                sum+=2*c*(y-x);
            }
            
            printf("%d\n",sum);
        }
    }else{
        printf("%d\n",a*x+b*y);
    }
    
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(s)-1,i##_len=(int)(n);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}


int main() {
	int H,W,h, w;
	scanf("%d%d%d%d", &H, &W, &h, &w);

	PRINTD(H*W - (h*W+w*H-h*w));
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string O,E;
  cin >> O >> E;
  
  for(int i = 0; i < E.size(); i++){
    cout << O[i] << E[i];
  }
  if(O.size() != E.size()){
    cout << O[O.size() - 1];
  }
  
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

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

        Set<Long> divisors = new TreeSet<>(Collections.reverseOrder());
        for (long i = 1; i <= (long) Math.sqrt(M); i++) {
            if (M % i == 0) {
                divisors.add(i);
                divisors.add(M / i);
            }
        }

        // p(a1' + a2' + ... + aN') = M
        // となる最大のpを求める
        for (long p : divisors) {
            if (M % p == 0 && M / p >= N) {
                out.println(p);
                return;
            }
        }
    }
}

Measured memory_bytes: 23380
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int cnt[10];
int main() {
	for (int i=0; i<4; i++) {
		int x; cin >> x;
		cnt[x]++;
	}

	bool ans = cnt[1]==1 && cnt[9]==1 && cnt[7]==1 && cnt[4]==1;
	puts(ans ? "YES" : "NO");



	return 0;
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))
ans=0

for i in range(n):
  minj=i
  for j in range(i+1,n):
    if A[j]<A[minj]:
      minj=j
  if i==minj: continue
  tmp=A[i]
  A[i]=A[minj]
  A[minj]=tmp
  ans+=1
print(*A)
print(ans)



Measured memory_bytes: 5608
n = int(input())
alphabet = [chr(i) for i in range(97, 97+26)]
result = ''
ans = 0

while n > 0:
    if n % 26 == 0:
        ans = 25
    else:
        ans = n % 26 - 1
    result = alphabet[ans] + result
    n = (n-ans) // 26

print(result)

Measured memory_bytes: 9084
def main(argv)
  n = gets.chomp.to_i

  playlist = []
  n.times do
    (s, t) = gets.chomp.split(' ')
    playlist.push({:name => s, :time => t.to_i})
  end

  x = gets.chomp
  sleep = 0
  flag = false
  n.times do |i|
    if flag then
      sleep += playlist[i][:time]
    else
      flag = true if playlist[i][:name] == x
    end
  end
  puts sleep.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

template<typename F> double bsearch(double ok, double ng, ll loop, F f) {
	REP(i, loop) {
		double middle = (ok + ng) / 2;
		(f(middle) ? ok : ng) = middle;
	}
	return ok;
}


int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m; cin >> n >> m;
	vvl path(n);
	REP(i, m) {
		ll a, b; cin >> a >> b;
		a--, b--;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	REP(i, n) {
		if (path[i].size() % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
graph G(100005);
int gIndex[100005];
int init(){
    for(int i = 0; i < 100005; i++){
        G[i] = vector<ll>(0);
        gIndex[i] = -1;
    }
}
int solve(int x,int id){
    if(gIndex[x] != -1){
        return 0;
    }
    gIndex[x] = id;
    for(int i = 0; i < G[x].size(); i++){
        solve(G[x][i],id);
    }
}
int main() {
    ll N,M;
    cin >> N >> M;
    init();
    ll p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
        p[i]--;
    }
    for(int i = 0; i < M; i++){
        ll x,y;
        cin >> x >> y;
        x--;y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for(int i = 0; i < N; i++){
        solve(i,i);
    }
    ll result = 0;
    for(int i = 0; i < N; i++){
        if(gIndex[p[i]] == gIndex[i]){
            result++;
        }
    }
    cout << result << endl;

}


Measured memory_bytes: 8960
template<int Size = 1000000, typename WeightType = int>
class WeightedUnionFind {
    int par[Size], rank[Size], sizes[Size];
    WeightType wei[Size];
    
public:
	WeightedUnionFind() = default;
	WeightedUnionFind(const WeightedUnionFind&) = default;
	WeightedUnionFind(WeightedUnionFind&&) = default;
	WeightedUnionFind& operator = (const WeightedUnionFind&) = default;
	WeightedUnionFind& operator = (WeightedUnionFind&&) = default;
 
    WeightedUnionFind(int size) {
		init(size);
	}
 
	void init(int size) {
        for(int i = 0; i < size; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizes[i] = 1;
            wei[i] = 0;
        }
    }
    
    int find(int x) {
        if(par[x] == x) {
            return x;
        }else {
            int p = find(par[x]);
            
            wei[x] += wei[par[x]];
            
            return par[x] = p;
        }
    }
    
    WeightType weight(int x) {
        find(x);
        
        return wei[x];
    }
    
    void unite(int x, int y, WeightType w) {
        w += weight(x); 
        w -= weight(y);
        x = find(x);
        y = find(y);
        
        if(x == y) return;
        
        if(rank[x] < rank[y]) {
            par[x] = y;
            sizes[y] += sizes[x];
            wei[x] = -w;
        }else {
            par[y] = x;
            sizes[x] += sizes[y];
            wei[y] = w;
            if(rank[x] == rank[y]) ++rank[x];
        }
    }
    
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    
    int size(int x) {
        return sizes[find(x)];
    }
    
    WeightType diff(int x, int y, WeightType disabledVal = static_cast<WeightType>(-1)) {
        if(!same(x, y)) {
            return disabledVal;
        }
        
        return weight(x) - weight(y);
    }
};

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>

int n;

int main() {
    while(std::cin >> n, n) {
        std::string tmp, lhs, rhs, times_raw;
        int cnt = 0;
        std::map<std::string, int> units;
        WeightedUnionFind<256> tree(n * 2);
        bool flag = true;
        
        for(int i = 0; i < n; ++i) {
            std::cin >> tmp >> lhs >> tmp >> times_raw >> rhs;
            
            if(!flag)
                continue;
            
            int times = std::stoi(times_raw.substr(times_raw.find("^") + 1));
            int l, r;
            if(units.count(lhs)) {
                l = units[lhs];
            }else {
                l = units[lhs] = cnt, ++cnt;
            }
            
            if(units.count(rhs)) {
                r = units[rhs];
            }else {
                r = units[rhs] = cnt, ++cnt;
            }
            if(tree.same(l, r)) {
                if(tree.diff(l, r) != times) {
                    flag = false;
                }
            }else {
                tree.unite(r, l, times);
            }
        }
        
        std::cout << (flag ? "Yes" : "No") << std::endl;
    }
}

Measured memory_bytes: 3192
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
A = A + [0,0,0,0]
for i,a in enumerate(A):
    if a == A[i+1]:
        ans = a
        i = i+2
        break
for j,a in enumerate(A[i:],i):
    if a == A[j+1]:
        ans *= a
        break
print(ans)

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll K, A, B;
    bool flag = false;
    cin >> K >> A >> B;
    for(ll i = 1;i <= 2000;i++) {
        if(A <= K * i && K * i <= B) flag = true;
    }
    cout << (flag ? "OK" : "NG") << endl;
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
count = 0
T,X,Y = 0,0,0
for i in range(n):
    t, x, y = map(int, input().split())
    if abs(X-x)+abs(Y-y) <= abs(T-t) and t%2==(x+y)%2:
        count += 1
    T,X,Y = t,x,y
print("Yes" if count==n else "No")

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int s;
    double w, h;
 
    while(scanf("%d, %lf, %lf", &s, &w, &h) != EOF){
        double BMI;
        BMI = w / pow(h, 2);
        if(BMI >= 25){
            cout << s << endl;
        }
    }
}


Measured memory_bytes: 3204
#include"bits/stdc++.h"
using namespace std;

int main(){
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0;i < N;++i) {
		for (int j = 0;j < D;++j) {
			cin >> X.at(i).at(j);
		}
	}
	int ans = 0;
	for (int i = 0;i < N-1;++i) {
		for (int j = i + 1;j < N;++j) {
			int x = 0;
			for (int k = 0;k < D;++k) {
				x += pow(X.at(i).at(k) - X.at(j).at(k), 2);
			}
			if (x == pow((int)sqrt(x),2)) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll N; cin >> N;
  ll p10 = 1; rep(i,N) p10 = p10 * 10 % MOD;
  ll p9 = 1; rep(i,N) p9 = p9 * 9 % MOD;
  ll p8 = 1; rep(i,N) p8 = p8 * 8 % MOD;

  ll result = ((p10-p8-(p9-p8)*2)%MOD+MOD)%MOD;
  cout << result << endl;
  return 0;
}

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

long long gcd(long long a, long long b){
    if(a>b) swap(a,b);
    long long c = b%a;
    if(c == 0) return a;
    else return gcd(c,a);
}

long long lcm(long long a, long long b){
    long long g = gcd(a,b);
    return (a/g)*(b/g)*g;
}

int main(){
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long E = lcm(C,D);
    long long n = (B/C - (A-1)/C) + (B/D - (A-1)/D) - (B/E -(A-1)/E);
    cout << (B-A+1-n) << endl;
    return 0;
}


Measured memory_bytes: 256
table = [
  "", "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL",
  "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"
]

while line = gets
  puts line.chomp.split("").each_with_object([]) { |i, a|
    !a.last.nil? && a.last[0] == i.to_i ? a.last[1] += 1 : a << [i.to_i, 0]
  }.map { |chr, i|
    if chr == 0
      i == 0 ? "" : " " * i
    else
      table[chr][i % table[chr].size]
    end
  }.join
end

Measured memory_bytes: 8764
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define HASH 18014398241046527
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}



void SOLVE(){
    ll A, B, n;
    cin >> A >> B >> n;
    ll x = min(B-1, n);
    cout << ((A*x/B) - A*(x/B)) << '\n'; 
}

int main() {
	fastIO();
	// #ifndef ONLINE_JUDGE
    //     freopen("i.txt", "r", stdin);
    //     freopen("o.txt", "w", stdout);
	// #endif
 
    ll TC;
    // cin >> TC;
    TC = 1;
    for(ll tc1=1; tc1<=TC; tc1++){
        SOLVE();
    }
    printclock;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
#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(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  vi A(N); REP(i,N) cin >> A[i];

  set<int> written;
  REP(i,N) {
    if (!written.count(A[i])) {
      written.insert(A[i]);
    }
    else {
      written.erase(A[i]);
    }
  }

  cout << written.size() << endl;
}

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

long long n,k,a[100010],ji,ans=2e18,l,r,gg;
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;++i)
	scanf("%lld",&a[i]);
	a[n+1]=0;
	++n;
	gg=k;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		if(ji==0&&a[i]==0)
		{
			ji=i;
			break;
		}		
	}
	if(ji+k<=n)
	{
		ans=min(ans,a[ji+k]);
		gg=1;
		while(ji-gg>0&&gg<=k)
		{
			ans=min(ans,a[ji+k-gg]-2*a[ji-gg]);
			++gg;
		}
	}
	else if(ji-k>=1)
	{
		ans=min(ans,-a[ji-k]);
		gg=1;
		while(ji+gg<=n&&gg<=k)
		{
			ans=min(ans,-a[ji-k+gg]+2*a[ji+gg]);
			++gg;
		}
	}
	else
	{
		ans=min(ans,a[n]-2*(a[n-k]));
//		cout<<ans<<endl;
		l=n-k;
		gg=1;
		while(l-gg>0&&gg<=k)
		{
			ans=min(ans,a[l+k-gg]-2*a[l-gg]);
			++gg;
		}
//		cout<<ans<<endl;
//		cout<<k<<" "<<ji<<endl;
		ans=min(ans,-a[1]+2*(a[k+1]));
//		cout<<ans<<endl;
		l=k+1;
		gg=1;
		while(l+gg<=n&&gg<=k)
		{
			ans=min(ans,-a[gg+1]+2*a[l+gg]);
			++gg;
		}
//		cout<<ans<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
//using namespace atcoder;

int main() {
	int N;
	cin >> N;
	int pmax=0, pmin=2*pow(10,9)+1, mmax=0, mmin=2*pow(10,9)+1;
	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		int p = x + y, m = y - x;
		pmax = max(pmax, p);
		pmin = min(pmin, p);
		mmax = max(mmax, m);
		mmin = min(mmin, m);
	}
	cout << max(pmax - pmin, mmax - mmin) << endl;
}


Measured memory_bytes: 3612
N,M = list(map(int, input().split()))
H = list(map(int, input().split()))

ans = [0]*N
for i in range(M):
    A,B = list(map(int, input().split()))
    if H[A-1] < H[B-1]:
        ans[A-1] -=1
    elif H[A-1] > H[B-1]:
        ans[B-1] -=1
    else:
        ans[A-1] -=1
        ans[B-1] -=1 
print(ans.count(0))

Measured memory_bytes: 20108
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
const ll mod=1e9+7;
const ll INF = 1e9;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b); 
}

bool is_prime(ll x){
    if(x==1) return false;
    for(ll i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

int main(){
    fast_io
    
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<int> cnt(3);
    rep(i,n) cin>>a[i];

    rep(i,n){
        if(a[i]%4==0) cnt[0]++;
        else if(a[i]%4%2) cnt[1]++;
        else cnt[2]++;
    }
    if(cnt[0]+cnt[1] == n && cnt[0]+1 == cnt[1]){
        cout<<"Yes"<<endl;
        return 0;
    }
    if(cnt[0]<cnt[1]) {
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b&&a!=c){
    cout<<"Yes"<<endl;
  }
  else if(a!=b&&a==c){
    cout<<"Yes"<<endl;
  }
  else if(b==c&&b!=a){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 3600
#include <cstdio>
const int N = 1e5 + 10;
int mi(int a, int b)
{
	return a < b ? a : b;
}
int n, m, T, a[N], b[N], x, y, c, ans, l = 1e9, r = 1e9;
int main()
{
	scanf("%d%d%d", &n, &m, &T);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		l = mi(l, a[i]);
	}
	for (int i = 1; i <= m; i++)
	{
		scanf("%d", &b[i]);
		r = mi(r, b[i]);
	}
	ans = l + r;
	while (T--)
	{
		scanf("%d%d%d", &x, &y, &c);
		ans = mi(ans, a[x] + b[y] - c);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll ans = -INF;
    vector<vector<int>> f(n,vector<int>(10));
    vector<vector<ll>> p(n,vector<ll>(11));
    rep(i,0,n){
        rep(j,0,10){
            cin >> f[i][j];
        }
    }
    rep(i,0,n){
        rep(j,0,11){
            cin >> p[i][j];
        }
    }
    vector<int> c(n,0);
    rep(bit,0,(1<<10)){
        c.assign(n,0);
        int flag = 0;
        rep(i,0,10){
            if(bit & (1<<i)){
                flag++;
                rep(j,0,n){
                    if(f[j][i]==1){
                        c[j]++;
                    }
                }
            }
        }
        if(flag==0) continue;
        ll ret = 0;
        rep(i,0,n){
            ret += p[i][c[i]];
        }
        chmax(ans,ret);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;
 
    //はじめはすべて根
    UnionFind(int N) {
        r = vector<int>(N, -1);
    }
    //根となる要素を返す
    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }
    //要素xとyの根が同じであれば結合不要→false
    //根が異なる場合は要素数が多い根xに、少ない根yをの要素数を足す
    //その後、yの根をxに置き換える
    //何でboolなんだろ
    //bool unite(int x, int y) {
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        //if (x == y) return false;
        if (x == y) return;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        //return true;
        return;
    }
    //xが含まれる木の要素数を返す
    int size(int x) {
        return -r[root(x)];
    }
}; 
 
int main() {
    int N, M;
    cin >> N >> M;
 
    //友達集合を作る
    UnionFind UF(N);
    for (int i = 0; i < M; i++)
    {
        int A, B;
        cin >> A >> B;
        A -= 1; B -= 1;
        UF.unite(A, B);
    }
 
    //最大の友達集合を求める
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans = max(ans, UF.size(i));
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4008
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
	int a, b; cin >> a >> b; cout << a - (a > b) << endl;
        return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include <string>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
#define nin(n) int n; cin >> n;
#define kin(k) int k; cin >> k;


int main() {
 int n;
  cin >> n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(n/2)-vec.at(n/2-1) << endl;
}

Measured memory_bytes: 640