akhauriyash/Code-Regression huggingface dataset:
import math
import sys

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

tmp = (2*a**2*b-2*x)/a**3
theta0 = math.degrees(math.atan(tmp))
aa = (2*b-a*math.tan(math.radians(theta0)))*a**2/2
if a*math.tan(math.radians(theta0)) < b and abs(x-aa) < 10-9:
    print(theta0)
    sys.exit()

theta1 = math.degrees(math.atan(2*x/a**3))
bb = a**3*math.tan(math.radians(theta1))
if a*math.tan(math.radians(theta1)) < b and abs(x-bb) < 10e-9:
    print(theta1)
    sys.exit()

theta2 = math.degrees(math.atan(a*b**2/(2*x)))
print(theta2)
cc = a*b**2/(2*math.tan(math.radians(theta2)))

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

#define int				long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )	for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )	FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP				make_pair
#define X				first.first
#define Y				first.second

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int maze[150][150];
int W, H;
bool flag;

void dfs( int sx, int sy, int gx, int gy, int color ) {
	REP( i, 4 ) {
		int nx = sx + dx[i];
		int ny = sy + dy[i];

		if( nx >= 0 && nx <= W && ny >= 0 && ny <= H && maze[nx][ny] == color ) {
			if( nx == gx && ny == gy ) flag = true;
			maze[nx][ny] = -1;
			dfs( nx, ny, gx, gy, color );
		}
	}
}

signed main() {
	while( cin >> W >> H, W ) {
		fill( maze[0], maze[150], -1 );

		int sx, sy, gx, gy, n;
		cin >> sx >> sy >> gx >> gy >> n;

		REP( i, n ) {
			int color, d, x, y;
			cin >> color >> d >> x >> y;

			if( d == 0 ) {
				REP( i, 4 ) {
					maze[x + i][y] = color;
					maze[x + i][y + 1] = color;
				}
			} else {
				REP( i, 4 ) {
					maze[x][y + i] = color;
					maze[x + 1][y + i] = color;
				}
			}
		}

		if( maze[sx][sy] == -1 ) {
			cout << "NG" << endl;
		} else {
			flag = false;
			dfs( sx, sy, gx, gy, maze[sx][sy] );
			cout << ( flag ? "OK" : "NG" ) << endl;
		}
	}
}


Measured memory_bytes: 3268
#include <stdio.h>

int main(void){

    int a, b, c;
    int count = 3;

    scanf("%d %d %d", &a, &b, &c);

    if (a == b)
    count --;
    if (a == c || b == c)
    count --;

    printf("%d", count);

    return 0;
}

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

vector<int> z_algorithm(string s) {
	int l = s.size();
	vector<int> Z(l);
	Z[0] = l;
	for (int i = 1, j = 0; i < l;) {
		while (i+j < l && s[j] == s[i+j]) ++j;
		Z[i] = j;
		if (j == 0) {++i; continue;}
		int k = 1;
		while (i+k < l && k + Z[k] < j) {
			Z[i+k] = Z[k];
			++k;
		}
		i += k; j -= k;
	}
	return Z;
}

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		auto Z = z_algorithm(s.substr(i, n-i));
		for (int j = 1; j < Z.size(); j++) {
			int now = min(j, Z[j]);
			ans = max(ans, now);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3664
function Main(input) {
  const numbers = input.split(' ').map(n => Number(n));
  const a = numbers[0];
  const b = numbers[1];
  if(a + b >= 10) {
    console.log('error');
  } else {
    console.log(a + b);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import sys
input = sys.stdin.readline
from collections import Counter
h,w,n=map(int,input().split())
c=Counter()
for _ in range(n):
    b,a=map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 2<=a+i<w and 2<=b+j<h:
                c[a+i,b+j]+=1
#print(c.items())
c2=Counter(c.values())
print((h-2)*(w-2)-sum(c2.values()))
for i in range(1,10):
    print(c2[i])


Measured memory_bytes: 150264
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi l(n);
    rep(i,n) cin >> l.at(i);
    sort(l.begin(), l.end());
    int64_t sum = 0;
    rep(i,n-1) sum+=l.at(i);
    if(sum>l.at(n-1)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

#define x first
#define y second

int main() {
	pair<double, double> p[4];
	for (;;) {
		for (auto &a: p)
			if (scanf("%lf %lf", &a.x, &a.y) == EOF)
				return 0;
		outl((p[0].x <= p[3].x && p[2].x <= p[1].x &&
			  p[0].y <= p[3].y && p[2].y <= p[1].y) ? "YES" : "NO");
	}
}


Measured memory_bytes: 2604
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000 + 10;
int a[maxn] = {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 main() {
    int x;  cin >> x;
    cout << a[x - 1];
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
	int H,W,SUM,ANS=100000000;
	cin>>H>>W;
	int A[H][W]={0};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>A[i][j];
		}
	}
	for(int k1=0;k1<H;k1++){
		for(int k2=0;k2<W;k2++){
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					SUM+=min(A[i][j]*abs(k1-i),A[i][j]*abs(k2-j));
				}
			}
			if(SUM<ANS){
				ANS=SUM;
			}
			SUM=0;
		}
	}
	cout<<ANS<<endl;
	return 0;
}


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

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define endl "\n"
#define endd "\n"; return 0;
#define all(v) v.begin(), v.end()

using namespace std;

const int MAXN = 1e5;
const int INF = 1e10;
const int MOD = 1e9 + 7;

main() {
    ios_base::sync_with_stdio(0);
    int n, w;
    cin >> n >> w;
    int a[n];
    int b[n];
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    map<int, int> k;
    map<int, int> k1;
    k[0] = 0;
    for (int i = 0; i < n; i++){
        for (auto v : k){
            k1[v.fs] = max(k1[v.fs], v.sc);
            k1[v.fs + a[i]] = max(k1[v.fs + a[i]], v.sc + b[i]);
        }
        swap(k, k1);
    }
    int ans = 0;
    for (auto v : k){
        if (v.fs <= w){
            ans = max(ans, v.sc);
        }
    }
    cout << ans;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//#define FOR(i, x, y) for (int i = x; i < y; i++)
//#define FORN(i, x, y) for (int i = x; i <= y; i++)
//#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll gcd(ll a, ll b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq( int x ) {return x * x;}
////////////////////////////////////////////////////////////////////Header
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
int n, k;
ll dp[105][maxn];
ll sum[105][maxn];
ll a[105];

ll add ( ll x, ll y ) {
    return ( x + y ) % mod;
}
ll sub ( ll x, ll y ) {
    ll r  = (x - y) % mod;
    if ( r < 0 ) return r + mod;
    return r;
}

int main () {
    scan2(n, k);
    for ( int i = 1; i <= n; i++ ) scan1(a[i]);
    
    dp[0][0] = 1;
    sum[0][0] = 1;
    for ( int i = 1; i <= k; i++ ) {
        sum[0][i] = add(sum[0][i-1], dp[0][i]);
    }
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 0; j <= k; j++ ) {
            ll x;
            if ( (ll)j - a[i] - 1 < 0 ) x = 0;
            else x = sum[i-1][(ll)j-a[i] -1];
            dp[i][j] = sub(sum[i-1][j], x);
        }
        sum[i][0] = dp[i][0];
        for ( int j = 1; j <= k; j++ ) sum[i][j] = add(sum[i][j-1], dp[i][j]);
    }
    printl1(dp[n][k]);
}

Measured memory_bytes: 160724
tmp= input().rstrip().split(' ')
N=int(tmp[0])
K=int(tmp[1])

tmp= input().rstrip().split(' ')
L = tmp.index("1")

out = L//(K-1) + (N-1-L)//(K-1)

if(L%(K-1)>0):
    out+=1
if((N-1-L)%(K-1)>0):
    out+=1

if ((L%(K-1)==0) or ((N-1-L)%(K-1)==0)):
    pass
elif((L%(K-1) + (N-1-L)%(K-1)) <= (K-1)):
        out -=1
    
print(out)

Measured memory_bytes: 10420
#include <iostream>
#include <cstring>

using namespace std;

int ret;
int s;

void dfs(int begin, int depth, int sum){
  int i;
  //cout << "(" << begin << " , " << depth << " , " << sum << ")" << endl;
  if(depth == 0){
	if(s == sum){
	  //cout << "ret++" << endl;
	  ret++;
	}
	return;
  }
  for(i=begin+1;i<=9;i++){
	dfs(i,depth-1, sum+i);
  }
}


int main(void){
  int n;
  int i;
  while(1){
	cin >> n >> s;
	if(n==0 && s==0) break;
	for(i=0;i<=9;i++){
	  dfs(i, n-1, i);
	}
	cout << ret << endl;
	ret = 0;
  }
  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    string s; cin >> s;
    rep(i, s.size()-1) {
        if(s[i] == s[i+1]) {
            cout << "Bad" << '\n';
            return 0;
        }
    }
    cout << "Good" << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    if((A+B) > (C+D)){
        cout << "Left" << endl;
    }else if((A+B)<(C+D)){
        cout << "Right" << endl;
    }else{
        cout << "Balanced" << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,A[26] = {0};
  string s;
  cin >> n >> s;
  for(int i=0; i < (int)s.size();i++)
  {
    A[s[i]-'a']++;
  }
  for (int i=0; i < 26;i++)
  {
    if(A[i] % 2 != 0 )
    {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}
  


Measured memory_bytes: 256
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7
#どちらかの値が切り替わってるところは、1通りしかなく、そこが矛盾している場合は弾く
h = [-1 for i in range(n)]
t = [0] + t
a += [0]
for i in range(n):
    if t[i+1] != t[i]:
        h[i] = t[i+1]
for i in range(n,0,-1):
    if h[i-1] != -1 and h[i-1] > a[i-1]:
        print(0)
        exit()
    if a[i] != a[i-1]:
        if h[i-1] == -1:
            h[i-1] = a[i-1]
        else:
            if h[i-1] != a[i-1]:
                print(0)
                exit()
ans = 1
for i in range(n):
    if h[i] == -1:
        #print("index:{} t:{} a:{}".format(i,t[i+1], a[i]))
        ans *= min(t[i+1], a[i])
        ans %= mod
print(ans)


Measured memory_bytes: 87396
s = input()
n = len(s)
tp = []
rl = [1]
for i in range(1, n):
    if s[i] == s[i - 1]:
        rl[-1] += 1
    elif s[i - 1] == "R" and s[i] == "L":
        tp.append((i - 1, i))
        rl.append(1)
    else:
        rl.append(1)

rll = tuple(zip(rl[::2], rl[1::2]))
#print(rll,tp)

inl = []
for i, j in rll:
    if (i%2 == 0 and j%2 == 0) or (i%2 == 1 and j%2 == 1):
        x, y = (i+j)//2, (i+j)//2
        inl.append((x,y))
    elif i % 2 == 1 and j % 2 == 0:
        x, y = (i+j)//2+1, (i+j)//2
        inl.append((x,y))
    else:
        x, y = (i+j)//2, (i+j)//2+1
        inl.append((x,y))
#print(inl)
inpt = dict()
for i, k in enumerate(tp):
    inpt[k[0]] = inl[i][0]
    inpt[k[1]] = inl[i][1]
#print(inpt)
res = []
for i in range(n):
    res.append(inpt.get(i, 0))
print(" ".join([str(i) for i in res]))


Measured memory_bytes: 31328
import sys

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

for i in range(N - 1, 0, -1):
    if hLst[i] < hLst[i - 1]:
        hLst[i - 1] -= 1

for i in range(N - 1):
    if hLst[i + 1] < hLst[i]:
        print('No')
        sys.exit()

print('Yes')

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

int main() {
  int N;
  scanf("%d", &N);

  vector<int> p(N, 0);
  vector<int> sort_p(N, 0);
  for (int i = 0; i < N; i++) {
    int value = 0;
    cin >> value;
    p.at(i) = value;
    sort_p.at(i) = value;
  }
  
  sort(sort_p.begin(), sort_p.end());

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (p.at(i) != sort_p.at(i)) {
      count++;
    }
  }

  if (count == 0 || count == 2) {
    printf("YES");
  } else {
    printf("NO");
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long h;
int n;
long long a[100040];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> h >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	long long sum = accumulate(a + 1, a + n + 1, 0ll);
	if(sum >= h) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 1024
s= input()
t= input()
a = len(s)
b = len(t)
i = 0
j = 0
cnt = 0
ans = b
while(j <= a - b):
    while (i < b):
        if (s[i + j] != t[i]):
            cnt+=1
        i+=1
    ans = min(ans, cnt)
    cnt = 0
    i = 0
    j+=1
print(ans)

Measured memory_bytes: 9004
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
        a: [u64;5],
    };
    let mut s = 0;
    let mut t = 0;

    for x in a {
        let y = (n + x - 1) / x;
        if y > s {
            t += y - s;
            s = y;
        }
        t += 1;
    }
    t -= 1;
    println!("{}", t);
}


Measured memory_bytes: 4352
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    a=7;
    ll lastper=7;
    rep(i,1000001){
        //cout<<"a="<<a<<" lastper="<<lastper<<endl;
        if(a%n==0){
            cout<<i+1<<endl;
            return 0;
        }
        if(f==0){
            lastper*=10;
            a+=lastper;
            if(lastper>=n) f=1;
        }else{
            lastper*=10;
            lastper%=n;
            a+=lastper;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3540
#include <stdio.h>

#include <stdio.h>

int main(){
    int N,D;
    scanf("%d%d",&N,&D);
    int can = 2*D+1;
    int i;
    for(i=0;i<100;i++){
        if(i*can>=N)break;
    }
    printf("%d\n",i);
    return 0;
}


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

#define min(a,b) (((a) > (b)) ? (b) : (a))
int main(void) {
    int64_t N, K;
    int64_t a1,a2;
   
    cin >> N >> K;
    a1 = N % K;
    a2 = K - a1;

    cout << min(a1,a2) << "\n";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))

tf_p = [True if p[i] == i+1 else False for i in range(n)]

c = 0
for i in range(n-1):
    if tf_p[i] and tf_p[i+1]:
        tf_p[i], tf_p[i+1] = False, False
        c += 1
        
print(c+sum(tf_p))

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
int main() {
  char c; cin >> c;
  if(c == 'A') cout << "T" << endl;
  if(c == 'T') cout << "A" << endl;
  if(c == 'G') cout << "C" << endl;
  if(c == 'C') cout << "G" << endl;
}

Measured memory_bytes: 256
import numpy as np
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

n = int(input())

a = list(map(int, input().split(' ')))

devisor = gcd_list(a)

a = np.array(a) / devisor
child = a.prod()
child *= devisor

mother = 0

for m in range(n):
    mother += np.delete(a, m).prod()

x = child / mother

print(x)



Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
pii p[200005];
multiset<pii> seg;
int main(){
    int n, d, a, x, h;
    scanf("%d%d%d", &n, &d, &a);
    for(int i=1;i<=n;i++) scanf("%d%d", &x, &h), p[i] = pii(x, h);
    sort(p+1, p+1+n);
    LL sum = 0, ans = 0;
    for(int i=1;i<=n;i++){
        x = p[i].first, h = p[i].second;
        while(!seg.empty() && seg.begin()->first < x){
            sum -= seg.begin()->second*1ll*a;
            seg.erase(seg.begin());
        }
        if(sum >= h) continue;
        int dv = (h-sum+a-1)/a;
        sum += dv*1ll*a;
        ans += dv;
        seg.insert(pii(min((LL)2e9, x+2*1ll*d), dv));
    }

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

Measured memory_bytes: 6528
// Copyright 2016 Parallelc
#include <bits/stdc++.h>
using namespace std;  // NOLINT
using LL = int64_t;
using T = LL;
const T INF = 1e15;
struct node {
    int v;
    T w;
};
T spfa(vector<vector<node>>& lj, int S, int N) {
    int n = lj.size();
    static vector<T> dis;
    fill(dis.begin(), dis.end(), -INF), dis.resize(n, -INF);
    static vector<int> us, cnt, pre;
    fill(us.begin(), us.end(), 0), us.resize(n);
    fill(cnt.begin(), cnt.end(), 0), cnt.resize(n);
    pre.resize(n);
    us[S] = 1;
    dis[S] = 0;
    queue<int> q;
    q.push(S);
    cnt[S] = 1;
    pre[S] = -1;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        us[now] = 0;
        for (auto& i : lj[now]) {
            if (cnt[i.v] <= n && dis[i.v] < dis[now] + i.w) {
                dis[i.v] = dis[now] + i.w;
                pre[i.v] = now;
                if (!us[i.v]) {
                    us[i.v] = 1;
                    q.push(i.v);
                    ++cnt[i.v];
                    if (cnt[N] > n) return -1;
                }
            }
        }
    }
    return dis[N];
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<node>> lj(n);
    for (int i = 0; i < m; i++) {
        int u, v;
        LL w;
        cin >> u >> v >> w;
        u--, v--;
        lj[u].push_back({v, w});
    }
    LL ans = spfa(lj, 0, n - 1);
    if (ans == -1) cout << "inf\n";
    else cout << ans << endl;
}


Measured memory_bytes: 384
n = int(input())
v = list(map(int,input().split()))
c = list(map(int,input().split()))

inf_min = -float("inf")
dp = [inf_min] * (n +1)
dp[0] = 0
for i in range(n):
  dp[i+1] = max(v[i] - c[i] +dp[i] , dp[i])
print(dp[n])

Measured memory_bytes: 3064
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int N, Q;
string S;
vector<pair<char, int>> q;

int check_right(int key){
    int crt = key;
    int ret = 0;
    for (int i = 0; i < Q; i++){
        if (S[crt] == q[i].first){
            if (q[i].second){
                crt++;
            }else{
                crt--;
            }
        }
        if (crt == N){
            ret = 1;
            break;
        }
        if (crt < 0) break;
    }
    return ret;
}

int check_left(int key){
    int crt = key;
    int ret = 0;
    for (int i = 0; i < Q; i++){
        if (S[crt] == q[i].first){
            if (q[i].second){
                crt++;
            }else{
                crt--;
            }
        }
        if (crt == -1){
            ret = 1;
            break;
        }
        if (N <= crt) break;
    }
    return ret;
}

int main(){
    cin.tie(0);

    cin >> N >> Q;
    cin >> S;
    for (int i = 0; i < Q; i++){
        char t; cin >> t;
        char tmp; cin >> tmp;
        int d;
        if (tmp == 'L') d = 0;
        else d = 1; 
        q.push_back({t, d});
    }

    int ng = -1;
    int ok = N;
    int mid;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (check_right(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    int fall_right = ok; 

    ng = N;
    ok = -1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (check_left(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    int fall_left = ok;
    int ans = max(N - (N-fall_right) - (fall_left+1), 0);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2804
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		int x,y,w;
		int i=0;
		Scanner scan = new Scanner(System.in);
		while(true)
		{
			x=scan.nextInt();
			y=scan.nextInt();
			if(x==0&&y==0)
				break;
			if(x>y)
			{
				w=x;
				x=y;
				y=w;
			}
			System.out.println(x+" "+y);
			
		}
		
	}


	}

Measured memory_bytes: 36896
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}



int main(){
  ll N,M;
  cin>>N>>M;
  priority_queue<ll> Q;
  for(int i=0;i<N;i++){
    ll a;
    cin>>a;
    Q.push(a);
  }
  while(M--){
    ll a=Q.top(); Q.pop();
    Q.push(a/2);
  }
  ll ans=0;
  while(!Q.empty()){ans+=Q.top(); Q.pop();}
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    ll x,d;
    cin >> n >> x >> d;
    if(d == 0) {
        cout << (x == 0 ? 1 : n+1) << endl;
        return 0;
    }
    if(d < 0) {
        x += d*(n-1);
        d = -d;
    }
    map<int,vector<LP>> mp;
    rep(i,n+1) {
        int rem = (x*i%d+d)%d;
        ll l = ll(i-1)*i/2;
        ll r = ll(n-1+n-i)*i/2;
        l += (x*i-rem)/d;
        r += (x*i-rem)/d;
        mp[rem].eb(l, r);
    }
    ll ans = 0;
    auto f = [](vector<LP> &v) {
        vl prs;
        ll ret = 0;
        for(auto p : v) {
            prs.pb(p.first);
            prs.pb(p.second);
        }
        sort(all(prs));
        prs.erase(unique(all(prs)),prs.end());
        int sz = prs.size();
        vi cnt(2*sz,0);
        for(auto p : v) {
            int l = lower_bound(all(prs),p.first)-prs.begin();
            int r = lower_bound(all(prs),p.second)-prs.begin();
            cnt[l*2]++;
            cnt[r*2+1]--;
        }
        rep(i,2*sz-1) {
            cnt[i+1] += cnt[i];
            if(cnt[i])  {
                if(i&1) ret += prs[i/2+1]-prs[i/2]-1;
                else ret += 1;
            }
        }
        return ret;
    };
    for(auto v : mp) ans += f(v.second);
    cout << ans << endl;
}


Measured memory_bytes: 22144
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define vi   vector<int>
#define vvi  vector<vi >
#define vvvi vector<vvi >
#define pii  pair<int,int>
#define INF  (int)1e9
#define MOD  (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	vvi is(n+1);
	REP(i,m){
		int a,b;
		cin>>a>>b;
		
		is[a].push_back(b);
	}
	
	for(auto itr:is[1]){
		for(auto itrr:is[itr]){
			if(itrr==n){
				cout<<"POSSIBLE"<<endl;
				return 0;
			}
		}
	}
	
	cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 8576
n,*a=map(int,open(0).read().split())
m=min(a)
while len(a)>1:
    m=min(a)
    f=0
    for i in range(len(a)):
        if a[i]!=m or f:
            a[i]%=m
        else:
            f=1
    *a,=filter(lambda x:x,a)
print(m)

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

signed main(){
  int x,y;
  cin>>x>>y;
  if(x>0){
    if(y>0){
      if(x<y)cout<<max(x-y,y-x)<<endl;
      else cout<<max(x-y,y-x)+2<<endl;
    }
    else cout<<max(x+y,-x-y)+1<<endl;
  }
  if(x==0){
    if(y>=0)cout<<y<<endl;
    else cout<<1-y<<endl;
  }
  if(x<0){
    if(y>0)cout<<max(x+y,-x-y)+1<<endl;
    if(y==0)cout<<-x<<endl;
    if(y<0){
      if(x>y)cout<<x-y+2<<endl;
      else cout<<y-x<<endl;
    }
  }
}


Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = [ir() for i in range(n)]
odd = 0
for num in a:
    if num%2 == 1:
        odd+=1
if odd == 0:
    print('second')
else:
    print('first')

Measured memory_bytes: 77012
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}

int A[2020];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K; cin >> N >> K;
	REP(i, N) {
		cin >> A[i];
	}
	int res = 0;
	REP(i, N - 1) {
		FOR(j, i + 1, N) {
			if (A[i] > A[j])res++;
		}
	}
	int res2 = 0;
	REP(i, N) {
		REP(j, N) {
			if (A[i] > A[j])res2++;
		}
	}
	//int cnt = bin_pow(2, K-1);
	//cnt = sub(cnt, 1);
	ll cnt = K * (K - 1) / 2;
	cnt %= MOD;
	res = mult(res, K);
	ll res3 = mult(res2, cnt);
	ll ans = add(res, res3);
	print(ans);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main()
{ll A,B;
cin >>A >>B;
if (A>=13) {cout<<B<<endl;}
else if(6<=A&&A<=12){cout<<B/2<<endl;}
else {cout<<"0"<<endl;}
    
}




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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<ll, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const int limit = 100010;
struct edge {
	int to;
	ll cost;
};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
	depth[v] = d;
	for (auto &e: tree[v]) {
		if (e.to == p) continue;
		dfs(e.to, v, d + e.cost);
	}
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	REP(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({b, c});
		tree[b].push_back({a, c});
	}
	
	int q, k;
	cin >> q >> k;
	k--;
	
	dfs(k, -1, 0);
	
	REP(i, q) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
ll combination(ll n) {
	ll nck[100][100];
	nck[0][0] = 1;
	for (int i = 1; i < 1 + n; i++) {
		nck[i][0] = nck[i][i] = 1;
		for (int j = 1; j < i; j++) {
			nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
	return 0;
}
ll GCD(ll u, ll v) {
	while (v != 0) {
		ll r = u % v;
		u = v;
		v = r;
	}
	return u;
}

//------------------変数-----------------------//
vector<vector<ll>>G(100001), cost(100001);
//-------------------関数----------------------//

bool vis[100001] = {}; ll goukei[100001] = {};
ll DFS(ll v, ll atai) {
	goukei[v] = atai;
	vis[v] = true;
	REP(i, G[v].size())
	{
		if (!vis[G[v][i]]) {
			DFS(G[v][i], atai + cost[v][i]);
		}
	}
	return 0;
}

int main() {
	ll n; cin >> n;
	fill_all(goukei,(ll) INF);
	REP(i, n-1) {
		ll a, b, c; cin >> a >> b >> c; a--; b--;
		G[a].push_back(b); G[b].push_back(a);
		cost[a].push_back(c); cost[b].push_back(c);
	}
	ll q, k; cin >> q >> k; k--; goukei[k] = 0;
	DFS(k, 0); ll cnt = 0;
	REP(i, q) {
		ll x, y; cin >> x >> y; x--, y--;
		cout << goukei[x] + goukei[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 16768
(N, M) = gets.chomp.split.map(&:to_i)
@a = gets.chomp.split.map(&:to_i)

limit = (@a.reduce(0, &:+) / (4 * M).to_f)
s = @a.delete_if {|a| a < limit } . length

puts s >= M ? 'Yes' : 'No'


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////
void solve(){
  ini(N); inl(K);
  vl A(N) , F(N); in(A , F);
  sort(all(A));
  sort(rbegin(F),rend(F));

  ll ng = -1 , ok = 1e13;
  while(ng + 1 < ok){
    ll med = (ng + ok) >> 1;
    ll cur = 0;
    // med以下になるようにA*Fを最小化
    rep(i , N){
      ll limit = med / F[i];
      cur += max(0LL , A[i] - limit);
    }
    (cur <= K ? ok : ng) = med;
  }
  out(ok);
}

Measured memory_bytes: 3328
fun main(args: Array<String>) {
  val (n, a) = readLine()!!.split(" ").map { it.toInt() }
  val xs = readLine()!!.split(" ").map { it.toInt() }
  val m = n * xs.max()!!
  val ys = xs.map { it - a }
  var dp = Array<LongArray>(n + 1) { LongArray(2 * m + 1) { 0L } }
  dp[0][m] = 1L
  for (i in 0 until n) {
    for (j in 0..2 * m) {
      dp[i + 1][j] = dp[i][j]
      if (0 <= j - ys[i] && j - ys[i] <= 2 * m) {
        dp[i + 1][j] += dp[i][j - ys[i]]
      }
    }
  }
  println(dp[n][m] - 1)
}


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

int main() {
	int N; std::cin >> N;
	int ans{ 0 };
	for (auto i{ 1 }; i <= N; ++i) {
		if (i % 2 == 1) {
			int count{ 0 };
			for (int j{ 1 }; j <= i; ++j) {
				if (i % j == 0) ++count;
			}
			if (count == 8) ++ans;
		}
	}
	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pf push_front
#define pb push_back
#define FOR(i,l,r) for(int i=l;i<r;i++)
#define ROF(i,r,l) for(int i=r;i>=l;i--)
#define comp(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define infile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi;
typedef vector<ll> vli;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvli;
const int M = 1e9+7;
const int N = 2e5;
ll po(int,int);


void solve(){
    int n;cin>>n;
    ll a[n];
    FOR(i,0,n) cin>>a[i];
    vector<ll> v;
    sort(a,a+n);
    v.pb(a[n-1]);
    ROF(i,n-2,0){
        v.pb(a[i]);
        v.pb(a[i]);
    }
    int x = v.size();
    FOR(i,1,x){
        v[i] += v[i-1];
    }
    cout<<v[n-2];
    
}





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


ll po(int a,int b){
    if(b==0) return 1;
    ll ans=1;
    if(b%2==0){
        ans = po(a,b/2)%M;
        ans=(ans%M * ans%M)%M;
    }
    else{
        ans = po(a,(b-1)/2)%M;
        ans = (ans%M * ans%M * a)%M;
    }
    return ans%M;
}


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

int chmin(int a,int b){
  if(b < a){
    return b;
  }
  else{
    return a;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int>data(n);
  vector<long>dp(n,1000000000);
  dp[0] = 0;
  for(int i = 0;i < n;i++){
    cin >> data[i];
  }
  dp[1] = abs(data[0]-data[1]);
  for(int i = 2;i < n;i++){
    int j1 = abs(data[i]-data[i-1]),j2 = abs(data[i]-data[i-2]);
    dp[i] = chmin(dp[i],dp[i-1]+j1);
    dp[i] = chmin(dp[i],dp[i-2]+j2);
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define MAX_N 200000
vector<int> A,B,C;
int main(){
    int N,input;
    cin >> N;
    REP(i,N){
        cin >> input;
        A.push_back(input);
    }
    REP(i,N){
        cin >> input;
        B.push_back(input);
    }
    REP(i,N){
        cin >> input;
        C.push_back(input);
    }
    ll ans = 0;
    int j=0;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    ll Bcount[MAX_N+1];
    REP(i,N){
        while(j < N && A[j] < B[i]) j++;
        Bcount[i+1] = j;
    }
    REP(i,N){
        Bcount[i+1] += Bcount[i];
    }
    j=0;
    REP(i,N){
        while(j < N && B[j] < C[i]) j++;
        ans += Bcount[j];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

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; } //最大公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<long double> x(n); //kane
    vector<string> u(n); //jpy or btc
    long double ans = 0;
    cout << fixed << setprecision(15);
    for(int i=0; i<n; i++) {
        cin >> x[i] >> u[i];
        if( u[i] == "JPY") ans += x[i];
        else {
            ans += 380000.0 * x[i];
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3736