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:
from collections import deque

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

c1 = list(0 for i in range(N))
c2 = deque()
c3 = deque()
c4 = deque()
c5 = deque()
c6 = deque()

counter = 0
def transfer(start, end, capacity):
    for i in range(capacity):
        if len(start) != 0:
            end.append(start.pop())
        else:
            break

while len(c6) != N:
    counter += 1
    transfer(c5, c6, E)
    transfer(c4, c5, D)
    transfer(c3, c4, C)
    transfer(c2, c3, B)
    transfer(c1, c2, A)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

c1 = deque(list(0 for i in range(N)))
c2 = deque()
c3 = deque()
c4 = deque()
c5 = deque()
c6 = deque()

counter = 0
def transfer(start, end, capacity):
    for i in range(capacity):
        if len(start) != 0:
            end.append(start.pop())
        else:
            break

while len(c6) != N:
    counter += 1
    transfer(c5, c6, E)
    transfer(c4, c5, D)
    transfer(c3, c4, C)
    transfer(c2, c3, B)
    transfer(c1, c2, A)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

c1 = deque(list(0 for i in range(N)))
c2 = deque()
c3 = deque()
c4 = deque()
c5 = deque()
c6 = deque()

counter = 0
def transfer(start, end, capacity):
    for i in range(capacity):
        if len(start) != 0:
            end.append(start.pop())
            
while len(c6) != N:
    counter += 1
    transfer(c5, c6, E)
    transfer(c4, c5, D)
    transfer(c3, c4, C)
    transfer(c2, c3, B)
    transfer(c1, c2, A)
print(counter)

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())

a = N
b = 0
c = 0
d = 0
e = 0


for i in range(N+5):
  if e != 0:
    if e > E :
      e = e-E
    else:
      e = e-e

  if d != 0:
    if d > D:
      e = e + D
      d = d - D
    else : 
      e = e + d
      d = d - d
    
  if c != 0:
    if c > C:
      d = d + C
      c = c- C
    else:
      d = d + c
      c = c - c
  
  if b != 0:
    if b > B:
      c = c + B
      b = b - B
    else :
      c = c + b
      b = b - b
      
  if a != 0:
    if a > A:
      b = b + A
      a = a - A
    else :
      b = b + a
      a = a - a
    
  if a == 0 and b == 0 and c == 0 and d == 0 and e == 0:
    break

print(i+1)

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())

l = list([n, 0, 0, 0, 0, 0])
count=0
while l[5] < n:
   d_5 = e if l[4] > e else l[4]
   l[5] += d_5
   l[4] -= d_5
   d_4 = d if l[3] > d else l[3]
   l[4] += d_4
   l[3] -= d_4
   d_3 = c if l[2] > c else l[2]
   l[3] += d_3
   l[2] -= d_3
   d_2 = b if l[1] > b else l[1]
   l[2] += d_2
   l[1] -= d_2
   d_1 = a if l[0] > a else l[0]
   l[1] += d_1
   l[0] -= d_1
   count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import permutations 
from time import sleep


def solve(nums):
    num_person, *caps = nums
    caps = caps + [0]
    #  (人数, 乗り物のキャパシティ) のタプルの配列
    cities = list(zip([num_person] + ([0] * (len(caps) - 1)), caps))
    time = 0

    # 最後の都市に全員が移動したら終了
    while cities[-1][0] < num_person:
        mov_nums = [min(*city) for i, city in enumerate(cities) if i < len(cities) - 1]
        for i, mov_num in enumerate(mov_nums):
            city = cities[i]
            next_city = cities[i + 1]
            cities[i] = (city[0] - mov_num, city[1])
            cities[i + 1] = (next_city[0] + mov_num, next_city[1])
        time = time + 1
    return time


def main():
    nums = [int(l) for l in stdin.readlines()]
    ans = solve(nums)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from itertools import permutations 
from time import sleep


def solve(nums):
    num_person, *caps = nums
    caps = caps + [0]
    #  (人数, 乗り物のキャパシティ) のタプルの配列
    cities = list(zip([num_person] + ([0] * (len(caps) - 1)), caps))
    time = 0

    # 最後の都市に全員が移動したら終了
    while cities[-1][0] < num_person:
        mov_nums = [min(*city) for city in cities[:-1]]
        for i, mov_num in enumerate(mov_nums):
            city = cities[i]
            next_city = cities[i + 1]
            cities[i] = (city[0] - mov_num, city[1])
            cities[i + 1] = (next_city[0] + mov_num, next_city[1])
        time = time + 1
    return time


def main():
    nums = [int(l) for l in stdin.readlines()]
    ans = solve(nums)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())

A, B, C, D, E = [int(input()) for i in range(5)]
Xs = [N, 0, 0, 0, 0, 0]
Fs = [A, B, C, D, E]
Fmin = min(Fs)
c = 0
while True:
    #print(Xs)
    nXs = copy.copy(Xs)
    for i in range(len(Fs)):
        if Xs[i] - Fs[i] > 0:
            nXs[i] -= Fs[i]
            nXs[i+1] += Fs[i]
        else:
            nXs[i] -= Xs[i]
            nXs[i+1] += Xs[i]
        #print(nXs)
    Xs = nXs
    c+=1
    if max(Xs[1:5]) == Fmin:
        c+=Xs[0]//Fmin
        Xs[0]%=Fmin
    if sum(Xs[0:5]) == 0:
        break

print(c)

Submission status: Time Limit Exceeded

Solution code:
import copy
N = int(input())

A, B, C, D, E = [int(input()) for i in range(5)]
Xs = [N, 0, 0, 0, 0, 0]
Fs = [A, B, C, D, E]
Fmin = min(Fs)
c = 0
while True:
    #print(Xs)
    nXs = copy.copy(Xs)
    for i in range(len(Fs)):
        if Xs[i] - Fs[i] > 0:
            nXs[i] -= Fs[i]
            nXs[i+1] += Fs[i]
        else:
            nXs[i] -= Xs[i]
            nXs[i+1] += Xs[i]
        #print(nXs)
    Xs = nXs
    c+=1
    if Xs[1:5] == [Fmin, Fmin, Fmin, Fmin]:
        c+=Xs[0]//Fmin
        Xs[0]%=Fmin
    if sum(Xs[0:5]) == 0:
        break

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())                                                                                                                                             
CN = 6                                                                                                                                                       
                                                                                                                                                             
TC = [0] * (CN-1)                                                                                                                                            
for i in range(CN-1):                                                                                                                                        
    TC[i] = int(input())                                                                                                                                     
                                                                                                                                                             
C = [0] * CN                                                                                                                                                 
C[0] = N                                                                                                                                                     
                                                                                                                                                             
time = 0                                                                                                                                                     
                                                                                                                                                             
while C[-1] < N:                                                                                                                                             
    time = time + 1                                                                                                                                          
    for i in range(CN-2,-1,-1):                                                                                                                              
        mc = min(C[i], TC[i])                                                                                                                                
        C[i] = C[i] - mc                                                                                                                                     
        C[i+1] = C[i+1] + mc                                                                                                                                 
                                                                                                                                                             
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())

a = [N, 0, 0, 0, 0, 0]
min = 0
while a[5] != N:
    if a[4] >= E:
        a[4] -= E
        a[5] += E
    elif a[4] > 0:
        a[5] += a[4]
        a[4] = 0

    if a[3] >= D:
        a[3] -= D
        a[4] += D
    elif a[3] > 0:
        a[4] += a[3]
        a[3] = 0

    if a[2] >= C:
        a[2] -= C
        a[3] += C
    elif a[2] > 0:
        a[3] += a[2]
        a[2] = 0

    if a[1] >= B:
        a[1] -= B
        a[2] += B
    elif a[1] > 0:
        a[2] += a[1]
        a[1] = 0

    if a[0] >= A:
        a[0] -= A
        a[1] += A
    elif a[0] > 0:
        a[1] += a[0]
        a[0] = 0

    min += 1

print(min)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

#各都市に行くためのコスト
lift = [int(input()) for i in range(5)]
#各都市にいる人数
city = [0] * 6
city[0] = N

ans = 0
target = []

while 1:
    if city[5] == N:
        break
    for i in range(0,5):
        #今回の操作で動かすもの一覧を作る（i-1に値があるものだけ動かす)
        if city[i] != 0:
            target.append(i+1)
    for i in reversed(target):
        if city[i-1] >= lift[i-1]:
            city[i] += lift[i-1]
            city[i - 1] -= lift[i-1]
        else:
            city[i] += city[i-1]
            city[i-1] = 0
    target = []
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
nn = int(input())
cap_list = list(range(5))
for ii in range(5):
    cap_list[ii] = int(input())
people_in_city = [nn, 0, 0, 0, 0, 0]
time = 0

while people_in_city[5] < nn:
    train = min(cap_list[0], people_in_city[0])
    bus = min(cap_list[1], people_in_city[1])
    taxi = min(cap_list[2], people_in_city[2])
    airplane = min(cap_list[3], people_in_city[3])
    ship = min(cap_list[4], people_in_city[4])
    
    people_in_city[0] += -train
    people_in_city[1] += train - bus
    people_in_city[2] += bus - taxi
    people_in_city[3] += taxi - airplane
    people_in_city[4] += airplane - ship
    people_in_city[5] += ship
    
    time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
state = [n, 0, 0, 0, 0, 0]
capacities = list(reversed([int(input()) for _ in range(5)]))
t = 0
while state[5]!=n:
    for idx, capa in enumerate(capacities):
        passengers = capa if capa <= state[4-idx] else state[4-idx]
        if passengers != 0:
            state[4-idx] -= passengers
            state[5-idx] += passengers
    t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
def move_people(city, nums_city_people, nums_transportation_seat):
    if nums_city_people[city] - nums_transportation_seat[city] >= 0:
        nums_city_people[city] -= nums_transportation_seat[city]
        nums_city_people[city+1] += nums_transportation_seat[city]
    else:
        nums_city_people[city+1] += nums_city_people[city]
        nums_city_people[city] = 0


NUM_CITIES = 6
NUM_TRANSPORTATION = 5

nums_city_people = [int(input())] + [0] * (NUM_CITIES-1)
nums_people_having_moved = list(reversed(nums_city_people))
nums_transportation_seat = [int(input()) for i in range(NUM_TRANSPORTATION)]
result = 0

while nums_city_people != nums_people_having_moved:
    result += 1
    for city in reversed(range(NUM_CITIES-1)):
        move_people(city, nums_city_people, nums_transportation_seat)

print(result)

Submission status: Time Limit Exceeded

Solution code:
def main():
  t = 0
  N = int(input())
  caps = []
  nums = [N, 0, 0, 0, 0, 0]
  for i in range(5):
    caps.append(int(input()))

  while nums[-1] != N:
    for i in range(5, 0, -1):
      n = min(caps[i - 1], nums[i - 1])
      nums[i - 1] -= n
      nums[i] += n
    t += 1
  print(t)


if __name__ == "__main__":
  main()

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())
Group = [N, 0, 0, 0, 0, 0]
X = [0] * 6
Y = [0] * 6
Method = [A, B, C, D, E]
T = 0
while Group[len(Method)] < N:
    for i in range(len(Method)):
        if Group[i]<=Method[i]:
            X[i+1] = Group[i]
            X[i] = 0
        else:
            X[i+1] = Method[i]
            X[i] = Group[i] - Method[i]
        Y[i] = Y[i] + X[i]
        Y[i+1] = Y[i+1] + X[i+1]
        X[i] = 0
        X[i+1] = 0
    Group[0] = Y[0]
    Group[1] = Y[1]
    Group[2] = Y[2]
    Group[3] = Y[3]
    Group[4] = Y[4]
    Group[5] = Group[5] + Y[5]
    Y = [0] * 6
    T += 1
print(T)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
X = [int(input()) for _ in range(5)]
a = [0] * 6
a[0] = N
t = 0
while True:
  for i in range(5):
    a[5-i] += min(X[4-i], a[4-i])
    a[4-i] = max(0, a[4-i]-X[4-i])
  t += 1
  if a[5] == N:
    break
print(t)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
c = [n, 0, 0, 0, 0]
a = []
for i in range(5):
  a.append(int(input()))
cnt = 0
sub = [0] * 5
add = [0] * 5
add_n =[0] * 6
while True:
  for i in range(5):
    c[i] = c[i] + add[i] - sub[i]
    if c[i] > a[i]:
      sub[i] = a[i]
      add_n[i+1] = a[i]
    else:
      sub[i] = c[i]
      add_n[i+1] = c[i]
  add = copy.copy(add_n)
  cnt += 1
  if sum(c) == 0:
    print(cnt-1)
    break

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

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

place = np.zeros(6)
place[0] = N
cnt = 0
while(True):
  cnt += 1
  place[5] += min(A[4], place[4])
  place[4] += min(A[3], place[3]) - min(A[4], place[4])
  place[3] += min(A[2], place[2]) - min(A[3], place[3])
  place[2] += min(A[1], place[1]) - min(A[2], place[2])
  place[1] += min(A[0], place[0]) - min(A[1], place[1])
  place[0] -= min(A[0], place[0])
  if int(place[5]) == N:
    break
    
ans = cnt  
print(ans)

Submission status: Time Limit Exceeded

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

#print ("N:",N)
#print ("cities:",cities)

ans = 0

people = [N,0,0,0,0,0]
latest = 0

# maybe O(N)

while True:
	if (people[-1] == N):
		break
	else:
		for i in reversed(range(len(cities))):
			tmp = people[i]
			people[i] = max(0, people[i] - cities[i])
			people[i+1] += tmp - people[i]


	ans += 1

print (ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
time=[]
for i in range(5):
  time.append(int(input()))
population=[n,0,0,0,0,0]
delay=0
while population[5]<n:
  temp=population[:]
  for i in range(5):
    trans=min(population[i],time[i])
    temp[i]-=trans
    temp[i+1]+=trans
  population=temp[:]
  delay+=1
print(delay)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
tran = [int(input()) for i in range(5)]
number = [N if i == 0 else 0 for i in range (6)]
count = 0

while number[5] != N:
    for i in range (5, 0, -1):
        if number[i-1] >= tran [i-1]:
            number[i-1] -= tran[i-1]
            number[i] += tran[i-1]
        else:
            number[i] += number[i-1]
            number[i-1] = 0
    count += 1

print (count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
cyapa = []
for i in range (1,6):
    cyapa.append(int(input()))
city1 = N
city2 = 0
city3 = 0
city4 = 0
city5 = 0
city6 = 0
mi = 0
while city6 < N:
    city6 = city6 + min(city5,cyapa[4])
    city5 = city5 + min(city4,cyapa[3]) - min(city5,cyapa[4])
    city4 = city4 + min(city3,cyapa[2]) - min(city4,cyapa[3])
    city3 = city3 + min(city2,cyapa[1]) - min(city3,cyapa[2])
    city2 = city2 + min(city1,cyapa[0]) - min(city2,cyapa[1])
    city1 = city1 - min(city1,cyapa[0])
    mi = mi + 1
print(mi)

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())
lst = [n] + [0] * 5
#print ('0', lst)
i = 0
tmp0 = 0

lst[0] != 0
tmp0 = min(lst[0], a)
lst[0] -= tmp0
lst[1] += tmp0
#print ('1', lst)

lst[1] != 0
tmp0 = min(lst[1], b)
lst[1] -= tmp0
lst[2] += tmp0
lst[0] != 0
tmp0 = min(lst[0], a)
lst[0] -= tmp0
lst[1] += tmp0
#print ('2', lst)

lst[2] != 0
tmp0 = min(lst[2], c)
lst[2] -= tmp0
lst[3] += tmp0
lst[1] != 0
tmp0 = min(lst[1], b)
lst[1] -= tmp0
lst[2] += tmp0
lst[0] != 0
tmp0 = min(lst[0], a)
lst[0] -= tmp0
lst[1] += tmp0
#print ('3', lst)

lst[3] != 0
tmp0 = min(lst[3], d)
lst[3] -= tmp0
lst[4] += tmp0
lst[2] != 0
tmp0 = min(lst[2], c)
lst[2] -= tmp0
lst[3] += tmp0
lst[1] != 0
tmp0 = min(lst[1], b)
lst[1] -= tmp0
lst[2] += tmp0
lst[0] != 0
tmp0 = min(lst[0], a)
lst[0] -= tmp0
lst[1] += tmp0
#print ('4', lst)

lst[4] != 0
tmp0 = min(lst[4], e)
lst[4] -= tmp0
lst[5] += tmp0
lst[3] != 0
tmp0 = min(lst[3], d)
lst[3] -= tmp0
lst[4] += tmp0
lst[2] != 0
tmp0 = min(lst[2], c)
lst[2] -= tmp0
lst[3] += tmp0
lst[1] != 0
tmp0 = min(lst[1], b)
lst[1] -= tmp0
lst[2] += tmp0
lst[0] != 0
tmp0 = min(lst[0], a)
lst[0] -= tmp0
lst[1] += tmp0
#print ('5', lst)

while i < (n + 4):
    if lst == [0, 0, 0, 0, 0, n]:
        print (i + 5)
        break
    else:
        i +=1
    if lst[4] != 0:
        tmp0 = min(lst[4], e)
        lst[4] -= tmp0
        lst[5] += tmp0
    if lst[3] != 0:
        tmp0 = min(lst[3], d)
        lst[3] -= tmp0
        lst[4] += tmp0
    if lst[2] != 0:
        tmp0 = min(lst[2], c)
        lst[2] -= tmp0
        lst[3] += tmp0
    if lst[1] != 0:
        tmp0 = min(lst[1], b)
        lst[1] -= tmp0
        lst[2] += tmp0
    if lst[0] != 0:
        tmp0 = min(lst[0], a)
        lst[0] -= tmp0
        lst[1] += tmp0
#    print (lst)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def move(max_num,before):
  return min(max_num,before)

people = [n,0,0,0,0,0]
max_nums = []
for i in range(5):
  max_nums.append(int(input()))

time = 0
while True:
#for j in range(10):
  time += 1
  move_p = [0] * 6
  for i in range(5):
    move_p[i] -= min(max_nums[i],people[i])
    move_p[i+1] += min(max_nums[i],people[i])
  people = list(map(sum,zip(people,move_p)))
  #print(people)
  if people[-1] == n:
    break

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def move(max_num,before):
  return min(max_num,before)

people = [n,0,0,0,0,0]
max_nums = []
for i in range(5):
  max_nums.append(int(input()))

time = 0
while True:
  time += 1
  move_p = [0] * 6
  for i in range(5):
    move_p[i] -= min(max_nums[i],people[i])
    move_p[i+1] += min(max_nums[i],people[i])
  people += move_p
  if people[-1] == n:
    break

print(time)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
def move(max_num,before):
  return min(max_num,before)

people = [n,0,0,0,0,0]
max_nums = []
for i in range(5):
  max_nums.append(int(input()))

time = 0
while True:
  time += 1
  move_p = [0] * 6
  for i in range(5):
    move_p[i] -= min(max_nums[i],people[i])
    move_p[i+1] += min(max_nums[i],people[i])
  people += move_p
  if people[-1] == n:
    break

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())

L = [0]*5
L[0] = N
count = 0
while sum(L) != 0:
    if L[4] != 0:
        tmp0 = min(L[4],E)
        L[4] -= tmp0
    if L[3] != 0:
        tmp0 = min(L[3],D)
        L[3] -= tmp0
        L[4] += tmp0
    if L[2] != 0:
        tmp0 = min(L[2],C)
        L[2] -= tmp0
        L[3] += tmp0
    if L[1] != 0:
        tmp0 = min(L[1],B)
        L[1] -= tmp0
        L[2] += tmp0
    if L[0] != 0:
        tmp0 = min(L[0],A)
        L[0] -= tmp0
        L[1] += tmp0
    count += 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())
stay_a=N
stay_b=0
stay_c=0
stay_d=0
stay_e=0
stay_f=0
for i in range(100000000000000):
  delta_a=min(stay_a,A)
  stay_a=stay_a-delta_a
  delta_b=min(stay_b,B)
  stay_b=stay_b-delta_b
  delta_c=min(stay_c,C)
  stay_c=stay_c-delta_c
  delta_d=min(stay_d,D)
  stay_d=stay_d-delta_d
  delta_e=min(stay_e,E)
  stay_e=stay_e-delta_e
  stay_b+=delta_a
  stay_c+=delta_b
  stay_d+=delta_c
  stay_e+=delta_d
  stay_f+=delta_e
  if stay_f==N:
    break
print(1+i)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

lst = []
pos = [0,0,0,0,0]

for i in range(5):
    lst.append(i)

pos[0] = num
while (pos[0] + pos[1] + pos[2] + pos[3]) != 0:
    if pos[0] != 0:
        if pos[0] >= lst[0]:
            pos[1] += lst[0]
        else:
            pos[1] += pos[0]
    
    if pos[1] != 0:
        if pos[1] >= lst[1]:
            pos[2] += lst[1]
        else:
            pos[2] += pos[1]
    
    if pos[2] != 0:
        if pos[2] >= lst[2]:
            pos[3] += lst[2]
        else:
            pos[3] += pos[2]

    if pos[3] != 0:
        if pos[3] >= lst[3]:
            pos[4] += lst[3]
        else:
            pos[4] += pos[3]
    
print(pos,lst)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc123
# -*- coding: utf-8 -*-

n=int(input())
v = [int(input()) for i in range(5)]
city = [ n, 0, 0, 0, 0, 0]

counter = 0
while city[5] is not n:
    counter += 1

    for i in range(5)[::-1]:
        if city[i] >= v[i]:
            city[i+1] += v[i]
            city[i] -= v[i]
        else:
            city[i+1] += city[i]
            city[i] = 0

print(counter)

Submission status: Time Limit Exceeded

Solution code:
# _*_ coding: utf-8 _*_

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

t = 0
bounds = [a, b, c, d, e]
nums = [n, 0, 0, 0, 0, 0]

while(nums[5] < n): # not all people have arrived at the destination
    for i in range(6):
        come = min(nums[i-1], bounds[i-1]) if i != 0 else 0
        go = min(nums[i], bounds[i]) if i != 5 else 0
        nums[i] = max(nums[i] + come - go, 0)

    t += 1

print(t)

Submission status: Time Limit Exceeded

Solution code:
numberOfToorists = int(input())

residents = [0,0,0,0,0,0]

transportCapacity = [0,0,0,0,0]
migrants = [0,0,0,0,0]

elapsedTime = 0

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

residents[0] = numberOfToorists

while residents[5] < numberOfToorists:
	for i in range(5):
		if residents[i] >= transportCapacity[i]:
			migrants[i] = transportCapacity[i]
		else:
			migrants[i] = residents[i]

	for i in range(5):
		residents[i] -= migrants[i]
		residents[i+1] += migrants[i]

	elapsedTime += 1

print(elapsedTime)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
if __name__ =="__main__":
    N = input()
    status = np.array([float(N), 0, 0, 0, 0])
    cap = np.zeros(5)
    for x in range(5):
        a = input()
        cap[x]=int(a)
    time=0
    move=np.zeros(5)
    while(True):
        pre_move = 0
        for x in range(4):
            move[x+1] = min(cap[x],status[x])
        status -= cap
        status=np.where(status<0,0,status)
        status+=move
        time+=1
        if sum(status)==0:
            break
    print(time)

Submission status: Time Limit Exceeded

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

# 移動者の状態
transferee = [N] + [0 for _ in range(5)]

# 毎ターンできる限りの人を次の都市に輸送
time = 0 # 現在時刻
while transferee[-1] != N:
    for i in range(0, 5)[::-1]:
        if transferee[i] - abcde[i] >= 0:
            transferee[i+1] += abcde[i]
            transferee[i] -= abcde[i]
        else:
            transferee[i+1] += transferee[i]
            transferee[i] = 0

    time += 1

print(time)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import copy

# 整数の入力
n = int(input())

ninzu = []

for inpcnt in range(5):
    ninzu.append(int(input()))

toshi = [n,0,0,0,0,0]
next_toshi = copy.deepcopy(toshi)
time = 0

while toshi[5] != n:
    # print("toshi[0]:{},[1]:{},[2]:{},[3]:{},[4]:{},[5]:{}".format(toshi[0],toshi[1],toshi[2],toshi[3],toshi[4],toshi[5]))
    time += 1
    for i in range(len(toshi)-1):
        if toshi[i] != 0:
            if toshi[i] > ninzu[i]:
                next_toshi[i] = next_toshi[i] - ninzu[i]
                next_toshi[i+1] = toshi[i+1]  + ninzu[i]
            else:
                next_toshi[i] = next_toshi[i] - toshi[i]
                next_toshi[i+1] = toshi[i+1] + toshi[i] 
        # print("toshi[{}]:{},toshi[{}]:{}".format(i,next_toshi[i],i+1,next_toshi[i+1]))
    toshi = copy.deepcopy(next_toshi)
    # print("next_toshi[0]:{},[1]:{},[2]:{},[3]:{},[4]:{},[5]:{}".format(next_toshi[0],next_toshi[1],next_toshi[2],next_toshi[3],next_toshi[4],next_toshi[5]))
        
print(str(time))

Submission status: Time Limit Exceeded

Solution code:
n, *l = [int(input()) for _ in range(6)]
city = [n, 0, 0, 0, 0, 0]
ans=0
while True:
    if city[5] == n:
        print(ans)
        break
    _city = [0]*6
    for i in range(5):
        _city[i+1] += min(l[i], city[i])
        _city[i] += city[i]-min(l[i], city[i])
    _city[5] += city[5]
    city = _city.copy()
    ans += 1

Submission status: Time Limit Exceeded

Solution code:
class city:
    
    def __init__(self, initial_population):
        self.population = initial_population
    
    def move_to(self, destination, number):
        if self.population > number:
            destination.population += number
            self.population -= number
        else:
            destination.population += self.population
            self.population = 0

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

city_1 = city(N)
city_2 = city(0)
city_3 = city(0)
city_4 = city(0)
city_5 = city(0)
city_6 = city(0)

time = 0
while city_6.population != N: 
    if time >= 4 : city_5.move_to(city_6, E)
    if time >= 3 : city_4.move_to(city_5, D)
    if time >= 2 : city_3.move_to(city_4, C)
    if time >= 1 : city_2.move_to(city_3, B)
    city_1.move_to(city_2, A)
    time += 1
    """
    print('at time = ' + str(time))
    print(city_1.population)
    print(city_2.population)
    print(city_3.population)
    print(city_4.population)
    print(city_5.population)
    print(city_6.population)
    """

print(time)

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())

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

now = [N, 0, 0, 0, 0, 0]

ans = 0

while now[5] != N:
	for i in reversed(range(5)):
		if now[i] > 0:
			if now[i] >= cap[i]:
				now[i] -= cap[i]
				now[i+1] += cap[i]
			elif now[i] < cap[i]:
				now[i+1] += now[i]
				now[i] = 0

	ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b,c,d,e=[int(input())for _ in range(6)]
t,T1,T2,T3,T4,T5,T6=0,n,0,0,0,0,0
while T6<n:
    t+=1
    T6=min(e,T5)+T6
    T5=min(d,T4)+T5-min(e,T5)
    T4=min(c,T3)+T4-min(d,T4)
    T3=min(b,T2)+T3-min(c,T3)
    T2=min(a,T1)+T2-min(b,T2)
    T1=T1-min(a,T1)
print(t)

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())

member = [A, B, C, D, E]
people = [N, 0, 0, 0, 0, 0]
count = 0
while people[5] < N:
    for i in reversed(range(5)):
        if people[i] >= member[i]:
            people[i+1] += member[i]
            people[i] -= member[i]
        elif people[i] > 0:
            people[i+1] += people[i]
            people[i] = 0
    count += 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())

groups = [N, 0, 0, 0, 0, 0]
capacities = [A, B, C, D, E]

def getNewPeople(oldGroups, newGroups, capacities, idx):
	if oldGroups[idx + 0] < capacities[idx]:
		newGroups[idx + 1] += oldGroups[idx + 0]
	else:
		newGroups[idx + 0] += oldGroups[idx + 0] - capacities[idx]
		newGroups[idx + 1] += capacities[idx]
	return newGroups

day = 0
while groups[5] != N:
	day += 1
	
	oldGroups = groups
	newGroups = [0, 0, 0, 0, 0, 0]
	for idx in range(0,5):
		newGroups = getNewPeople(oldGroups, newGroups, capacities, idx)
	newGroups[5] += oldGroups[5]
	
	groups = newGroups
	
	if groups[5] == N:
		print(day)
		break