akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var pg = new Program();

            pg.Execute();

        }

        private void Execute()
        {
            var input = ReadLineLong;
            var queue = new Queue<long>() { };
            for (int i = 1; i < 10; i++)
            {
                queue.Enqueue(i);
            }

            for (int i = 1; i < (int)input; i++)
            {
                var x = queue.Dequeue();
                if (x % 10 != 0)
                {
                    queue.Enqueue(10 * x + (x % 10) - 1);
                }
                queue.Enqueue(10 * x + (x % 10));
                if (x % 10 != 9)
                {
                    queue.Enqueue(10 * x + (x % 10) + 1);
                }
            }
            OutputResult(queue.Dequeue());
        }

        private void OutputResult<Type>(Type result)
        {
            Console.WriteLine(result);
        }

        static long ReadLineLong => long.Parse(Console.ReadLine());
        static string ReadLineString => Console.ReadLine();
        static IEnumerable<long> ReadLinesLongList => Console.ReadLine().Split(' ').Select(i => long.Parse(i));
        static IEnumerable<string> ReadLinesStringList => Console.ReadLine().Split(' ');

    }
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define ll long long

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    if (v.empty()) {
        ostr << "{ }";
        return ostr;
    }
    ostr << "{" << v.front();
    for (auto itr = ++v.begin(); itr != v.end(); itr++) {
        ostr << ", " << *itr;
    }
    ostr << "}";
    return ostr;
}

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

void solve() {
    int N;
    cin >> N;

    typedef pair<ll, ll> P;
    reps(i, 3501) {
        ll t = gcd(i, N);
        ll n = N * i / t;

        P p = P(4 * n / N - (n / i), n);
        if (p.first <= 0) continue;

        reps(j, 3501) {
            P p2 = p;
            ll t = gcd(j, p.second);
            ll n = p.second * j / t;

            p2.first = p.first * (n / p.second) - (n / j);
            p2.second = n;

            if (p2.first <= 0) continue;

            if (p2.second % p2.first == 0) {
                printf("%d %d %d\n", i, j, int(p2.second / p2.first));
                exit(0);
            }
        }
    }
}

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

    solve();
}


Measured memory_bytes: 256
#!/usr/bin/python

import sys

def main(argv):
    for line in sys.stdin:
        n, m = map(lambda i: int(i), line.split(' ', 2))

        answer = 0
        if m >= 2 * n:
            answer = n + int((m - 2 * n) / 4)
        else:
            answer = int(m / 2)
        print answer

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)2e5+9;


int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    int a, b, c;
    cin>>a>>b>>c>>k;
    ll ans = 0;

    p = min(a, k); ans+=p; k-=p;
    p = min(b, k); k-=p;
    p = min(c, k); ans-=p;

    cout<<ans<<endl;

  //  main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 3488
fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize_read();
    let a: Vec<i64> = sc.read_vec(n);
    let max = a.iter().map(|&a| a).max().unwrap();
    let selected: Vec<usize> = if max < 0 {
        vec![(0..n).filter(|&i| a[i] == max).next().unwrap()]
    } else {
        let even: Vec<usize> = (0..n).filter(|&i| i % 2 == 0 && a[i] >= 0).collect();
        let odd: Vec<usize> = (0..n).filter(|&i| i % 2 != 0 && a[i] >= 0).collect();
        if even.iter().map(|&i| a[i]).sum::<i64>() > odd.iter().map(|&i| a[i]).sum() {
            even
        } else {
            odd
        }
    };

    println!("{}", selected.iter().map(|&i| a[i]).sum::<i64>());
    let mut procedure = vec![];
    for i in ((selected[selected.len() - 1] + 1)..n).rev() {
        procedure.push(i);
    }
    for i in (1..selected.len()).rev() {
        let head = selected[i - 1];
        let tail = selected[i];
        let num = (tail - head) / 2;
        for i in (0..num).rev() {
            procedure.push(head + i + 1);
        }
    }
    for _ in 0..selected[0] {
        procedure.push(0);
    }

    println!("{}", procedure.len());
    for &i in &procedure {
        println!("{}", i + 1);
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

if N == 2:
    print(max(A)-min(A))
    print('{} {}'.format(max(A),min(A)))
else:
    p = [a for a in A if a>=0]
    n = [a for a in A if a<0]

    ans = []
    if len(n) == 0:
        p.sort()
        x = p.pop(0)
        y = p.pop()
        ans.append('{} {}'.format(x,y))
        n.append(x-y)
    if len(p) == 0:
        n.sort()
        x = n.pop()
        y = n.pop(0)
        ans.append('{} {}'.format(x,y))
        p.append(x-y)

    x = n.pop()
    while len(p)>1:
        y = p.pop()
        ans.append('{} {}'.format(x,y))
        x -= y
    y = x
    x = p[0]
    ans.append('{} {}'.format(x,y))
    x -= y
    while n:
        y = n.pop()
        ans.append('{} {}'.format(x,y))
        x -= y

    print(x)
    for s in ans:
        print(s)

Measured memory_bytes: 17208
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll res,n,v[1<<17];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++) cin >> v[i];
    for(int i = 0; i < n; i++) for(int j = 0; j < i; j++) res += v[i]*v[j];
    cout << res << '\n';
}


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

int main(){
  int64_t W, H, x, y;
  cin >> W >> H >> x >> y;

  cout << setprecision(10);

  if(2*x == W && 2*y == H){
    cout << W*H/2.0 << " " << 1 << endl;
  } else {
    cout << W*H/2.0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
//#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define SET set<int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x);  ->  printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;

void solve()
{
    string k;
    cin>>k;
    out(k[k.length()-1]=='s'?k+"es":k+"s")
    return ;
}
main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)solve();
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rrep(i,n) for (int i = 1; i <= (n); i++)
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  std::vector<int> c(n);
  Graph a(n, std::vector<int>(m));
  rep(i,n) {
    cin >> c.at(i);
    rep(j,m) {
      cin >> a.at(i).at(j);
    }
  }
  ll ans = 1e18;
  rep(bit,1<<n) {
    std::vector<int> d(n);
    rep(i,n) {
      if (bit>>i&1) d[i] = 1;
    }
    ll cost = 0;
    std::vector<int> total(m);
    bool ok = true;
    rep(i,n) {
      if (d[i]) {
        cost += c[i];
        rep(j,m) {
          total[j] += a[i][j];
        }
      }
    }
    rep(j,m) if (total[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == 1e18) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
int maxTime(int x){
  return (x + 9) / 10 * 10;
}
int los(int x){
  return maxTime(x) - x;
}
int main(){
  int a, b, c, d, e, ans;
  cin >> a >> b >> c >> d >> e;
  ans = maxTime(a) + maxTime(b) + maxTime(c) + maxTime(d) + maxTime(e);
  ans -= max({los(a),los(b),los(c),los(d),los(e)});
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,l; cin>>n>>l;
    vector<string> s(n);
    rep(i,n) cin>>s[i];
    sort(s.begin(), s.end());
    rep(i,n) cout<<s[i];
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n;
    int x[10000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
   scanf("%d",&x[i]);
    }
    for(int i=n-1;i>=0;i--){
       printf("%d",x[i]);
        if(i!=0)
        printf(" ");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2728
#include <iostream>
#include <cassert>
#include <vector>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <fstream>
#include <string>
#include <sstream>
#include <iterator>
#include <map>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <limits>
#include <typeinfo>
#include <numeric>
 
#include <stdio.h>
#include <string.h>
 
using namespace std;
  
int main(int argc, char* argv[])
{
 
	unsigned N;
	bool flg;
	long long sum;
 
	cin >> N;
 
	vector <int> s(N);
 
	for(unsigned i=0;i<N;i++){
		cin >> s[i];
	}
  
	sort(s.begin(),s.end());
 
 #if 0
	flg=false; 
	for(unsigned i=0;i<s.size();i++){
		sum = std::accumulate(s.begin() + i,s.end(),0ll);
		if(sum % 10 != 0){
			cout << sum << endl;
			flg=true;
			break;
		}	
	}
#else
	int cnt = 0;
	flg=false;
	sum = std::accumulate(s.begin(),s.end(),0ll);
	if(sum % 10 !=0){
		flg = true;
		cout << sum << endl;
	}else{
		while(cnt < s.size()){
			sum = std::accumulate(s.begin(),s.end(),0ll) - s[cnt];
			if(sum % 10 != 0){
				cout << sum << endl;
				flg=true;
				break;
			}
			cnt++;	
		}
	}
#endif

	if(!flg){
		cout << 0 << endl;
	}
 
	return 0;
 
}

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

int main() {
  int a, b, c, tmp;
  cin >> a >> b >> c >> tmp;
  if(a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  if(b > c) {
    tmp = b;
    b = c;
    c = tmp;
  }
  if(a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }
  cout << a << " " << b << " " << c << "\n";
  return 0;
}


Measured memory_bytes: 3100
import sys
import numpy as np 
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
from itertools import permutations

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, m, R = I[:3]
r = I[3:3+R] - 1
a, b, c = I[3+R:].reshape(-1, 3).T
graph = csr_matrix((c, (a-1, b-1)), shape=(n, n))

def main():
    dist = floyd_warshall(graph, directed=False).astype(np.int64)
    
    perms = np.array(list(permutations(r)))
    res = dist[perms[:, :-1], perms[:, 1:]]
    ans = np.amin(np.sum(res, axis=1))
    return ans

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

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

int main(){
    int n;
    cin >> n;
    int ans = 0, m = 0;
    if(n == 1){
        cout << '1' << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++){
        int num = i;
        int cnt = 0;
        while(1){
            if(num % 2 != 0) break;
            num /= 2;
            cnt++;
        }
        if(cnt > m){
            m = cnt;
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

string s,t;
ll a[200005], b[200005], pa[200005], pbb[200005];

int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("output.txt","w",stdout);
    int n,m,x,i;
	ll tests=1;
	//cin >> tests;
	while (tests--)
	{
		cin >> n >> m >> x;
		for (i = 0; i < n; i++)
		{
			cin >> a[i];
			pa[i+1] = pa[i] + a[i];
		}
		for (i = 0; i < m; i++)
		{
			cin >> b[i];
			pbb[i+1] = pbb[i] + b[i];
		}
		int ans = 0;
		for (i = 0; i <= n; i++)
		{
			if (pa[i] <= x)
			   ans = max(ans, i+(int)(upper_bound(pbb, pbb+m+1, x-pa[i])-pbb-1));
			else
				break;
		}
		cout << ans << endl;
	}
    return 0;
}


Measured memory_bytes: 9880
def imas(hoge_l, p, track):
    s_weights = 0
    now_track = 1
    for val in hoge_l:
        s_weights += val
        if s_weights > p:
            s_weights = val
            now_track += 1
        if now_track > track:
            return False
    return True

num, track = [int(x) for x in input().split()]
hoge_l = list()
for _ in range(num):
    hoge_l.append(int(input()))
left = 0
right = 100000 * 10000

while left < right :
    mid = (right + left) // 2
    if imas(hoge_l, mid, track):
        right = mid 
    else:
        left = mid + 1
        
max_num = max(hoge_l)
if max_num > right:
    right = max_num
print (right)


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

using namespace std;

typedef long long int ll;
#define fin(ans) cout << (ans) << endl;

#define rep(i, n) for (ll i = 0; i < (n); ++i)

void Main()
{
  ll n, a, b; cin >> n >> a >> b;
  a = a * n;
  fin(min(a, b))
}

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


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int[] x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
      int k = sc.nextInt();
      System.out.println(x[k-1]);
    }
}

Measured memory_bytes: 35536
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}

void solve(){
    ll n,m,k; cin>>n>>m>>k; vector<ll> arr(n),brr(m);
    rep(n) cin>>arr[i]; rep(m) cin>>brr[i];
    //rep(n-1) arr[i+1]+=arr[i]; rep(m-1) brr[i+1]+=brr[i];
    ll mp=0; ll cs=0; ll ap=-1,bp=-1;
    while(ap+1<n&&cs+arr[ap+1]<=k){ ap++; cs+=arr[ap]; }
    while(bp+1<m&&cs+brr[bp+1]<=k){ bp++; cs+=brr[bp]; }
    mp=max(mp,ap+bp+2);
    while(ap>-1){
        cs-=arr[ap]; ap--;
        while(bp+1<m&&cs+brr[bp+1]<=k) bp++,cs+=brr[bp];
        mp=max(mp,ap+bp+2);
    }
    cout<<mp<<endl;
}

int main(){
    fast;
    ll t=1; //cin>>t;
    rep(t) solve();
}


// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)

Measured memory_bytes: 6360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int cmpfunc(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){
    int n,t,i;
    scanf("%d %d",&n,&t);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    long long ans=0;
    long long end_time=t;
    for(i=0;i<n-1;i++){
        if(a[i+1]-a[i]>=t){
            ans+=t;
            end_time=a[i+1]+t;
        }
        else{
            ans+=a[i+1]-a[i];
            end_time=a[i+1]+t;
        }
    }
    ans+=t;
    printf("%lld\n",ans);
    return 0;
}


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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

void solve() {
    int n, k;
    cin >> n >> k;

    if ((n-1)/2>=(k-1)) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	vector<ll> a(100001,0);
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		ans+=x;
		a[x]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll x,y;
		cin>>x>>y;
		ll op=a[x]*x;
		ans-=op;
		ans+=(y*a[x]);
		a[y]+=a[x];
		a[x]=0;
		cout<<ans<<"\n";
	}

	return 0;
}

Measured memory_bytes: 3992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  
  ll a1 = a*c;
  ll a2 = b*c;
  ll a3 = a*d;
  ll a4 = b*d;

  ll ans = max(max(a1,a2),max(a3,a4));
  
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll N = 10000000;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int a,b,m; cin>>a>>b>>m;
	int arr1[a]; int arr2[b];
	for(int i=0;i<a;i++){
		int y;cin>>y;
		arr1[i] = y;
	}
	for(int i=0;i<b;i++){
		int y;cin>>y;
		arr2[i] = y;
	}
	int mini = N;
	for(int i=0;i<m;i++){
		int x,y,c;cin>>x>>y>>c;
		mini = min(mini,arr1[x-1]+arr2[y-1]-c);
	}
	sort(arr1,arr1+a); sort(arr2,arr2+b);
	mini = min(mini,arr1[0]+arr2[0]);
	cout<<mini<<endl;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
int main() {
  ll n;
  cin>>n;
  if(n%2==0){
    putout((n-1)/2);
  }
  else{
    putout(n/2);
  }
  
  
}

Measured memory_bytes: 256
res=Array.new
loop do
n=gets.to_i
if n==0 then break end
d=gets.split(' ').map(&:to_f)
m=d.inject(0.00000){|r,i|r+=i}/d.size
s=0
d.each do |x|
  s+=(x-m)*(x-m)
end
res.push(Math.sqrt(s/n))
end

res.each do |r|
    printf("%f\n",r)
end

Measured memory_bytes: 8716
//kruskal tree
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<double,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,k,m,n;
	double x,y,z,r;
	for(;cin>>n,n;){
		vector<vector<double> >v;
		for(i=0;i<n;i++)cin>>x>>y>>z>>r,v.push_back({x,y,z,r});
		for(i=0;i<n;i++)parent[i]=i;
		for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
			for(x=k=0;k<3;k++)x+=(v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			x=sqrt(x)-v[i][3]-v[j][3];
			if(x<0)x=0;
			a[m]=i,b[m]=j,node[m].first=x,node[m].second=m++;
		}
		sort(node,node+m);
		for(x=i=0;i<m;i++)if(unite(a[node[i].second],b[node[i].second]))x+=node[i].first;
		cout<<fixed<<setprecision(3)<<x<<endl;
	}
}

Measured memory_bytes: 1504
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    if(k+k<b-a+1){
        for(int i=a;i<a+k;i++){
            cout << i << endl;
        }
        for(int i=b-k+1;i<=b;i++){
            cout << i << endl;
        }
    }else{
        for(int i=a;i<=b;i++){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 256
n, l = map(int, input().split())
ans = sum([l + i - 1 for i in range(1, n+1)])

prev_abs_min = 1000
abs_min = 0
for i in range(1, n+1):
    if prev_abs_min > abs(l + i - 1):
        prev_abs_min = abs(l + i - 1)
        abs_min = l + i - 1
ans -= abs_min
print(ans)

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	if (a+b >= c) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

char f[50][50];

void resolve() {
    int h,w;
    cin >> h >> w;
    REP(i,0,h) REP(j,0,w) cin >> f[i][j];
    REP(i,0,h) REP(j,0,w) {
        int cnt = 0;
        if (f[i][j] != '.') continue;
        REP(k,-1,2) REP(l,-1,2) {
            if (k == 0 && l == 0) continue;
            if (i+k<0) continue;
            if (j+l<0) continue;
            if (i+k>=h) continue;
            if (j+l>=w) continue;
            if (f[i+k][j+l] == '#') ++cnt;
        }
        f[i][j] = '0' + cnt;
    }
    REP(i,0,h) {
        REP(j,0,w) cout << f[i][j];
        cout << endl;
    }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> ab(M);
  for (int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    ab[i]=make_pair(b,a);
  }
  sort(ab.begin(),ab.end());
  int ans=0,now=0;
  for (int i=0;i<M;i++){
    if (now<=ab[i].second){
      ans++;
      now=ab[i].first;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    ll N;
    set<ll> A;

    cin >> N;
    REP(i, N) {
        ll a;
        cin >> a;
        A.insert(a);
    }

    if(A.size() == N) { printf("YES\n"); }
    else { printf("NO\n"); }

    return 0;
}


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

using namespace std;
using ll = unsigned long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = n-1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl
#define mp(a, b) make_pair(a, b)
#define pb push_back

const long long MOD = 1000000007;

ll dp[1010][1<<12];

int main(){
    ll n, m;
    cin >> n >> m;
    ll as[m];
    ll bs[m];
    ll c;
    vector<ll> cs[m];
    rep(i, m){
        cin >> as[i] >> bs[i];
        rep(j, bs[i]){
            cin >> c;
            cs[i].push_back(c);
        }
    }

    rep(i, m+1){
        rep(j, 1<<12){
            dp[i][j] = 1LL<<60;
        }
    }
    dp[0][0] = 0;

    rep(i, m){
        ll mask = 0;
        for(auto e: cs[i]){
            mask |= (1<<(e-1));
        }
//        cerr << mask << endl;
        rep(j, 1<<12){
            dp[i+1][j|mask] = min(dp[i+1][j|mask], dp[i][j]+as[i]);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

//    rep(i, m+1){
//        rep(j, 1<<n){
//            cerr << dp[i][j] << "\t";
//        }
//        cerr << endl;
//    }

    ll mask = (1<<n)-1;
//    cerr << mask << endl;
    ll res = 1LL<<60;
    rep(i, m+1){
        if(i == 0)continue;
        res = min(res, dp[i][mask]);
    }
    if(res >= 1LL<<60){
        cout << -1 << endl;
        return 0;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 32512
#include<stdio.h>
int main(void)
{
	int a,b,x;
	
	scanf("%d",&a);
	scanf("%d",&b);
	x=a+b;
	
	if(x==24) {
		x=0;
	}
	if(x>24) {
		x=x-24;
	}
	printf("%d\n",x);
	return 0;
}

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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const int mod=1000000000+7;

int addm(int& a,int b) {return (a+=b)<mod?a:a-=mod;}

template<class T,class U> bool smin(T& a,U b) {return a>b?(a=b,1):0;}
template<class T,class U> bool smax(T& a,U b) {return a<b?(a=b,1):0;}

int N,M,Q,col[100000],exitdist[100000];
int lastvis[100000];
int dist[100000],ct;
vvi al;
typedef pair<ii,int> iii;
vector<iii> quer;

void bfs(const vvi& al, int s, int d,int c) {
	queue<int> q;
	//vi dist(al.size(),INT_MAX);
	dist[s]=0;
	lastvis[s]=ct;
	if (col[s]==0) col[s]=c;
	if (exitdist[s]>d) return;
	exitdist[s]=d+1;
	q.push(s);
	while (!q.empty()) {
		int i=q.front();q.pop();
		for (int j:al[i]) if (lastvis[j]<ct) {
			dist[j]=dist[i]+1;
			lastvis[j]=ct;
			if (dist[j]<=d) {
				if (col[j]==0) col[j]=c;
				if (exitdist[j]>d-dist[j]) continue;
				exitdist[j]=d-dist[j]+1;
				q.push(j);
			}
		}
	}
	return;
}

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

	cin >> N >> M;
	al.resize(N);
	for (int i=0;i<M;i++) {
		int u,v;cin >> u >> v;u--;v--;
		al[u].push_back(v);
		al[v].push_back(u);
	}

	cin >> Q;
	quer.resize(Q);
	for (iii &a:quer) {
		cin >> a.x.x >> a.x.y >> a.y;
		a.x.x--;
	}

	reverse(quer.begin(),quer.end());
	for (iii a:quer) {
		ct++;
		bfs(al,a.x.x,a.x.y,a.y);
	}

	for (int i=0;i<N;i++) cout << col[i] << '\n';

}

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

int main(){
    string str;
    getline(cin, str);

    int len = str.length();
    int tot = 0;
    if(str[0] == '0'){
        for(int i=0;i<len;i+=2){
            if(str[i]!='0') tot++;
        }
        for(int k=1;k<len;k+=2){
            if(str[k]!='1') tot++;
        }
    }else{
        for(int i=0;i<len;i+=2){
            if(str[i]!='1') tot++;
        }
        for(int k=1;k<len;k+=2){
            if(str[k]!='0') tot++;
        }
    }

    cout << tot << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main()
{
string S;
cin>>S;
if(S=="Sunny")
{
    cout<<"Cloudy"<<endl;
}
else if(S=="Cloudy")
{
    cout<<"Rainy"<<endl;
}
else
{
    cout<<"Sunny"<<endl;
}
    return 0;
}


Measured memory_bytes: 3408
// "static void main" must be defined in a public class.
import java.util.*;
public class Main {
    
    static double Probability(double p[], int n) 
{ 
  
    // Declaring the DP table 
    double [][]dp = new double[n + 1][n + 1]; 
  
    // Base case 
    dp[0][0] = 1.0; 
  
    // Iterating for every coin 
    for (int i = 1; i <= n; i += 1)  
    { 
  
        // j represents the numbers of heads 
        for (int j = 0; j <= i; j += 1)  
        { 
  
            // If number of heads is equal to zero 
            // there there is only one possiblity 
            if (j == 0) 
                dp[i][j] = dp[i - 1][j] 
                        * (1.0 - p[i]); 
            else
                dp[i][j] = dp[i - 1][j] 
                            * (1.0 - p[i]) 
                        + dp[i - 1][j - 1] * p[i]; 
        } 
    } 
  
    double ans = 0.0; 
  
    // When the number of heads is greater than (n+1)/2 
    // it means that heads are greater than tails as 
    // no of tails + no of heads is equal to n for 
    // any permuation of heads and tails 
    for (int i = (n + 1) / 2; i <= n; i += 1) 
        ans += dp[n][i]; 
  
    return ans; 
}
    public static void main(String[] args) {
        Scanner s= new Scanner(System.in);
      
           int n = s.nextInt();
            double arr[] = new double[n+1];
        
            for (int i = 1 ; i<= n  ; i++) {
                arr[i] = s.nextDouble();
            }
            
            
        
            
            System.out.println(Probability(arr,n));
        
    }
}

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

#define MAX 2000001
#define VMAX 10000

int main(void){
  int n;
  int i,j;
  int C[MAX];
  unsigned short *A,*B;

  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0; i<=VMAX; i++){
    C[i]=0;
  }

  for(i=0; i<n; i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1; i<=VMAX; i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=1; j<=n; j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1; i<=n; i++){
    if(i>1){
      printf(" ");
    }
    printf("%d",B[i]);
  }

  printf("\n");

  return 0;
}


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

int n;
vector<long long> a, sum;

int sub(int x){
    int ok = 0, ng = n+1;
    while(ok + 1 < ng){
        int mid = (ok + ng) / 2;
        if(a[mid] >= x) ok = mid;
        else ng = mid;
    }
    return ok;
}

long long f(int x){
    long long res = 0;
    for(int i=1;i<=n;i++){
        res += sub(x-a[i]);
    }
    return res;
}

long long g(int x){
    long long res = 0;
    for(int i=1;i<=n;i++){
        int t = sub(x-a[i]);
        res += a[i]*t + sum[t];
    }
    return res;
}

int main(void){
    long long m;
    cin >> n >> m;
    a.assign(n+1, 0);
    sum.assign(n+1, 0);
    for(int i=1;i<=n;i++) cin >> a[i];
    sort(a.begin()+1, a.end(), greater<long long>());
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + a[i];
    int ok = 1, ng = 1e6;
    while(ok + 1 < ng){
        int mid = (ok + ng) / 2;
        if(f(mid) >= m) ok = mid;
        else ng = mid;
    }

    long long ans = g(ok);
    ans -= ok * (f(ok) - m);
    cout << ans << endl;
}


Measured memory_bytes: 1920
#include "bits/stdc++.h"

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n; cin >> n;
  string s; cin >> s;
  int k; cin >> k;
  char c = s[k - 1];

  rep(i,s.length()){
    if(s[i] != c)
      cout << '*';
    else
    cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ1200().doIt();
	}
	class AOJ1200{
		void doIt(){
			int max = 1<<15;
			max += 100;
			boolean prime[] = new boolean[max];
			Arrays.fill(prime, true);
			prime[0] = false;prime[1] = false;
			for(int i=0;i<max;i++)if(prime[i]){
				for(int s=i+i;s<max;s+=i)prime[s] = false;
			}
			while(true){
				int n = in.nextInt();
				if(n==0)break;
				int cnt = 0;
				for(int i=2;i<=n/2;i++){
					if(prime[i]&&prime[n-i])cnt++;
				}
				System.out.println(cnt);
			}
		}
	}
}

Measured memory_bytes: 19984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (LLONG_MAX)
#define MOD (1000000007)
#define MAX (110)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

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

template<typename T1, typename T2>
T1 mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  T1 tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

bool isPrime(int n){
  if(n == 1) return false;
  rep(i, 2, min((int)(pow(n, 0.5) + 1), n)){
    if(n % i == 0) return false;
  }
  return true;
}

/////////////////////////////////////////////////////////

void Main() {
  ll Q, H, S, D, N; cin >> Q >> H >> S >> D >> N;
  ll res = INF;
  if(N % 2){
    chmin(res, N * 4 * Q);
    chmin(res, N * 2 * H);
    chmin(res, N * S);
    chmin(res, (N - 1) / 2 * D + 4 * Q);
    chmin(res, (N - 1) / 2 * D + 2 * H);
    chmin(res, (N - 1) / 2 * D + S);
  }
  else{
    chmin(res, N * 4 * Q);
    chmin(res, N * 2 * H);
    chmin(res, N * S);
    chmin(res, N / 2 * D);
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b,c,d = list(map(int, input().split()))
ans = max(a*c, a*d, b*c, b*d)
print(ans)

Measured memory_bytes: 61804
import math

a, b, x = map(int, input().split())

d = x / (a ** 2)
c = -(2 * d - 2 * b)
e = a * d * 2 / b

if a * d < a * b / 2:
    r = math.degrees(math.atan2(b, e))
else:
    r = math.degrees(math.atan2(c, a))

print(r)




Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#include<cstring>
#define inf 0x3f3f3f3f
#define maxn 5000005
using namespace std;
struct edge
{
    int v,next,w;
}edges[maxn];
int cnt;
int n,m;
int dis[maxn];
int head[maxn];
int vis[maxn];
void init()
{
    memset(head,-1,sizeof(head));
    cnt=0;
}
void addedge(int u,int v,int w)
{
    edges[cnt].next=head[u];
    edges[cnt].v=v;
    edges[cnt].w=w;
    head[u]=cnt++;
}
map<pair<int,int>,int>mp;
int tot;
int getid(int x,int y)
{if(!mp[make_pair(x,y)])
mp[make_pair(x,y)]=++tot;
    return mp[make_pair(x,y)];
}
int spfa(int u)
{
    int i,v,w;
    for(int i=0;i<maxn;i++)
        dis[i]=inf;
    queue<int>q;
    while(!q.empty())
        q.pop();
    memset(vis,0,sizeof(vis));
    dis[u]=0;
    vis[u]=1;
    q.push(u);
    while(!q.empty())
    {
        u=q.front();
        q.pop();
        vis[u]=0;
        for(int i=head[u];i!=-1;i=edges[i].next)
        {
            v=edges[i].v;
            w=edges[i].w;
            if(dis[v]>dis[u]+w)
                {dis[v]=dis[u]+w;
             if(!vis[v])
             {
                 q.push(v);
                 vis[v]=1;
             }
        }

    }
}
return dis[n]==inf?-1:dis[n]/2;
}
int main()
{
scanf("%d%d",&n,&m);
tot=n;
init();
for(int i=1;i<=m;i++)
{int u,v,c;
    scanf("%d%d%d",&u,&v,&c);
    int n1=getid(u,c);
    int n2=getid(v,c);
    addedge(u,n1,1);
    addedge(n1,u,1);
    addedge(n1,n2,0);
    addedge(n2,n1,0);
    addedge(v,n2,1);
    addedge(n2,v,1);


}
printf("%d\n",spfa(1));
return 0;
}


Measured memory_bytes: 99456
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 
int main() {
	ll n,d,s;
	cin>>n>>d;	d=(d*d);ll c=0;
	while(n--)
	{
	ll	x,y;s=0;
		cin>>x>>y;
		s=(x*x)+(y*y);
	
		if(s<=d)
		{
			c++;
		}
	}
	cout<<c;
	return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)

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

string s;
int head, tail;
int main(void) {
    cin >> s;
    REP(i, s.size()){
        if(s[i] == 'A'){
            head=i;
            break;
        }
    }
    REPR(i, s.size()){
        if(s[i] == 'Z'){
            tail=i;
            break;
        }
    }
    if(head>tail) cout << 0 << endl;
    else cout << tail-head+1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n,k,p[1001];
int ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n)
	cin>>p[i];
	sort(p,p+n);
	rep(i,k)
	ans+=p[i];
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int n,m;
int dp[100010];
long double kingaku;
double x;
string u;

const long long INF = 1LL << 62;

int main(){
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> x >> u;
        if(u=="JPY"){
            kingaku += x;
        }else{
            kingaku += x*380000;
        }
    }
    cout << kingaku;
}

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

int main() {
  int N;
  string S;
  int j=0;
  vector<int> vec(26);
  cin >> N >> S ;
  
  for (char c='a'; c<='z' ; c++){
    vec.at(j)=1;
    for(int i=0; i<N; i++){
      if( S.at(i) == c){
        vec.at(j)++;
      }
    }
    j++;
  }
  int m;
  long K=1;
  for (int i=0; i<26; i++){
    K *= vec.at(i);
    K = K%1000000007;
  }
  cout << K-1 << endl;

}


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

int main()
{
  int n, m;
  cin >> n >> m;
  dsu d(n);

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    d.merge(--a, --b);
  }

  cout << d.groups().size() - 1 << endl;
}


Measured memory_bytes: 8972