akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>



int main()
{
    int n,m,i,j,count=1;

    scanf("%d %d",&n,&m);

    while(n!=0&&m!=0){

        for(i = 0;i < n;i++){

          if(i==0||n-1==i){
            for(j = 0;j < m;j++){
                printf("#");
            }
            printf("\n");
          }

          else{

            for(j = 0;j < m;j++){

                if(j==0||j==m-1){
                    printf("#");
                }
                else{
                    printf(".");
                }

            }
            printf("\n");

          }
        }
        printf("\n");

        scanf("%d %d",&n,&m);
    }


    return 0;
}


Measured memory_bytes: 2024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var dp = new int[N + 1];
		for (var i = 0; i <= N; i++) dp[i] = i;
		var t = new int[] { 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049 };
		foreach (var x in t) for (var i = x; i <= N; i++) dp[i] = Min(dp[i], dp[i - x] + 1);
		WriteLine(dp[N]);
	}
}


Measured memory_bytes: 11232
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pr pair<int,int>
#define endl "\n"
#define MOD 1000000007 // 10^9 + 7
#define sz(x) (int)(x).size()
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define all(c) (c).begin(), (c).end()

#define FOR(i,b) for (int i = 0; i < (b); i++)
#define FORR(i,a,b) for (int i = a; i < (b); i++)
#define FORB(i,b) for (int i = (b); i >= (0); i--)
#define FORRB(i,a,b) for (int i = (a);i>= (b); i--)
#define MAXN 1010
using namespace std;

int h,w;
char grid[MAXN][MAXN];
int dp[MAXN][MAXN];

int solve(int i,int j){
	if(i >= h || j >= w) return 0;
	if(i == h-1 && j == w-1) return 1;
	if(dp[i][j] != -1) return dp[i][j];
	if(grid[i][j] == '#') return 0;
	dp[i][j] = (solve(i+1,j)%MOD + solve(i,j+1)%MOD)%MOD;
	return dp[i][j];
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	//freopen("addin.txt","r",stdin);
	//freopen("addout.txt","w",stdout);
	cin >> h >> w;
	for(int i = 0 ;i < h;i++){
		for(int j = 0 ;j<w;j++){
			cin >> grid[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<solve(0,0)<<endl;
	return 0;
}

Measured memory_bytes: 5376
def f a;a==($u[a]||=a)?a:$u[a]=f($u[a])end
while 0<n=gets.to_i
$u={}
h=Hash.new{0}
n.times{
h[a=gets[0]]+=1
h[b=$_[-2]]-=1
$u[f b]=f a
}
puts h.any?{|k,v|f k;v!=0}||$u.values.uniq[1]?:NG:"OK"
end

Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int a,b,c;
  cin>>a>>b>>c;

  cout<<((a+b+c>21)? "bust":"win")<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long H,W,i,j;
    cin>>H>>W;
    char A[H][W];
    long long B[H][W];
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin>>A[i][j];
            if(A[i][j]=='#'){
                B[i][j]=0;
            }else{
                B[i][j]=10000;
            }
        }
    }
    long long m1,m2;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            if(i==0){
                m1=B[i+1][j];
            }else if(i==H-1){
                m1=B[i-1][j];
            }else{
                m1=min(B[i-1][j],B[i+1][j]);
            }
            if(j==0){
                m2=B[i][j+1];
            }else if(j==W-1){
                m2=B[i][j-1];
            }else{
                m2=min(B[i][j-1],B[i][j+1]);
            }
            B[i][j]=min(B[i][j],min(m1,m2)+1);
        }
    }
    for(i=H-1;i>-1;i--){
        for(j=W-1;j>-1;j--){
            if(i==0){
                m1=B[i+1][j];
            }else if(i==H-1){
                m1=B[i-1][j];
            }else{
                m1=min(B[i-1][j],B[i+1][j]);
            }
            if(j==0){
                m2=B[i][j+1];
            }else if(j==W-1){
                m2=B[i][j-1];
            }else{
                m2=min(B[i][j-1],B[i][j+1]);
            }
            B[i][j]=min(B[i][j],min(m1,m2)+1);
        }
    }
    long long M=0;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            M=max(M,B[i][j]);
        }
    }
    cout<<M<<endl;
}


Measured memory_bytes: 9088
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<unordered_map<int, int>> a(N);
  for(int i=0; i<N-1; i++){
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    a[u][v] = a[v][u] = w%2;
  }
  vector<int> r(N, -1);
  r[0] = 0;
  queue<int> q({0});
  while(!q.empty()){
    int i = q.front(); q.pop();
    for(auto aj: a[i]){
      if(r[aj.first]!=-1) continue;
      r[aj.first] = (r[i]+aj.second)%2;
      q.push(aj.first);
    }
  }
  for(int ri: r) cout << ri << endl;
  return 0;
}

Measured memory_bytes: 16768
#include <iostream>

using namespace std;
string x; string y; int z;int c; string u;
int main()
{

  cin>>x>>y;
  cin>>z>>c;
  cin>>u;
  if(u==x){cout<<z-1<<" "<<c<<endl;}
  else{cout<<z<<" "<<c-1<<endl;}



    return 0;
}


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

int main() {
  int N,K,i,sum;
  cin>>N>>K;
  sum=0;
  for(i=0;i<N;i++){
    int x;
    cin>>x;
    if(K>2*x)sum+=2*x;
    else sum+=(2*K-2*x);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

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;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int d[100100];
//ll rec(int num) {
//	if (num == 0) return 0;
//	return rec(num - 1) + num;
//}
ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll calc(ll b,ll n){
	if (n < b) return n;
	return calc(b, n / b) + n % b;
}

int n, a[4];
int sum[4];
ll t[10];
ll rec(int in) {

	if (in == 3) return 0;

	int ta = a[in];
	ll res = INF;
	for (size_t i = 0; i < n; i++)
	{
		if (use[i]) continue;
		use[i] = true;
		sum[in] += t[i];
		if (sum[in] > a[in]) {
			res = min(res,sum[in] - a[in] + rec(in + 1));
		}
		else {
			res = min(res, min(abs(sum[in] - a[in]) + rec(in + 1), 10 + rec(in)));
		}
		sum[in] -= t[i];
		use[i] = false;
	}
	return res;
}
void Solve() {

	cin >> n >> a[0] >> a[1] >> a[2];
	for (size_t i = 0; i < n; i++)
	{
		cin >> t[i];
	}
	cout << rec(0) << endl;
}


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



Measured memory_bytes: 6016
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
const int MOD=1e9+7;

struct modint {
    int val;
    modint inv() const{
        int tmp,a=val,b=MOD,x=1,y=0;
        while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
        return modint(x);
    }
public:
    modint():val(0){}
    modint(ll x){if((val=x%MOD)<0)val+=MOD;}
    modint pow(ll t){modint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
    modint& operator+=(const modint& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
    modint& operator-=(const modint& x){if((val+=MOD-x.val)>=MOD)val-=MOD; return *this;}
    modint& operator*=(const modint& x){val=(ll)val*x.val%MOD; return *this;}
    modint& operator/=(const modint& x){return *this*=x.inv();}
    bool operator==(const modint& x) const{return val==x.val;}
    bool operator!=(const modint& x) const{return val!=x.val;}
    bool operator<(const modint& x) const{return val<x.val;}
    bool operator<=(const modint& x) const{return val<=x.val;}
    bool operator>(const modint& x) const{return val>x.val;}
    bool operator>=(const modint& x) const{return val>=x.val;}
    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;}
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> la(n);
  for (int &a: la) cin >> a;
  vector<int> lb(m);
  for (int &b: lb) cin >> b;
  sort(la.rbegin(), la.rend());
  sort(lb.rbegin(), lb.rend());
  modint ans(1);
  for (int i = 0; i < la.size()-1; ++i) {
    if (la[i] == la[i+1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0; i < lb.size()-1; ++i) {
    if (lb[i] == lb[i+1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  la.push_back(-1);
  lb.push_back(-1);

  int x = n*m;
  int a = 0, b = 0;

  while (x > 0) { 
    if (la[a] == x && lb[b] == x) {
      ++a;
      ++b;
    }
    else if (la[a] == x) { 
      ++a;
      ans *= b;
    }
    else if (lb[b] == x) {
      ans *= a;
      ++b;
    }
    else {
      ans *= a*b-(n*m-x);
    }
    --x;
  }
  cout << ans.val << endl;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let ans: i32 = buf.trim().chars().map(|c| match c {
        '+' => 1,
        '-' => -1,
        _ => 0
    }).sum();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
vector<int> manacher(const string& s){
    int n = (int) s.size();
    vector<int> res(n);
    for(int i = 0, j = 0; i < n;){
        while(i - j >= 0 and i + j < n and s[i - j] == s[i + j])j++;
        res[i] = j;
        int k = 1;
        while(i - k >= 0 and i + k < n and k + res[i - k] < j){
            res[i + k] = res[i - k];
            k++;
        }
        i += k;
        j -= k;
    }
    return res;
}
int longest_palindrome(const string &s){
    string t;
    t += '#';
    for(char c : s){
        t += c;
        t += '#';
    }
    auto d = manacher(t);
    return *max_element(d.begin(), d.end()) - 1;
}
int main(){
    int n;
    cin >> n;
    vector<int>a(1<<n);
    for(int &i : a)cin >> i;
    sort(a.begin(),a.end());
    multiset<int>st,st2;
    rep(i,(1<<n)-1)st.insert(-a[i]);
    st2.insert(a.back());
    rep(_,n){
        vector<int>add;
        for(int x : st2){
            auto it = st.upper_bound(-x);
            if(it != st.end()){
                add.push_back(-(*it));
                st.erase(it);
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
        for(int x : add)st2.insert(x);
    }
    cout << "Yes" << endl;
}

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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll p[maxs];
ll r[maxs];
ll sz[maxs];

ll fn(ll x){
    if(x==p[x])
        return x;
    return p[x] = fn(p[x]);
}

bool add(ll x,ll y){
    x = fn(x);
    y = fn(y);

    if(x==y)
        return false;
    
    if(r[x] < r[y])
        swap(x,y);
    
    p[y] = x;
    sz[x] += sz[y];
    if(r[x] == r[y])
        r[x]++;
}

void solve(){
    ll n,m,k;
    cin >> n >> m >> k;
    for(ll i=0;i<n+1;i++)
        p[i] = i , sz[i] = 1;
    map<ll,set<ll> > MAP;
    while(m--){
        ll s,d;
        cin >> s >> d;
        MAP[s].I(d);
        MAP[d].I(s);
        add(s,d);
    }

    map<ll,set<ll>> MP;
    while(k--){
        ll s,d;
        cin >> s >> d;
        if(fn(s) == fn(d) and !MAP[s].count(d)){
            MP[s].I(d);
            MP[d].I(s);
        }
    }
    for(ll i=1;i<n+1;i++){
        ll ans = sz[fn(i)] - MAP[i].size() - MP[i].size() - 1;
        cout << ans << " ";
    }

}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    cout << "2018/01/" << s[8] << s[9] << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef unordered_map<ll, ll> uii;
typedef unordered_map<ll, ll> uuii;
typedef unordered_map<ll, ll> uuuii;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}


int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt"); if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    ll X, t; cin >> X >> t;
    cout << max(X-t, 0ll) << endstr;
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = str(input()).split()

for i in range(0,n):
    a[i] = int(a[i])
    
def abs(c): 
    if c > 0: 
        return c 
    else: 
        return -c

pre = abs(a[0]) + abs(a[n-1])
for i in range(0,n-1): 
    pre += abs(a[i+1] - a[i]) 


print(pre-abs(a[0])-abs(a[1]-a[0])+abs(a[1]))

for i in range(1,n-1): 
    print(pre-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]))

print(pre-abs(a[n-1]-a[n-2])-abs(a[n-1])+abs(a[n-2]))

Measured memory_bytes: 11232
w, h, x, y = map(int, input().split())
ans = []

if w == x*2 and h == y*2:
    ans.append('{:.7f}'.format(w*h/2))
    ans.append(1)
else:
    ans.append('{:.7f}'.format(w*h/2))
    ans.append(0)

print(*ans, sep=' ')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define OUT(x) cout << #x << " = " << x << endl; 
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	int a, b, c; cin >> a >> b >> c;
	if(a <= c && c <= b){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
x,k,d = map(int, input().split())

if abs(x)-k*d>=0:
    print(abs(x)-k*d)
    exit()

x=abs(x)
idoukaisuu=x//d
nokorikyori=x%d

if (k-idoukaisuu)%2==0:
    print(nokorikyori)
else:
    print(abs(nokorikyori-d))

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef kk
    freopen("in.txt","r",stdin);
    #endif // kk
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    ll qq=(q*4);
    ll hh=h*2;
    ll ss=s;
    ll dd=d/2;
    if(n<2){
        cout<<min(qq,min(hh,ss))<<endl;
    }
    else{
        ll cc=(min(qq,min(hh,ss)));
        //cout<<cc<<endl;
        if(dd<cc){
           // cout<<"gg";
            ll ds=n/2;
            ll df=n%2;
            cout<<(ds*d)+(df*cc)<<endl;
        }
        else{
            cout<<(cc*n)<<endl;
        }

    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli r, D, val;
    cin >> r >> D >> val;
    REP(i, 10)
    {
        val = r * val - D;
        cout << val << "\n";
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int n,c;string S;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>S;if(S=="A")c++;else c--;
		if(c<0){cout<<"NO"<<endl;return 0;}
	}
	if(c==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


int main()
{
	
	fastio;
	ll t,n,m;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];

	}
	sort(a,a+n,greater<ll>());
	
	ll sum=a[0];
	ll n_f=n/2;
	for(int i=1;i<n_f;i++)
	{
		sum+=a[i]*2;
	}
	if(n%2!=0)
	sum+=a[n_f];

	cout<<sum;
	



	return 0;
		

		
}


Measured memory_bytes: 5192
//#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long TYPE;

TYPE N,x,y,t,i,T,X,Y,mv,mt;

int main(void) {
  T =
    X = 
    Y = 0;
  // input
  scanf("%d",&N);
  for(i=0;i<N;++i){
    scanf("%d %d %d",&t,&x,&y);
    mt = t - T;
    mv = abs(x-X) + abs(y-Y);
    if(mt-mv<0){
	  printf("No");
      return 0;
    }
    if((mt-mv)%2>0) {
	  printf("No");
      return 0;
    }
    X = x;
    Y = y;
    T = t;
  }
  
  // output
  printf("Yes");
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        for (int i = 0; i < 3; i++) {
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        System.out.println(A[2] -A[0]);
    }
}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

const int HMAX=32,WMAX=32;

int grid[HMAX][WMAX];
static pii dp[HMAX][WMAX][HMAX+1][WMAX+1]; // (最大グループ数,最大グループ数での最小消費電力)
int umin;

void solve(int i1,int j1,int i2,int j2)
{
	if(dp[i1][j1][i2][j2]!=mp(-1,-1))
		return;
	dp[i1][j1][i2][j2]=mp(0,0); // (0,0)ならば解なし
	
	int usum=0;
	repi(i,i1,i2) repi(j,j1,j2)
		usum+=grid[i][j];
	if(usum<umin)
		return;
	dp[i1][j1][i2][j2]=mp(1,usum);
	
	repi(i,i1,i2){
		solve(i1,j1,i,j2);
		solve(i,j1,i2,j2);
		
		pii& top=dp[i1][j1][i][j2],bottom=dp[i][j1][i2][j2];
		if(top==mp(0,0) || bottom==mp(0,0))
			continue;
		
		pii temp(top.first+bottom.first,min(top.second,bottom.second));
		dp[i1][j1][i2][j2]=max(dp[i1][j1][i2][j2],temp);
	}
	repi(j,j1,j2){
		solve(i1,j1,i2,j);
		solve(i1,j,i2,j2);
		pii& left=dp[i1][j1][i2][j],right=dp[i1][j][i2][j2];
		if(left==mp(0,0) || right==mp(0,0))
			continue;
		
		pii temp(left.first+right.first,min(left.second,right.second));
		dp[i1][j1][i2][j2]=max(dp[i1][j1][i2][j2],temp);
	}
}

int main()
{
	for(int h,w,s;scanf("%d%d%d",&h,&w,&s),h|w|s;){
		rep(i,h) rep(j,w) scanf("%d",&grid[i][j]);
		int usum=0;
		rep(i,h) rep(j,w) usum+=grid[i][j];
		
		umin=usum-s; // 1つのグループの消費電力は (Σ u_ij)-s 以上でなければならない
		memset(dp,-1,sizeof dp);
		
		solve(0,0,h,w);
		int g=dp[0][0][h][w].first;
		int r=dp[0][0][h][w].second-umin;
		printf("%d %d\n",g,r);
	}
	
	return 0;
}

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

int main(){

  int X, Y, Z;
  int K;
  cin >> X >> Y >> Z;
  cin >> K;
  vector<long long> A(X), B(Y), C(Z);

  for(int i = 0 ; i < X ; i++) cin >> A[i];
  for(int i = 0 ; i < Y ; i++) cin >> B[i];
  for(int i = 0 ; i < Z ; i++) cin >> C[i];

  vector<long long> AB;

  for(int i = 0 ; i < X ; i++){
    for(int j = 0 ; j < Y ; j++){
      AB.push_back(A[i] + B[j]);
    }
  }

  sort(AB.begin(), AB.end());
  reverse(AB.begin(), AB.end());
  // sort(AB.begin(), AB.end(), greater<long long>);

  vector<long long> ABC;

  for(int i = 0 ; i < min(K, (int)AB.size()); i++){

    for(int j = 0 ; j < Z ; j++){
      ABC.push_back(AB[i] + C[j]);
    }
  }

  sort(ABC.begin(), ABC.end());
  reverse(ABC.begin(), ABC.end());
  // sort(ABC.begin(), ABC.end(), greater<long long>);

  for(int i = 0 ; i < K ; i++){
    cout << ABC[i] << endl;
  }

}

Measured memory_bytes: 43240
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
int main() {
	int n;
	vector<int> L;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		int len;
		cin >> len;
		L.push_back(len);
	}
	sort(L.begin(), L.end());

	long count = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			auto k = lower_bound(L.begin(), L.end(), L[i] + L[j]);
			count += (k - L.begin()) - (j + 1);
		}
	}


	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


// value
int N, M;

void solve() {

	cin >> N >> M;
    UnionFind UF(N);
    for(int i=0;i<M;i++){
      int X, Y, Z;
      cin >> X >> Y >> Z;
      X--; Y--;
      UF.unite(X, Y);
    }
    int ans = 0;
    for(int i=0;i<N;i++){
      if(UF.par[i] == i) ans++;
    }
  
    cout << ans << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const long long INF = 1LL<<60;

int main(){
    int sum = 0;
    int a[3][3];
    int st[3][3];
    int x[3],y[3];
    rep(i,3){
        rep(j,3){
            cin >> st[i][j];
        }
    }
    x[0] = 0;
    rep(i,3){
        y[i] = st[0][i]-x[0];
    }
    REP(i,1,3){
        x[i] = st[i][0]-y[0];
    }
    rep(i,3){
        rep(j,3){
            if(x[i]+y[j]!=st[i][j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

#define REP(i,a,b) for((i)=(a);(i)<(int)(b);(i)++)
#define rep(i,n) REP(i,0,n)
// BEGIN CUT HERE
#define foreach(itr,c) for(typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
// END CUT HERE

int main(){
  int i,in;
  int w[10] = {1,2,4,8,16,32,64,128,256,512};

  while(cin >> in){
    vector<int> ans;
    string to;

    for(i=0;in;i++){ to += in%2 + '0'; in /= 2;}
    rep(i,to.size()) if(to[i] == '1') ans.push_back(w[i]);
    rep(i,ans.size()){
      cout << ans[i];
      (i == ans.size()-1) ? cout << endl : cout << " ";
    }
  }


  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<string> board(h);
    rep(i, h) {
        cin >> board[i];
    }

    vector<vector<int>> cnt(h, vector<int>(w));
    rep(i, h) {

        vector<int> done(w);
        rep(j, w) {

            if(board[i][j] == '#' || done[j]) {
                continue;
            }

            int l = 0;
            while(j+l < w) {
                if(board[i][j+l] == '#') {
                    break;
                }
                l++;
            }

            rep(k, l) {
                cnt[i][j+k] += l;
                done[j+k] = 1;
            }
        }
    }
    rep(j, w) {

        vector<int> done(h);
        rep(i, h) {

            if(board[i][j] == '#' || done[i]) {
                continue;
            }

            int l = 0;
            while(i+l < h) {
                if(board[i+l][j] == '#') {
                    break;
                }
                l++;
            }

            rep(k, l) {
                cnt[i+k][j] += l;
                done[i+k] = 1;
            }
        }
    }

    int ans = 0;
    rep(i, h) {
        rep(j, w) {
            ans = max(ans, cnt[i][j] - 1);
        }
    }

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

Measured memory_bytes: 20096
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}
long long gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  long long g=gcd(a,b);
  return a/g*b;
}
long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}







int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int x=n-1;
  bool ok=true;
  for(int i=0;i<n;i++){
    cout<<a[x]<<endl;
    if(ok){
      x-=2;
      if(x==-2){
        x=1;
        ok=false;
      }
      if(x==-1){
        x=0;
        ok=false;
      }
    }else{
      x+=2;
    }
    

  }


}



  
  


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int64 a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (a < b) {
        if (a + v*t >= b + w*t)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
    else {
        if (a - v*t <= b - w*t)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i, n-2) if (s[i] == 'A') {
        if (s[i+1] == 'B' && s[i+2] == 'C') ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 640

vi adj[N];
double pr[N], ex[N], sum[N];

int main()
{
    canhazfast();

    int n, m;
    double ans;

    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int s, t;
        cin >> s >> t;
        adj[s].pb(t);
    }
    for (int i = n-1; i > 0; --i) {
        for (int j : adj[i]) sum[i] += ex[j];
        ex[i] = sum[i]/adj[i].size()+1.0;
    }
    ans = ex[1];
    pr[1] = 1.0;
    for (int i = 1; i < n; ++i) {
        double p = pr[i]/adj[i].size();
        for (int j : adj[i]) pr[j] += p;
    }
    for (int i = 1; i < n; ++i) {
        ctif(adj[i].size() < 2);
        for (int j : adj[i]) {
            double tmp = (sum[i]-ex[j])/(adj[i].size()-1)+1.0;
            //cerr << "diff(" << i << ", " << j << ") = " << pr[i]*(tmp-ex[i]) << '\n';
            ans = min(ans, ex[1]+pr[i]*(tmp-ex[i]));
        }
    }
    cout << setprecision(9) << ans << '\n';

    return 0;
}


Measured memory_bytes: 1408
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////
vector<LL> sum(51),P(51);

LL eat(int L, LL &x) {
	if (x <= 0) {
		return 0;
	}
	LL ans = 0;
	if (sum[L] <= x) {
		x -= sum[L];
		return P[L];
	}

	--x;
	if (x < sum[L - 1]) {
		return eat(L - 1, x);
	}
	ans += P[L - 1];
	x -= sum[L - 1];
	///////////////////////////
	if (x == 0) {
		return ans;
	}
	x--;
	ans++;

	if (x < sum[L - 1]) {
		return ans + eat(L - 1, x);
	}
	ans += P[L - 1];
	x -= sum[L - 1];
	
	return ans;
}
void solve() {
	LL N, X;
	cin >> N >> X;
	sum[0] = 1; P[0] = 1;
	for (int i = 1; i <= N; ++i) {
		sum[i] = sum[i - 1] * 2 + 3;
		P[i] = P[i - 1] * 2 + 1;
	}
	
	cout << eat(N, X) << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef unsigned long long ull;

int main(void)
{
    ull H, W;
    cin >> H >> W;

    ull ans = 1;
    ull sum = H * W;
    if (H == 1 || W == 1)
    {
        cout << ans << endl;
        return 0;
    }
    if (sum % 2 == 0)
    {
        ans = sum / 2;
    }
    else
    {
        ans = (sum / 2) + 1;
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
/*
Luis Henrique Morelli
Walk
https://atcoder.jp/contests/dp/tasks/dp_r
10/09/2020
*/

#include <bits/stdc++.h>

#define MAX 50
#define MOD 1000000007

using namespace std;

void multiplyMatrix(int N, long long a[][MAX], long long b[][MAX]){
    long long c[MAX][MAX];

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            c[i][j] = 0;
            
            for(int k = 0; k < N; k++){
                c[i][j] = (c[i][j] % MOD + (a[i][k] % MOD * b[k][j] % MOD) % MOD) % MOD;
            }
        }
    }

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            b[i][j] = c[i][j];
        }
    }
}

long long matrixPower(int N, long long g[][MAX], long long K){
    long long paths[MAX][MAX];

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(i != j){
                paths[i][j] = 0;
            }
        }

        paths[i][i] = 1;
    }

    while(K > 0){
        if(K % 2 != 0){
            multiplyMatrix(N, g, paths);
        }

        multiplyMatrix(N, g, g);

        K /= 2;
    }

    long long totalPaths;

    totalPaths = 0;

    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            totalPaths = (totalPaths % MOD + paths[i][j] % MOD) % MOD; 
        }
    }

    return totalPaths % MOD;
}

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

    cin >> N >> K;

    long long adjMatrix[MAX][MAX];

    for(int i = 0 ; i < N; i++){
        for(int j = 0; j < N; j++){
           cin >> adjMatrix[i][j];
        }
    }

    cout << matrixPower(N, adjMatrix, K) << "\n";
    
    return 0;
}

Measured memory_bytes: 3692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {
        static int[][] mtx ;
        static List<int>[] tm;
        static int n;
        static int[] results;
        static List<string> cons = new List<string>();
        static void Main(string[] args)
        {
//            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(Console.ReadLine());
            //            int k = int.Parse(s[1]);
            //           int q = int.Parse(s[2]);

            Console.WriteLine( (double)(((n+1)/2))/(double)n);

        }


        static int rec(int[] n, int i, int j, int x)
        {
            if (i+1 == j)
            {
                return Math.Min(n[j], x);
            }
            return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
        }
    }

}

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

using namespace std;

#define int long long
typedef pair<int,int> pii;

const int N = 1e5 + 100, INF = 1e9;

vector<pii> adj[N];
int sz[N], mx[N];
int n, mn = INF, sum;

void dfs(int v, int p) {
    mx[v] = -1;
    for (auto x : adj[v]) {
	int u = x.first, w = x.second;
	if (u == p) continue;
	dfs(u, v);
	if (mx[v] == -1 || sz[mx[v]] < sz[u])
	    mx[v] = u;
	sz[v] += sz[u];
	sum += 2 * min(sz[u], n - sz[u]) * w;
    }
    sz[v]++;
}

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i < n; i++) {
	int v, u, w;
	cin >> v >> u >> w;
	adj[--v].push_back({--u, w});
	adj[u].push_back({v, w});
    }
    dfs(0, 0);
    for (int i = 0; i < n; i++) {
	int v = mx[i];
	if (sz[i] * 2 > n && (v == -1 || sz[v] * 2 <= n)) {
	    if (v == -1 || sz[v] * 2 == n) {
		for (auto x : adj[i])
		    if (x.first == v)
			mn = min(mn, x.second);
	    }
	    else
		for (auto x : adj[i])
		    mn = min(mn, x.second);
	}
    }
    return cout << sum - mn, 0;
}

Measured memory_bytes: 14720
//ライブラリにするほどか？
//橋
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100001
vector<int> G[MAX_N];
vector<pair<int,int> > ans;
int cnt[MAX_N],dep[MAX_N];

void dfs(int pos,int pre){
    for(int i = 0; i < G[pos].size(); i++){
        int nx = G[pos][i];
        if (nx == pre || dep[nx] > dep[pos]) continue;
        
        if (dep[nx] != -1 && dep[nx] < dep[pos]){
            cnt[nx]--;
            cnt[pos]++;
        } else {
            dep[nx] = dep[pos] + 1;
            dfs(nx,pos);
            if (cnt[nx] == 0){
                ans.push_back({min(pos,nx),max(pos,nx)});
            }
            cnt[pos] += cnt[nx];
        }
    }
}


int main(){
    int n,m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(dep,-1,sizeof(dep));
    dep[0] = 0;
    dfs(0,-1);
    sort(ans.begin(),ans.end());
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    //return 0;
}


Measured memory_bytes: 7512