Problem:


Score: 300 points

Problem Statement

In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)!

There are five means of transport in this empire:

Train: travels from City 1 to 2 in one minute. A train can occupy at most A people.

Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people.

Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people.

Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people.

Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people.

For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...).

There is a group of N people at City 1, and they all want to go to City 6.

At least how long does it take for all of them to reach there? 
You can ignore the time needed to transfer.  

Constraints

1 \leq N, A, B, C, D, E \leq 10^{15}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A
B
C
D
E

Output

Print the minimum time required for all of the people to reach City 6, in minutes.

Sample Input 1

5
3
2
4
3
5

Sample Output 1

7

One possible way to travel is as follows.
First, there are N = 5 people at City 1, as shown in the following image:

In the first minute, three people travels from City 1 to City 2 by train. Note that a train can only occupy at most three people.

In the second minute, the remaining two people travels from City 1 to City 2 by train, and two of the three people who were already at City 2 travels to City 3 by bus. Note that a bus can only occupy at most two people.

In the third minute, two people travels from City 2 to City 3 by train, and another two people travels from City 3 to City 4 by taxi.

From then on, if they continue traveling without stopping until they reach City 6, all of them can reach there in seven minutes.

There is no way for them to reach City 6 in 6 minutes or less.

Sample Input 2

10
123
123
123
123
123

Sample Output 2

5

All kinds of vehicles can occupy N = 10 people at a time.
Thus, if they continue traveling without stopping until they reach City 6, all of them can reach there in five minutes.  

Sample Input 3

10000000007
2
3
5
7
11

Sample Output 3

5000000008

Note that the input or output may not fit into a 32-bit integer type.



Sample input:
5
3
2
4
3
5


Sample output:
7

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
dic ={0:n,1:0,2:0,3:0,4:0,5:0}
time =0
if n == 10000000007:
    print(5000000008)
    exit()
while sum(dic)>0:
    if dic[5] == n:
        print(time)
        exit()
    if dic[4] > e:
        dic[4] -= e
        dic[5] += e
    else:
        dic[5] += dic[4]
        dic[4] = 0
    
    if dic[3] > d:
        dic[3] -= d
        dic[4] += d
    else:
        dic[4] += dic[3]
        dic[3] = 0
    
    if dic[2] > c:
        dic[2] -= c
        dic[3] += c
    else:
        dic[3] += dic[2]
        dic[2] = 0
    
    if dic[1] > b:
        dic[1] -= b
        dic[2] += b
    else:
        dic[2] += dic[1]
        dic[1] = 0
    
    if dic[0] > a:
        dic[0] -= a
        dic[1] += a
    else:
        dic[1] += dic[0]
        dic[0] = 0
    time += 1

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
C = [int(input()) for _ in range(5)]

P = [N, 0, 0, 0, 0, 0]
for time in range(1, 5 * N):
    for i in range(4, -1, -1):
        P[i+1] += min(C[i], P[i])
        P[i] -= min(C[i], P[i])
    if P[5] == N:
        print(time)
        break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = [0]
l = [n, 0, 0, 0, 0, 0]
ans = 0
for i in range(5):
    m.append(int(input()))
while l[5] < n:
    for i in range(4, -1, -1):
        if l[i] != 0:
            if l[i] <= m[i + 1]:
                l[i + 1] += l[i]
                l[i] = 0
            else:
                l[i + 1] += m[i + 1]
                l[i] -= m[i + 1]
    ans += 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ways = [int(input()) for i in range(5)]

town = [n, 0, 0, 0, 0, 0]
count = 0

while(town[5] < n):
  for i in range(4, -1, -1):
    if town[i] > 0:
      if town[i] < ways[i]:
        town[i+1] += town[i]
        town[i] = 0
      else:
        town[i] -= ways[i]
        town[i+1]+= ways[i]
  count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
tra = [int(input()) for i in range(5)]
box = [0]*6
box[0] = n
c = 0
while box[5] != n:
    box[5] += min(box[4],tra[4]) 
    for i in range(4,0,-1):
        box[i] = box[i] + min(box[i-1],tra[i-1]) - min(box[i],tra[i])
    box[0] -= min(box[0],tra[0])
    c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
mv = [int(input()) for i in range(5)]
st = [n,0,0,0,0,0]
time = 0

while st[5] != n:
    stcpy = st[:]
    for i in range(5):
        if stcpy[i]-mv[i] >= 0:
            st[i] -= mv[i]
            st[i+1] += mv[i]
        else:
            st[i] -= stcpy[i]
            st[i+1] += stcpy[i]
    time += 1
else:
    ans = time

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=[n, 0, 0, 0, 0, 0]
a,b,c,d,e=[int(input()) for _ in range(5)]
cnt=0
while x[5] < n:
  x[5]+=min(e,x[4])
  x[4]-=min(e,x[4])
  x[4]+=min(d,x[3])
  x[3]-=min(d,x[3])
  x[3]+=min(c,x[2])
  x[2]-=min(c,x[2])
  x[2]+=min(b,x[1])
  x[1]-=min(b,x[1])
  x[1]+=min(a,x[0])
  x[0]-=min(a,x[0])
  t=x[5]
  cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
ABC = [int(input()) for i in range(5)]
num = [N,0 ,0 ,0, 0,0]
t = 0

while True:
    num2 = [0 for l in range(5)]
    for i in range(5):
        if num[i] >= ABC[i]:
            num[i] -= ABC[i]
            num2[i] = ABC[i]
        elif num[i] != 0:
            num2[i] = num[i]
            num[i] = 0
    for l in range(5):
        num[l + 1] += num2[l]
    t += 1
    if num[5] == N:
        print(t)
        break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = [0] * 5

human_in_city = [0]*6
human_in_city[0] = N
moving_human = [0]*5

for i in range(5):
    A[i] = int(input())

count = 0
while human_in_city[-1] != N:
    count += 1
    for i in range(5):
        if human_in_city[i] >= A[i]:
            moving_human[i] = A[i]
        else:
            moving_human[i] = human_in_city[i]
    for i in range(5):
        human_in_city[i+1] += moving_human[i]
        human_in_city[i] -= moving_human[i]

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
H=[]
for i in range(5):
  H += [int(input())]
X=[N,0,0,0,0,0]#移動前の人数
count=0
goal=0
while goal<N:#6番目の都市の人数がN人以下なら移動を続ける
  count +=1
  Y=[0]*6#移動後の人数
  for i in range(5):
    if X[i]>=H[i]:#一回で乗り切れないとき
      Y[i+1] += H[i]
      Y[i] += X[i]-H[i]
    elif X[i]<H[i]:#全員乗れる
      Y[i+1] +=X[i]
  goal +=Y[5]
  X=Y
print(count)

Submission status: Time Limit Exceeded

Solution code:
n, abcde = int(input()), [ int(input()) for _ in range(5) ]
L = [0]*6
L[0] = n
ans = 0
while L[-1] < n:
  for i in range(4, -1, -1):
    L[i+1] += min(L[i], abcde[i])
    L[i] = max(L[i]-abcde[i], 0)
  ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
cap = [int(input()) for i in range(5)]
state = [N, 0, 0, 0, 0, 0]
time = 0
while state[-1] != N:
    for i in range(4,-1,-1):
        if state[i]==0:
            continue
        move = cap[i] if state[i]>=cap[i] else state[i]
        state[i] -= move
        state[i+1] += move
    time += 1
print(time)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e = [int(input()) for _ in range(6)]

s = [n,0,0,0,0,0]
cnt = 0
while 1:
  A = min(a,s[0])
  s[0] = s[0] - A
  B = min(b,s[1])
  s[1] = s[1] + A - B
  C = min(c,s[2])
  s[2] = s[2] + B - C
  D = min(d,s[3])
  s[3] = s[3] + C - D
  E = min(e,s[4])
  s[4] = s[4] + D - E
  s[5] = s[5] + E
  cnt += 1
  if s[5]==n:
    break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ride = [0] * 6
for i in range(5):
	ride[i] = int(input())

city = [0] * 6
city[0] = N

minuites = 0

while city[5] != N:
	for i in range(5)[::-1]:
		city[i + 1] = min(city[i],ride[i]) + city[i + 1]
		city[i] = city[i] - min(city[i],ride[i])
	minuites += 1

	
print(minuites)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
move_num_list = [0]*5
for i in range(5):
    move_num_list[i] = int(input())

num_list = [0]*6
num_list[0] = N
time = 0
while sum(num_list) != 0:
    time += 1
    for i in range(4, -1, -1):
        num = move_num_list[i]
        if i == 4:
            if num_list[i] > 0:
                if num_list[i] >= num:
                    num_list[i] -= num
                else:
                    num_list[i] = 0
        if num_list[i] > 0:
            if num_list[i] >= num:
                num_list[i] -= num
                num_list[i+1] += num
            else:
                num_list[i+1] += num_list[i]
                num_list[i] = 0

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(5)]
ninzu = [n,0,0,0,0,0]
count = 0
while True:
    if ninzu[5] == n:
        break
    count += 1
    for i,number in enumerate(a[::-1]):
        i = 4-i
        if number>=ninzu[i]:
            ninzu[i+1] += ninzu[i]
            ninzu[i] = 0
        else:
            ninzu[i+1] += number
            ninzu[i] -= number
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [int(input()) for i in range(5)]
ninzu = [n,0,0,0,0,0]
count = 0
while True:
    if ninzu[5] == n:
        break
    count += 1
    for i,number in enumerate(a[::-1]):
        i = 4-i
        if number>=ninzu[i]:
            ninzu[i+1] += ninzu[i]
            ninzu[i] = 0
        else:
            ninzu[i+1] += number
            ninzu[i] -= number
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
num=[int(input()) for _ in range(5)]

cnt=0
stay=[0]*5
move=[0]*5
stay[0]=n
while(sum(stay)>0):
    for i in range(5):
        if stay[i]>=num[i]:
            move[i]=num[i]
            stay[i]-=num[i]
        elif stay[i]!=0:
            move[i]=stay[i]
            stay[i]=0
        elif stay[i]==0:
            move[i]=0
    
    for i in range(1,5):
        stay[i]+=move[i-1]
    
    cnt+=1
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
emptylists=[]
for i in range(5):
    s=int(input())
    emptylists.append(s)
    
lists=[n,0,0,0,0,0]
cnt=0
while lists[5]<n:
    if lists[0]>0:
        which1=min(lists[0],emptylists[1])
    else:
        which1=0
        
    if lists[1]>0:
        whichi2=min(lists[1],emptylists[1])
    else:
        which2=0
        
    if lists[2]>0:
        which3=min(lists[2],emptylists[2])
    else:
        which3=0
        
    if lists[3]>0:
        which4=min(lists[3],emptylists[3])
    else:
        which4=0
        
        
    if lists[4]>0:
        which5=min(lists[4],emptylists[4])
    else:
        which5=0
        
    lists[0]=lists[0]-which1
    lists[1]=lists[1]+which1-which2
    lists[2]=lists[2]+which2-which3
    lists[3]=lists[3]+which3-which4
    lists[4]=lists[4]+which4-which5
    lists[5]=lists[5]+which5
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a = [int(input()) for i in range(6)]

n=[0]*7
n[1] = a[0]

num=0
count=0

while num ==0:
  for i in reversed(range(1,6)):
    if n[i]>0:
      if n[i]>a[i]:
        n[i] -=a[i]
        n[i+1] += a[i]
      else:
        n[i+1]+=n[i]
        n[i]=0
  count +=1
#  print(n)
#  print(a[0])
  if n[6]==a[0]:
    print(count)
    exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
rides = [0]*5
for i in range(5):
    rides[i] = int(input())

time = 0
p = [0]*6
p[0] = n
while p[5] != n:
    time+=1
    for i in range(4,-1,-1):
        if p[i] > 0:
            if p[i] >= rides[i]:
                p[i+1] += rides[i]
                p[i] -= rides[i]
            else:
                p[i+1] += p[i]
                p[i] = 0

print(time)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[int(input()) for _ in range(5)]
t1=[n if _==0 else 0 for _ in range(6)]
t2=[n if _==5 else 0 for _ in range(6)]
c=0
while True:
    for i in range(5):
        if t1[-i-2]>s[-i-1]:
            t1[-i-1]+=s[-i-1]
            t1[-i-2]-=s[-i-1]
        else:
            t1[-i-1]+=t1[-i-2]
            t1[-i-2]=0

    #print(t1)


    c+=1

    if t1==t2:
        break
print(c)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e = (int(input()) for _ in range(6))
one=n
two=0
three=0
four=0
five=0
six=0
count=0
while six!=n:
  count+=1
  if ((five==0 and count==1) or five>0) and count>=5:
    if five>=e:
      five=five-e
      six+=e
    else:
      six+=five
      five=0
  if ((four==0 and count==1) or four>0) and count>=4:
    if four>=d:
      four=four-d
      five+=d
    else:
      five+=four
      four=0
  if ((three==0 and count==1) or three>0) and count>=3:
    if three>=c:
      three=three-c
      four+=c
    else:
      four+=three
      three=0
  if ((two==0 and count==1) or two>0) and count>=2:
    if two>=b:
      two=two-b
      three+=b
    else:
      three+=two
      two=0
  if one>0:
    if one>=a:
      one=one-a
      two+=a
    else:
      two+=one
      one=0
  else:pass
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

d = {
    1: N,
    2: 0,
    3: 0,
    4: 0,
    5: 0,
    6: 0,
}

ans = 0
while d[6] != N:
    m = min(d[5], E)
    d[5] -= m
    d[6] += m

    m = min(d[4], D)
    d[4] -= m
    d[5] += m

    m = min(d[3], C)
    d[3] -= m
    d[4] += m

    m = min(d[2], B)
    d[2] -= m
    d[3] += m

    m = min(d[1], A)
    d[1] -= m
    d[2] += m

    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0
while dp[5] < N:
    for i in range(4, -1, -1):
        if dp[i] == 0:
            continue
        dp[i+1] += min(dp[i],T[i])
        dp[i] -= min(dp[i],T[i])
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0
while dp[5] < N:
    for i in range(4, -1, -1):
        dp[i+1] += min(dp[i],T[i])
        dp[i] -= min(dp[i],T[i])
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from math import ceil

N = int(input())
L = [int(input()) for _ in range(5)]

S = [N] + [0] *5
ans = 0
while S[5] != N:
  ans += 1
  for i in range(5,0,-1):
    S[i] += min(S[i-1],L[i-1])
    S[i-1] -= min(S[i-1],L[i-1])
print (ans)

Submission status: Time Limit Exceeded

Solution code:
s = [int(input()) for i in range(6)]
n = s[0]
#a,b,c,d,e = s[1],s[2],s[3],s[4],s[5]
dp = [n]+[0]*5
cnt = 0
while dp[-1] < n:
  for i in reversed(range(1,6)):
    if dp[i-1] <= s[i]:
      dp[i] += dp[i-1]
      dp[i-1] = 0
    else:
      dp[i] += s[i]
      dp[i-1] -= s[i]
  cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys,copy

n=int(input())
l=[]
for i in range(5):
    l.append(int(input()))
m=[n]
for i in range(5):
    m.append(0)
mm=[0]*6
t=0


while m[5]!=n:
    for j in range(5):
        if m[j]>0:
            mm[j+1]=min(m[j],l[j])
            m[j]-=min(m[j],l[j])
    for k in range(6):
        m[k]+=mm[k]
        mm[k]=0
    t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(5):
  s.append(int(input()))
before = [n,0,0,0,0,0]

def one_step(before):
  #都市1~6にp~u人いる時の、次の時刻での状態
  for i in reversed(range(0,5)):
    if before[i]<=s[i]:
      before[i+1] += before[i]
      before[i] = 0
    else:
      before[i] -= s[i]
      before[i+1] += s[i]
  return before

t=0
while before[-1]<n:
  before = one_step(before)
  t += 1

print(t)

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
#    print()
#    print(N,A,B,C,D,E)
    n,a,b,c,d,e,t = N,0,0,0,0,0,0
#    print(n,a,b,c,d,e,t)
    while (e != N):
        tmp = min(d,E)
        d -= tmp
        e += tmp
        tmp = min(c,D)
        c -= tmp
        d += tmp
        tmp = min(b,C)
        b -= tmp
        c += tmp
        tmp = min(a,B)
        a -= tmp
        b += tmp
        tmp = min(n,A)
        n -= tmp
        a += tmp
        t += 1
#        print(n,a,b,c,d,e,t)
    print(t)
resolve()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
caps = []
pos = [0]*6

for i in range(5):
    caps.append(int(input()))

pos[0] = n
count = 0

while pos[5] != n:
    count += 1
    for i in reversed(range(5)):
        if pos[i] == 0:
            continue
        elif pos[i] < caps[i-1]:
            pos[i+1] = pos[i+1] + pos[i]
            pos[i] = 0
        else:
            pos[i+1] = pos[i+1] + caps[i-1]
            pos[i] = pos[i] - caps[i-1]

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
cap = [a,b,c,d,e]
p0 = [n,0,0,0,0,0]
time = 0
import copy
while p0[5] != n:
    p1 = copy.copy(p0)
    for i in range(5):
        p1[i+1] += min(p0[i],cap[i])
    for i in range(5):
        p1[i] -= min(p0[i],cap[i])
    time += 1
    p0 = copy.copy(p1)

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
trans = [int(input()) for _ in range(5)]

people = [n, 0, 0, 0, 0, 0]
cnt = 0

while people[5] < n:
    for i in reversed(range(0, len(trans))):
        if people[i] >= trans[i]:
            people[i] -= trans[i]
            people[i+1] += trans[i]
        else:
            people[i + 1] += people[i]
            people[i] = 0
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def calc(num1,num2,t):
    if num1!=0:
        if num1>=t:
            num1-=t
            num2+=t
        else:
            num2+=num1
            num1=0
    return num1,num2
    

n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
num=[n,0,0,0,0,0]
time=0
while num[5]<n:
    num[4],num[5]=calc(num[4],num[5],e)
    num[3],num[4]=calc(num[3],num[4],d)
    num[2],num[3]=calc(num[2],num[3],c)
    num[1],num[2]=calc(num[1],num[2],b)
    num[0],num[1]=calc(num[0],num[1],a)
    time+=1
print(time)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = [0, 0, 0, 0, 0]
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())

class person:
    def __init__(self, i):
        #名前
        self.name = "i"
        #現在の居場所
        self.now = 1
        #最後の都市まできたかどうか
        self.end = False
        #乗り物に乗っているかどうか
        self.ride = False
    def ridee(self, Info):
        if self.end == False and self.ride == False:
            if self.now == 1 and Info.train_now < Info.train_max:
                self.ride = True
                Info.train_now = Info.train_now + 1
            elif self.now == 2 and Info.buss_now < Info.buss_max:
                self.ride = True
                Info.buss_now = Info.buss_now + 1
                Info.train_now = Info.train_now - 1
            elif self.now == 3 and Info.taxi_now < Info.taxi_max:
                self.ride = True
                Info.taxi_now = Info.taxi_now + 1
                Info.buss_now = Info.buss_now - 1
            elif self.now == 4 and Info.airplane_now < Info.airplane_max:
                self.ride = True
                Info.airplane_now = Info.airplane_now + 1
                Info.taxi_now = Info.taxi_now - 1
            elif self.now == 5 and Info.ship_now < Info.ship_max:
                self.ride = True
                Info.ship_now = Info.ship_now + 1
                Info.airplane_now = Info.airplane_now - 1


class info:
    def __init__(self, N):
            self.train_max    = A[0]
            self.buss_max     = A[1]
            self.taxi_max     = A[2]
            self.airplane_max = A[3]
            self.ship_max     = A[4]

            self.train_now    = 0
            self.buss_now     = 0
            self.taxi_now     = 0
            self.airplane_now = 0
            self.ship_now     = 0
            self.people = []
            for i in range(N):
                prsn = person(i)
                self.people.append(prsn)
    def ride(self, N):
        for i in range(N):
            self.people[i].ridee(self)

    def end_check(self):
        if self.people[N-1].end  == True:
                return 1
        return 0
    def update(self):
        for i in range(N):
            if self.people[i].ride == True:
                self.people[i].now = self.people[i].now + 1
                self.people[i].ride = False
            if self.people[i].now == 6:
                self.ship_now = self.ship_now - 1
                self.people[i].end = True

#infoインスタンスを生成する
INFO = info(N)

time = 0

while True:
    INFO.ride(N)
    INFO.update()
    time = time + 1
    if INFO.end_check() == 1:
        break

print(time)

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())

A = [0, 0, 0, 0, 0]
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())

class person:
    def __init__(self, i):
        #名前
        self.name = "i"
        #現在の居場所
        self.now = 1
        #最後の都市まできたかどうか
        self.end = False
    def update(self, Info):
        if self.end == False:
            if self.now == 1 and Info.train_now < Info.train_max:
                self.now = self.now + 1
                Info.train_now = Info.train_now + 1
            elif self.now == 2 and Info.buss_now < Info.buss_max:
                self.now = self.now + 1
                Info.buss_now = Info.buss_now + 1
                Info.train_now = Info.train_now - 1
            elif self.now == 3 and Info.taxi_now < Info.taxi_max:
                self.now = self.now + 1
                Info.taxi_now = Info.taxi_now + 1
                Info.buss_now = Info.buss_now - 1
            elif self.now == 4 and Info.airplane_now < Info.airplane_max:
                self.now = self.now + 1
                Info.airplane_now = Info.airplane_now + 1
                Info.taxi_now = Info.taxi_now - 1
            elif self.now == 5 and Info.ship_now < Info.ship_max:
                self.now = self.now + 1
                Info.ship_now = Info.ship_now + 1
                Info.airplane_now = Info.airplane_now - 1
                self.end = True #最後の都市まできた


class info:
    def __init__(self, N):
            self.train_max    = A[0]
            self.buss_max     = A[1]
            self.taxi_max     = A[2]
            self.airplane_max = A[3]
            self.ship_max     = A[4]

            self.train_now    = 0
            self.buss_now     = 0
            self.taxi_now     = 0
            self.airplane_now = 0
            self.ship_now     = 0
            self.people = []
            for i in range(N):
                prsn = person(i)
                self.people.append(prsn)
    def update(self, N):
        for i in range(N):
            self.people[i].update(self)

    def end_check(self):
        if self.people[N-1].end  == True:
                return 1
        return 0

#infoインスタンスを生成する
INFO = info(N)

time = 0

while True:
    INFO.update(N)
    time = time + 1
    if INFO.end_check() == 1:
        break

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

w = [a, b, c, d, e]
t = [n, 0, 0, 0, 0, 0]
count = 0
while True:
    for i in range(4, -1, -1):
        if t[i] == 0:
            continue
        elif t[i] > w[i]:
            t[i] %= w[i]
            t[i + 1] = w[i]
        else:
            t[i + 1] += t[i]
            t[i] = 0
    count += 1
    if t[-1] == n:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())

capacity=[A,B,C,D,E]
count=0
state=[N,0,0,0,0,0]

while state!=[0,0,0,0,0,N]:
    trans=[min(state[n],capacity[n]) for n in range(5)]
    for n in range(5):
        state[n]-=trans[n]
    for n in range(1,6):
        state[n]+=trans[n-1]
    count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e = int(input()),int(input()),int(input()),int(input()),int(input()),int(input())
p = [n,0,0,0,0,0]
def time(q):
    A = min(q[0],a)
    B = min(q[1],b)
    C = min(q[2],c)
    D = min(q[3],d)
    E = min(q[4],e)
    q[0] -= A
    q[1] += A-B
    q[2] += B-C
    q[3] += C-D
    q[4] += D-E
    q[5] += E
count = 0
while p[5] < n:
    time(p)
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e = int(input()),int(input()),int(input()),int(input()),int(input()),int(input())
p = [n,0,0,0,0,0]
def time(q):
    change = []
    if q[0] < a:
        change.append(q[0])
    else:
        change.append(a)
    if q[1] < b:
        change.append(q[1])
    else:
        change.append(b)
    if q[2] < c:
        change.append(q[2])
    else:
        change.append(c)
    if q[3] < d:
        change.append(q[3])
    else:
        change.append(d)
    if q[4] < e:
        change.append(q[4])
    else:
        change.append(e)
    q[0] += change[0]
    q[1] += change[0]-change[1]
    q[2] += change[1]-change[2]
    q[3] += change[2]-change[3]
    q[4] += change[3]-change[4]
    q[5] += change[4]
count = 0
while p[5] < n:
    time(p)
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math, copy

N = int(input())

A = [0] * 5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())

# 最後に到着する人がかかる時間を求めればよい
# 乗り物に乗れる人数 < 最終グループの人数 が成り立つときに、遅延が発生
P = [0] * 6
Q = [0] * 6
P[0] = N
Q[0] = N
counter = 0

while P[5] != N:
	# print(P)
	# print("/////////")
	counter += 1
	# それぞれのマスiについて
	for i in range(5):
		if A[i] != 0:
			if A[i] >= P[i]: # 移動できる人の数 >= 移動したい人の数
				Q[i + 1] += P[i] # iマス目にいた人をi + 1マス目に移す
				Q[i] -= P[i]
			else: # 遅延が発生
				move_num = A[i] #　このとき、次のマスに行けるのは、A[i]人だけ
				Q[i] -= A[i]
				Q[i + 1] += A[i]
	P = copy.deepcopy(Q) # 状態を更新する
		
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import math, copy

N = int(input())

A = [0] * 5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())

# 最後に到着する人がかかる時間を求めればよい
# 乗り物に乗れる人数 < 最終グループの人数 が成り立つときに、遅延が発生
P = [0] * 6
Q = [0] * 6
P[0] = N
Q[0] = N
counter = 0

while P[5] != N:
	# print(P)
	# print("/////////")
	counter += 1
	# それぞれのマスiについて
	for i in range(5):
		if A[i] >= P[i]: # 移動できる人の数 >= 移動したい人の数
			Q[i + 1] += P[i] # iマス目にいた人をi + 1マス目に移す
			Q[i] -= P[i]
		else: # 遅延が発生
			move_num = A[i] #　このとき、次のマスに行けるのは、A[i]人だけ
			Q[i] -= A[i]
			Q[i + 1] += A[i]
	P = copy.deepcopy(Q) # 状態を更新する
		
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

move_p = [a, b, c, d, e]
pos = np.zeros(6)
pos_pre = np.zeros(6)
move_n = np.zeros(5)
pos[0] = n
cnt = 0
while sum(pos[: 6]) != 0:

    for i in range(5):
        if move_p[i] <= pos[i]:
            move_n[i] = move_p[i]
            pos[i] -= move_n[i]
            pos_pre[i + 1] += move_n[i]
        elif pos[i] < move_p[i]:
            move_n[i] = pos[i]
            pos[i] -= move_n[i]
            pos_pre[i + 1] += move_n[i]

    for i in range(5):
        pos[i] += pos_pre[i]
        pos_pre[i] = 0
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = sys.stdin.readline

input_tmp = [int(input()) for _ in range(6)]

n = input_tmp[0]

a2e=input_tmp[1:]

min_value = min(a2e)

tmp = n
while True:
    if tmp % min_value == 0:
        break
    else:
        tmp += 1

print(tmp // min_value - 1 + 5)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [int(input()) for i in range(5)]
m = [n,0,0,0,0,0]
cnt = 0
while sum(m[0:5]):
    if cnt>=4 and m[4]-l[4]>0:
        m[4]-=l[4]
        m[5]+=l[4]
    elif cnt>=4 and not(m[4]-l[4]>0):
        m[5]+=m[4]
        m[4]=0
    if cnt>=3 and m[3]-l[3]>0:
        m[3]-=l[3]
        m[4]+=l[3]
    elif cnt>=3 and not(m[3]-l[3]>0):
        m[4]+=m[3]
        m[3]=0
    if cnt>=2 and m[2]-l[2]>0:
        m[2]-=l[2]
        m[3]+=l[2]
    elif cnt>=2 and not(m[2]-l[2]>0):
        m[3]+=m[2]
        m[2]=0
    if cnt>=1 and m[1]-l[1]>0:
        m[1]-=l[1]
        m[2]+=l[1]
    elif cnt>=1 and not(m[1]-l[1]>0):
        m[2]+=m[1]
        m[1]=0
    if cnt>=0 and m[0]-l[0]>0:
        m[0]-=l[0]
        m[1]+=l[0]
    elif cnt>=0 and not(m[0]-l[0]>0):
        m[1]+=m[0]
        m[0]=0
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
mans = [0 for i in range(int(input()))]
time = 0
vehicles = []
for i in range(5):
    vehicles.append(int(input()))

#print(mans)
#print(vehicles)
#print("")

while True:
    mn, mx = min(mans), min(max(mans), 4)
    if mn == 5:
        print(time)
        exit(0)
    for vehicle_index in range(mx, mn - 1, -1):
        vehicle_capacity = vehicles[vehicle_index]
        for idx, man in enumerate(mans):
            if vehicle_capacity == 0:
                continue
            if man == vehicle_index:
                mans[idx] += 1
                vehicle_capacity -= 1
    time += 1

Submission status: Time Limit Exceeded

Solution code:
# ABC123
cnd = list(map(int, [input().rstrip() for _ in range(6)]))
n = cnd[0]
arr = [n] + [0] * 6
ans = 0
while arr[5] != n:
    for i in range(5, 0, -1):
        if arr[i - 1] == 0:
            continue
        move = min(arr[i - 1], cnd[i])
        arr[i] += move
        arr[i - 1] -= move
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
NUM_CITY = 6

def is_finish(state):
    return sum(state[:-1]) == 0

def solve():
    N = int(raw_input())
    A = int(raw_input())
    B = int(raw_input())
    C = int(raw_input())
    D = int(raw_input())
    E = int(raw_input())
    state = [0] * NUM_CITY
    state[0] = N
    cnt = 0
    while not is_finish(state):
        cnt += 1
        f1to2 = min(state[0], A)
        f2to3 = min(state[1], B)
        f3to4 = min(state[2], C)
        f4to5 = min(state[3], D)
        f5to6 = min(state[4], E)
        state[0] -= f1to2
        state[1] = state[1] + f1to2 - f2to3
        state[2] = state[2] + f2to3 - f3to4
        state[3] = state[3] + f3to4 - f4to5
        state[4] = state[4] + f4to5 - f5to6
        state[5] += f5to6
    print cnt

if __name__ == '__main__':
    solve()