akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
	int s1[5],s2[5],namae;
	char demise[] = {'A','B','C','D','E'};
	while(1){
		int max=0;
		for(int i=0 ; i<5 ; ++i){
			cin >> s1[i] >> s2[i];
			if(s1[0]==0 && s2[0]==0)break;
		}
		if(s1[0]==0 && s2[0]==0)break;
		for(int i=0 ; i<5 ; ++i){
			if(max<s1[i]+s2[i]){
				max=s1[i]+s2[i];
				namae=i;
			}
		}
		cout << demise[namae] << " " << max << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)


Measured memory_bytes: 26648
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
const int INF = 1 << 30;
int dp[100005][3],h[100005][3];

int main(){
  int n; cin >> n;
  rep(i,n){
    cin >> h[i][0] >> h[i][1] >> h[i][2];
  }
  
//  fill(dp[0], dp[100005], INF);
  
  dp[0][0] = h[0][0];
  dp[0][1] = h[0][1];
  dp[0][2] = h[0][2];
  
  for(int i = 1; i < n; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(j==k) continue;
        chmax(dp[i][k],dp[i-1][j]+h[i][k]);
      }
    }
  }
  
  int ans = 0;
  rep(i,3) chmax(ans, dp[n-1][i]);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2560
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
int A[MAXN];

void input()
{
    read(N);
    for (int i = 1; i <= N; ++i) {
        read(A[i]);
    }
}

void solve()
{
    LL sum = 0;
    for (int i = 1; i <= N; ++i) {
        sum += A[i];
    }
    LL atom = (LL)(1 + N) * N / 2;
    if (sum % atom != 0) {
        puts("NO");
        return;
    }
    int tot = sum / atom;

    A[0] = A[N];
    for (int i = 1; i <= N; ++i) {
        LL d = A[i] - A[i - 1];
        if (tot - d < 0 || (tot - d) % N != 0) {
            puts("NO");
            return;
        }
    }

    puts("YES");
}

int main()
{
#ifdef __DEBUG
    freopen("B.in", "r", stdin);
    freopen("B.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 一郡官闲唯副使，一年冷节是清明。
//     -- 王禹偁《清明日独酌》


Measured memory_bytes: 640
#include <iostream>

using namespace std;

void solve()
{
	int d;
	while(cin >> d)
	{
		int sum = 0;
		for(int i = 0; i < 600; i += d)
		{
			sum += d * i * i;
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define oo (long long)1e18
#define ll long long
#define setdp memset(dp,-1,sizeof(dp))
const ll mod = 1e9+7;
void _IOS(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);}
#define PI 3.14159265359
int n,l,r,x;
    vector<int>b(200009),a(200009);
int main()
{
    map<string,int>mp;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    for(auto s:{"AC","WA","TLE","RE"})
    {
            cout<<s<<" x "<<mp[s]<<endl;
    }
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

void solve() {
  int A, B;
  cin >> A >> B;
  for (int i = 0; i < 1000000; i++) {
    int a = i * 8 / 100;
    int b = i * 10 / 100;
    if (a == A && b == B) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=55;

ll a[N],sum,k;
int n;

il ll calc(ll mx){
	ll sum=0;
	rep(i,1,n){
		sum+=qmax(a[i]-mx,0ll)/(n+1);
	}
	return sum;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%lld",a+i);
		sum+=a[i];
	}
	if(sum>n*n){
		ll x=sum-n*(n-1);
		k+=x;
		rep(i,1,n) a[i]+=x;
		ll ul=-1,ur=50000000000000000;
		while(ur-ul>1){
			ll mid=ul+ur>>1;
			if(calc(mid)<=x) ur=mid;else ul=mid;
		}
		x-=calc(ur);
		rep(i,1,n) a[i]-=qmax(a[i]-ur,0ll)/(n+1)*(n+1);
		while(x--){
			ll mx=a[1];
			rep(i,1,n) getmax(mx,a[i]);
			rep(i,1,n) if(a[i]==mx){
				a[i]-=n+1;
				break;
			} 
		} 
	}
	while(true){
		ll mx=0;
		rep(i,1,n) getmax(mx,a[i]);
		if(mx<n) break;
		++k;
		rep(i,1,n){
			if(a[i]==mx) a[i]-=n,mx=-1;
			else ++a[i];
		}
	}
	printf("%lld\n",k); 
	return 0;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <functional>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> a(n);
    REP(i, 0, n) {
        cin, a[i];
    }
    vector<vector<int>> G(n);
    REP(i, 0, n - 1) {
        int u, v;
        cin, u, v;
        u--;
        v--;
        G[v].push_back(u);
        G[u].push_back(v);
    }

    const ll inf = 1LL << 60;
    vector<ll> lis(n, inf);
    vector<ll> ans(n, 0);
    auto dfs = [&](auto dfs1, int pos, int prev) -> void {
        auto it = lower_bound(lis.begin(), lis.end(), a[pos]);
        ll res = *it;
        *it = a[pos];
        ans[pos] = lower_bound(lis.begin(), lis.end(), inf) - lis.begin();
        for (int v : G[pos]) {
            if (v == prev) continue;
            dfs1(dfs1, v, pos);
        }
        *it = res;
    };
    dfs(dfs, 0, -1);
    REP(i, 0, n) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 38220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, ll>;
using P2 = pair<P, int>;
#define rep(i,n) for(int i=0;i<n;i++)
inline ll in() {ll x;cin>>x;return x;}

const int N = 305;
const int INF = 1001001001;
const ll LINF = 1LL<<60;

vector<vector<ll>> dist(N, vector<ll>(N, LINF));
vector<vector<P>> cost(N, vector<P>(N, {INF, LINF}));

int n, m;
ll l;

void dijkstra() {
  rep(s,n) {
    priority_queue<P2, vector<P2>, greater<P2>> q;
    q.push({{0, 0}, s});
    while (!q.empty()) {
      P2 p2 = q.top(); q.pop();
      P p = p2.first;
      int v = p2.second;
      if (p > cost[s][v]) continue;
      rep(t,n) {
        if (dist[v][t] > l) continue;
        ll need = p.second + dist[v][t];
        P newp;
        if (need > l) newp = {p.first + 1, dist[v][t]};
        else newp = {p.first, need};
        if (cost[s][t] > newp) {
          cost[s][t] = newp;
          q.push({newp, t});
        }
      }
    }
  }
}

int main() {
  cin >> n >> m >> l;
  rep(i,m) {
    int a = in() - 1, b = in() - 1;
    dist[a][b] = dist[b][a] = in();
  }
  dijkstra();
  int q = in();
  rep(i, q) {
    int s = in() - 1, t = in() - 1;
    if (cost[s][t].first == INF) cout << -1 << endl;
    else cout << cost[s][t].first << endl;        
  }
  return 0;
}

Measured memory_bytes: 4736
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = 0
for i in range(n-1):
    d += b[a[i]-1]
    if a[i]+1 == a[i+1]:
        d += c[a[i]-1]
print(d+b[a[-1]-1])

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

using namespace std;
typedef long long ll;

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  ll diff = v - w;
  if (diff <= 0) {
    puts("NO");
    return 0;
  }

  ll dist = abs(a - b);

  if (t * diff >= dist) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}



Measured memory_bytes: 3624
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn seq_ln(start: i64, end: i64) -> i64 {
    let mut tmp = end;
    let mut count = 0;
    while start <= tmp {
        count += 1;
        tmp /= 2;
    }
    count
}

fn main() {
    from_line!(x: i64, y: i64);
    let mut max = 0;
    println!("{}", seq_ln(x, y));
    // for i in x..2*x {
    //     let length = seq_ln(i, y);
    //     println!("i:{} ln:{}", i, length);
    //     if max < length {
    //         max = length;
    //     }
    // }
    // println!("{}", max);
}


Measured memory_bytes: 4352
#include<stdio.h>

int main(){
  int n, k, l[50];
  int i, j, tmp, ans=0;
  
  scanf("%d%d", &n, &k);

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

  for(i=0; i<n-1; i++){
    for(j=i+1; j<n; j++){
      if(l[i]<l[j]){
	tmp=l[i];
	l[i]=l[j];
	l[j]=tmp;
      }
    }
  }

  for(i=0; i<k; i++){
    ans+=l[i];
  }

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

  return 0;
}


Measured memory_bytes: 128
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [a, b, k] = head . drop (k - 1) $ sortBy (flip compare) [i | i <- [1..x], x `mod` i == 0, y `mod` i == 0]
    where
        [x, y] = sort [a, b]

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ll long long
#define ld long double
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
const double pi = 2*acos(0.0);
const int INF = 1e9+1;
const int mod = 1e9+7;
const int mod1 = 998244353;
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}

bool compare(const pair<int, int>&i, const pair<int, int>&j) {
    return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void test() {
   ll n;
   cin >> n;

   vector<char> m = {'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

   string s;
   while(n) {
      int x = n % 26;
      if(x == 0) x = 26;
      s += m[x];
      n--;
      n /= 26;
   }
   reverse(s.begin(), s.end());
   cout << s;
}

int main() {
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   faster;
   cout.precision(10);
   cout << fixed;

   int t = 1;
   //cin >> t;
   while(t--)
      test();

   return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
    int n;
    int min = 10000000;
    int max = -10000000;
    long long sum = 0;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++ ){
        cin >> a[i];
        if (min > a[i]){
            min = a[i];
        }
        if (max < a[i]){
            max = a[i];
        }
        sum += a[i];
    }
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
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;
}

int main()
{
  int n;
  ll ans = 0;
  cin >> n;
  repi(i, 1, n + 1)
  {
    if (i % 15 == 0)
      continue;
    if (i % 5 == 0)
      continue;
    if (i % 3 == 0)
      continue;
    ans += i;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  int n, k;
  cin >> n >> k;
  ivec a(n);
  REP(i, k) {
    int d;
    cin >> d;
    REP(j, d) {
      int num;
      cin >> num;
      num--;
      a[num]++;
    }
  }
  int ans = 0;
  REP(i, n) {
    if (a[i] == 0) ans++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
using namespace std;
map<int,int> mp;
int A,B,C,D;
int a(int n){
  if(mp.count(n))return mp[n];
  int m=min({a(n/2)+A+n%2*D,a((n+1)/2)+A+(2-n%2)%2*D,
                    a(n/3)+B+n%3*D,a((n+2)/3)+B+(3-n%3)%3*D,
                    a(n/5)+C+n%5*D,a((n+4)/5)+C+(5-n%5)%5*D});
  if(m/D>=n)return mp[n]=n*D;
  return mp[n]=m;
}
signed main(){
  int Q;
  cin>>Q;
  while(Q--){
    mp.clear();
    int N;
    cin>>N>>A>>B>>C>>D;
    mp[0]=0,mp[1]=D;
    cout<<a(N)<<endl;
  }
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


struct edge{
    ll to;
    ll cost;
};

vector<edge>g[100010];
ll d[100010];

void dijkstra(ll root){
    for(ll i=0;i<100010;i++)d[i]=10000000000000000;
    queue<P>q;
    d[root]=0;
    q.push(P(root,0));
    while(!q.empty()){
        P p=q.front();q.pop();
        ll now=p.first;
        ll di=p.second;
        for(ll i=0;i<(ll)g[now].size();i++){
            ll next=g[now][i].to;
            ll c=g[now][i].cost;
            if(d[next]>di+c){
                d[next]=di+c;
                q.push(P(next,d[next]));
            }
        }
    }
}

int main(void){
    ll n,u,v,w;
    cin>>n;
    for(ll i=0;i<n-1;i++){
        cin>>u>>v>>w;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    dijkstra(1);
    for(ll i=1;i<=n;i++){
        if(d[i]%2==0)cout<<0<<endl;
        else cout<<1<<endl;
    }
    return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> A(N),B(N),C(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i)>>B.at(i)>>C.at(i);
  }
  vector<ll> D(M),E(M),F(M);
  for(int j=0;j<M;j++){
    cin>>D.at(j)>>E.at(j)>>F.at(j);
  }

  vector<ll> x_coor;
  vector<ll> y_coor;
  for(int i=0;i<N;i++){
    x_coor.push_back(A.at(i));
    x_coor.push_back(B.at(i));
    y_coor.push_back(C.at(i));
  }
  for(int j=0;j<M;j++){
    x_coor.push_back(D.at(j));
    y_coor.push_back(E.at(j));
    y_coor.push_back(F.at(j));
  }
  x_coor.push_back(-INF);
  x_coor.push_back(0);
  y_coor.push_back(-INF);
  y_coor.push_back(0);

  sort(x_coor.begin(),x_coor.end());
  sort(y_coor.begin(),y_coor.end());

  map<ll,int> mx,my;
  map<int,ll> mxr,myr;
  int x_size=0;
  for(int i=0;i<x_coor.size();i++){
    if(i==0){
      mx[x_coor.at(i)]=x_size;
      mxr[x_size]=x_coor.at(i);
      x_size++;
      continue;
    }
    if(x_coor.at(i-1)!=x_coor.at(i)){
      mx[x_coor.at(i)]=x_size;
      mxr[x_size]=x_coor.at(i);
      x_size++;
    }
  }
  int y_size=0;
  for(int i=0;i<y_coor.size();i++){
    if(i==0){
      my[y_coor.at(i)]=y_size;
      myr[y_size]=y_coor.at(i);
      y_size++;
      continue;
    }
    if(y_coor.at(i-1)!=y_coor.at(i)){
      my[y_coor.at(i)]=y_size;
      myr[y_size]=y_coor.at(i);
      y_size++;
    }
  }

  vector<vector<bool>> x_u(x_size,vector<bool>(y_size,true)),x_d(x_size,vector<bool>(y_size,true)),y_u(x_size,vector<bool>(y_size,true)),y_d(x_size,vector<bool>(y_size,true));
  for(int i=0;i<N;i++){
    int y=my[C.at(i)];
    for(int x=mx[A.at(i)];x<mx[B.at(i)];x++){
      y_u.at(x).at(y-1)=false;
      y_d.at(x).at(y)=false;
    }
  }
  for(int i=0;i<M;i++){
    int x=mx[D.at(i)];
    for(int y=my[E.at(i)];y<my[F.at(i)];y++){
      x_u.at(x-1).at(y)=false;
      x_d.at(x).at(y)=false;
    }
  }

  bool inf=false;
  vector<vector<bool>> visit(x_size,vector<bool>(y_size,false));
  ll ans=0;
  queue<pair<int,int>> q;
  q.push(make_pair(mx[0],my[0]));
  visit.at(mx[0]).at(my[0])=true;
  while(!q.empty()){
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    if(x==x_size-1||y==y_size-1||x==0||y==0){
      inf=true;
      break;
    }
    ans+=(mxr[x+1]-mxr[x])*(myr[y+1]-myr[y]);
    if(x_u.at(x).at(y)){
      if(!visit.at(x+1).at(y)){
        visit.at(x+1).at(y)=true;
        q.push(make_pair(x+1,y));
      }
    }
    if(x_d.at(x).at(y)){
      if(!visit.at(x-1).at(y)){
        visit.at(x-1).at(y)=true;
        q.push(make_pair(x-1,y));
      }
    }
    if(y_u.at(x).at(y)){
      if(!visit.at(x).at(y+1)){
        visit.at(x).at(y+1)=true;
        q.push(make_pair(x,y+1));
      }
    }
    if(y_d.at(x).at(y)){
      if(!visit.at(x).at(y-1)){
        visit.at(x).at(y-1)=true;
        q.push(make_pair(x,y-1));
      }
    }
  }

  if(inf){
    cout<<"INF"<<endl;
  }else{
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 10716
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    ll h;
    cin >> h;
    ll ans = 0, mon = 1;
    while(h){
        ans += mon;
        mon*= 2;
        h /= 2;
    }
    printf("%lld", ans);
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <set>

int a[100000];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int xor_sum = 0;
  for (int i = 0; i < n; i++)
    xor_sum ^= a[i];
  std::set<int> s;
  for (int i = 0; i < n; i++)
    s.insert(a[i] ^ (a[i] - 1));
  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (s.count(x)) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n); rep (i, n) cin >> a[i];
    ll ans = 100000000000000000;
    rep (i, -100, 101) {
        ll tmp = 0;
        rep (j, n) {
            tmp += (a[j] - i) * (a[j] - i);
        }
        chmin(ans, tmp);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS = 1e-12;
const double INF = 1e12;


int main(){
	int N,M;
	while(cin>>N>>M){
		int masu[1001];
		int me[1001];
		if(N==0&&M==0)break;
		REP(i,N)cin>>masu[i];
		REP(i,M)cin>>me[i];
		int pos=0;
		REP(i,M){
			pos+=me[i];
			if(pos>=N-1){
				cout<<i+1<<endl;
				break;
			}
			pos+=masu[pos];
			if(pos>=N-1){
				cout<<i+1<<endl;
				break;
			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

ll mp[11][11];
ll dist[222][222];
ll mi[22][22];

int main()
{
	int a,b;cin >> a >> b;
	REP(i,22)REP(j,22)mi[i][j] = 10000;
	
	REP(i,a)
	{
		REP(j,b)
		{
			cin >> mp[i][j];
		}
	}
	
	REP(i,101)
	{
		REP(j,101)
		{
			ll tmp = 0;
			REP(x,a)
			{
				REP(y,b)
				{
					tmp = max(tmp,mp[x][y]-(i*(x+1))-(j*(y+1)));
				}
			}
			
			REP(x,a)
			{
				REP(y,b)
				{
					mi[x][y] = min(mi[x][y],tmp+(i*(x+1))+(j*(y+1)));
				}
			}
			
			dist[i][j] = tmp;
		}
	}
	
	bool flag = true;
	
	REP(i,a)
	{
		REP(j,b)
		{
			if(mi[i][j] != mp[i][j])
			{
				flag = false;
				break;
			}
		}
	}
	
	if(!flag)
	{
		cout << "Impossible" << endl;
		return 0;
	}
	else
	{
		cout << "Possible" << endl;
		cout << 202 << ' ' << 10401 << endl;
		
		REP(i,100)
		{
			cout << i+1 << ' ' << i+2 << ' ' << 'X' << endl;
		}
		
		REP(i,100)
		{
			cout << i+102 << ' ' << i+103 << ' ' << 'Y' << endl;
		}
		
		REP(i,101)
		{
			REP(j,101)
			{
				cout << 1+i << ' ' << 202-j << ' ' << dist[i][j] << endl;
			}
		}
		cout << 1 << ' ' << 202 << endl;
		
		/*
		REP(i,a)
		{
			REP(j,b)
			{
				cout << mi[i][j] << endl;
			}
		}
		*/
		
		return 0;
	}
			
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	//rwww
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	int cr = 0;
	for (auto t : s) {
		cr += (t == 'R');
	}
	int ans = n;
	for (int i = 0; i <= n; i++) {
		int lw = i - cnt;
		int rr = cr - cnt;
		int c = 0;
		int tk = min(lw, rr);
		lw -= tk;
		rr -= tk;
		c += tk;
		c += lw;
		c += rr;
		ans = min(ans, c);
		if (i < n) cnt += (s[i] == 'R');
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3448
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const double PI=3.14159265358979323846;

int main(){
    double r;
    cin >> r;
    cout << r * 2 * PI << endl;

    return 0;
}

Measured memory_bytes: 3784
n, k = map(int, input().split())
ans = 0

for i in range(1,n+1):
    if i >= k:
        ans += 1/n
    else:
        c = 0
        while i*2**c < k:
            c += 1
        ans += 1/n *(1/2)**c
print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll dp[1000000 + 100][2][2];
int main() {
  ll N;
  cin >> N;
  dp[0][0][0] = 1;
  REP(i, N) {
    dp[i + 1][1][1] += dp[i][1][1] * 10;
    dp[i + 1][1][1] %= MOD;
    dp[i + 1][1][1] += dp[i][0][1];
    dp[i + 1][1][1] %= MOD;
    dp[i + 1][1][1] += dp[i][1][0];
    dp[i + 1][1][1] %= MOD;
    dp[i + 1][0][1] += dp[i][0][1] * 9;
    dp[i + 1][0][1] %= MOD;
    dp[i + 1][1][0] += dp[i][1][0] * 9;
    dp[i + 1][1][0] %= MOD;
    dp[i + 1][0][1] += dp[i][0][0];
    dp[i + 1][0][1] %= MOD;
    dp[i + 1][1][0] += dp[i][0][0];
    dp[i + 1][1][0] %= MOD;
    dp[i + 1][0][0] += dp[i][0][0] * 8;
    dp[i + 1][0][0] %= MOD;
  }
  cout << dp[N][1][1] << endl;
}

Measured memory_bytes: 34772
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);
int L,R;
int a[502][502];
signed main(){
    string s;
    cin>>s;

    int gg=0;
    int pp=0;

    rep(i, s.length()) {
        if(s[i]=='g')gg++;
        else pp++;
    }
    int ans = (gg-pp)/2;
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3756
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
	std::string str;
	cin >> str;
	int length = str.length();
	bool yes = false;
	if (length > 1 && length < 11) {
		for (int i = 0; i < length; i++) {
			if (i % 2 == 0) {
				if (str[i] != 'h') {
					cout << "No" << endl;
					return 0;
					yes = false;
				}
				else {
					yes = false;
				}
			}
			if (i % 2 == 1) {
				if (str[i] != 'i') {
					cout << "No" << endl;
					return 0;
				}
				else {
					yes = true;
				}
			}
		}
	}

	//int x = 100 * a / 108;
	//int y = 100 * b / 110;

	if (yes) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
using namespace std::chrono;
#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,T,k,q;

vector<vector<ll> > C1(200000, vector<ll>());
vector<vector<ll> > C2(200000, vector<ll>());

ll B[200000] = {0};
ll D[200000] = {0};
ll CS[200000] = {0};
ll act[200000] = {0};

vector<ll> A;

vector<ll> L;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    cin >> n >> m;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a;
        a--;
        A.push_back(a);
        if(c1 > 0){
            C2[a].push_back(c1-1);
            C1[A[c1-1]].push_back(c1-1);
            L.push_back((a-A[c1-1]+m)%m);
        }
    }
    d = 0;
    b = 0;
    for(ll c1 = 0; c1 < 3*m; c1++){
        ll c2 = c1%m;
        CS[c2] += b;
        for(ll c3 = 0; c3 < C1[c2].size(); c3++){
            a = C1[c2][c3];
            if(act[a] == 0){
                act[a] = 1;
                d++;
            }
        }

        for(ll c3 = 0; c3 < C2[c2].size(); c3++){
            a = C2[c2][c3];
            if(act[a] == 1){
                act[a] = 2;
                b -= L[a];
                d--;
            }
        }
        b += d;
    }

    ll ma = 0;
    ll i = 0;

    for(ll c1 = 0; c1 < m; c1++){
        if(CS[c1] > ma){
            ma = CS[c1];
            i = c1;
        }
    }

    ll ans = 0;
    //cout << i+1 << "\n";

    for(ll c1 = 1; c1 < n; c1++){
        a = A[c1-1];
        b = A[c1];
        d = (b-a+m)%m;

        ll d2 = (b-i+m)%m + 1;

       // cout << min(d,d2) << " ";
        ans += min(d,d2);
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 19176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,x=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    int a=i/10000;
    int b=i/1000-a*10;
    int c=i/100-a*100-b*10;
    int d=i/10-a*1000-b*100-c*10;
    int e=i%10;
    if(a==e && b==d){
      x++;
    }
  }
  cout<<x<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
                                                                                                
  
int comp(const void *a, const void *b){

    return strcmp( ( char * )a , ( char * )b );

    }


int main(void){
                                                                                                
   
    int a, b, c;
   
    char s[5];
   
      
    scanf("%s", s );
   

    qsort( s, 3, sizeof(char), comp );
   

    if( s[0] == 'a' && s[1] == 'b' && s[2] == 'c' ){

        printf("Yes\n");

        return 0;

        }

    else printf("No\n");


    return 0;
                                                          
}

Measured memory_bytes: 128
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    c = Counter(a)
    b = sum(v * (v - 1) // 2 for v in c.values())
    return "\n".join(str(b - c[_a] + 1) for _a in a)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 33548
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e18;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;

void a(){
  ll x; cin >> x;
  cout << (x?0:1) << endl; 
}

void b(){
    ll A,B,C,D; cin >> A >> B >> C >> D;
    ll K[4]={A*C,A*D,C*B,B*D};
    ll ans = -INF;
    rep(i,4) chmax(ans,K[i]);
    cout << ans << endl;
}

void c(){
  
}


void d(){

}

void e(){
   
}

void f(){
    
}

int main(void){
    b();
    return 0;
 }

Measured memory_bytes: 3636
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main()
{
	int n;
	while(1)
	{
		cin >> n;
		if(!n) return 0;
		int x[10005];
		for(int i=0;i<n;i++)
		{
			cin >> x[i];
		}
		int res = -1;
		for(int i=0;i<=10000;i++)
		{
			for(int j=0;j<n;j++) if(x[j] != j+1) goto nxt;
			res = i; break; nxt:;
			int cur = 0;
			for(int j=0;j<n;j++)
			{
				if(x[j] > 1)
				{
					x[cur] = x[j]-1;
					cur++;
				}
			}
			x[cur] = n;
			n = cur+1;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1172
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    int n, m;
    cin>>n>>m;
    int ss = 1, se = m, bs = m+1,  be = 2*m + 1;
    while(be > bs)
    {
        cout<<bs++ << " " << be--<<"\n";
        if(ss < se)
            cout<<ss++<<" " << se--<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    int n;
    cin>>n;
    map<int,int> s;
    rep(i,n)
    {
        int a;
        cin>>a;
        s[a]=i+1;
    }
    for(auto itr=s.begin();itr!=s.end();itr++)
    {
        cout<<itr->second<<" ";
    }
    
}

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

#define ll long long
const int mod = 1e9 + 7;

void solve() {
	int r, g, b, k;
	cin >> r >> g >> b >> k;
	if (b > g && g > r) {
		cout << "Yes";
		return;
	}
	while (g <= r) {
		g *= 2;
		k--;
		if (k < 0) {
			cout << "No";
			return;
		}
	}
	if (k < 0) {
		cout << "No";
		return;
	}
	while (b <= g) {
		b *= 2;
		k--;
		if (k < 0) {
			cout << "No";
			return;
		}
	}
	if (k < 0) {
		cout << "No";
		return;
	}
	cout << "Yes";
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;
	// int c = 1;
	while (t--) {
		// cout << "Case #" << c << ": ";
		solve();
		// c++;
	}
}

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

#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int64_t root(vector<int64_t>& g, int64_t v) {
    if (g[v] != v) {
        g[v] = root(g, g[v]);
    }

    return g[v];
}

void merge(vector<int64_t>& g, int64_t v, int64_t u) {
    g[root(g, v)] = root(g, u);
}

int main() {
    int64_t n, m;
    cin >> n >> m;

    vector<int64_t> x(n);
    for (auto&& xx : x) {
        cin >> xx;
    }

    vector<pair<int64_t, pair<int64_t, int64_t>>> links(m);
    for (auto i : irange(0L, m)) {
        cin >> links[i].second.first >> links[i].second.second >>
                links[i].first;
        --links[i].second.first;
        --links[i].second.second;
    }

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

    vector<int64_t> g(n), a(n);
    iota(g.begin(), g.end(), 0L);

    int64_t r = 0;
    for (const auto& link : links) {
        auto w = link.first;
        auto v = link.second.first;
        auto u = link.second.second;

        if (root(g, v) != root(g, u)) {
            auto x1 = x[root(g, v)];
            auto x2 = x[root(g, u)];
            auto a1 = a[root(g, v)];
            auto a2 = a[root(g, u)];
            merge(g, v, u);
            x[root(g, v)] = x1 + x2;
            a[root(g, v)] = a1 + a2 + 1;
        } else {
            ++a[root(g, v)];
        }

        if (w <= x[root(g, v)]) {
            r += a[root(g, v)];
            // cerr << v << "-" << u << ":" << a[root(g, v)] << endl;
            a[root(g, v)] = 0;
        }
    }

    cout << m - r << endl;
}

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

long long n,k,a[100005],ans,x;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 39; i >= 0; i--){
		int cnt = 0;
		for(int j = 0; j < n; j++) cnt += (a[j]>>i) & 1;
		if(2*cnt < n && (x | (1ll<<i)) <= k) x |= (1ll<<i);
	}
	for(int i = 0; i < n; i++)
		ans += x^a[i];
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<vector<int>, int> mp;

  long long ans = 0;
  while ( n-- > 0 ) {
    vector<int> alp(26, 0);
    string s;
    cin >> s;
    for ( int i = 0; i < s.size(); i++ ) {
      alp[s[i]-'a']++;
    }
    ans += mp[alp];
    mp[alp]++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 22328
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<char,ll> SUM,PTC;

int main(){
    crep(i){
        SUM[i]=MOD;
    }
    ll N;
    string  S,V;
    cin >> N;
    rep(i,N){
        cin >> S;
        rep(j,S.size()){
            PTC[S[j]]++;
        }
        crep(i){
            SUM[i]=min(SUM[i],PTC[i]);
            PTC[i]=0;
        }
    }
    for(auto P : SUM){
        if(P.second!=MOD){
            rep(i,P.second){
                V+=P.first;
            }
        }
    }
    cout << V <<  endl;
}

Measured memory_bytes: 256