akhauriyash/Code-Regression huggingface dataset:
program tenquestionseven
implicit none
integer N, i, res
integer,allocatable,dimension(:) ::A
res=1
read(*,*) N
allocate(A(N))
read(*,*) A
call heapsort(N,A)
 do i=1,N
  if ((A(i)).ne.(A(i+1))) res=res+1
 end do
 res=res-1
write(*,*) res
end program

subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n                           
  integer,intent(inout) :: array(1:n)     
  integer ::i,k,j,l
  double precision :: t
  
  if(n.le.0)then                                    
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return                                 

  l=n/2+1                                           
  k=n
  do while(k.ne.1)                                 
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1          
        endif
        if (t.lt.array(j))then                      
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		while (a % 2 == 0) {
			a >>= 1;
			ans++;
		}
	}
	cout << ans << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <algorithm>

int main()
{
  long long int n,x;
  scanf("%lld",&n);
  scanf("%lld",&x);
  long long int i;
  long long int a[n];
  for(i=0;i<n;i++) {
    scanf("%lld",&a[i]);
  }
  long long int counter = 0;
  while(x>=0 && counter < n) {
    long long int min = 10000000000;
    long long int id = 0;
    for(i=0;i<n;i++) {
      if(min > a[i] && a[i]!=0) {
        min = a[i];
        id = i;
      }
    }
    x = x-min;
    counter++;
    a[id] = 0;
  }
  if(x!=0) {
    counter--;
  }
  printf("%lld\n",counter);
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import division,print_function
import time
import sys
import io
import re
import math
start = time.clock()
i = 0
def walk(index,tm,L,d,f):
    tm+=1
    d[index]=tm
    for i in L[index]:
        if not d[i-1]:
            tm=walk(i-1,tm,L,d,f)
    tm+=1
    f[index]=tm
    return tm

def main():
    num=int(sys.stdin.readline())
    L=[]
    for _ in range(num):
        L.append([int(s) for s in sys.stdin.readline().split()[2:]])
    d=[0]*num
    f=[0]*num
    tm=0
    for i in range(num):
        if not d[i]:
            tm=walk(i,tm,L,d,f)
    for i in range(num):
        print(i+1,d[i],f[i])

main()

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    for (int i=0; i<n; ++i) {
        cin >> x.at(i);
    }

    sort(x.begin(), x.end());
    vector<vector<int>> modM(m);
    vector<int> cnt(m);
    int tmp = 0;
    for (int i=0; i<n; ++i) {
        if (i > 0 && x.at(i) != x.at(i-1)) {
            modM.at(x.at(i-1)%m).push_back(tmp);
            cnt.at(x.at(i-1)%m) += tmp;
            tmp = 1;
        } else {
            ++tmp;
        }
    }
    modM.at(x.back()%m).push_back(tmp);
    cnt.at(x.back()%m) += tmp;
    int res = 0;
    res += cnt.at(0) / 2;
    if (m%2 == 0) res += cnt.at(m/2) / 2;
    for (int i=1; i<=m/2; ++i) {
        int i0 = i, i1= m-i;
        if (i0 == i1) continue;
        if (cnt.at(i0) < cnt.at(i1)) swap(i0, i1);
        priority_queue<int> p;
        for (int x : modM.at(i0)) p.push(x);
        while (!p.empty() && cnt.at(i0) - 2 >= cnt.at(i1)) {
            int cur = p.top(); p.pop();
            if (cur > 1) {
                ++res;
                cnt.at(i0) -= 2;
                if (cur-2 > 0) p.push(cur-2);
            }
        }
        res += cnt.at(i1);
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 100005
#define MOD (int)(1e9+7)

using namespace std;

long long N,ans=1,dp[NMAX];
vector<int > p;

void solve(){
	for (int i = 0; i < N; ++i)
	{
		int k = p.size()+1;
		if(dp[i] >= 2*k-1){
			p.push_back(dp[i]);
			ans *= (k);
		}else{
			ans = ans * (k);
		}
		ans = ans % MOD;
	}
}

void answer(){
	printf("%lld\n",ans);
}

int main(){
	scanf("%lld",&N);
	for (int i = 0; i < N; ++i)
	{
		scanf("%lld",&dp[i]);
	}
	solve();
	answer();

	return 0;
}

Measured memory_bytes: 1660
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = new int[][](N, N);
    foreach (i; 0..N) A[i][] = -1;

    foreach (i; 0..N) {
        int a = readln.chomp.to!int;
        foreach (j; 0..a) {
            auto s = readln.split.map!(to!int);
            auto x = s[0] - 1;
            auto y = s[1];
            A[i][x] = y;
        }
    }

    int ans = 0;

    foreach (mask; 0..1<<N) {
        bool ok = true;
        foreach (i; 0..N) {
            if (mask & (1 << i)) {
                foreach (j, a; A[i]) {
                    if (a == 0) {
                        if (mask & (1 << j)) {
                            ok = false;
                            break;
                        }
                    } else if (a == 1) {
                        if (!(mask & (1 << j))) {
                            ok = false;
                            break;
                        }
                    }
                }
                if (!ok) {
                    break;
                }
            }
        }
        if (ok) ans = max(ans, mask.popcnt);
    }

    ans.writeln;
}

Measured memory_bytes: 380
x_max, y_max, N = map(int, input().split())
x_min, y_min = 0, 0
l = [[int(i) for i in input().split()] for _ in range(N)]
for i in range(N):
  if l[i][2] == 1:
    x_min = max(x_min, l[i][0])
  elif l[i][2] == 2:
    x_max = min(x_max, l[i][0])
  elif l[i][2] == 3:
    y_min = max(y_min, l[i][1])
  elif l[i][2] == 4:
    y_max = min(y_max, l[i][1])
if x_max-x_min > 0 and y_max-y_min:
  print((x_max-x_min)*(y_max-y_min))
else:
  print(0)
  

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

int main() {
  int N;
  cin >> N;
  
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i) >> B.at(i);
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  
  sort(B.begin(),B.end());
  
  cout << A.at(0)+B.at(0) << endl;
  
}

Measured memory_bytes: 4032
N = int(input())
L1 = 2
L2 = 1
L3 = 3
if N == 0:
    print(L1)
elif N == 1:
    print(L2)
else:
    for i in range(N-2):
        L1 = L3
        L3 += L2
        L2 = L1
    print(L3)


Measured memory_bytes: 2940
var n,i,j,tot,ans:longint;
    a:array[0..100007] of longint;
procedure qsort(lx,rx:longint);
var i,j,m,t:longint;
begin
  i:=lx;j:=rx;m:=a[random(rx-lx+1)+lx];
  repeat
	while (a[i]<m) do inc(i);
	while (a[j]>m) do dec(j);
	if (i<=j) then
	begin
	  t:=a[i];a[i]:=a[j];a[j]:=t;
	  inc(i);dec(j);
	end;
  until (i>j);
  if (i<rx) then qsort(i,rx);
  if (j>lx) then qsort(lx,j);
end;
begin
  randomize;
  readln(n);
  fillchar(a,sizeof(a),0);
  for i:=1 to n do
	read(a[i]);
  readln;
  qsort(1,n);
  tot:=0;
  for i:=2 to n do
	if (a[i]=a[i-1]) then inc(tot);
  ans:=n-tot;
  tot:=tot mod 2;
  if (tot=1) then dec(ans);
  writeln(ans);
end.
	

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int k = sc.nextInt();
		
		char tmp = s.charAt(k - 1);
		
		StringBuilder sb = new StringBuilder();
		
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == tmp) {
				sb.append(tmp);
			} else {
				sb.append('*');
			}
		}
		
		System.out.printf(sb.toString());
	}
}


Measured memory_bytes: 21844
def bubble_sort(A, n):
	for i in range(n):
		for j in range(n-1, i, -1):
			if A[j][1] < A[j-1][1]:
				A[j], A[j-1] = A[j-1], A[j]

	print(' '.join(A))

def selection_sort(A, n):
	for i in range(n):
		minj = i
		for j in range(i, n):
			if A[j][1] < A[minj][1]:
				minj = j
		if i != minj:
			A[i], A[minj] = A[minj], A[i]

	print(' '.join(A))

if __name__ == '__main__':
	n = int(input())
	A = list(input().split())
	B = A[:]

	bubble_sort(A, n)
	print('Stable')

	selection_sort(B, n)
	print('Stable' if A == B else 'Not stable')

Measured memory_bytes: 7736
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  ll a[n+1]={},b[n+1]={};
  ll sum[n+1]={};
  vector<pair<ll,pair<ll,ll>>> v;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    sum[i]=a[i]+b[i];
    v.push_back(make_pair(sum[i],make_pair(a[i],b[i])));
  }
  sort(sum,sum+n);
  reverse(sum,sum+n);
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  ll ansa=0,ansb=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      ansa+=v[i].second.first;
    }else{
      ansb+=v[i].second.second;
    }
  }

  cout<<ansa-ansb<<endl;

  return 0;
}


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

#define ll long long int 
#define oo (1L<<60)

int N; int CAP;
ll memo [100005][100];
int pesos [100005];
int valores [100005];

ll mochila(int cap, int it){
	if(cap < 0) return -oo;
	if(!cap || it == -1) return 0;
	if(memo[cap][it]) return memo[cap][it];
	return memo[cap][it] =max(mochila(cap, it-1), 
							  valores[it]+mochila(cap-pesos[it], it-1));
}

int main() {
	cin>>N>>CAP;
	for(int i = 0; i<N;i++)
		cin>>pesos[i]>>valores[i];
	cout<<mochila(CAP, N-1)<<endl;
	return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll A, B, C;
    cin >> A >> B >> C;

    if(A+B >= C){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin >>n >>m;
    int a[n][m];
    int b[m];
    int c[n] = {};
    for (int i=0; i<n;i++){
        for (int j=0; j<m;j++){
            cin >>a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        cin >>b[i];
    }
    for (int i=0;i<n; i++){
        for (int j=0; j<m; j++ ){
            c[i] += a[i][j]*b[j];
        }
    }
    for (int i=0; i<n; i++){
        cout <<c[i]<<endl;
    }
}



Measured memory_bytes: 3108
n = gets.to_i
f = n.times.map{gets.chomp.split(" ").map(&:to_i)}
p = n.times.map{gets.chomp.split(" ").map(&:to_i)}
combi = Array.new(10,0)
ans = -10**n
for i in 1..1023
  sum = 0
  10.times do |j|
    combi[j] = i%2
    i /= 2
  end
  for j in 0..n-1
    same = 0
    10.times do |k|
      if combi[k] == 1 && f[j][k] == 1
        same += 1
      end
    end
    sum += p[j][same]
  end
  ans = [ans,sum].max
end
p ans

Measured memory_bytes: 1788
#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;
const int maxn = 12;
const int maxm = 1e3+3;
int n,m, W[maxm], V[maxm], dp[maxm][1<<maxn];

int dfs(const int i, const int mask)
{
    if (i == m) {
        if (mask+1 == (1<<n))
            return 0;
        else
            return inf;
    }
    int& ans = dp[i][mask];
    if (-1 == ans) {
        ans = inf;
        ans = min(ans, W[i]+dfs(i+1,mask|V[i]));
        ans = min(ans, dfs(i+1,mask));
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> m) {
        memset(dp,-1,sizeof(dp));
        FOR(i,0,m) {
            int a,b; cin >> a >> b;
            int value = 0;
            FOR(_,0,b) {
                int c; cin >> c; c--; value |= (1<<c);
            }
            V[i] = value;
            W[i] = a;
        }
        const int ans = dfs(0,0);
        cout << (ans < inf ? ans : -1) << endl;
    }
    return 0;
}



Measured memory_bytes: 16384
#include<stdio.h>
#define MAX 2000010
#define OVERMIN -1

int heap[MAX];
int H = 0;

void swap(int i, int j) {
	int buf = heap[i];
	heap[i] = heap[j];
	heap[j] = buf;
}

void maxHeap(int H, int i) {
	int l = 2 * i, r = 2 * i + 1;
	int largest = i;
	if (l <= H && heap[l] > heap[i])largest = l;
	if (r <= H && heap[r] > heap[largest])largest = r;
	if (largest != i) {
		swap(i, largest);
		maxHeap(H, largest);
	}
}

void InsertKey(int H, int k) {
	int pos = H;
	if (heap[H] > k) {
		printf("Insertion Error\n");
		return;
	}
	else {
		heap[H] = k;
		while (pos / 2 > 0 && heap[pos] > heap[pos / 2]) {
			swap(pos, pos / 2);
			pos /= 2;
		}
	}
}

void Insert(int k) {
	H++;
	heap[H] = OVERMIN;
	InsertKey(H, k);
}

int extractMax() {
	int out = heap[1];
	heap[1] = heap[H];
	H--;
	maxHeap(H, 1);
	return out;
}

int main() {
	char input_str[10];
	int input_ele;

	while (1) {
		scanf("%s", input_str);
		if (input_str[0] == 'i') {
			scanf("%d", &input_ele);
			Insert(input_ele);
		}
		else {
			if (input_str[1] == 'x') {
				printf("%d\n", extractMax());
			}
			else break;
		}
	}

	return 0;
}


Measured memory_bytes: 5652
import java.util.Scanner;

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

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


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

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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	ll n,a,b;cin>>n>>a>>b;
	if(a%2==b%2) cout<<((max(a,b))-min(a,b))/2;
	else{
		if(a>b) swap(a,b);
		cout<<min((a+b-1)/2,((n-a)+(n-b)+1)/2);
	}
		
	
	return 0;
}



Measured memory_bytes: 256
n,x= map(int, input().split())
a= sorted(list(map(int, input().split())))
cnt=0
for i in range(n):
    if x>=a[i]:
        cnt+=1
        x-=a[i]
    else:
        break
    if i==n-1 and x>0:
        cnt-=1
print(cnt)

Measured memory_bytes: 38384
/*
 * AOJ #2399 Save Your Privacy!
 */
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, m, i, j, p, count, answer;
    unsigned char **candidate, *leaker;

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

        candidate = malloc((n + 1) * sizeof(candidate[0]));
        for (i = 1; i <= n; i++) {
            candidate[i] = malloc(n + 1);
            for (j = 1; j <= n; j++) { candidate[i][j] = 0; }
        }
        for (i = 1; i <= n; i++) {
            scanf("%d", &m);
            for (j = 0; j < m; j++) {
                scanf("%d", &p);
                candidate[p][i] = 1;
            }
        }

        leaker = malloc(n + 1);
        for (i = 1; i <= n; i++) { leaker[i] = 1; }

        scanf("%d", &m);
        for (j = 0; j < m; j++) {
            scanf("%d", &p);
            for (i = 1; i <= n; i++) {
                leaker[i] &= candidate[p][i];
            }
        }

        count = 0;
        for (i = 1; i <= n; i++) {
            if (leaker[i]) {
                count++;
                answer = i;
            }
        }
        if (count == 1) {
            printf("%d\n", answer);
        } else {
            printf("-1\n");
        }

        free(leaker);
        for (i = 1; i <= n; i++) { free(candidate[i]); }
        free(candidate);
    }
    return 0;
}

Measured memory_bytes: 0
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np
n,k=map(int,readline().split())
a=np.array(readline().split(),np.int64)
f=np.array(readline().split(),np.int64)
a.sort()
f.sort()
f=f[::-1]

s=-1
e=10**12
while s+1<e:
    mid=(s+e)//2
    if a.sum()- np.minimum(a,mid//f).sum() <=k:
        e=mid
    else:
        s=mid
print(e)

Measured memory_bytes: 26092
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict
import copy

INF = float("inf")

#入力受け取り
def getlist():
	return list(map(int, input().split()))

def build(d, n):
	cost = 0
	for k in range(n):
		for i in range(n):
			for j in range(n):
				if d[i][j] == d[i][k] + d[k][j] and k != i and k != j:
					d[i][j] = INF
				
	return d

def judge(d, n):
	for k in range(n):
		for i in range(n):
			for j in range(n):
				d[i][j] = min(d[i][j],d[i][k] + d[k][j])
	return d

#処理内容
def main():
	#受け取り
	N = int(input())
	d = []
	for i in range(N):
		g = getlist()
		d.append(g)

	#ワーシャルフロイド判定
	d2 = copy.deepcopy(d)
	d2 = judge(d2, N)

	if d != d2:
		print(-1)
	else:
		#構築
		X = build(d2, N)
		ans = 0
		for i in range(N):
			for j in range(N):
				if d2[i][j] != INF:
					ans += d2[i][j]
		print(ans // 2)


if __name__ == '__main__':
	main()

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

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

    int n;
    cin >> n;

    map<string, int> mp;
    rep(i, n) {
        string mark;
        int num;
        cin >> mark >> num;
        mark += to_string(num);
        mp[mark] = 1;
    }

    string marks = "SHCD";
    for (auto mark : marks) {
        for (int i = 1; i <= 13; i++) {
            string key = mark + to_string(i);
            if (mp.find(key) == mp.end()) {
                cout << mark << " " << i << endl;
            }
        }
    }
    return 0;
}



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

char getGrade(int m, int f, int r){
  int sum = m + f;
  char grade;
  if ( m == -1 || f == -1 ) {
    grade = 'F';
  } else if ( 80 <= sum ) {
    grade = 'A';
  } else if ( 65 <= sum && sum < 80 ){
    grade = 'B';
  } else if ( 50 <= sum && sum < 65 ){
    grade = 'C';
  } else if ( 30 <= sum && sum < 50 ){
    if ( 50 <= r ) grade = 'C';
    else grade = 'D';
  } else if ( sum < 30 ){
    grade = 'F';
  }
  
  return grade;
}

 int main(){
   int m, f, r;
   while(1){
     cin >> m >> f >> r;
     if ( m == -1 && f == -1 && r == -1 ) break;
     cout << getGrade(m, f, r) << endl;
   }
   
   return 0;
 }


Measured memory_bytes: 3084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int main(){
   int n,k;
   cin>>n>>k;
   k--;
   int y;
   rep(i,n){
       int x;cin>>x;
       if(x==1)y=i+1;
   }
   int ans=0;
   ans=(n-2+k)/k;
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

using namespace std;
using ull = unsigned long long;

void solve() {
    int h, w, n;
    cin >> h >> w >> n;
    int a[n];
    int b[h][w];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    int l = 1;
    for(int i = 0; i < h; i++){
        if(i % 2 == 0){
            for(int j = 0; j < w; j++){
                //cout << l << " ";
                b[i][j] = l;
                a[l-1]--;
                if(a[l-1] <= 0){
                    l++;
                }
            }
        }else{
            for(int j = w-1; j >= 0; j--){
                //cout << l << " ";
                b[i][j] = l;
                a[l-1]--;
                if(a[l-1] <= 0){
                    l++;
                }
            }
        }
        cout << endl;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << b[i][j] << " ";
        }
        cout << endl;
    }
}

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define pb push_back
#define eb emplace_back
int main()
{
   ll t;

   cin>>t;
   double n;

cin>>n;
   ll cnt=0;

   while(t--)
   {
        double a,b;

        cin>>a>>b;

       double sum=sqrt((a*a)+(b*b));


        if(sum<=n)cnt++;




   }


   cout<<cnt<<endl;





}


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

vector<int> v[100010];
int b[100010];

void dfs(int i, int p) {
    b[i] = p;
    for (auto e : v[i]) {
        if (e == p) continue;
        dfs(e, i);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int i = que.front();
        que.pop();

        for (int nv : v[i]) {
            if (dist[nv] != -1) continue;

            dist[nv] = i + 1;
            que.push(nv);
        }
    }

    bool ok = true;
    rep(i, n) if (dist[i] == -1) ok = false;
    if (ok) {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i++) cout << dist[i] << endl;
    } else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 10248
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;

int main(){
    char a ;
    cin >> a;
    int b=0;
    b = a - 'a';
    if(b>=0){
         cout << 'a' << endl;
    }
    else{
        cout << 'A' << endl;
    }
    return 0;

}


Measured memory_bytes: 3620
from math import sqrt
N = int(input())
D = [list(map(int, input().split())) for i in range(N)]
total = 0
for i in range(N):
  for j in range(N):
    if i != j:
      total += sqrt((D[i][0] - D[j][0]) ** 2 + (D[i][1] - D[j][1]) ** 2)
print(total / N)

Measured memory_bytes: 9144
fun main(args: Array<String>) {
    abc056c()
}

fun abc056c() {
    val x = readLine()!!.toLong()

    val answer = lowerBound(x)

    println(answer)
}

private fun lowerBound(key: Long): Long {
    var ng = -1L
    var ok = key

    val predicate = fun(mid: Long, key: Long): Boolean {
        return (mid + 1) * mid / 2 >= key
    }

    while (ok - ng > 1) {
        val mid = (ok + ng) / 2
        if (predicate(mid, key)) ok = mid else ng = mid
    }
    return ok
}


Measured memory_bytes: 33280
#include <stdio.h>

int main(void) {
  int n;
  int p;
  int i;
  int min = 200001;
  int cnt = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &p);
    if(p <= min) {
      min = p;
      cnt++;
    }    
  }
  printf("%d\n", cnt);
  
  return 0;
}


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

#[fastout]
fn main() {
    input! {
        n: i128,
    }

    let mut sum_10: i128 = 1;
    let mut sum_8: i128 = 1;
    let mut sum_9: i128 = 1;
    for _ in 0..n {
        sum_10 *= 10;
        sum_10 %= 1000000007;
        sum_8 *= 8;
        sum_8 %= 1000000007;
        sum_9 *= 9;
        sum_9 %= 1000000007;
    }

    let mut ans: i128 = sum_10 - sum_9 - sum_9 + sum_8;
    ans %= 1000000007;
    ans = (ans + 1000000007) % 1000000007;
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include <stdio.h>
#include <stdlib.h>

#define MAXV 100
#define MAXE 1000

int v, e;
int a = 0;
int *visited;
int *s, *t;

void resultSearch(int);

int main(){

        int i;

        scanf("%d %d", &v, &e);

        if(e < 0 || MAXE < e || v < 1 || MAXV < v)return 0;

        s = (int*)malloc(e*sizeof(int));
        t = (int*)malloc(e*sizeof(int));


        visited = (int*)malloc(v*sizeof(int));

        for(i = 0;i < e;i ++)
                {
                        scanf("%d %d", &s[i], &t[i]);
                }

        for(i = 0;i < v;i ++)
                {
                        visited[i] = 0;
                }

        for(i = 0;i < v;i ++)
                {
                        if(a == 1)
                                {
                                        break;
                                }else if(visited[i]  == 0 && a == 0)
                                {
                                        resultSearch(i);
                                }
                }

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

        free(s);
        free(t);
        free(visited);

        return 0;
}

void resultSearch(int v){
        int i;

        if(visited[v] == 1){
                a = 1;
        }else if(visited[v] == 0){
                visited[v] = 1;

                for(i = 0; i < e; i ++)
                {
                        if(s[i] == v)resultSearch(t[i]);
                }
                visited[v] = 2;
        }
}


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

int a[100010];

int main(){
	int n, C, k; scanf("%d%d%d", &n, &C, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int ans = 0, now = 1, pos = a[0];
	for (int i = 1; i < n; i++){
		if (now != C){
			if (a[i] - pos <= k) now++;
			else ans++, now = 1, pos = a[i];
		} else ans++, now = 1, pos = a[i];
	}
	printf("%d\n", ans + 1);
	return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long k = sc.nextLong();
      long res = n % k;
      res = Math.min(res, k - res);
      System.out.println(res);
  }
}

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

int main() {
	vector<int> vec(100); vector<int> cop; int temp;
	fill(vec.begin(), vec.end(), 0);
	while (cin >> temp) vec[temp - 1]++;
	copy(vec.begin(), vec.end(), back_inserter(cop));
	sort(cop.begin(), cop.end(), greater<int>());
	for (int i = 0; i < 100; i++)
		if (vec[i] == cop[0]) cout << i + 1 << endl;
	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
 using namespace std;
 int main() {
 int A, B, M;
 cin >> A >> B >> M;
 vector<int> a(A);
 vector<int> b(B);
 for (int i = 0; i < A; i++)cin >> a[i];
 for (int i = 0; i < B; i++)cin >> b[i];
 int minA = *min_element(a.begin(), a.end());
   int minB = *min_element(b.begin(), b.end());
 int ans = minA+minB;
 for (int i = 0; i < M; i++) {
 int x, y, c;
 cin >> x >> y >> c; x--; y--;
 ans = min(ans, a[x] + b[y] - c);
 }
 cout << ans << endl;
 return 0;
 }

Measured memory_bytes: 1024
import java.util.*;

class Main{
 Scanner sc = new Scanner(System.in);
 
 Main(){
  while(true){
   int H = sc.nextInt();
   int W = sc.nextInt();
   if ( H == 0 && W == 0 ) break;
   for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
     System.out.print("#");
    }
    System.out.printf("\n");
   }
   System.out.printf("\n");
  }
 }
 public static void main(String[] args){
  new Main();
 }
}



Measured memory_bytes: 37812
#include<iostream>
#include<string>
//#include<vector>

int main(){
	int p = 0;
	std::string s,t;
	std::cin>>s>>t;

	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			p++;
		}
	}


	std::cout<<p<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if A % 2 != 0 or B % 2 != 0:
        if A > 8 or B > 8:
            print(':(')
            return

    print('Yay!')
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


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

const int MOD = 924844033;
int N , K , C[2003][2003] , dp[2003] , jc[2003];

int main(){
	cin >> N >> K;
	C[0][0] = 1;
	for(int i = 1 ; i <= N ; ++i){
		C[i][0] = 1;
		for(int j = 1 ; j <= N ; ++j)
			C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
	}
	dp[0] = 1; int all = 0;
	for(int i = 1 ; i <= 2 * K && i <= N ; ++i){
		int sum = 0;
		for(int j = i ; j <= N ; j += 2 * K) sum += (j - K > 0) + (j + K <= N);
		for(int j = all ; j >= 0 ; --j)
			for(int k = (sum + 1) / 2 ; k ; --k)
				dp[j + k] = (dp[j + k] + 1ll * dp[j] * C[sum - k + 1][k]) % MOD;
		all += (sum + 1) / 2;
	}
	jc[0] = 1; for(int i = 1 ; i <= N ; ++i) jc[i] = 1ll * jc[i - 1] * i % MOD;
	for(int i = 0 ; i <= N ; ++i) dp[i] = 1ll * dp[i] * jc[N - i] % MOD;
	int ans = 0; for(int i = 0 ; i <= N ; ++i) ans = (ans + (i & 1 ? -1ll : 1ll) * dp[i] + MOD) % MOD;
	cout << ans; return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
  	cin>>s>>t;
 	int i,n=s.size(),m=t.size();
	vector<int> a(n),b(m);
  	for(i=0;i<n;i++){
		a[i]=s[i]-'0';
    }
  	for(i=0;i<m;i++){
		b[i]=t[i]-'0';
    }
  	
	sort(a.begin(),a.end());
  	sort(b.begin(),b.end());
  	reverse(b.begin(),b.end());
  	
  	for(i=0;i<min(n,m);i++){
      if(a[i]-'0'<b[i]-'0'){
		cout<<"Yes"<<endl;
        return 0;
      }else if(a[i]-'0'>b[i]-'0'){
        cout<<"No"<<endl;
      	return 0;
      	}
      if(i==min(n,m)-1){
		if(n>=m){
			cout<<"No"<<endl;
          	return 0;
        }else{
			cout<<"Yes"<<endl;
          return 0;
        }
      }
    }
  cout<<"No"<<endl; 	
}
		
  	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  map<string, string> mp;
  mp["Sunny"] = "Cloudy";
  mp["Cloudy"] = "Rainy";
  mp["Rainy"] = "Sunny";
  string s; cin >> s;
  cout << mp[s] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  X,Y,A,B,C;
ll  P[100007],Q[100007],R[100007];
ll dp[3][100007];

int main(){
  cin >> X >> Y >> A >> B >> C;
  rep(i,A){
    cin >> P[i];
  }
  rep(i,B){
    cin >> Q[i];
  }
  rep(i,C){
    cin >> R[i];
  }
  sort(P,P+A);
  sort(Q,Q+B);
  sort(R,R+C);
  reverse(P,P+A);
  reverse(Q,Q+B);
  reverse(R,R+C);
  ll ANS=0;
  rep(i,X){
    ANS+=P[i];
  }
  rep(i,Y){
    ANS+=Q[i];
  }
  X--;Y--;
  rep(i,C){
    ll key=R[i];
    if((X>=0 && key>P[X]) && (P[X]<Q[Y] || Y<0)){
      ANS+=key-P[X];
      X--;
    }
    else if(Y>=0 && key>Q[Y]){
      ANS+=key-Q[Y];
      Y--;
    }
    else{
      break;
    }
  }
  cout << ANS << endl;
}

Measured memory_bytes: 2944
H,W = gets.chomp.split(" ").map(&:to_i)
N = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = Array.new(H){Array.new(W,0)}
h = 0
w = 0
forward = true
N.times do |i|
  a[i].times do
    ans[h][w] = i+1
    if forward
      if w == W-1
        h += 1
        forward = false
      else
        w += 1
      end
    else
      if w == 0
        h += 1
        forward = true
      else
        w -= 1
      end
    end
  end
end
H.times do |i|
  W.times do |j|
    print "#{ans[i][j]} "
  end
  puts ""
end


Measured memory_bytes: 14908
#include <stdio.h>

int ANTEI(char *,int *,char *,int *);

int main()
{
  int n,i,j,flag,min,tmp;
  char change;

  scanf("%d",&n);

  char a[n],as[n];
  int b[n],bs[n];

  for(i=0;i<n;i++)
    {
      scanf(" %c%d",&a[i],&b[i]);
      as[i]=a[i];
      bs[i]=b[i];
    }

  for(i=0;i<n;i++)
    {
      /*バブルソート*/
      for(j=n-1;j>i;j--)
	{
	  if(b[j]<b[j-1])
	    {
	      change=a[j-1];
	      a[j-1]=a[j];
	      a[j]=change;

	      tmp=b[j-1];
	      b[j-1]=b[j];
	      b[j]=tmp;
	    }
	}
      
      /*選択ソート*/
      min=i;
      for(j=i+1;j<n;j++)
	{
	  if(bs[j]<bs[min])min=j;
	}
      if(min!=i)
	{
	  change=as[min];
	  as[min]=as[i];
	  as[i]=change;

	  tmp=bs[min];
	  bs[min]=bs[i];
	  bs[i]=tmp;
	}
    }
  
  flag=1;
  for(i=0;i<n;i++)
    {
      if(a[i]!=as[i])
	{
	  flag=0;
	  break;
	}
    }
 
  for(i=0;i<n-1;i++)printf("%c%d ",a[i],b[i]);
  printf("%c%d\n",a[n-1],b[n-1]);
  printf("Stable\n");
  
   for(i=0;i<n-1;i++)printf("%c%d ",as[i],bs[i]);
  printf("%c%d\n",as[n-1],bs[n-1]);
  if(flag==0)printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>

#define mod 1000000007
#define INF2 9999999999
#define INF (1<<30)
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
//#define P pair<int, int>

using namespace std;
using ll = __int64_t;

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

void solve(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];
  for(int i = n-1; i >= 0; i-=2){
    cout << a[i] << " ";
  }
  if(n%2 == 0){
    for(int i = 0; i < n; i+=2){
      cout << a[i] << " ";
    }
  }else{
    for(int i = 1; i < n; i+=2){
      cout << a[i] << " ";
    }    
  }
  cout << endl;
}

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


Measured memory_bytes: 3712
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

const int MX = 4005;

int n, a[MX], dp[MX][MX/2];
int ca[MX], cb[MX], ina[MX][MX], inb[MX][MX], qa[MX], qb[MX];
char c[MX];

void obtG (int i, int &cn, int in[], int qb[]) {
    cn = 0;
    for (int j = 0; j < i; j++)
        if (c[j] == c[i] && a[j] > a[i])
            cn++;

    int acu = 0;
    for (int j = n / 2 - 1; j >= 0; j--) {
        acu += qb[j] < i;
        in[j] = acu;
    }
}

int obtRes (int i, int j) {
    if (i == n)
        return 0;

    int &_ = dp[i][j], k = i - j;
    if (_ != -1)
        return _;
    _ = 1e9;

    if (j < n / 2)
        _ = min(_, obtRes(i+1, j+1) + ca[j] + ina[j][k]);

    if (k < n / 2)
        _ = min(_, obtRes(i+1, j) + cb[k] + inb[k][j]);

    return _;
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i = 0; i < MX; i++)
        for (int j = 0; j < MX / 2; j++)
            dp[i][j] = -1;

    cin >> n;
    n *= 2;
    for (int i = 0; i < n; i++)
        cin >> c[i] >> a[i];

    int x = 0, y = 0;
    for (int i = 0; i < n; i++)
        if (c[i] == 'W')
            qa[x++] = i;
        else
            qb[y++] = i;

    sort (qa, qa+x, [&] (int i, int j) {
        return a[i] < a[j];
    });
    sort (qb, qb+x, [&] (int i, int j) {
        return a[i] < a[j];
    });

    for (int i = 0; i < n; i++) {
        if (c[i] == 'W') {
            obtG (i, ca[a[i]-1], ina[a[i]-1], qb);
            x++;
        } else {
            obtG (i, cb[a[i]-1], inb[a[i]-1], qa);
            y++;
        }
    }

    cout << obtRes (0, 0) << endl;

    return 0;
}


Measured memory_bytes: 97280
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
  int d, t, s;
  cin >> d >> t >> s;

  if (d / (double)s <= t)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(void)

{
    int a,b,c,d,s1,s2,s;

    scanf("%d%d%d%d",&a,&b,&c,&d);
        if(a>=b){
      s1=b;}
    else{
      s1=a;}
     if(c>=d){
      s2=d;}
     else{
      s2=c;}
     s=s1+s2;
     printf("%d",s);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll N;
vector<ll> stones;
vector<ll> dp;

ll rec (int curr){
    if(curr >= N-1){
        return 0;
    }
    if(dp[curr] != -1){
        return dp[curr];
    }
    
    ll res = oo;

    FOR(i, 1, 3){
        if(curr+i >= N){ break;}
        ll new_cost = abs(stones[curr] - stones[curr+i]);
        ll next = rec(curr + i) + new_cost;
        res = min(res, next);
    }
    dp[curr] = res;
    return res;
}

int main() {

    cin >> N;
    stones.resize(N);
    dp.assign(N, -1);
    FOR(i, 0, N){
        cin >> stones[i];
    }
    
    cout << rec(0) << endl;
    
    return 0;
}



Measured memory_bytes: 9600
# 写経

n = int(input())
s = input()


cnt = s[1:].count("E")
ans = cnt
for i in range(1, n):
    if s[i-1] == "W":
        cnt += 1
    if s[i] == "E":
        cnt -= 1
    ans = min(ans, cnt)


print(ans)


Measured memory_bytes: 3700
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */

public class Main {

	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		
		int num = 0;
		
		for(int i = 0; i < 4; i++){
			if(S.charAt(i) == '+') num++;
			else num--;
		}
		
		System.out.println(num);
	}
}

Measured memory_bytes: 21844
A,B,C=map(int,input().strip().split())
K=int(input())
if A<B and B<C:
    print("Yes")
else:
    i=0
    while i<K:
        if A>=B:
            B*=2
        else:
            C*=2
        if A<B and B<C:
            print("Yes")
            break
        i+=1
    else:
        print("No")

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  long long sum=0;
  
  if(a>=k){
    sum+=k;
    cout<<sum;
    return 0;
  }
  k-=a;
  sum=a;
  if(b>=k){
    cout<<sum;
    return 0;
  }
  k-=b;
  if(c>=k){
    sum-=k;
    cout<<sum;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 3572
a, b = map(int, input().split())
# a - k = -b + k or b - k
# a + b == 2k or a - b = 0
if a == b:
    print(0)
elif (a + b) % 2 == 0:
    print((a + b) // 2)
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 9140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int n;
static int edge[100000][3];
static int degree[100000];
static vector<vector<int>> connect[100000];
static int color[100000];

void operation(int start) {
	int i = start;
	for (int j = 0; j < connect[i].size(); j++) {
		if (color[connect[i][j][0]] == -1) {
			if (connect[i][j][1] % 2 == 0) {
				color[connect[i][j][0]] = color[i];
			}
			else {
				if (color[i] == 1) {
					color[connect[i][j][0]] = 0;
				}
				else {
					color[connect[i][j][0]] = 1;
				}
			}
			operation(connect[i][j][0]);
		}
	}
};

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		degree[i] = 0;
		color[i] = -1;
	}

	for (int i = 0; i < n - 1; i++) {
		cin >> edge[i][0] >> edge[i][1] >> edge[i][2];

		degree[edge[i][0] - 1]++;
		degree[edge[i][1] - 1]++;
		connect[edge[i][0] - 1].push_back({ edge[i][1] - 1, edge[i][2] });
		connect[edge[i][1] - 1].push_back({ edge[i][0] - 1, edge[i][2] });
	}

	int start;
	for (int i = 0; i < n - 1; i++) {
		if (degree[i] == 1) {
			start = i;
			break;
		}
	}

	color[start] = 0;

	operation(start);

	for (int i = 0; i < n; i++) {
		cout << color[i] << endl;
	}
}

Measured memory_bytes: 20608
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;

	vector<int> v(n);

	for(int i = 0; i < n; i++) cin >> v[i];

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

	int ans = 0;

	for(int i = 0; i < k; i++) ans += v[i];

	cout << ans;
	
	return 0;
}


Measured memory_bytes: 3640