#!python # -*- coding: utf-8 -*- N = int(input()) S = input() R = 0 L = 0 for i, c in enumerate(S): if c == '(': L += len(S) - i else: R += len(S) - i if S[0] == '(': print(R * 2) if S[0] == ')': print(L * 2)