akhauriyash/Code-Regression huggingface dataset:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int[] a = na(n);
		int prev = Integer.MAX_VALUE;
		int max = 0;
		int cur = 0;
		for(int i = 0; i < n; i++) {
			if(prev >= a[i]) {
				cur++;
			}
			else {
				cur = 1;
			}
			prev = a[i];
			max = Math.max(max, cur);
		}
		out.println(max - 1);
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private float nf() {
		return Float.parseFloat(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

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

int main(){
    int K, N;
    std::cin >> K >> N;
    std::vector<int> d(N);
    for(int i = 0; i < N; i++){
        std::cin >> d[i];
    }

    int maxDist = d[0] + K - d[N - 1];
    for(int i = 0; i < N - 1; i++){
        maxDist = std::max(maxDist, d[i + 1] - d[i]);
    }

    std::cout << K - maxDist << std::endl;
    return 0;
}


Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

s=""
while true
  s_input=gets
  break if s_input.nil?
  break if s_input.chomp==""
  s_input=s_input.chomp.split("")
  s+=s_input.join("").downcase
  #break if s_input[s_input.size-1]=="."
end
alphabet=("a".."z").to_a
26.times do|i|
  puts "#{alphabet[i]} : #{s.count(alphabet[i])}"
end


Measured memory_bytes: 6904
S=input()
mx=0
flag=1
for i in range(11):
    for j in range(11):
        if i>=j:
            continue
        for s in S[i:j]:
            if s not in ['A','G','C','T']:
                flag=0
        if flag:
            mx=max(len(S[i:j]),mx)
        else:
            flag=1

print(mx)

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

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

using namespace std;


using Weight=long long;
using Edge=struct{int to;Weight cost;};
using Graph=vector<vector<Edge>>;
const Weight inf=1LL<<60;

vector<Weight> dijkstra(const Graph &g,int s){
	int n=g.size();
	using state=tuple<Weight,int>;
	vector<Weight> dist(n,inf);
	priority_queue<state,vector<state>,greater<state>> q;
	dist[s]=0,q.push(state(0,s));
	while(!q.empty()){
		Weight c; int v;
		tie(c,v)=q.top();q.pop();
		for(auto &e:g[v]){
			Weight nc=c+e.cost; int nv=e.to;
			if(chmin(dist[nv],nc)) q.push(state(nc,nv));
		}
	}
	return dist;
}

int main(void){
	int v,e,s;
	cin >> v >> e >> s;
	Graph graph(v);
	rep(loop,e){
		int a,b,c;
		cin >> a >> b >> c;
		graph[a].push_back({b,c});
	}

	auto dist=dijkstra(graph,s);
	rep(i,v){
		if(dist[i]==inf)
			puts("INF");
		else
			cout << dist[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 19392
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	cin >> N;
	vl A(N);
	vpll P(N);
	vl B(N);
	for (i = 0; i < N; i++) {
		B[i] = 0;
	}
	for (i = 0; i < N; i++) {
		cin >> A[i];
		B[A[i] - 1]++;
	}
	for (i = 0; i < N; i++) {
		ans += B[i] * (B[i] - 1) / 2;
	}
	for (i = 0; i < N; i++) {
		cout << ans - (B[A[i] - 1] - 1) << endl;
	}
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      G[u].push_back(P(v,c));
    }
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;

  priority_queue<P,vector<P>,greater<P> > q;
  d[0]=0;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

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

int n, a[110];

int main(){
	while(cin >> n && n > 0){
		int mins = 1010;
		int maxs = 0;
		int sum = 0;
		for(int i=0; i<n; ++i){
			cin >> a[i];
			mins = min(mins, a[i]);
			maxs = max(maxs, a[i]);
			sum += a[i];
		}
		int ans = (sum - mins - maxs) / (n-2);
		cout << ans << endl;
	}
}


Measured memory_bytes: 3032
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll x,mx,val;
  cin >> x;
  if(x>=2000){
    cout <<"1\n";
  }else if(x<100){
    cout <<"0\n";
  }else{
    mx = (x/100)*5;
    val = x%100;
    if(val<=mx){
      cout <<"1\n";
    }else{
      cout <<"0\n";
    }
  }
}


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

int main() {
  int N;
  cin >> N;
  int a = N / 100000000;
  int b = (N % 100000000) /10000000;
  int c = (N % 10000000) / 1000000;
  int d = (N % 1000000) / 100000;
  int e = (N % 100000) / 10000;
  int f = (N % 10000) / 1000;
  int g = (N % 1000) / 100;
  int h = (N % 100) / 10;
  int i = N % 10;
  if(N %(a+b+c+d+e+f+g+h+i) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
memo = Array.new(4096, 0)

0.upto 1000 do |i|
  0.upto 1000 do |j|
    memo[i+j] += 1
  end
end

while n = gets
  n = n.chomp.to_i

  ans = 0
  0.upto 2000 do |left|
    ans += memo[left] * memo[n - left] if n - left >= 0
  end

  puts ans
end

Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N;
    int d[57];
    int Ans=0;
    cin >> N;
    REP(i,N){
        cin >> d[i];
    }
    REP(i,N){
        REP(j,N){
            if(i<j){
                Ans+=d[i]*d[j];
            }
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "Yes\n"
#define N cout << "No\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

long long mod = 1000000007 , ans = 1 ;
int p(long long a , long long b)
{
    while(b)
    {
        if(b%2)
        {
            ans = ( (ans%mod)*(a%mod) ) %mod ;
        }
        a = ((a%mod)*(a%mod))%mod ;
        b /= 2 ;
    }
    return ans ;
}


int prime[1000010] ;
void fun()
{
	for (int i = 2; i < 1000001; i++)
	{
		if (prime[i] == 0)
		{
			for (int j = i + i; j < 1000001; j += i)
			{
				prime[j] = 1;
			}
		}
	}
}
int gcd(ll a,ll b)
{
     if(b == 0)
     {
          return a ;
     }
     return gcd(b,a%b) ;
}
int main()
{
     // ios_base::sync_with_stdio(false);
     // cin.tie(NULL);
     float d , t ,s ;
     cin >> d >> t >> s ;
     d /= s ;
     if(d > t)
     {
          N ;
     }
     else
     {
          Y ;
     }
}


Measured memory_bytes: 3732
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int[] n = Input.ScanIntArray();
          
          Out(Math.Min(n[2],n[0]*n[1]));
        }

        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define ll long long
int main(){
  int N,i;
  cin>>N>>i;
  cout<<N+1-i<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int i,n,kari,count;

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

    while(n != 1){
      if(n%2 == 0)
	n /= 2;
      else
	n = 3 * n +1;
      count++;
    }

    printf("%d\n",count);
  }

  return 0;
}

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

int A[200][200];

int main(){
  int n,m,t,p;
  while(1){
    cin>>n>>m>>t>>p;
    if(n==0&&m==0&&t==0&&p==0)break;

    for(int i=0;i<200;i++)
      for(int j=0;j<200;j++)
        A[i][j]=0;
    
    for(int i=0;i<m;i++)
      for(int j=0;j<n;j++)
        A[i][j]=1;
    
    for(int u=0;u<t;u++){
      int d,c;
      cin>>d>>c;
      if(d==1){
        
        for(int i=0;i<m;i++){
          for(int j=0;j<c;j++){
            int dist=c-j;
            A[i][c+dist-1]+=A[i][j];
            A[i][j]=0;
          }
        }

        for(int i=0;i<100;i++){
          for(int j=0;j<100;j++){
            A[i][j]=A[i][j+c];
          }
        }
        
      }else{
        
        for(int i=0;i<c;i++){
          for(int j=0;j<n;j++){
            int dist=c-i;
            A[c+dist-1][j]+=A[i][j];
            A[i][j]=0;
          }
        }

        for(int i=0;i<100;i++){
          for(int j=0;j<100;j++){
            A[i][j]=A[i+c][j];
          }
        }
        
      }
      
    }
    
    for(int i=0;i<p;i++){
      int x,y;
      cin>>x>>y;
      cout<<A[y][x]<<endl;
    }
    
  }
  return 0;
}



Measured memory_bytes: 3212
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		ll ans=0,v=100;
		REP(i, 100000) {
			ans++;
			v=(double)v*101.0/100.0;
//			DD(v);
			if(N<=v) break;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
bool s[100001];
main()
{
	std::ios_base::sync_with_stdio(0),std::cin.tie(0);
	char ch;
	int n = 0;
	while ((ch = std::cin.get()) != 10)
		s[++ n] = ch == 49;
	if (s[1] && ! s[n])
	{
		bool * sL = s + 1,* sR = s + n - 1;
		while (sL < sR)
		{
			if (* sL != * sR)
				break;
			++ sL,-- sR;
		}
		if (sL >= sR)
		{
			int pre = 1;
			for (int i = 2;i < n;++ i)
				if (s[i])
					while (pre < i)
						std::cout << i << ' ' << pre ++ << '\n';
			std::cout << n << ' ' << pre << '\n';
			return 0;
		}
	}
	std::cout << "-1\n";
}

Measured memory_bytes: 1536
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))

# Aを昇順ソートした列をBとして、
# B_{k + 1} > 2(B_1 + ... + B_k) を満たす最大のkを求める。
# N - k が解となる
B = sorted(A)
S = list(accumulate([0] + B))
ans = N - next(
    i
    for i in reversed(range(N))
    if B[i] > 2 * S[i]
)

print(ans)


Measured memory_bytes: 14428
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, a, b, c, d);
    print(min(a, b) + min(c, d));

    return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
	int l, r, d, ans;
	cin >> l >> r >> d;
	if (l % d == 0 || r % d == 0) {
		ans = (r - l) / d + 1;
	}
	else {
		ans = (r - l) / d;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
int d[100000],s[100000];
int i,j;
int n,m;
int ans;

void set(int i,int m){
	if(m==1){
		if(d[i-1]<0){
			d[i]=d[i-1]-1;
			s[i]=s[i-1];
		}
		else{
			d[i]=-1;
			s[i]=i;
		}
	}
	if(m==0){
		if(d[i-1]>0){
			d[i]=d[i-1]+1;
			s[i]=s[i-1];
		}
		else{
			d[i]=1;
			s[i]=i;
		}
		ans++;
	}
}


int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		ans=0;
		for(i=0;i<n;i++){
			d[i]=0;
			s[i]=0;
		}
		for(i=0;i<n;i++){
			scanf("%d",&m);
			if(i==0){
				if(m==0){
					d[i]=1;
					ans++;
				}
				else d[i]=-1;
				s[0]=0;
				continue;
			}
			if(i%2==0)set(i,m);
			else{
				if(m==1&&d[i-1]<0){
					d[i]=d[i-1]-1;
					s[i]=s[i-1];
				}
				if(m==0&&d[i-1]>0){
					d[i]=d[i-1]+1;
					s[i]=s[i-1];
					ans++;
				}
				if(m==1&&d[i-1]>0){
					if(s[i-1]>0){
						if(d[s[i-1]-1]>0){
							d[i]=-d[i-1]-d[s[i-1]-1]-1;
							s[i]=s[s[i-1]-1];
							ans-=d[i-1]+d[s[i-1]-1];
						}
						else{
							d[i]=-d[i-1]+d[s[i-1]-1]-1;
							s[i]=s[s[i-1]-1];
							ans-=d[i-1];
						}
					}
					else{
						d[i]=-d[i-1]-1;
						s[i]=0;
						ans-=d[i-1];
					}
				}
				if(m==0&&d[i-1]<0){
					if(s[i-1]>0){
						if(d[s[i-1]-1]<0){
							d[i]=-d[i-1]-d[s[i-1]-1]+1;
							s[i]=s[s[i-1]-1];
							ans+=d[i];
						}
						else{
							d[i]=-d[i-1]+d[s[i-1]-1]+1;
							s[i]=s[s[i-1]-1];
							ans+=-d[i-1]+1;
						}
					}
					else{
						d[i]=-d[i-1]+1;
						s[i]=0;
						ans+=d[i];
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1808
// Colorful Balls
// * frank_c1
// * 2017 / 11/ 07

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

LL pow_mod(LL b, LL p, LL k) {
	LL ret = 1;
	for (; p; p >>= 1) {
		if (p & 1) ret = ret * b % k;
		b = b * b % k;
	}
	return ret;
}

const int maxn = (int)(2e5) + 5;
const int mo = (int)(1e9) + 7;
vector<pii> T[maxn], G;
vector<int> nxt[maxn];
int fac[maxn], ivf[maxn];
int vi[maxn], co[maxn];
map<int, int> H;

void addedge(int u, int v) {
	nxt[u].push_back(v); nxt[v].push_back(u);
}

void dfs(int x) {
	if (!H.count(co[x])) H[co[x]] = 1; else H[co[x]]++;
	vi[x] = 1; for (int i = 0; i < (int)nxt[x].size(); ++i) if (!vi[nxt[x][i]]) dfs(nxt[x][i]);
}

int main() {
	int n, X, Y; fac[0] = ivf[0] = 1;
	scanf("%d%d%d", &n, &X, &Y);
	for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mo;
	ivf[n] = pow_mod(fac[n], mo - 2, mo);
	for (int i = n - 1; i >= 1; --i) ivf[i] = 1LL * ivf[i + 1] * (i + 1) % mo;
	for (int i = 1; i <= n; ++i) {
		int c, w; scanf("%d%d", &c, &w);
		T[c].push_back(make_pair(w, i)); co[i] = c;
	}
	for (int i = 1; i <= n; ++i) if (T[i].size()) {
		sort(T[i].begin(), T[i].end());
		for (int j = 1; j < (int)T[i].size(); ++j) {
			if (T[i][0].first + T[i][j].first <= X) 
				addedge(T[i][0].second, T[i][j].second);
		} G.push_back(T[i][0]);
	} sort(G.begin(), G.end());
	pii a = G[0], b = G.size() > 1u ? G[1] : G[0];
	for (int i = 1; i <= n; ++i) if (T[i].size()) {
		for (int j = 0; j < (int)T[i].size(); ++j) {
			if (co[a.second] != co[T[i][j].second] && a.first + T[i][j].first <= Y) 
				addedge(a.second, T[i][j].second); 
			if (co[b.second] != co[T[i][j].second] && b.first + T[i][j].first <= Y)
				addedge(b.second, T[i][j].second);
		}
	}
	int ret = 1;
	for (int i = 1; i <= n; ++i) if (!vi[i]) {
		H.clear(); dfs(i); int tot = 0;
		for (map<int, int>::iterator it = H.begin(); it != H.end(); ++it) ret = 1LL * ret * ivf[it->second] % mo, tot += it->second;
		ret = 1LL * ret * fac[tot] % mo;
	}
	return printf("%d\n", ret), 0;
}

Measured memory_bytes: 30488
//ABC120B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
using namespace std;

int main(){
	int a, b, k;
	cin >> a >> b >> k;
	vector <int> num(a);
	int m = 0;
	for(int i=min(a,b);i>0;i--){
		if(a % i == 0 && b % i == 0){
			num.at(m) = i;
			m++;
		}
	}
	cout << num.at(k-1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
const int maxn = 1005;
const int maxm = 200005;
std::vector<int> G[maxn], RG[maxn];
inline void ins_edge(int u, int v) {
  G[u].push_back(v);
  RG[v].push_back(u);
}

bool rvis[maxn];
void dfs_r(int x) {
  rvis[x] = true;
  for(int v : RG[x]) {
    if(!rvis[v]) {
      dfs_r(v);
    }
  }
}

int typ[maxn][2];
void dfs_t(int x, int bg) {
  if(typ[x][0]) {
    typ[x][1] = bg;
  } else {
    typ[x][0] = bg;
  }
  for(int v : G[x]) {
    if(!typ[v][1] && typ[v][0] != bg) {
      dfs_t(v, bg);
    }
  }
}

int E[maxm][2];
int flag[maxn][maxn];
inline void deal(int s) {
  memset(rvis, 0, sizeof(rvis));
  dfs_r(s);
  for(int v : G[s]) {
    if(rvis[v]) {
#ifdef LOCAL
      printf("Edge (%d, %d) type 1\n", s, v);
#endif
      flag[s][v] ^= 1;
    }
  }
  memset(typ, 0, sizeof(typ));
  typ[s][0] = typ[s][1] = 0x7f7f7f7f;
  for(int v : G[s]) {
    dfs_t(v, v);
  }
  for(int v : G[s]) {
    if(typ[v][1]) {
#ifdef LOCAL
      printf("Edge (%d, %d) type 2(%d, %d)\n", s, v, typ[v][0], typ[v][1]);
#endif
      flag[s][v] ^= 1;
    }
  }
}

int main() {
  int n, m; scanf("%d%d", &n, &m);
  for(int i = 1; i <= m; i ++) {
    int u, v; scanf("%d%d", &u, &v);
    E[i][0] = u; E[i][1] = v;
    ins_edge(u, v);
  }
  for(int i = 1; i <= n; i ++) deal(i);
  for(int i = 1; i <= m; i ++) {
    const int u = E[i][0], v = E[i][1];
    if(flag[u][v]) {
      puts("diff");
    } else {
      puts("same");
    }
  }
  return 0;
}

Measured memory_bytes: 9728
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;

#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 _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> iii;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"

template<class T>
void pairsort(vector<T>& x, vector<T>& y){
    int n = sz(x);
    vector<tuple<T, T>> t(n);
    rep(i, n){
        t[i] = make_tuple(x[i], y[i]);
    }
    sort(all(t));
    rep(i, n){
        x[i] = get<0>(t[i]);
        y[i] = get<1>(t[i]);
    }
}

int solve() {
    int n;cin>>n;
    vi a(n), b(n);
    rep(i, n){
        cin>>a[i]>>b[i];
    }
    pairsort(b, a);

    int time = 0;
    rep(i, n){
        time += a[i];
        if (time>b[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

		String first_lines = input.readLine();

		// ??\????????????????????????????´???????

		Dice insdice = new Dice(first_lines.split(" "));

		String second_lines = input.readLine();

		second_lines.toCharArray();

		insdice.dice_roll(second_lines.toCharArray());

		System.out.println(insdice.get_top());

	}
}

class Dice {

	int[] array_dice = new int[6];

	int top = 0;

	int bottom = 0;

	int front = 0;

	int back = 0;

	int right = 0;

	int left = 0;

	int num;

	// ????????????????????????????????£????????????????????\????????????????????§???????????§?????????
	Dice(String[] strings) {

			this.top=Integer.parseInt(strings[0]);

			this.front=Integer.parseInt(strings[1]);

			this.right=Integer.parseInt(strings[2]);

			this.left=Integer.parseInt(strings[3]);

			this.back=Integer.parseInt(strings[4]);

			this.bottom=Integer.parseInt(strings[5]);

			}

	void dice_roll(char []direction){

		      for(int direction_spot=0;direction_spot<direction.length; direction_spot++){

		    	  if(direction[direction_spot]=='N'){

		    		  num=top;

		    		  top=front;

		    		  front=bottom;

		    		  bottom=back;

		    		  back=num;
		    	  }else if(direction[direction_spot]=='S'){

		    		  num=top;

		    		  top=back;

		    		  back=bottom;

		    		  bottom=front;

		    		  front=num;

		    	  }else if(direction[direction_spot]=='E'){

		    		  num=top;

		    		  top=left;

		    		  left=bottom;

		    		  bottom=right;

		    		  right=num;

		    	  }else{

		    		  num=top;

		    		  top=right;

		    		  right=bottom;

		    		  bottom=left;

		    		  left=num;

		    	  }

		      }



	}

	int get_top(){

		return top;

	}
}

Measured memory_bytes: 24408
use std::cmp::max as max;
use std::cmp::min as min;

use itertools::Itertools;

fn build(buildings: &Vec<u64>, build_ups: &Vec<u64>) -> u64 {
    //println!("{:?}", build_ups);
    let mut highest = buildings[0] - 1;
    let mut costs = 0;

    for i in 0..buildings.len() {
        //print!("{}: ", i);
        //print!("highest: {} ", highest);
        let cost = if build_ups.contains(&(i as u64)) {
            //print!("( if ) ");
            if highest + 1 < buildings[i] { 0 } else { highest + 1 - buildings[i] }
        } else {
            //print!("( else ) ");
            0
        };
        costs += cost;
        highest = max(highest, buildings[i] + cost);
        //print!("highest: {} ", highest);
        //println!("cost: {}\n", cost);
    }
    //println!("------");
    costs
}

fn solve(buildings: Vec<u64>, n: usize, k: usize) -> u64 {
    let mut result = 9223372036854775807;

    for build_ups in (0..n as u64).combinations(k) {
        result = min(build(&buildings, &build_ups), result)
    }

    result
}

fn main() {
//    let (n, k) = (5, 3);
//    let buildings = vec![4, 4, 2, 6, 4];
    let (n, k) = read_tup2();
    let buildings = read_vec();

    println!("{}", solve(buildings, n, k));
}

// utils

fn read_tup2<T: std::str::FromStr + Copy>() -> (T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v = s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect::<Vec<T>>();
    (v[0], v[1])
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|c| c.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


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

  int i;
  while(1){

    int N;
    cin >> N;
    if(N == 0) break;

    int XY[21][21]={0};
    int x, y;
    for(i=0; i<N; i++){
      cin >> x >> y;
      XY[x][y]=1;
    }

    int M;
    cin >> M;

    x=10;
    y=10;
    int cnt=0;
    string Direc;
    int Step;
    for(i=0; i<M; i++){
      cin >> Direc >> Step;
      if(Direc == "W"){
        REP(i, Step){
          x--;
          if(XY[x][y]==1){
            cnt++;
            XY[x][y]=0;
          }
        }
      }
      if(Direc == "E"){
        REP(i, Step){
          x++;
          if(XY[x][y]==1){
            cnt++;
            XY[x][y]=0;
          }
        }
      }
      if(Direc == "N"){
        REP(i, Step){
          y++;
          if(XY[x][y]==1){
            cnt++;
            XY[x][y]=0;
          }
        }
      }
      if(Direc == "S"){
        REP(i, Step){
          y--;
          if(XY[x][y]==1){
            cnt++;
            XY[x][y]=0;
          }
        }
      }
    }
    if(N == cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
    return 0;
  }

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<n/(a+b) * a +min(n%(a+b), a)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner


object Main {

  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = IndexedSeq.fill(n)(sc.nextLong())
    (n, a)
  }

  def solve(n: Int, a: IndexedSeq[Long]): Long = {
    val as0 = IndexedSeq.concat(0 until n by 2, 1 until n by 2, 0 until n by 2, 1 until n by 2).map(a)
    val as1 = IndexedSeq.concat(1 until n by 2, 0 until n by 2, 1 until n by 2, 0 until n by 2).map(a)
    val cumAS0 = as0.scanLeft(0L)(_ + _)
    val cumAS1 = as1.scanLeft(0L)(_ + _)
    val sum = a.sum
    val y0 = IndexedSeq.tabulate(n / 2 + 1)(i =>
      sum/2 - (cumAS0(i + n / 2 + 1) - cumAS0(i + 1))
    )
    val y1 = IndexedSeq.tabulate(n / 2)(i =>
      sum/2 - (cumAS1(i + n / 2 + 1) - cumAS1(i + 1))
    )
    print(y0((n-1)/2) * 2)
    print(" ")
    for(i<- 0 until n-1){
      if(i %2 == 0){
        print(y0(i/2)*2)
      } else{
        print(y1(i/2)*2)
      }
      print(" ")
    }
    println()
    0
  }

  def main(args: Array[String]): Unit = {
    val (n, a) = read()
    solve(n, a)
  }
}

Measured memory_bytes: 101128
#include <bits/stdc++.h>
using namespace std;
#define LL long long int
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int k; cin>>k;
    string s; cin>>s;
    int n = (int) s.size();
    if(n<=k) cout<<s<<"\n";
    else cout<<s.substr(0, k)+"...\n";
    return 0;
}

Measured memory_bytes: 3644
#include "stdio.h"
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define DEEP 19

long long int gfb[(1 << DEEP)];
long long int mkb[(1 << DEEP)];

void adb(long long int* a,int b,long long int x)
{
	int n = b + 1;
	while(n != (1 << DEEP))
	{
		a[n - 1] += x;
		n += (n & (-n));
	}
}

long long int wa(long long int* a,int b)
{
	long long int w = 0;
	int n = b + 1;
	while(n != 0)
	{
		w += a[n - 1];
		n -= (n & (-n));
	}
	return w;
}

pair<long long int,int> aw[(1 << DEEP)];
int at[(1 << DEEP)];
pair<long long int,int> bw[(1 << DEEP)];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		int aq,bq;
		scanf("%d %d",&aq,&bq);
		aw[i] = make_pair(aq,i);
		bw[i] = make_pair(bq,i);
	}
	sort(aw,aw + n);
	for(int i = 0; i < n; i++)
	{
		at[aw[i].second] = i;
	}
	sort(bw,bw + n,greater<pair<long long int,int> >());
	bw[n] = make_pair(-1,-1);
	for(int i = 0; i < (1 << DEEP); i++)
	{
		gfb[i] = 0;
		mkb[i] = 0;
	}
	
	int na = 0;
	int max = 0;
	for(int i = 0; i < n; i++)
	{
		adb(gfb,at[bw[i].second],aw[at[bw[i].second]].first);
		adb(mkb,at[bw[i].second],1);
		if(bw[i].first == bw[i + 1].first)
		{
			continue;
		}
		
		long long int minf = bw[i].first;
		if(wa(gfb,na) <= minf * wa(mkb,na))
		{
			while(1)
			{
				if(na >= n - 1)
				{
					if(max < wa(mkb,na) && wa(gfb,na) <= minf * wa(mkb,na))
					{
						max = wa(mkb,na);
					}
					break;
				}
				
				if(wa(gfb,na + 1) > minf * wa(mkb,na + 1))
				{
					if(max < wa(mkb,na) && wa(gfb,na) <= minf * wa(mkb,na))
					{
						max = wa(mkb,na);
					}
					break;
				}
				na++;
			}
		}
		else
		{
			while(1)
			{
				if(na <= 0)
				{
					if(max < wa(mkb,na) && wa(gfb,na) <= minf * wa(mkb,na))
					{
						max = wa(mkb,na);
					}
					break;
				}
				
				if(wa(gfb,na) <= minf * wa(mkb,na))
				{
					if(max < wa(mkb,na) && wa(gfb,na) <= minf * wa(mkb,na))
					{
						max = wa(mkb,na);
					}
					break;
				}
				na--;
			}
		}
	}
	printf("%d\n",max);
	return 0;
}

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

using namespace std;

using ll = long long;
const int maxw = 100010;
int N, W;
ll dp[maxw];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> N >> W;
	ll v; int w;
	while (N--) {
		cin >> w >> v;
		for (int j = W; j >= w; j--) {
			dp[j] = max(dp[j], dp[j-w] + v);
		}
	}
	ll ans = 0;
	for (int j = 0; j <= W; j++) ans = max(ans, dp[j]);

	cout << ans << endl;
}

Measured memory_bytes: 1024
import collections
import math

def comb(n, r):
    if n < 2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N = int(input())
L = input().split(" ")

c = collections.Counter(L)

d = {}
tmp_total = 0 

memo1 = {}
L2 = {}

for i in c:
    if c[i] not in memo1.keys():
        tmp = comb(c[i], 2)
        memo1[c[i]] = tmp
        tmp_total += tmp
    else:
        tmp_total += memo1[c[i]]
        
total = tmp_total

for i in L:
    ans = total - memo1[c[i]] + memo1[c[i]]*(c[i]-2)//c[i]
    print(ans)

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

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


Measured memory_bytes: 3132
l,r=map(int,input().split())
if r-l>=2019:
  print(0)
else:
  ll=l%2019
  rr=r%2019
  if rr<ll:
    print(0)
  else:
    keep=2020
    for i in range(ll,rr+1):
      for j in range(i+1,rr+1):
        modmod=(i*j)%2019
        if modmod<keep:
          keep=modmod
    print(keep)


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    set<int> st; rep(i, N){int a; cin >> a; st.insert(a);}
    cout << st.size() << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main() {
    int h, w;
    cin >> h >> w;
 
    vector<vector<int>> map(h + 2, vector<int>(w + 2, -1));
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
 
        for (int j = 1; j <= w; j++) {
            if (s[j - 1] == '.') {
                map[i][j] = 0;
            }
        }
    }
 
    vector<vector<int>> row_lr(h + 2, vector<int>(w + 2, -1));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (map[i][j] == 0) {
                row_lr[i][j] = row_lr[i][j - 1] + 1;
            }
        }
    }
 
    vector<vector<int>> row_rl(h + 2, vector<int>(w + 2, -1));
    for (int i = 1; i <= h; i++) {
        for (int j = w; j >= 1; j--) {
            if (map[i][j] == 0) {
                row_rl[i][j] = row_rl[i][j + 1] + 1;
            }
        }
    }
 
    vector<vector<int>> col_tb(h + 2, vector<int>(w + 2, -1));
    for (int i = 1; i <= w; i++) {
        for (int j = 1; j <= h; j++) {
            if (map[j][i] == 0) {
                col_tb[j][i] = col_tb[j - 1][i] + 1;
            }
        }
    }
 
    vector<vector<int>> col_bt(h + 2, vector<int>(w + 2, -1));
    for (int i = 1; i <= w; i++) {
        for (int j = h; j >= 1; j--) {
            if (map[j][i] == 0) {
                col_bt[j][i] = col_bt[j + 1][i] + 1;
            }
        }
    }
 
    int max = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (map[i][j] == 0) {
                int sum = row_lr[i][j] + row_rl[i][j] + col_tb[i][j] + col_bt[i][j] + 1;
                if (max < sum) {
                    max = sum;
                }
            }
        }
    }
 
    cout << max << endl;
}

Measured memory_bytes: 78848
// Problem : C - /\/\/\/
// Contest : AtCoder - AtCoder Beginner Contest 111
// URL : https://atcoder.jp/contests/abc111/tasks/arc103_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,ce=0,co=0,o,e;
	cin>>n;
	unordered_map<int,int> even,odd;
	loop(i,n)
	{
		int temp;
		cin>>temp;
		if(i%2==0)
		{
			even[temp]++;
			ce++;
		}
		else
		{
			odd[temp]++;
			co++;
		}
	}
	int mn1=imax,mn2=imax;
	trav(i,odd)
	{
		if(mn1>co-i.s)
		{
			o=i.f;
			mn1=co-i.s;
		}
	}
	trav(i,even)
	{
		if(mn2>ce-i.s)
		{
			e=i.f;
			mn2=ce-i.s;
		}
	}
		if(e!=o)
		cout<<mn1+mn2<<nl;
		else
		{
			int mnn1=100000,mnn2=100000;
			trav(i,odd)
			{
				if(mnn1>co-i.s&&i.f!=o)
					mnn1=abs(co-i.s);
				}
			trav(i,even)
			{
				if(mnn2>ce-i.s&&i.f!=e)
					mnn2=abs(ce-i.s);
				}
			//	cout<<mnn1<<" "<<" "<<mn2<<" "<<mnn2<<" "<<mn1<<nl;
			if(mnn2==100000&&mnn1==100000)
			cout<<n/2;
			else
			cout<<min(mnn2+mn1,mn2+mnn1);
		}
	
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 7328
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=a;i--)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << " "
#define pw(x) (1ll<<(x))
#define pq priority_queue
#define endl "\n"
int main()
{
    ios::sync_with_stdio(false);
	ll a;
	string b;
	cin >> a >> b;
	ll ans=0;
	ans+=(b[0]-'0')*a;
	ans+=((b[2]-'0')*a*10+(b[3]-'0')*a)/100;
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
import Control.Applicative ((<$>))
import Control.Monad (replicateM)
import Data.List (sort)

main :: IO ()
main = do
  n <- readLn
  es <- replicateM n (map read <$> words <$> getLine) :: IO [[Int]]
  putStr $ unlines $ map orth es

orth :: [Int] -> String
orth = (\xs -> if (xs!!2)^2 == (xs!!0)^2 + (xs!!1)^2 then "YES" else "NO") . sort

Measured memory_bytes: 4532