akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    A,B,C,D,E,F = inputMap()
    A = A*100
    B = B*100
    
    ans_muzu = 0
    ans_satou = 0
    ans = -1
    
    for i in range(0, F, A):
        for j in range(0, F, B):
            for ii in range(0, F, C):
                for jj in range(0, F, D):
                    
                    if F < i + j + ii + jj:
                        continue
                        
                    mizu = i+j
                    satou = ii+jj
                    
                    if mizu == 0:
                        continue
                    
                    if satou / mizu > E / 100:
                        continue
                    
                    tmp = (satou / (satou+mizu)) * 100
                    if ans < tmp:
                        ans = tmp
                        ans_muzu = mizu
                        ans_satou = satou
                        
    print("{} {}".format(ans_muzu+ans_satou, ans_satou))
    
    
    
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 41580
N,K=map(int,input().split())
count=[0]*(100001)
for i in range(1,N+1) :
  a,b=map(int,input().split())
  count[a]+=b
for i in range(1,100001) :
  if K<=count[i] :
    print(i)
    break
  K-=count[i]


Measured memory_bytes: 11688
[K,N] = list(map(int,input().split()))
A = list(map(int,input().split()))
B = [0]*N
for i in range(0,N):
    B[i]=A[i]-A[i-1]
B[0] = B[0]+K
S = sum(B)
T = max(B)
print(S-T)


Measured memory_bytes: 78796
program pr5
  implicit none
  integer, allocatable :: a(:)
  integer :: k, t
  integer :: i, ans
  read(*,*) k, t
  allocate(a(t))
  read(*,*) a

  if ( maxval(a) > sum(a) - maxval(a) + 1 ) then
     ans = maxval(a) - (sum(a) - maxval(a)) - 1
  else if ( t == 1 ) then
     ans = k - 1
  else
     ans = 0
  end if

  write(*,'(i0)') ans
  
  stop
end program pr5


Measured memory_bytes: 2844
#define _[301][301]
N,M,i,j,t,r,C _,D _;char S _;main(v){for(scanf("%d%d ",&N,&M);i=j=++t<M;r+=v)for(;j>N?j=i++<N:1;++j)i-1||gets(S+j),v=D[i][j]=fmin(D[i-1][j],D[i][j-1])+(C[i][j]=C[i-1][j-1]+(S[i][t-1]==S[j][t]));printf("%d",r);}

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

const long long MOD = 1e9 + 7;
using ll = long long;

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}
	ll ans = 0;
	for (int i = 0; i < n; ++i)
	{
		sum -= a[i];
		ans += (sum % MOD) * (a[i] % MOD);
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 4056
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    print(min(n*a,b))
    return

#B
def B():
    s = S()
    print(s.count("1"))
    return

#C
def C():
    n = list(map(int, S()))
    k = 0
    s = sum(n)
    for i in range(len(n)):
        k *= 10
        k += n[i]
    if k%s == 0:
        print("Yes")
    else:
        print("No")
    return

#D
def D():
    n = I()
    a = LI()
    ans = float("inf")
    for i in range(n):
        m = 0
        while a[i]%2 == 0:
            m += 1
            a[i] //= 2
        ans = min(m,ans)
    print(ans)
    return

#E
def E():
    n = I()
    f = LIR(n)
    p = LIR(n)

    return

#F
def F():
    n,k = LI()
    a = LI()
    d = defaultdict(int)
    for i in a:
        d[i] += 1
    d = list(d.values())
    d.sort()
    ans = 0
    for i in range(len(d)-k):
        ans += d[i]
    print(ans)
    return

#G
def G():
    n,c = LI()
    ch = LIR(n)
    T = [[0 for i in range(100002)] for j in range(c+1)]
    for s,t,cha in ch:
        T[cha-1][s] += 1
        T[cha-1][t+1] -= 1
    for i in range(c):
        for j in range(100000):
            T[i][j+1] += T[i][j]
            if T[i][j] >= 1:
                T[i][j] = 1
    ans = 0
    for i in range(100001):
        m = 0
        for j in range(c+1):
            m += T[j][i]
        ans = max(m,ans)
    print(ans)
    return

#H
def H():
    n = I()
    a = LI()
    ma = a.index(max(a))
    mi = a.index(min(a))
    ans = []
    if abs(a[ma]) > abs(a[mi]):
        ans.append([ma+1,1])
        ans.append([ma+1,1])
        a[0] += 2*a[ma]
        for i in range(n-1):
            ans.append([i+1,i+2])
            ans.append([i+1,i+2])
            a[i+1] += 2*a[i]
    else:
        ans.append([mi+1,n])
        ans.append([mi+1,n])
        a[-1] += 2*a[mi]
        for i in range(n-1)[::-1]:
            ans.append([i+2,i+1])
            ans.append([i+2,i+1])
            a[i] += 2*a[i+1]
    print(len(ans))
    for i in ans:
        print(*i)
    return

#I
def I_():
    return

#J
def J():
    return

#Solve
if __name__ == "__main__":
    H()


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main()
{
	int a, p;
	cin >> a >> p;

	cout << (3*a+p)/2 << endl;

	return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[100002];

int main() {
	cin >> n;
	inc1(i, n) { cin >> a[i]; }
	
	int sum = 0;
	incII(i, 0, n) {
		sum += abs(a[i + 1] - a[i]);
	}
	
	inc1(i, n) {
		int ans = sum + abs(a[i + 1] - a[i - 1]) - abs(a[i + 1] - a[i]) - abs(a[i] - a[i - 1]);
		cout << ans << "\n";
	}
	
	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> c(9,vector<int>(9));//1~Nでcij先頭1末尾jの数字の数

    string tmp;
    for(int i=1;i<N+1;i++){
        tmp = to_string(i);
        if(i%10!=0) c[int(tmp[0]-'0')-1][i%10-1]++;
    }

    int ans=0;

    for(int i=0;i<9;i++){
        for(int j=0;j<9;j++){
            ans+=c[i][j]*c[j][i];
        }
    }

    cout << ans << endl;

    return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

bool cmp(P a, P b)
{
  return a.second < b.second;
}

int main()
{
  int M, N;
  cin >> N >> M;

  vector<P> ab(M);
  for(int i=0; i<M; i++)
    cin >> ab[i].first >> ab[i].second;
  
  sort(ab.begin(), ab.end(), cmp);

  int count = 0;
  ll tmp=0;
  for(int i=0; i<M; i++)
    {
      if(ab[i].first>=tmp)
	{
	  tmp = ab[i].second;
	  count++;
	}
    }

  cout << count << endl;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

int main() {
  long long X;
  cin >> X;

  double money_d;
  long long money_i=100;
  int i=0;
  while (money_i < X){
    money_d = 1.01*money_i;
    money_i = money_d;
    i++;
  }

  cout << i << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

struct ei{
    int a,b,c;
    ei(int a,int b,int c):a(a),b(b),c(c){}
};
ei operator+(const ei &x,const ei &y){
    ei z(0,0,0);
    z.a=x.a*y.a%mod;
    z.b=(x.a*y.b+x.b*y.a)%mod;
    z.c=(x.a*y.c+x.b*y.b+x.b*y.c+x.c*y.a+x.c*y.b+x.c*y.c)%mod;
    return z;
}

int N;
vint G[222222];
vector<ei>dp[222222];

int cnt[222222];
int po[222222];
void dfs(int v,int d){
    cnt[d]++;
    dp[v].pb(ei(1,1,0));

    int ma=0;

    for(auto u:G[v]){
        dfs(u,d+1);
        if(dp[v].size()<dp[u].size())swap(dp[v],dp[u]);
        chmax(ma,dp[u].size());
        int b=(int)dp[v].size()-(int)dp[u].size();
        for(int i=0;i<dp[u].size();i++){
            dp[v][b+i]=dp[v][b+i]+dp[u][i];
        }
    }

    for(int i=0;i<ma;i++){
        ei &z=dp[v][dp[v].size()-1-i];
        z.a=(z.a+z.c)%mod;
        z.c=0;
    }

    if(v!=0)dp[v].pb(ei(1,0,0));
}


signed main(){
    po[0]=1;
    for(int i=1;i<222222;i++)po[i]=po[i-1]*2%mod;

    cin>>N;N++;
    for(int i=1;i<N;i++){
        int p;cin>>p;
        G[p].pb(i);
    }

    dfs(0,0);

    int ans=0;
    for(int i=0;i<dp[0].size();i++)ans=(ans+dp[0][(int)dp[0].size()-i-1].b*po[N-cnt[i]])%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 67568
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
#define fi first
#define se second
#define mod 1000000007
#define maxn 200005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;while(t--)
#define go_pt int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef pair<ll,ll>pii;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int infi = 100005;
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    //freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    //freopen("output.txt", "w", stdout);
    #endif

    fastio;
    int n;
    cin>>n;
    int b[n],a[n];
    for(int i=0;i<n-1;i++)
    {cin>>b[i];a[i]=100005;}
    a[n-1] = 100005;
    for(int i=0;i<n-1;i++)
    {
        a[i] = min(a[i],b[i]);
        a[i+1] = min(a[i+1],b[i]);
    }
    int sum=0;
    for(int i=0;i<n;i++)
        sum+=a[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define prev prev228
#define all(x) (x).begin(), (x).end()

const long long INF = 1e14;

int n;
int a[105];
long long x;
vector<int> graph[500];
long long v[2000], u[2000], c[2000], f[2000], cnt, bw[2000];
int dist[500];
int pnt[500];

long long dfs(int v, long long want)
{
    if (v == n + 1) return want;
    long long lec = 0;
    for (; pnt[v] < graph[v].size(); pnt[v]++)
    {
        int e = graph[v][pnt[v]];
        int w = u[e];
        if (dist[w] == dist[v] + 1 && f[e] + 1 <= c[e] && want > 0)
        {
            long long go = dfs(w, min(c[e] - f[e], want));
            f[e] += go;
            f[bw[e]] -= go;
            lec += go;
            want -= go;
        }
    }
    return lec;
}

bool step()
{
    for (int i = 0; i <= n + 1; i++) dist[i] = 1e9, pnt[i] = 0;
    dist[0] = 0;
    vector<int> q = {0};
    for (int i = 0; i < q.size(); i++)
    {
        int x = q[i];
        for (auto e : graph[x])
        {
            int y = u[e];
            if (dist[x] + 1 < dist[y] && f[e] + 1 <= c[e])
            {
                dist[y] = dist[x] + 1;
                q.push_back(y);
            }
        }
    }
    long long F = dfs(0, INF);
    return (F > 0);
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], x += max(0, a[i]);
    for (int i = 1; i <= n; i++)
        if (a[i] < 0)
        {
            graph[0].push_back(cnt);
            v[cnt] = 0, u[cnt] = i, c[cnt] = -a[i], bw[cnt] = cnt + 1;
            cnt++;
            graph[i].push_back(cnt);
            v[cnt] = i, u[cnt] = 0, bw[cnt] = cnt - 1;
            cnt++;
        }
        else
        {
            graph[i].push_back(cnt);
            v[cnt] = i, u[cnt] = n + 1, c[cnt] = a[i], bw[cnt] = cnt + 1;
            cnt++;
            graph[n + 1].push_back(cnt);
            v[cnt] = n + 1, u[cnt] = i, bw[cnt] = cnt - 1;
            cnt++;
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j * i <= n; j++)
    {
        graph[i].push_back(cnt);
        v[cnt] = i, u[cnt] = i * j, c[cnt] = INF, bw[cnt] = cnt + 1;
        cnt++;
        graph[i * j].push_back(cnt);
        v[cnt] = i * j, u[cnt] = i, bw[cnt] = cnt - 1;
        cnt++;
    }
    while (step()) ;
    long long s = 0;
    for (int i = 0; i < graph[0].size(); i++)
    {
        s += f[graph[0][i]];
    }
    cout << x - s;
}


Measured memory_bytes: 384
#include <iostream>

int main()
{
	int n;
	while( std::cin >> n )
	{
		int num = 0;
		for( int i1=0; i1<=9; ++i1 )
		{
			for( int i2=0; i2<=9; ++i2 )
			{
				for( int i3=0; i3<=9; ++i3 )
				{
					for( int i4=0; i4<=9; ++i4 )
					{
						num += (i1+i2+i3+i4 == n);
					}
				}
			}
		}

		std::cout << num << '\n';
	}
}

Measured memory_bytes: 1160
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramA a = new ProgramA();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int d = int.Parse(s[3]);
            int e = int.Parse(s[4]);

            Console.WriteLine(d + c * 60 - b - a * 60 - e);

        }
    }

    class ProgramB
    {
        public void main()
        {

            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int d = int.Parse(s[3]);

            if (a > d || b < c)
                Console.WriteLine("0");
            else
                Console.WriteLine(Math.Abs(Math.Min(b, d) - Math.Max(a, c)));
            

        }
    }

    class ProgramC
    {
        public void main()
        {
            


        }
    }

    class Dis
    {
        public int a;
        public long b;
        public Dis(int a, long b)
        {
            this.a = a;
            this.b = b;
        }
    }
}






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


#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define pair < int , int > pii

int cnt[100];
string s, t;

int main(){

	cin >> s >> t;
	for(int i = 0; i < s.size(); i++)
		cnt[s[i]-'a']++;

	s = "";
	for(int i = 0; i < 26; i++)
		while(cnt[i]--)
			s += (char)(i+'a');

	memset(cnt, 0, sizeof(cnt));

	for(int i = 0; i < t.size(); i++)
		cnt[t[i]-'a']++;
	t = "";
	for(int i = 25; i >= 0; i--)
		while(cnt[i]--)
			t += (char)(i+'a');
	if(s < t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	
}

Measured memory_bytes: 256
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}


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

    int N; cin >> N;
    vl a(N); REP(i, N) cin >> a[i];
    const int AMAX = 1e5-1;

    vi h(AMAX+MGN, 0);
    REP(i, N) h[a[i]]++;

    int ans = h[0] + h[1] + h[2];
    FOR(i,2,AMAX){
        ans = max(ans, h[i - 1] + h[i] + h[i + 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
n = int(input())
A = [0, 1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
dp = [10**6] * (10**6 + 1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = min(dp[i-a]+1 for a in A if i>=a)
print(dp[n])

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int n; cin >> n;
    vi a(n); REP(i, n) cin >> a[i];

    if(n % 2 == 1)
    {
        for(int i = a.size()-1; i >= 0; i -= 2)
        {
            cout << a[i] << " ";
        }
        for(int i = 1; i < a.size(); i += 2)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
    else
    {
        for(int i = a.size()-1; i >= 1; i -= 2)
        {
            cout << a[i] << " ";
        }
        for(int i = 0; i < a.size(); i += 2)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

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

    return 0;
}

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

int main(){
 int a,c,d,e;
  cin>>a>>c>>d;
e=max(a,max(c,d));
     if(a==e){
    cout<<c+d<<endl;
     }
  else if(c==e){
 cout<<a+d<<endl;
  }
  else{
    cout<<a+c<<endl;
    }
     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr(i1,m) for(int i1=0;i1<m;i1++)
using namespace std;
  long long a[500100],s=0,i;
int main()
{
        long long n,p;
        while(cin>>n)
        {

             fr(i,n*3)
             cin>>a[i];

             sort(a,a+n*3);
            p=n*3;
            p=p-2;
           while(n>0)
           {
              s+=a[p];
              n--;
              p=p-2;
           }
             cout<<s<<"\n";
        }

        return 0;

}




Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
  double a, b, C;
  scanf("%lf %lf %lf", &a, &b, &C);

  printf("%lf\n", a*b*sin(C*M_PI/180)/2);
  printf("%lf\n", a+b+sqrt(a*a+b*b-2*a*b*cos(C*M_PI/180)));
  printf("%lf\n", b*sin(C*M_PI/180));
  return 0;
}


Measured memory_bytes: 2040
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    data = list(map(int, input().split()))
    for i, d in enumerate(data):
        if d == 0:
            print(i + 1)

    #print('\33[32m' + 'end' + '\033[0m') # debug


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL h,w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  LL ans=0;
  for(LL i=0;i<h;i++){
    for(LL j=0;j<w;j++){
      cin >> a[i][j];
      ans+=a[i][j]*(i+1)*(h-i)*(j+1)*(w-j);
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main(void)
{
    int N, L;

    cin >> N >> L;

    vector<string> S(N, "");

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

    auto f = [L](const string& a, const string& b){
        for(int i = 0; i < L; ++i)
        {
            if(a[i] < b[i]) return true;
            else if(a[i] > b[i]) return false;
        }
        return true;
    };

    std::sort(S.begin(), S.end());

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

    return 0;
}



Measured memory_bytes: 3620
# ABC153
# B

H, N = input().split()
A_list = input().split()
A_list.sort(reverse=True)

damage = 0
flg = True
for s in A_list:
    damage += int(s)
    if damage >= int(H):
        print("Yes")
        flg = False
        break
if flg:
    print("No")

Measured memory_bytes: 10532
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		sc.close();
		if (Math.abs(a - c) <= d || (Math.abs(a - b) <= d && Math.abs(b - c) <= d))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 23508
import sys
aa=list(map(int,sys.stdin.read().split()))
aa=aa[1:aa[0]+1]
n=len(aa)
import bisect
bb=[]
for i in range(n):
    if not bb:
        bb.append(aa[-i-1])
    else:
        if bb[-1] <= aa[-i-1]:
            bb.append(aa[-i-1])
        else:
            j = bisect.bisect_right(bb,aa[-i-1])
            bb[j] = aa[-i-1]
print(len(bb))

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

int main(){
    int n, x, t, eq=0;
    scanf("%d %d %d", &n, &x, &t);
    if(n%x==0){
        eq=(n/x)*t;
    }
    else{
        eq= ((n/x)+1)*t;
    }
    
    printf("%d", eq);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=998244353;
const int N=2e5+5;
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        ll n;cin>>n;
        ll ans=0;
        for(ll i=1;i<=n;i++){
            if(i%3!=0&&i%5!=0){
                ans+=i;
            }
        }
        cout<<ans;
    }   
    return 0;   
} 


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

using namespace std;

const int Mod = 1e9 + 7, Nmax = 3005;
typedef long long ll;

void add_to(int &x, int y) { x+=y; if(x>=Mod) x-=Mod; }
int inm(int x, int y) { return (ll)x*y%Mod; }

int n, m, X, Y, ones, cate, i, j, k, kmin, kmax, nr, ans, rest;
int x[Nmax], y[Nmax], nr1[Nmax], dp[Nmax][Nmax], comb[Nmax][Nmax];
char a[Nmax];

int main()
{
 //   freopen("input", "r", stdin);
 //   freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n >> m;
    cin >> (a+1);
    for(i=1; i<=n; ++i) nr1[i] = nr1[i-1] + (a[i] == '1');

    for(i=1; i<=m; ++i)
    {
        cin >> X >> Y;
        if(Y > y[nr]) x[++nr] = X, y[nr] = Y;
    }

    for(i=0; i<=n; ++i)
    {
        comb[i][0] = 1;
        for(j=1; j<=i; ++j)
        {
            comb[i][j] = comb[i-1][j];
            add_to(comb[i][j], comb[i-1][j-1]);
        }
    }

    ans = 1;

    for(i=1; i<=nr; ++i)
    if(i>1 && i<nr && x[i] <= y[i-1] && x[i+1] <= y[i])
    {
        ones = nr1[y[i]] - nr1[y[i-1]];
        cate = x[i+1] - x[i];
        rest = y[i] - x[i+1] + 1;

        for(j=0; j + ones <= rest + cate; ++j)
        {
            kmin = max(0, j+ones-rest);
            kmax = min(j+ones, cate);

            for(k=kmin; k<=kmax; ++k)
                add_to(dp[i+1][j+ones-k], inm(dp[i][j], comb[cate][k]));
        }
    }
    else if(i<nr && x[i+1] <= y[i])
    {
        ones = nr1[y[i]] - nr1[x[i]-1];
        cate = x[i+1] - x[i];
        rest = y[i] - x[i+1] + 1;

        kmin = max(0, ones-rest);
        kmax = min(ones, cate);
        for(k=kmin; k<=kmax; ++k)
            add_to(dp[i+1][ones-k], inm(ans, comb[cate][k]));
    }
    else if(i>1 && x[i] <= y[i-1])
    {
        cate = y[i] - x[i] + 1;
        ones = nr1[y[i]] - nr1[y[i-1]];

        ans = 0;
        for(j=0; ones + j <= cate; ++j)
            add_to(ans, inm(dp[i][j], comb[cate][ones + j]));
    }
    else
    {
        cate = y[i] - x[i] + 1;
        ones = nr1[y[i]] - nr1[x[i]-1];
        ans = inm(ans, comb[cate][ones]);
    }

    cout << ans << '\n';

    return 0;
}


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

#pragma warning(disable : 4996)

using namespace std;

int N, W, H, X, Y, S, T, r[100][100];

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

		if (N == 0) break;

		memset(r, 0, sizeof(r));

		scanf("%d", &W);
		scanf("%d", &H);

		for (int i = 0; i < N; i++)
		{
			scanf("%d", &X);
			scanf("%d", &Y);

			r[Y - 1][X - 1] = 1;
		}

		scanf("%d", &S);
		scanf("%d", &T);

		int ret = 0;

		for (int i = 0; i <= H - T; i++)
		{
			for (int j = 0; j <= W - S; j++)
			{
				int res = 0;

				for (int k = i; k < i + T; k++)
				{
					for (int l = j; l < j + S; l++)
					{
						res += r[k][l];
					}
				}

				ret = ret > res ? ret : res;
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

Measured memory_bytes: 3244
#include<bits/stdc++.h> 
#define ll long long 
#define ld long double
using namespace std;
const int N = 1e5+5;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;cin>>n;
	cout<<n*n*n<<"\n";
	return 0;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    ll n;
    cin >> n;
    vector<ll> l(87);
    l.at(0) = 2;
    l.at(1) = 1;
    rep(i, n-1){
        l.at(i+2) = l.at(i) + l.at(i+1);
    }
    cout << l.at(n) << endl;
    return 0;
}

Measured memory_bytes: 256
/*WELCOME TO AYUSH RANJAN CODE'S*/
/*EVERY PROBLEM HAS A SOLUTION SOMETIMES ELEGENT OTHERWISE COMPLEX ELEGENCE*/

#include <bits/stdc++.h>
using namespace std;

    int chkpower2(int x){
        return (x&&!(x&x-1));
    }


    void solve(){
       long long int d1,n,i=0,sum=0;
        cin>>n;
        int a[n];
        vector<int> ans;
        for(int i1=0;i1<n;i1++){
            cin>>a[i1];
            ans.push_back(a[i1]);
            ans.push_back(a[i1]);
        }
        sort(ans.begin(),ans.end());
        ans.pop_back();
        sort(ans.rbegin(),ans.rend());
        for(int i1=0;i1<n-1;i1++){
            sum+=ans[i1];
        }
        cout<<sum;

    }

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

        int t;
       t=1;//cin>>t;
        while(t--){
            solve();
            cout<<"\n";
        }
        return 0;
    }


Measured memory_bytes: 5884
import fractions
n, x = map(int, input().split())
xi = list(map(int, input().split()))
xi.sort()

L = []
for i in range(n):
    L.append(abs(x - xi[i]))
if 0 in L:
    L.remove(0)

for i in range(len(L) - 1):
    L[i+1] = fractions.gcd(L[i], L[i+1])
print(L[len(L) - 1])

Measured memory_bytes: 16240
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main()
{jizz
	int n,k;
	cin >> n >> k;
	if(k>1) cout << n-k << "\n";
	else cout << "0\n";
}

Measured memory_bytes: 892
#include <iostream>
#include <string>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    char S[N];
    cin >> S;

    if (S[K-1] == 'A') {
        S[K-1] = 'a';
    } else if (S[K-1] == 'B') {
        S[K-1] = 'b';
    } else {
        S[K-1] = 'c';
    }

    cout << S;
}

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


int fill_update_skip(std::vector<int>& fill_map, const int pos){
  if(fill_map[pos] == -1) return pos;
  return fill_map[pos] =  fill_update_skip(fill_map, fill_map[pos]);
}

template <typename T>
auto fill_repeat(std::vector<T>& target, std::vector<int>& fill_map, const T& val, const int begin, const int end){
  for(int i = begin; i < end; ){
    if(fill_map[i] == -1){
      fill_map[i] = end;
      target[i] = val;
      i++;
    }else{
      i = fill_update_skip(fill_map, i);
    }
  }
}

int main(){
        int N,Q;
        std::cin >> N >> Q;
        using stop_type = std::tuple<int, int, int>;
        std::vector<stop_type> stop_arr(N);
        for(int i = 0; i < N; i++){
                std::cin >> std::get<0>(stop_arr[i]) >> std::get<1>(stop_arr[i]) >> std::get<2>(stop_arr[i]);
        }
        std::vector<int> Q_arr(Q);
        for(int i = 0; i < Q; i++){
                std::cin >> Q_arr[i];
        }

        std::sort(stop_arr.begin(), stop_arr.end(), [](const stop_type& l, const stop_type& r){return std::get<2>(l) < std::get<2>(r);});

        std::vector<int> ans_arr(Q, -1);
  std::vector<int> fill_map(Q+1, -1);

        for(auto&& it: stop_arr){
                auto s = std::get<0>(it);
                auto t = std::get<1>(it);
                auto x = std::get<2>(it);
                auto q_start = std::distance(Q_arr.begin(), std::lower_bound(Q_arr.begin(), Q_arr.end(), s-x));
                auto q_stop = std::distance(Q_arr.begin(), std::lower_bound(Q_arr.begin(), Q_arr.end(), t-x));
    fill_repeat(ans_arr, fill_map, x, q_start, q_stop);
        }

        for(auto&& a: ans_arr){
                std::cout << a << "\n";
        }
        std::cout << std::endl;

        return 0;
}


Measured memory_bytes: 6528
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        
        cin = new Scanner();
        int[] abk = cin.arrayInt(3);
        int a = abk[0];
        int b = abk[1];
        int k = abk[2];
        int count = 0;
        int ans = 0;
        for(int c = Math.Min(a, b); c >0 ; c--)
        {
            if (a % c == 0 && b % c == 0) count++;
            if (count == k)
            {
                ans = c;
                break;
            }
        }
        WriteLine(ans);
        ReadLine();

    }
}





class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string input()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return input();
        i = 0;
        return s[i++];
    }

    public int inputInt()
    {
        return int.Parse(input());
    }
    public int[] arrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputInt() + add;
        }
        return Array;
    }

    public long inputLong()
    {
        return long.Parse(input());
    }

    public long[] arrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputLong() + add;
        }
        return Array;
    }

    public double inputDouble()
    {
        return double.Parse(input());
    }


    public double[] arrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	num := 1
	for i := 0; i < n; i++  {
		a := num * 2
		b := num + k
		if a > b {
			num = b
			continue
		}
		num = a
	}
	fmt.Println(num)
}


Measured memory_bytes: 1772
#include <iostream>
using namespace std;
typedef long long LL;
const int N = 100000+10;
const LL INF = 1e16;

int n; 
LL c, x[N], v[N];
LL w[N], preMax[N];

LL solve() {
    preMax[0] = -INF;
    for(int i=1;i<=n;i++) {
        w[i]=v[i]-(x[i]-x[i-1]);
        w[i]=w[i-1]+w[i];
        preMax[i]=max(preMax[i-1],w[i]);
    }
    LL ret = -INF;
    ret = preMax[n];

    LL sum = 0;
    for(int i=n;i>=1;i--) {
        sum += v[i];
        ret=max(ret, sum-2*(c-x[i])+preMax[i-1]);
    }
    return ret;
}
int main() {
    scanf("%d %lld",&n,&c);
    for(int i=1;i<=n;i++) 
        scanf("%lld %lld", &x[i], &v[i]);
    LL ans = max(solve(),0LL);

    for(int i=1;i<=n;i++)
        if(i<n+1-i) {
            swap(x[i],x[n+1-i]);
            swap(v[i],v[n+1-i]);
        }
    for(int i=1;i<=n;i++)
        x[i]=c-x[i];
    ans = max(ans,solve());
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#!/usr/bin/env python3
#ABC138 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = LI()
    g[a-1].append(b-1)

ans = [0]*n
for _ in range(q):
    p,x = LI()
    ans[p-1] += x

que = deque()
que.append(0)
check = [True]*n
while que:
    v = que.popleft()
    for i in g[v]:
        if check[i]:
            check[i] = False
            que.append(i)
            ans[i] += ans[v]
print(*ans)


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

typedef long long ll;

ll A,B,C;

int main()
{
    scanf("%lld%lld%lld",&A,&B,&C);
    if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0)printf("0\n");
    else printf("%lld\n",min(min(A * B,B * C),C * A));
    return 0;
}


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


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

	string ans = "NG";
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			ans = "OK";
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

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

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	int n, a, b, nyak1 = 0, nyak2 = 0, nyak3 = 0;
	int p[105];
	cin >> n;
	cin >> a >> b;
	REP(i, n) {
		cin >> p[i];
		if (p[i] <= a) nyak1++;
		else if (p[i] <= b) nyak2++;
		else nyak3++;	
	}
	cout << min(nyak1, min(nyak2, nyak3)) << '\n';
}

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

long long N, A, B;

int main() {
	cin >> N >> A >> B;
	if ((A - B + (1LL << 60)) % 2 == 0) {
		cout << abs(A - B) / 2LL << endl;
	}
	else {
		// パターン 1
		long long S1 = 1, S2 = B - A;
		long long S3 = A, S4 = (S2 - S1) / 2LL;

		// パターン 2
		long long T1 = A + (N + 1LL - B), T2 = N;
		long long T3 = (N + 1LL - B), T4 = (T2 - T1) / 2LL;

		cout << min(S3 + S4, T3 + T4) << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int fi = 0;
  int ve = 0;
  int N = 0;
  cin>>N;
  fi = N/500;
  N = N-fi*500;
  while(N>=5){
    N-=5;
    ve++;
  }
  cout << fi*1000+ve*5 << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

def main():
    n,m = map(int,input().split())
    dq = []
    for i in range(n):dq.append(deque())
    for _ in range(m):
        q = input().split()
        ind = int(q[1])
        if q[0] == '0':dq[ind].append(int(q[2]))
        elif dq[ind]:
            if q[0] == '1':print(dq[ind][0])
            else          :dq[ind].popleft()


if __name__ == '__main__':
    main()




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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A[3];
int K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A[0]>>A[1]>>A[2];
	sort(A,A+3);
	cin>>K;
	FOR(i,K) A[2]*=2;
	cout<<(A[0]+A[1]+A[2])<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define T long long
#define mat vector<vector<T>>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define cld complex<long double>
using namespace std;
const int N = 405;

inline ll mul(ll x, ll y){
	return x * y % MOD;
}

inline ll add(ll x, ll y){
	ll res = x + y;
	if(res >= MOD)res-=MOD;
	return res;
}


ll mod_pow(ll x, ll p){
	ll res = 1;
	while(p > 0){
		if(p&1)res = res * x % MOD;
		p>>=1;
		x = x * x % MOD;
	}
	return res;
}

int main(){
	fast_io();
	vector<vector<int>> p(N, vector<int>(N));
	cu(i,1,N){p[0][i] = i;}
	cu(i,1,N){
		cu(j,1,N){
			p[i][j] =  add(p[i][j-1], mod_pow(j, i));
		}
	}
	int n,c;cin >> n >> c;
	vector<int> a(N),b(N);
	cu(i,0,n)cin >> a[i];
	cu(i,0,n)cin >> b[i];
	vector<vector<int>> dp(N, vector<int>(N));
	dp[0][0] = 1;
	fu(i,1,n){
		fu(j,0,c){
			fu(k,0,j){
				dp[i][j] = add(dp[i][j], mul(add(p[j-k][b[i-1]], MOD - p[j-k][a[i-1]-1]), dp[i-1][k]));
			}
		}
	}
	cout << dp[n][c] << '\n';
}


Measured memory_bytes: 1536
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		Set<String> s = new HashSet<>();
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			String a = sc.next();
			if(a.equals("insert")) {
				s.add(sc.next());
			}else if(a.equals("find")) {
				boolean b = s.contains(sc.next());
				if(b == true) System.out.println("yes");
				else System.out.println("no");
			}
		}
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 252656
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int > vi;
typedef pair<int ,int > pii;
typedef vector<pii> vii;
const int inf=0x3f3f3f3f, maxn=2007, mod=1e9+7;
const ll linf=0x3f3f3f3f3f3f3f3fLL;
int n;
int a[maxn];
bool e[maxn][maxn];
vi e1[maxn];
bool vis[maxn];
int ind[maxn];
bool book[maxn];
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<='0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+ch-'0',ch=getchar();
   return s*w;
}
inline void write(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
void dfs(int u){
//	cout<<u<<endl;
	vis[u]=true;
	for(int i=1;i<=n;i++){
		if(!vis[i]&&e[u][i]==true){
//			cout<<i<<endl;
			e1[u].pb(i);
			ind[i]++;
			dfs(i);
		}
	}
}

int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(__gcd(a[i],a[j])!=1)e[i][j]=true,e[j][i]=true;
		}
	}
	for(int i=1;i<=n;i++){
		if(!vis[i])dfs(i);
//		cout<<endl;
	}
	for(int i=1;i<=n;i++){
		for(int j=n;j>=1;j--){
			if(!book[j]&&ind[j]==0){
				book[j]=true;
				printf("%d ",a[j]);
				for(int k=0;k<e1[j].size();k++){
					ind[e1[j][k]]--;
				}
				break;
			}
		}
	}
	return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int xcomp(pii& a, pii& b) {
	return a.first > b.first;
}
#define XSORT(c) sort((c).begin(),(c).end(),xcomp)


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL N,M;
  cin >> N >> M;
  vector<LL> A(N);
  REP(i,N){
    cin >> A[i];
  }
  vector<pii> B(M);

  SORT(A);

  REP(i,M){
    LL BB, C;
    cin >> BB >> C;
    B[i] = {C, BB};
  }
  XSORT(B);

  LL AAidx = 0;
  LL Bidx = 0;

  vector<LL> AA(N, 0);

  while(true){
    if(AAidx>=N||Bidx>=M){
      break;
    }
    if(B[Bidx].second<=0){
      Bidx++;
    }else{
      AA[AAidx] = B[Bidx].first;
      B[Bidx].second--;

      AAidx++;
    }
  }

  LL sum = 0;

  REP(i,N){
    sum += max(A[i], AA[i]);
  }
  cout << sum << endl;
}


Measured memory_bytes: 3456
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  ll N;

  cin >> N;

  int ans = 0;
  for (int M = 1; M <= N; M += 2) {
    int cnt = 0;
    for (int i = 1; i * i <= M; i++) {
      if (M % i == 0) {
        cnt++;
        if (M / i != i) cnt++;
      }
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    getline(cin,a);
	getline(cin,b);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),greater<char>());
    if(a<b)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256