N = int(eval(input()))

A = list(map(int,input().split()))

m = 1000

s = 0

flag = 0

a = A[0]

for i in range(N):

    if A[i]>a and flag==0:

        n = m//a

        s += n

        m -= n*a

        flag = 1

    elif A[i]<a and flag==1:

        m += s*a

        s = 0

        flag = 0

    a = A[i]

if flag==1:

    m += s*A[-1]

print(m)
N = int(eval(input()))

A = list(map(int,input().split()))

x = 1000

cnt = 0

flag = 0

for i in range(1,N):

    if flag==0 and A[i]-A[i-1]>0:

        cnt += x//A[i-1]

        x = x%A[i-1]

        flag = 1

    elif flag==0 and A[i]-A[i-1]<0:

        x += cnt*A[i-1]

        cnt = 0

        flag = -1

    elif flag==1 and A[i]-A[i-1]<0:

        x += cnt*A[i-1]

        cnt = 0

        flag = -1

    elif flag==-1 and A[i]-A[i-1]>0:

        cnt += x//A[i-1]

        x = x%A[i-1]

        flag = 1

if flag==1:

    x += cnt*A[N-1]

    cnt = 0

print(x)
N = int(eval(input()))
A = list(map(int, input().split()))
m = 1000
s = 0
flag = 0
a = A[0]
for i in range(N):
    if A[i] > a and flag == 0:
        n = m // a
        s += n
        m -= n * a
        flag = 1
    elif A[i] < a and flag == 1:
        m += s * a
        s = 0
        flag = 0
    a = A[i]
if flag == 1:
    m += s * A[-1]
print(m)

N = int(eval(input()))
A = list(map(int, input().split()))
x = 1000
cnt = 0
flag = 0
for i in range(1, N):
    if flag == 0 and A[i] - A[i - 1] > 0:
        cnt += x // A[i - 1]
        x = x % A[i - 1]
        flag = 1
    elif flag == 0 and A[i] - A[i - 1] < 0:
        x += cnt * A[i - 1]
        cnt = 0
        flag = -1
    elif flag == 1 and A[i] - A[i - 1] < 0:
        x += cnt * A[i - 1]
        cnt = 0
        flag = -1
    elif flag == -1 and A[i] - A[i - 1] > 0:
        cnt += x // A[i - 1]
        x = x % A[i - 1]
        flag = 1
if flag == 1:
    x += cnt * A[N - 1]
    cnt = 0
print(x)

-m = 1000 -s = 0 +x = 1000 +cnt = 0 -a = A[0] -for i in range(N): -    if A[i] > a and flag == 0: -        n = m // a -        s += n -        m -= n * a +for i in range(1, N): +    if flag == 0 and A[i] - A[i - 1] > 0: +        cnt += x // A[i - 1] +        x = x % A[i - 1] -    elif A[i] < a and flag == 1: -        m += s * a -        s = 0 -        flag = 0 -    a = A[i] +    elif flag == 0 and A[i] - A[i - 1] < 0: +        x += cnt * A[i - 1] +        cnt = 0 +        flag = -1 +    elif flag == 1 and A[i] - A[i - 1] < 0: +        x += cnt * A[i - 1] +        cnt = 0 +        flag = -1 +    elif flag == -1 and A[i] - A[i - 1] > 0: +        cnt += x // A[i - 1] +        x = x % A[i - 1] +        flag = 1 -    m += s * A[-1] -print(m) +    x += cnt * A[N - 1] +    cnt = 0 +print(x)