akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

		for(int i=0;i<n;i++) {
			L[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		Arrays.sort(L);
		int max = L[n-1];
		int sum = 0;
		for(int i=0;i<n-1;i++) {
			sum += L[i];
		}
		if(max < sum) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

int ketawa(int n) {
    int wa = 0;
    while (n>0) {
        wa += n % 10;
        n /= 10;
    }
    return wa;
}

int main(){
    int N,A,B;
    cin >> N >> A >> B;
    int cnt =0;
    for (int i=0;i<=N;i++) {
        if(ketawa(i)>=A&&ketawa(i)<=B) {
            cnt+=i;
        }
    }
    cout << cnt << endl;
}

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

#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long INF = 1e9;
const long long mod = 1e9 + 7;

int n;
int a[N];
int b[N];
int main()
{
    /// freopen("sum.in", "r", stdin);
    /// freopen("sum.out", "w", stdout);

    ios_base::sync_with_stdio( 0 );

    cin >> n;
    for ( int i = 1; i <= n; i ++ ){
        cin >> a[i];
        b[i] = a[i];
    }
    sort( a + 1, a + n + 1 );
    for ( int i = 1; i <= n; i ++ ){
        cout << a[n - ( b[i] == a[n] )] << "\n";
    }
}


Measured memory_bytes: 3200
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 1e6;
int s[maxn], a[maxn];
signed main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.setf(ios::fixed); cout.precision(10);
  int n, m, v, p;
  cin >> n >> m >> v >> p;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  reverse(a + 1, a + n + 1);
  for(int i = 1; i <= n; ++i) {
    s[i] = s[i - 1] + a[i];
  }
  int res = p;
  a[0] = -1;
  for(int i = p + 1; i <= n; ++i) {
    if(a[i] == a[i - 1]) {
      res = i;
      continue;
    }
    int x = i - p;
    int sum = s[i - 1] - s[p - 1];
    // cout << sum - a[i] * x << ' ' << x << endl;
    if(m < max((sum - a[i] * x + n - v - 1) / (n - v), a[p] - a[i])) {
      break;
    }
    res = i;
  } 
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int a,b; cin>>a>>b;
    int ans=a;
    int count=1;
    if(b==1) cout<<0<<endl;
    else{
    while(ans<b){
        ans+=a;
        ans--;
        count++;
    }
    cout<<count<<endl;
    }
    return 0;  
}



Measured memory_bytes: 256
N, A = map(int, input().split())
X = [int(x) for x in input().split()]

m = {}
def f(cv, cur, rest):
    tgt = A * len(cur)
    if len(rest) == 0:
        if cv == tgt and cv != 0:
            return 1
        else:
            return 0
    if cv > tgt and rest[0] > A:
        return 0
    
    ans = 0
    
    cc = cur.copy()
    r = rest[1:]
    sig = (cv, len(cc), tuple(r))
    if sig in m:
        ans += m[sig]
    else:
        ret = f(cv, cc, r)
        m[sig] = ret
        ans += ret

    cc.append(rest[0])
    cv += rest[0]
    sig = (cv, len(cc), tuple(r))
    if sig in m:
        ans += m[sig]
    else:
        ret = f(cv, cc, r)
        m[sig] = ret
        ans += ret
    return ans

print(f(0, [], sorted(X)))

Measured memory_bytes: 68456
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100000];
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx-sx;
    int y = ty-sy;
    for(int i=1;i<=y;i++)
    {
        cout<<"U";
    }
    for(int i=1;i<=x;i++)
    {
        cout<<"R";
    }
    for(int i=1;i<=y;i++)
    {
        cout<<"D";
    }
    for(int i=1;i<=x;i++)
    {
        cout<<"L";
    }
    cout<<"L";
    for(int i=0;i<=y;i++)
    {
        cout<<"U";
    }
    cout<<"R";
    for(int i=0;i<x;i++)
    {
        cout<<"R";
    }
    cout<<"D";
    cout<<"R";
    for(int i=0;i<=y;i++)
    {
        cout<<"D";
    }
    cout<<"L";
    for(int i=0;i<x;i++)
    {
        cout<<"L";
    }
    cout<<"U";
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split(" "))
denQs=[]
count=0
for i in range(m):
	denQ=[]
	line=input().split(" ")
	for j in range(int(line[0])):
		denQ.append(int(line[j+1]))
	denQs.append(denQ)
denQrights=input().split(" ")
ansLst=[[0],[1]]
for i in range(n-1):
	nxtAnsLst=[]
	for a in ansLst:
		nxtAnsLst.append(a+[0])
		nxtAnsLst.append(a+[1])
	ansLst=nxtAnsLst
for a in ansLst:
	isFound=True
	for i in range(m):
		c=0
		for j in denQs[i]:
			c+=a[j-1]
		if c%2!=int(denQrights[i]):
			isFound=False
			break;
	if isFound:
		count+=1
print(count)

Measured memory_bytes: 3188
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        long output=1;
        long mod=1000000007;
        for(int i=0;i<n;i++){
            output*=i+1;
            output%=mod;
        }
        System.out.println(output);
    }
}

Measured memory_bytes: 23124
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process()throws IOException
    {
        int n=ni()%10;

        if(n==2 || n==4 || n==5 || n==7 || n==9)
            pn("hon");
        else if(n==0 || n==1 || n==6 || n==8)
            pn("pon");
        else
            pn("bon");
    }
 
 
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new FastReader();
 
        long s = System.currentTimeMillis();
        int t=1;
       // t=ni();
        while(t-->0)
            process();
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }
    
    
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static int ni()throws IOException{return Integer.parseInt(sc.next());}
    static long nl()throws IOException{return Long.parseLong(sc.next());}
    static double nd()throws IOException{return Double.parseDouble(sc.next());}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    
    static long mod=(long)1e9+7l;
 
    static<T> void r_sort(T arr[],int n){
        Random r = new Random(); 
        for (int i = n-1; i > 0; i--){ 
            int j = r.nextInt(i+1); 
                  
            T temp = arr[i]; 
            arr[i] = arr[j]; 
            arr[j] = temp; 
        } 
        Arrays.sort(arr); 
    }
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

Measured memory_bytes: 36616
#include<iostream>
#include<cmath>
#define rep(i, a, b) for(int i=(a); i<(b); i++)
using namespace std;

int main(){
  int N,S1[100]={},S2[100]={},sum=0,sum2=0,dif=101;
  cin >> N;
  rep(i,0,N){
    int s_temp;
    cin >> s_temp;
    S1[i]=s_temp;
    sum+=s_temp;
  }
  rep(i,0,N){
    int s_temp;
    if(dif > abs(sum - sum2)){
      dif = abs(sum - sum2);
    }else if(i == 0){
      dif = abs(sum - sum2);
    }else{
      break;
    }
    //cout<< dif <<endl;
    sum -= S1[N-i-1];
    sum2 += S1[N-i-1];
    //cout<<sum << " "<<sum2<<endl;
  }

  cout<< dif << endl;
}


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

int main(void){
    ll n,m; cin >> n >> m;
    if(m/2 < n) cout << m/2 << endl;
    else{
        cout << n +(m - (2*n))/4 << endl;
    }


    return 0;
}

Measured memory_bytes: 256
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,K = two_int()
H=many_int()

sH=sorted(H)

newK = max(N-K,0)

min_sH = sH[:newK]

print(sum(min_sH))

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n,m, k, a[202020],b[202020], c[202020];
i64 v[3030][3030];
i64 dp[3030][3030][4];
void solve(){
	cin >> n >> m >> k;
	for(int i = 0; i < k; i++){
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
		v[a[i]][b[i]] = c[i];
	}
	
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			i64 ue = dp[i][j+1][3];
			dp[i+1][j+1][0] = ue;
			dp[i+1][j+1][1] = dp[i+1][j][1];
			dp[i+1][j+1][2] = dp[i+1][j][2];
			dp[i+1][j+1][3] = dp[i+1][j][3];
			chmax(dp[i+1][j+1][1], ue+v[i][j]);
			chmax(dp[i+1][j+1][1], dp[i+1][j][0]+v[i][j]);
			chmax(dp[i+1][j+1][2], dp[i+1][j][1]+v[i][j]);
			chmax(dp[i+1][j+1][3], dp[i+1][j][2]+v[i][j]);
			chmax(dp[i+1][j+1][3], max({dp[i+1][j+1][0],dp[i+1][j+1][1],dp[i+1][j+1][2]}));
		}
	}
	cout << dp[n][m][3] << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 363312
a, b, x = gets.split.map(&:to_i)

def solve(a, b, x)
  if 0.5 * a**2 * b < x then
    return Math.atan((2.0 * a**2 * b - 2.0 * x) / a ** 3)
  else
    return 0.5 * Math::PI - Math.atan(2.0 * x / (1.0 * a * b**2))
  end
end

puts solve(a, b, x) * 180.0 / Math::PI


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

int main(){
  int n,a,b,an,bn;
  char s;
  cin>>n>>a>>b;
  an=0;
  bn=0;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s=='a'){
      if(an+bn<a+b){
	an++;
	cout<<"Yes"<<endl;
      }else cout<<"No"<<endl;
    }else if(s=='b'){
	if(an+bn<a+b&&bn+1<=b){
	  bn++;
	  cout<<"Yes"<<endl;
	}else cout<<"No"<<endl;
    }else if(s=='c')cout<<"No"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 640
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var atotal = 0;
            var btotal = 0;
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = int.Parse(line[0]);
                var b = int.Parse(line[1]);
                if (a > b) atotal += a + b;
                else if (a < b) btotal += a + b;
                else
                {
                    atotal += a;
                    btotal += b;
                }
            }
            Console.WriteLine("{0} {1}", atotal, btotal);
        }
    }
}

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll n,ans=0;
    cin >> n;
    vl v(n);
    rep(i,n)cin >> v[i];
    sort(all(v));
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            ans+= upper_bound(all(v),v[j]+v[i]-1)-v.begin()-j-1;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

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

    int n;
    cin >> n;

    map<int, int> odd, even;
    for (int i = 0; i < n; ++i) {
        int v; cin >> v;
        if (i % 2 != 0) ++even[v];
        else ++odd[v];
    }

    vector<pair<int, int>> o, e;
    for (auto it : odd) o.push_back(make_pair(it.second, it.first));
    for (auto it : even) e.push_back(make_pair(it.second, it.first));

    sort(o.begin(), o.end(), greater<pair<int, int>>());
    sort(e.begin(), e.end(), greater<pair<int, int>>());

    if (o.size() == 1 && e.size() == 1) {
        if (o[0].second == e[0].second)
            cout << n / 2 << endl;
        else
            cout << "0\n";
    }
    else if (o.size() == 1) {
        if (o[0].second != e[0].second)
            cout << (n / 2 - e[0].first) << endl;
        else
            cout << (n / 2 - e[1].first) << endl;
    }
    else if (e.size() == 1) {
        if (e[0].second != o[0].second)
            cout << (n / 2 - o[0].first) << endl;
        else
            cout << (n / 2 - o[1].first) << endl;
    }
    else {
        if (o[0].second != e[0].second)
            cout << (n / 2 - o[0].first) + (n / 2 - e[0].first) << endl;
        else if (o[0].first + e[1].first >= o[1].first + e[0].first)
            cout << (n / 2 - o[0].first) + (n / 2 - e[1].first) << endl;
        else
            cout << (n / 2 - o[1].first) + (n / 2 - e[0].first) << endl;
    }

    return 0;
}


Measured memory_bytes: 6140
from math import gcd
from functools import reduce
 
n=int(input())
s=input()
 
ret=0
 
for i,x in enumerate(s):
	for j,y in enumerate(s[i+1:],start=i+1):
		if x==y:
			continue
		if i+(j-i)*2 < n :
			z=s[i+(j-i)*2]
			if y!=z!=x:
				ret-=1
 
dic={}
for x in s:
	if not x in dic: 
		dic[x]=0
	dic[x]+=1
 
for i,x in dic.items():
	for j,y in dic.items():
		for k,z in dic.items():
			if i<j<k:
				ret+=x*y*z
print(ret)

Measured memory_bytes: 75008
#include <stdio.h>

int main()
{
    long long int a,b,k,dif;
    scanf("%lld %lld %lld",&a, &b, &k);

     if(a+b<=k){
            a=0;
            b=0;
        printf("%lld %lld",a,b);
     }
     else{
        dif=a-k;
        if(dif>=0){
           a=dif;
           printf("%lld %lld",a,b);
        }
        else{
            a=0;
            b=b-(-dif);
            printf("%lld %lld",a,b);
        }
     }

    return 0;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    int p[n];
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];

        if (i < 2)
        {
            continue;
        }
        else
        {
            if ((p[i] - p[i - 1]) * (p[i - 2] - p[i - 1]) < 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

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

void solve(long long N, long long K, std::vector<long long> l)
{
    RSORT(l);
    int ans = 0;
    REP(i, K)
    {
        ans += l[i];
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> l(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &l[i]);
    }
    solve(N, K, std::move(l));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(void){
	int a, b, c, d;
	int W, H, x, y, r;
	
	std::cin >> W >> H >> x >> y >> r;
	
	/*まず円の4点の構成要素を計算*/
	a = x - r;
	b = x + r;
	c = y - r;
	d = y + r;
	
	if (0 <= a && b <= W && 0 <= c && d <= H ) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>

int main()
{
  int k,x;

  std::cin >> k;
  std::cin >> x;

  for (int i = x-(k-1); i < x+k; ++i){
    std::cout << i; 
    if ( i < x+k-1){
    std::cout << ' '; 
    }
  }

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


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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

ll answer(ll H) {
    if (H == 1)
        return 1;
    else if(H>1)
        return 2 * answer(H / 2) + 1;
}
    int main(void)
    {
        ll H;
        cin >> H;

        ll ans = answer(H);
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<pair<long long,int>, null_type, less<pair<long long,int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
 
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(num) num.begin(), num.end()
#define lp(i, nodess) for (int i = 0; i < nodess; i++)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define X real()
#define Y imag()
#define angle(u) (atan2(u.Y, u.X))
#define vec(u, v) ((v) - (u))
//#define length(u) (hypot(u.Y , u.X))
#define normalize(u) (u) / length(u)
#define dotP(u, v) ((conj(u) * v).X)
#define crossP(u, v) ((conj(u) * v).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(u) dotP(u, u)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(vis, m) conj(vis / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll nodess, ll num, ll m) {
  if (!num)
    return 1;
  if (num % 2)
    return nodess * fastpow(nodess, num - 1, m)%m;
  ll p = fastpow(nodess, num / 2, m);
  p %= m;
  p *= p;
  p %= m;
  return p;
}
 
ll my_mod(ll num, ll mod) {
  ll reto = num % mod;
  while (reto < 0)
    reto += mod;
  return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
long long dist(pair<ll, ll> u, pair<ll, ll> v) {
  return 
      abs(u.f - v.f)  + abs(u.se - v.se);
}
long long getDist(pair<ll, ll> &u, pair<ll, ll> &v) {
  return 
     (u.f - v.f)*(u.f - v.f)  + (u.se - v.se)*(u.se-v.se);
}
 
 
 
/*vector<int> ap;
int np[MX+5];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <=MX; j+=i) np[j] = 0;
        }
    }
    int idx = 1;
    for(ll i = 2 ; i<= MX ; i++){
		if(np[i]){
			np[i] = idx;
			idx++; 
			ap.pb(i);
		}
	}
	//cout<<idx;
}*/
const int MX = 10009;

int main()
{
    IO;
	int n;
	cin>>n;
	vector<int> arr(n);
	for(int i =0 ;i < n; i++) cin>>arr[i];
	int mini = arr[0];
	int cnt = 1;
	for(int i =1 ;i < n; i++){
		mini= min(arr[i], mini);
		cnt += arr[i] <= mini;
	}
	cout<<cnt;
	
	return 0;
}



















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

const int N = (int) 2e5 + 5;

int n, k;
long long a[N];
unordered_map <long long, long long> remain;

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	remain[0]++;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i]; a[i] += a[i - 1];
		if (i - k >= 0) remain[(a[i - k] - (i - k)) % k]--;
		ans += remain[(a[i] - i) % k]++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 10056
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt(), M = NextInt();
        int root = (int)Math.Sqrt(M);
        List<int> prime = new List<int>();
        for (int i = 2; i <= root; i++)
        {
            int x = 0;
            while (M % i == 0) { M /= i; x++; }
            if (x > 0) prime.Add(x);
        }
        if (M != 1) prime.Add(1);
        long ans = 1;
        foreach (var e in prime)
        {
            ans *= nHr(N, e);
            ans %= MOD;
        }
        Console.WriteLine(ans);
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
    public static long nHr(long n, long r)
    {
        n = n + r - 1;
        long a = 1;
        for (long x = 0; x < r; x++) { a *= (n - x); a %= MOD; }
        long b = 1;
        for (long x = 2; x <= r; x++) { b *= x; b %= MOD; }
        b = RepPow(b, MOD - 2) % MOD;
        return a * b % MOD;

    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 0) return 1;
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13268
N, K = map(int, input().split())
MOD = 10**9+7
ans = 0
# K < N/2
for i in range(K, N+2):
    # print(i*N, (i-1)*i, 1, i*N - (i-1)*i + 1)
    ans += i*N - (i-1)*i + 1
    ans %= MOD

print(ans)


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

using namespace std;

constexpr int MAXN = 1e5 + 5, MOD = 1e9 + 7;

template <typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

struct BIT {  // Binary Index Trees, 1based
    int lowbit(int x) { return x & (~x + 1); }
    /* O(n) 建树*/
    void build(int x = 2, int sub = 1) {
        while (x <= n) {
            for (int i = x; i <= n; i += x) c[i] += c[i - sub];
            x <<= 1, sub <<= 1;  // 2 ^ n
        }
    }
    /*@param x the position to add val*/
    void add(int x, int val) {
        while (x <= n) c[x] += val, x += lowbit(x);
    }
    /*查询 [1, x] 的前缀和*/
    int query(int x, int res = 0) {
        while (x) res += c[x], x -= lowbit(x);
        return res;
    }
    int n;
    array<int, MAXN> c;
};

struct Node {
    Node *lson, *rson;
    int cnt, tag, l, r;
};

int tc, n, m;
array<int, MAXN> a;

int main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * c, max(b * d, max(b * c, a * d)));
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

using namespace std;

typedef long long ll;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> A(n, vector<int>(m));
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {
		cin >> A[i][j];
		A[i][j]--;
	}
	
	int l = 0, r = n;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		
		vector<int> ind(n), fail(m);
		
		int ok = 1;
		for (int it = 0; ; it++) {
			for (int i = 0; i < n; i++) if (ind[i] != -1) {
				while (ind[i] < m && fail[A[i][ind[i]]]) ind[i]++;
				if (ind[i] == m) ok = 0;
			}	
			if (!ok) break;
		
			map<int, int> cnt;
			for (int i = 0; i < n; i++) if (ind[i] != -1) {
				cnt[A[i][ind[i]]]++;
			}
			
			if (cnt.empty()) break;
			
			int bad = 0;
			for (auto c : cnt) {
				if (c.second > mid) {
					fail[c.first] = 1;
					bad = 1;
				}
			}
			if (!bad) {
				for (auto c : cnt) {
					for (int i = 0; i < n; i++) if (ind[i] != -1 && A[i][ind[i]] == c.first)
						ind[i] = -1;
				}
			}
		}
		
		if (*max_element(ind.begin(), ind.end()) > -1 || !ok) l = mid;
		else r = mid;
	}
	cout << r << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    vector<int> l(N);
    rep(i,N) cin>>l[i];
    ll ans=0;
    sort(l.begin(),l.end());
    auto b_itr=l.begin();
    rep(i,N-2){
        for(int j=i+1; j<N; j++){
            auto itr = upper_bound(l.begin(),l.end(),l[i]+l[j]-1);
            int c=(itr-b_itr)-j+1;
            ans+=c-2;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> va,vb,vc;
priority_queue<int, vector<int> ,greater<int> > p;

int main(){
    int x,y,a,b,c;
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    for (int i = 0; i < a; i++){
        int X;
        scanf("%d",&X);
        va.push_back(X);
    }
    for (int i = 0; i < b; i++){
        int X;
        scanf("%d",&X);
        vb.push_back(X);
    }
    for (int i = 0; i < c; i++){
        int X;
        scanf("%d",&X);
        vc.push_back(X);
    }
    sort(va.begin(),va.end(),greater<int>());
    sort(vb.begin(),vb.end(),greater<int>());
    sort(vc.begin(),vc.end(),greater<int>());
    ll ans = 0;
    for (int i = 0; i < x; i++){
        ans += va[i];
        p.push(va[i]);
    }
    for (int i = 0; i < y; i++){
        ans += vb[i];
        p.push(vb[i]);
    }
    for (int i = 0; i < c; i++){
        int X = vc[i];
        ans += X;
        p.push(X);
        ans -= p.top();
        p.pop();
    }
    printf("%lld ",ans);


}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    int n;
    cin>>n;
   bool OK = false;
	for (int j = 0; j <= n / 4; j++) {
		for (int k = 0; k <= n / 7; k++) {
			if (4 * j + 7 * k == n)
			OK = true;
		}
	}
	if (OK == false)
	cout << "No" << endl;
	else cout << "Yes" << endl;
    return 0;
}


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

int main() {
  int N; cin >> N;
  cout << N * N * N << endl;
}


Measured memory_bytes: 256
arr = gets.chomp.split('')

  if arr[0] == "R" && arr[1] == "R" && arr[2] == "R"
  puts "3"
    exit
  end
  if arr[0] == "R" && arr[1] == "R"
   puts "2"
    exit
 end
if arr[1] == "R" && arr[2] == "R"
   puts "2"
  exit
 end
if arr.include?("R")
  puts "1"
else
  puts "0"
end

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n)*(n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
  char strong;
  while(cin>>strong,strong!='#'){
    // tuple<int, int, char, int> cards[13][4];
    vector<tuple<int, int ,char ,int>> cards[13];
    REP(i, 4){
      REP(j, 13){
        char n, m;
        cin >> n >> m;
        switch (n) {
          case 'T':
          n = 10;
          break;
          case 'J':
          n = 11;
          break;
          case 'Q':
          n = 12;
          break;
          case 'K':
          n = 13;
          break;
          case 'A':
          n = 14;
          break;
          default:
          n = n - '0';
          break;
        }
        tuple<int, int, char, int> t = make_tuple((m==strong)?2:0, (int)n, (char)m, (int)i);
        cards[j].push_back(t);
      }
    }
    int direction = 3;
    int p[4] = {0};
    REP(j, 13){
      REP(i, 4){
        strong = get<2>(cards[j][direction]);
        if (get<2>(cards[j][i]) == strong) get<0>(cards[j][i]) = 1;
      }
      RSORT(cards[j]);
      direction = get<3>(cards[j][0]);
      p[direction]++;
      // LOG("%d", direction);
    }
    if (p[0] + p[2] > p[1] + p[3]){
      printf("NS %d\n", (p[0]+p[2])%6);
    }else{
      printf("EW %d\n", (p[1]+p[3])%6);
    }
  }
}

Measured memory_bytes: 3108
import sys
input = sys.stdin.readline
from collections import deque
N, M = map(int, input().split())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

A = [0] * N
AA = [1] * N
for i in R[::-1]:
    a = 1
    for j in X[i]:
        a = a * (A[j] + 1) % M
    A[i] = a
for i in R:
    B = [1] * (len(X[i]) + 1)
    for j in range(len(X[i])):
        B[j+1] = B[j] * (A[X[i][j]] + 1) % M
    a = 1
    for j in range(len(X[i]))[::-1]:
        t = a * B[j]
        a = a * (A[X[i][j]] + 1) % M
        AA[X[i][j]] = (AA[i] * t + 1) % M

for t in [a * aa % M for a, aa in zip(A, AA)]:
    print(t)

Measured memory_bytes: 93104
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int X,Y,sum=0,count=100000000;
      cin >> X;
      Y = X;
      for (int i=0; i<9; i++){
        sum += X / count;
        X = X % count;
        count /= 10;
      }
      if(Y % sum == 0)cout<<"Yes";
      else cout<<"No";
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int N=15,M=1010;
int h,w,k;
int s[N][M];

int main(){
    cin>>h>>w>>k;

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++) {
            char m;
            cin>>m;
            int e=m-'0';
            s[i][j]=e+s[i-1][j]+s[i][j-1]-s[i-1][j-1];    
            //cout<<s[i][j]<<" ";
        }
        //cout<<endl;
    }
    
    int minsum=h+w-2;
    for(int i=0;i<(1<<(h-1));i++){//枚举横切情况
        vector<int> q;
        q.push_back(0);
        int sum=0;
        
        for(int j=0;j<h-1;j++){
            if(i>>j&1) {
                q.push_back(j+1);
                sum++;
            }
        }
        q.push_back(h);
        
        bool flag=true;
        int lastline=0;
        for(int j=1;j<=w;j++){//贪心纵切
            
            int wmax=0;
            for(int d=1;d<q.size();d++){

                wmax=max(wmax,s[q[d]][j]-s[q[d]][lastline]-s[q[d-1]][j]+s[q[d-1]][lastline]);
            }
        
            
            if(wmax>k){
                if(j==1){
                    flag=false;
                    break;
                }
                sum++;
                lastline=j-1;
            }
        }
        if(!flag) continue;
        minsum=min(minsum,sum);
    }
    cout<<minsum<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<endl
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define PI 3.14159265358979323846264338327
#define INF 2e14
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int n;

struct node{
	string F; ll S,idx;
};

vector<node> arr;

bool cmp(node a,node b){
	if(a.F!=b.F) return a.F<b.F;
	return a.S>b.S;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin>>n;
	forn(i,0,n){
		string s; ll x; cin>>s>>x;
		node tmp;
		tmp.F=s; tmp.S=x; tmp.idx=i;
		arr.pb(tmp);
	}
	
	sort(arr.begin(),arr.end(),cmp);
	
	forn(i,0,n) cout<<arr[i].idx+1<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

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

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}

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

const ll mod = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.14159265358979323846;


// ****************************************CODE***************************************//







int main(){
        int n,m;
        cin >> n >> m;
        vector<int> num(n+3,0);
        for(int i = 0; i < m; i++){
                int l,r;
                cin >> l >> r;
                num[l]++;
                num[r+1]--;
        }

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

        int sum = 0;
        for(int i = 0; i <= n; i++){
                if(num[i] == m) sum++;
        }

        cout << sum << endl;

}





















Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x;
cin>>n>>x;
  int m[105];
  int min = 1000000;
  for(int i = 0; i<n; i++){
      cin>>m[i];
      x = x-m[i];
      if(min>m[i]){
          min=m[i];
      }
  }
  
  cout<<x/min+n<<endl;
  return 0;
  
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll memo[(ll)(1<<17)];
ll grid[17][17];
ll cost[(ll)(1<<17)];
const ll M=1e9+7;

ll solve(ll mask,int n){
    ll maxx=(1<<n)-1;
    if(mask==0) return 0;
    if(memo[mask]!=-1) return memo[mask];
    ll ret=-1e18;
    for(int i=mask;i>0;i=(i-1)&mask){
        bool flag=true;
        ret=max(ret, cost[i]+ solve(mask^i,n));
    }
    
    return memo[mask]=ret;
}
int main(){
    memset(memo,-1,sizeof(memo));
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>grid[i][j];
        }
    }
    
    for(int i=0;i<=(1<<n)-1;i++){
        vector<int>vec;
        for(int j=0;j<n;j++){
            if(i&(1<<j)) vec.push_back(j);
        }
        ll temp=0;
        for(int j=0;j<vec.size();j++){
            for(int k=j;k<vec.size();k++)
            {
                temp+=grid[vec[j]][vec[k]];
            }
        }
        vec.clear();
        cost[i]=temp;
    }
    ll ans=solve((1<<n)-1,n);
    cout<<ans<<endl;
}


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

double dp[3001][3001]={};

double solve(double *arr,int n,int head)
{
	if(head==0)
		return 1;
	if(n==0)
		return 0;
	if(dp[n][head]>-1)
		return dp[n][head];
	return dp[n][head]=(arr[n])*solve(arr,n-1,head-1)+(1-arr[n])*solve(arr,n-1,head);
}

int main()
{
	int n;
	cin>>n;
	double arr[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];
    memset(dp,-1,sizeof dp);
	cout<<fixed<<setprecision(11)<<solve(arr,n,(n+1)/2);
}

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

int main() {
    int n;
    cin >> n;
    bool color[8];
    fill(color, color + 8, false);
    int over_red = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a /= 400;
        if (a < 8) color[a] = true;
        else over_red++;
    }
    int min_res = 0;
    for (int i = 0; i < 8; i++) {
        if (color[i]) min_res++;
    }
    cout << ((min_res == 0) ? 1 : min_res) << ' ' << (min_res + over_red) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, l, r) for (int i = int(l), __border_right##i = int(r); i < __border_right##i; i++)
#define STRUCT3(v1, v2, v3, name) struct name \
        {   \
            int v1, v2, v3; \
            name(int v1 = 0, int v2 = 0, int v3 = 0) : v1(v1), v2(v2), v3(v3) {} \
            friend bool operator < (const name& athis, const name& other) \
            {   \
                if (athis.v1 != other.v1) return athis.v1 < other.v1;   \
                if (athis.v2 != other.v2) return athis.v2 < other.v2;   \
                return athis.v3 < other.v3;   \
            }\
        }
#define PB push_back
#define LS (((k) << 1) + 1)
#define RS (((k) << 1) + 2)
#define LM ((l) + (r) >> 1)
#define RM (LM + 1)
#define LOG(x) tb[(UI(x) * (UI)263572066) >> 27]
#define FST first
#define SCD second
#define retunr return
#define modp 1000000007
#define EPS 1e-7
#define INF 0x3f3f3f3f
#define MAX2 113
#define MAX3 1013
#define MAX4 10013
#define MAX5 100013
#define MAX6 1000013
#define MAXN 2 * MAX5
#define MANX MAXN
using namespace std;
typedef long long LL;
typedef unsigned int UI;
//typedef pair<int, int> P;
const UI tb[32] = {13, 0, 27, 1, 28, 18, 23, 2, 29, 21, 19, 12, 24, 9, 14, 3, 30, 26, 17, 22, 20, 11, 8, 13, 25, 16, 10, 7, 15, 6, 5, 4};
typedef pair<LL,int> PAL;
typedef pair<int,int> PA;

int n,m;

PA h[10];

int main()
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out1.txt", "w", stdout);
#endif
    int T;
    // scanf("%d", &T);
    int Q,H,S,D;
    scanf("%d%d%d%d",&Q,&H,&S,&D);
    scanf("%d",&n);
    h[0]=PA(Q*8,1);
    h[1]=PA(H*4,2);
    h[2]=PA(S*2,4);
    h[3]=PA(D*1,8);
    sort(h,h+4);
    LL N=n*4LL;
    LL ans = 0;
    int i=0;
    while (N) {
        ans+=N/h[i].SCD*(h[i].FST/(8/h[i].SCD));
        N%=h[i].SCD;
        ++i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int q; cin >> q;
    rep(i,q){
        ll k; cin >> k;
        cout << binary_search(all(a), k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


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


    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = 0;
    ans += min(a,k);
    k -= min(a,k);
    k -= min(b,k);
    if(k>=0){
        ans -= min(k,c);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll MAX_N = ll(1e5 + 5);
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i,n) for (int i = n; i >=0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n, m, ans, tmp;
    vector<int> p, sum;
    while(1){
        cin >> n >> m;
        if(n==0)break;
        p.resize(n);
        sum.clear();
        REP(i,n)cin >> p[i];
        SORT(p);
        for(int i = 0; i<n; i++){
            if(p[i] > m)break;
            sum.push_back(p[i]);
            if(p[i] > m/2)continue;
            for(int j = i; j<n; j++){
                if(p[i]+p[j]>m)break;
                sum.push_back(p[i]+p[j]);
            }
            
        }
        sum.push_back(0);
        SORT(sum);
        ans = 0;
        for(auto& itr : sum){
            if(itr > m/2)break;
            tmp = itr + *--upper_bound(ALL(sum),m-itr);
            if(tmp > m)continue;
            ans = max(ans, tmp);
            if(ans == m)break;
        }
        cout << ans << endl;
    }
    return 0;
}



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


int main(){
    int N,W;
    cin >> N >> W;
    vector<ll> w(N),v(N);
    rep(i,N)cin >> w[i] >> v[i];

    vector<vector<ll> > dp(N+1,vector<ll>(W+1,0));
    rep(i,N){
        rep(j,W+1){
            if(j - w[i] >= 0) {
                dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]); 
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 80256
N, T = map(int, input().split())
ct = [list(map(int, input().split())) for _ in range(N)]

ans = 'TLE'
for ci, ti in ct:
    if ti > T: continue
    #
    if ans == 'TLE':
        ans = ci
    else:
        ans = min(ans, ci)

print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
#define lson l, mid, i<<1
#define rson mid+1, r, i<<1|1
#define PII pair<int, int>
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF  = 0x3f3f3f3f;
const int N = 1e2+5;

char str[N];

int main() {
    scanf("%s", str);
    int len = (int)strlen(str);
    int answer = INF;
    for(int i=0; i<26; i++) {
        int maxx = 0, pre = -1;
        for(int j=0; j<len; j++) {
            if(str[j] - 'a' == i) {
                maxx = max(maxx, j-pre-1);
                pre = j;
            }
        }
        maxx = max(maxx, len-pre-1);
        answer = min(answer, maxx);
    }
    printf("%d\n", answer);
}







Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
using namespace std;
int main(){
  int n;
  int a_from,b_from;
  int a_to,b_to;
  string str;
  cin>>n;
  cin>>a_from>>b_from;
  cin>>a_to>>b_to;
  cin>>str;
  a_from--;b_from--;
  a_to--;b_to--;

  if(a_to < b_to){
    int cnt=0;
    bool success=true;
    for(int i = a_from;i <= b_to&&success;i++){
      if(str[i]=='#'){
	cnt++;
      }else{
	cnt=0;
      }
      if(cnt>=2){
	success=false;
      }
    }
    
    if(success){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    int cnt=0;
    bool first=true;
    for(int i = a_from;i <= a_to&&first;i++){
      if(str[i]=='#'){
	cnt++;
      }else{
	cnt=0;
      }
      if(cnt>=2){
	first=false;
      }
    }

    cnt=0;
    bool second=false;
    for(int i = b_from - 1;i <= min(b_to+1,n-1)&&!second;i++){
      if(str[i]=='.'){
	cnt++;
      }else{
	cnt=0;
      }
      if(cnt>=3){
	second=true;
      }
    }

    if(first&&second){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return(0);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll n,m,k;
    cin >> n >> m >>k;
    vector<set<int>> ng(n);
    UnionFind uf(n);
    rep(i,m){
        int a,b;cin >> a >> b; --a; --b;
        ng[a].ins(b);
        ng[b].ins(a);
        uf.merge(a,b);
    }
    rep(i,k){
        int a,b;cin >> a >> b; --a; --b;
        if(!uf.same(a,b))continue;
        ng[a].ins(b);
        ng[b].ins(a);
    }
    rep(i,n){
        int a=uf.size(i)-ng[i].size()-1;
        cout << a << " ";
    }
}

Measured memory_bytes: 24704