input()
l = [int(x) if x not in "()" else x for x in input().split()]
M = 10**9 + 7

while True:
    o = True
    for i in range(len(l)):
        if l[i] == ")":
            break
        elif l[i] == "(":
            o = not o
    else:
        break

    for j in range(i-1, -1, -1):
        if l[j] == "(":
            break

    if o:
        new = sum(l[j+1:i])
    else:
        new = 1
        for el in l[j+1:i]:
            new *= el

    l = l[:j] + [new % M] + l[i+1:]

print(sum(l) % M)
