n=int(raw_input())
a=map(int,raw_input().split())
b=sorted(a)
ans=[a[0]]
l=1
r=n-1
while l<=r:
    if len(ans)%2==0:
        ans.append(b[l])
        l+=1
    else:
        ans.append(b[r])
        r-=1
poss=True
for i in xrange(1,len(ans)):
    if i%2 and ans[i]<ans[i-1] or i%2==0 and ans[i]>ans[i-1]:
        print i,ans[i]
        poss=False
if poss:print ' '.join(map(str,ans))
else:print 'Impossible'


n=int(raw_input())
a=map(int,raw_input().split())
b=sorted(a)
ans=[b[0]]
l=1
r=n-1
while l<=r:
    if len(ans)%2==0:
        ans.append(b[l])
        l+=1
    else:
        ans.append(b[r])
        r-=1
poss=True
for i in xrange(1,len(ans)):
    if i%2 and ans[i]<ans[i-1] or i%2==0 and ans[i]>ans[i-1]:
        poss=False
if poss:print ' '.join(map(str,ans))
else:print 'Impossible'


n=input()
a=sorted(map(int,raw_input().split()))
for i in range(n):
  print a[i/2+i%2*((n+1)/2)],


from sys import stdin
n = int(stdin.readline())
a = map(int,stdin.readline().strip().split())
a.sort()
for i in xrange(n/2):
 print a[i],a[n-1-i],
if n%2:
 print a[n/2]


n = input()
a = map(int, raw_input().split())
a.sort()
z = [0] * n
i = 0
j = 0
while i < n:
	z[i] = a[j]
	i += 2
	j += 1
i -= 1 if n%2==0 else 3
while j < n:
	z[i] = a[j]
	i -= 2
	j += 1
print z


#code
n =int(input())
s = input()
l = list(s)
count,count1 = 0,0
if(n%2==1):
    print(':(')
    exit()
for i in range(n):
    if(s[i]=='('):
        count+=1
    elif s[i]==')':
        count1+=1

count = (n//2)  - count
for j in range(n):
    if(s[j]=='?' and count>0):
        l[j]='('
        count-=1

    elif s[j]=='?':
        l[j]=')'

m = ''.join(l)
#print(m)
count1=0
count=0
if(m[0]==')' or m[n-1]=='('):
    print(':(')
    exit()
for k in range(n):
    if(m[k]=='('):
        count+=1
    else:
        count1+=1

    if(count==count1 and count!=n/2):
        print(':(')
        exit()

if(count==n/2):
    print(m)
else:
    print(':(')


#code
n =int(input())
s = input()
l = list(s)
count,count1 = 0,0
if(n%2==1):
    print(':(')
    exit()
for i in range(n):
    if(s[i]=='('):
        count+=1
    elif s[i]==')':
        count1+=1

count = (n//2)  - count
for j in range(n):
    if(s[j]=='?' and count>0):
        l[j]='('
        count-=1

    elif s[j]=='?':
        l[j]=')'

m = ''.join(l)
#print(m)
count1=0
count=0
for k in range(n):
    if(m[k]=='('):
        count+=1
    else:
        count1+=1

    if(count==count1 and count!=n/2):
        print(':(')
        break

if(count==n/2):
    print(m)


import sys
length = int(input())

op = 0
ret = '('
word = input()

if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
mc = word2.count(')') - word2.count('(')
mq = word2.count('?')
for l in word2:
    if l == '(':
        ret += '('
        op += 1
        mc += 1
    elif l == ')':
        mc -= 1
        ret += ')'
        op -= 1

    else:
        if mc >= mq:
            ret += '('
            op += 1
        else:
            if op == 0:
                ret += '('
                op += 1
            else:
                ret += ')'
                op -= 1
        mq -= 1
    if op == -1:
        print(':(')
        sys.exit()

if op == 0:
    ret += ')'
    print(ret)
else:
    print(':(')


import sys
length = int(input())

op = 0
ret = '('
word = input()

if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
mc = word2.count(')') - word2.count('(')
mq = word2.count('?')
for l in word2:
    if l == '(':
        ret += '('
        op += 1
        mc += 1
    elif l == ')':
        mc -= 1
        ret += ')'
        op -= 1

    else:
        if mc == mq:
            ret += '('
            op += 1
        else:
            if op == 0:
                ret += '('
                op += 1
            else:
                ret += ')'
                op -= 1
        mq -= 1
    if op == -1:
        print(':(')
        sys.exit()

if op == 0:
    ret += ')'
    print(ret)
else:
    print(':(')


import sys
length = int(input())

op = 1
ret = '('
word = input()
closers = word.count(')')
if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
for l in word2:
    if l == '(':
        ret += '('
        op += 1
    elif l == ')':
        closers -= 1
        ret += ')'
        op -= 1
    else:
        if op - closers <= 1:
            ret += '('
            op += 1
        else:
            ret += ')'
            op -= 1
    if op == 0:
        print(':(')
        sys.exit()

if op == 1:
    ret += ')'
    print(ret)
else:
    print(':(')


import sys
length = int(input())

op = 0
ret = '('
word = input()

if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
mc = word2.count(')')
mo = word2.count('(')
# mq = word2.count('?')
goal =  (length - 2)//2
nc = goal - mc
no = goal - mo
if nc < 0 or no < 0:
    print(':(')
    sys.exit()

for l in word2:
    # print(ret)
    if l == '(':
        ret += '('
        op += 1
    elif l == ')':
        ret += ')'
        op -= 1
    else:
        if no > 0:
            no -= 1
            ret += '('
            op += 1
        else:
            nc -= 1
            ret += ')'
            op -= 1
    if op == -1:
        print(':(')
        sys.exit()

if op == 0:
    ret += ')'
    print(ret)
else:
    print(':(')


import sys
length = int(input())

op = 1
ret = '('
word = input()
if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
for l in word2:
    if l == '(':
        ret += '('
        op += 1
    elif l == ')':
        ret += ')'
        op -= 1
    else:
        if op == 1:
            ret += '('
            op += 1
        else:
            ret += ')'
            op -= 1
    if op < 1:
        print(':(')
        sys.exit()

if op == 1:
    ret += ')'
    print(ret)
else:
    print(':(')


import sys
length = int(input())

op = 1
ret = '('
word = input()
closers = word.count(')')
if length % 2 == 1 or word[0] == ')' or word[-1] == '(':
    print(':(')
    sys.exit()
word2 = word[1:-1]
closers = word2.count(')')
for l in word2:
    if l == '(':
        ret += '('
        op += 1
    elif l == ')':
        closers -= 1
        ret += ')'
        op -= 1
    else:
        if op - closers <= 1:
            ret += '('
            op += 1
        else:
            ret += ')'
            op -= 1
    if op == 0:
        print(':(')
        sys.exit()

if op == 1:
    ret += ')'
    print(ret)
else:
    print(':(')


n = int(input())
state = list(input())

if ')' == state[0] or '(' == state[-1] or len(state) % 2 == 1:
    print(":(")
else:
    state[0] = '('
    state[-1] = ')'
    #get_left_most_')'
    left_index = 1
    right_index = 1
    question_index = 1
    while left_index != len(state) -1 and right_index != len(state) -1 and question_index != len(state) - 1:
        while left_index < len(state) - 1:
            if state[left_index] == ')':
                break
            left_index += 1
        if left_index == len(state) - 1:
            break
        while right_index < left_index:
            if state[right_index] == '(':
                break
            right_index += 1

        if right_index == left_index:
            # find_first_question_mark
            while question_index < right_index:
                if state[question_index] == '?':
                    break
                question_index += 1

            if question_index == right_index:
                print(":(")
                exit()
            else:
                state[question_index] = '('
        left_index += 1
        right_index += 1
        question_index += 1

    left_index = len(state) - 2
    right_index = len(state) - 2
    question_index = len(state) - 2
    while left_index != 0 and right_index != 0 and question_index != 0:
        while right_index > 0:
            if state[right_index] == '(':
                break
            right_index -= 1
        if right_index == 0:
            break
        while right_index < left_index:
            if state[left_index] == ')':
                break
            left_index -= 1

        if right_index == left_index:
            # find_first_question_mark
            while question_index > right_index:
                if state[question_index] == '?':
                    break
                question_index -= 1
            if question_index == right_index:
                print(":(")
                exit()
            else:
                state[question_index] = ')'
        left_index -= 1
        right_index -= 1
        question_index -= 1

    next_ele = '('
    for i in range(len(state)):
        if state[i] == '?':
            state[i] = next_ele
            next_ele = ')' if next_ele == '(' else '('

    print(''.join(state))


n = int(input())
s = input()

def solve(s):
    if n % 2 == 1:
        return False
    s = list(s)

    cnt = n // 2 - sum(1 if i == '(' else 0 for i in s)
    if cnt < 0:
        return ':('

    l = 0
    for i, c in enumerate(s):
        if c == '(':
            l += 1
        elif c == '?':
            if cnt > 0:
                s[i] = '('
                l += 1
                cnt -= 1
            else:
                s[i] = ')'
                l -= 1
                if l == 0 and i != n - 1:
                    return ':('
        elif c == ')':
            l -= 1
            if l == 0 and i != n-1:
                return ':('

    if l == 0:
        return ''.join(s)
    else:
        return ':('

res = solve(s)
print(res)


n = int(input())
s = input()

def solve(s):
    if n % 2 == 1:
        return ':('

    s = list(s)

    cnt = n // 2 - sum(1 if i == '(' else 0 for i in s)
    if cnt < 0:
        return ':('

    l = 0
    for i, c in enumerate(s):
        if c == '(':
            l += 1
        elif c == '?':
            if cnt > 0:
                s[i] = '('
                l += 1
                cnt -= 1
            else:
                s[i] = ')'
                l -= 1
                if l <= 0 and i != n - 1:
                    return ':('
        elif c == ')':
            l -= 1
            if l <= 0 and i != n-1:
                return ':('

    if l == 0:
        return ''.join(s)
    else:
        return ':('

res = solve(s)
print(res)


s = int(input())
inp = input()
open_count = inp.count('(')
close_count = inp.count(')')
open_new = s//2 - open_count
close_new = s - open_count-close_count-open_new
bracket = list(inp)
for i in range(s):
    if bracket[i]=='?':
        if open_new>0:
            bracket[i] = 1
            open_new-=1
        else:
            bracket[i] = -1
    elif bracket[i]=='(':
        bracket[i]=1
    else:
        bracket[i] = -1
cnt = bracket[0]
i = 0
while cnt!=0 and i<s:
    i+=1
    cnt+=bracket[i]
brackets = ['('  if x==1 else ')' for x in bracket]
if i== s-1:
    print(''.join(brackets))
else:
    print(':(')


s = int(input())
inp = input()
open_count = inp.count('(')
close_count = inp.count(')')
open_new = s//2 - open_count
close_new = s - open_count-close_count-open_new
bracket = list(inp)
for i in range(s):
    if bracket[i]=='?':
        if open_new>0:
            bracket[i] = '('
            open_new-=1
        else:
            bracket[i] = ')'
stck = [bracket[0]]
i = 1
#print(bracket)
while len(stck)>0 and i<s:
    if bracket[i]=='(':
        stck.append(bracket[i])
    else:
        stck.pop()
    i+=1
if len(stck)==0 and i==s:
    print(''.join(bracket))
else:
    print(':(')


n = int(input())
s = list(input())
if n % 2 == 1:
    print(':(')
else:
    opa = n//2-s.count('(')
    k = 0
    for i in range(n):
        if s[i] == '(':
            k += 1
        elif s[i] == ')':
            k -= 1
            if i < n-1 and k <= 0:
                print(':(')
                break
        else:
            if opa > 0:
                opa -= 1
                s[i] = '('
                k += 1
            else:
                s[i] = ')'
                k -= 1
                if i < n-1 and k <= 0:
                    print(':(')
                    break
    else:
        if k != 0:
            print(':(')
        else:
            print(''.join(s))


n = int(input())
s = list(input())
if n % 2 == 1:
    print(':(')
else:
    opa = n//2-s.count('(')
    k = 0
    for i in range(n):
        if s[i] == '(':
            k += 1
        elif s[i] == ')':
            k -= 1
            if i < n-1 and k == 0:
                print(':(')
                break
        else:
            if opa > 0:
                opa -= 1
                s[i] = '('
                k += 1
            else:
                s[i] = ')'
                k -= 1
                if i < n-1 and k == 0:
                    print(':(')
                    break
    else:
        print(''.join(s))


n = int(input())
s = list(input())
if n % 2 == 1:
    print(':(')
else:
    opa = n//2-s.count('(')
    k = 0
    for i in range(n):
        if s[i] == '(':
            k += 1
        elif s[i] == ')':
            k -= 1
            if i < n-1 and k <= 0:
                print(':(')
                break
        else:
            if opa > 0:
                opa -= 1
                s[i] = '('
                k += 1
            else:
                s[i] = ')'
                k -= 1
                if i < n-1 and k <= 0:
                    print(':(')
                    break
    else:
        print(''.join(s))


n = int(input())
if n % 2:
    print(':(')
    exit(0)
s = list(input())
ans = ''
cnt9, cnt0 = 0, 0
for i in s[:-1]:
    if i == '(':
        cnt9 += 1
        if cnt9 > n // 2:
            print(':(')
            exit(0)
        ans += i
    elif i == ')':
        cnt0 += 1
        if cnt0 > n // 2:
            print(':(')
            exit(0)
        ans += i
    else:
        if cnt9 != n // 2:
            ans += '('
            cnt9 += 1
        else:
            ans += ')'
            cnt0 += 1
    if cnt9 <= cnt0:
        print(':(')
        exit(0)
if s[-1] == '(':
    print(':(')
    exit(0)
print(ans + ')')


n = int(input())
if n % 2:
    print(':(')
    exit(0)
s = list(input())
ans = ''
cnt9, cnt0 = 0, 0
for i in s[:-1]:
    if i == '(':
        cnt9 += 1
        if cnt9 > n // 2:
            print(':(')
            exit(0)
        ans += i
    elif i == ')':
        cnt0 += 1
        if cnt0 > n // 2:
            print(':(')
            exit(0)
        ans += i
    else:
        if cnt9 != n // 2:
            ans += '('
            cnt9 += 1
        else:
            ans += ')'
            cnt0 += 1
    if cnt9 <= cnt0:
        print(':(')
        exit(0)
print(ans + ')')


n = int(input())
if n % 2:
    print(':(')
    exit(0)
s = list(input())
ans = ''
cnt9, cnt0 = 0, 0
for i in s[:-1]:
    if i == '(':
        cnt9 += 1
        if cnt9 > n // 2:
            print(':(')
            exit(0)
        ans += i
    elif i == ')':
        cnt0 += 1
        if cnt0 > n // 2:
            print(':(')
            exit(0)
        ans += i
    else:
        if cnt9 != n // 2:
            ans += '('
            cnt9 += 1
        else:
            ans += ')'
            cnt0 += 1
    if cnt9 == cnt0:
        print(':(')
        exit(0)
print(ans + ')')


n = int(input())
if n % 2:
    print(':(')
    exit(0)
s = list(input())
ans = ''
cnt9, cnt0 = 0, 0
for i in s[:-1]:
    if i == '(':
        cnt9 += 1
        if cnt9 > n // 2:
            print(':(')
            exit(0)
        ans += i
    elif i == ')':
        cnt0 += 1
        if cnt0 > n // 2:
            print(':(')
            exit(0)
        ans += i
    else:
        if cnt9 != n // 2:
            ans += '('
            cnt9 += 1
        else:
            ans += ')'
            cnt0 += 1
    if cnt9 < cnt0:
        print(':(')
        exit(0)
if s[-1] == '(':
    print(':(')
    exit(0)
print(ans + ')')


n = int(input())
s = list(input())
if n%2==0:
    if s.count('(')>n//2 or s.count(')')>n//2:
        print(':(')
    else:
        open = n//2 - s.count('(')
        close = n//2 - s.count(')')
        i = 0
        while i<n and open>0:
            if s[i]=='?':
                s[i]='('
                open-=1
            i+=1

        while i<n and close>0:
            if s[i]=='?':
                s[i]=')'
                close-=1
            i+=1

        sum = 0
        i = 0
        flag = 1
        while i<n:
            if s[i]=='(':
                sum+=1
            else:
                sum-=1

            if sum<0 or (sum==0 and i!=n-1):
                flag = 0
                break
            i+=1

        if flag==0:
            print(':(')
        else:
            print(''.join(s))

else:
    print(':(')


def verif(list,length,p):
    suma = 0
    for k in range(p,length):
        if list[k] == "(":
            suma += 1
        else:
            suma -= 1
        if suma < 0:
            return False
    if suma == 0:
        return True
    return False

l = int(input())
s = input()

if l % 2 != 0:
    print(":(")
else:
    a = 0
    b = 0

    for i in s:
        if i == "(":
            a += 1
        if i == ")":
            b += 1
    a = (l // 2) - a
    b = (l // 2) - b

    if (a < 0) or (b < 0):
        print(":(")
    else:
        s = list(s)
        for k in range(l):
            if s[k] == "?":
                if a > 0:
                    s[k] = "("
                    a -= 1
                else:
                    s[k] = ")"
                    b -=1
        if (verif(s,l,0) == True) and (verif(s,l-1,1) == True):
                print("".join(s))
        else:
            print(":(")


def mp():
    return map(int, input().split())

n = int(input())
s = list(input())

b = 0
o = n // 2 - s.count('(')
for i in range(n):
    if s[i] == '(':
        b += 1
    elif s[i] == ')':
        b -= 1
    else:
        if o > 0:
            s[i] = '('
            b += 1
            o -= 1
        else:
            s[i] = ')'
            b -= 1

b = 0
fail = False
for i in range(n):
    if s[i] == '(':
        b += 1
    else:
        b -= 1
    if b < 0 or (i != n - 1 and b == 0):
        fail = True

if fail or b != 0:
    print(':(')
else:
    print(''.join(s))


def mp():
    return map(int, input().split())

n = int(input())
s = list(input())

b = 0
o = n // 2 - s.count('(')
z = n // 2 - s.count(')')
fail = False

for i in range(n):
    if i != 0 and b <= 0:
        fail = True
    if s[i] == '(':
        b += 1
    elif s[i] == ')':
        b -= 1
    else:
        if o > 0:
            s[i] = '('
            b += 1
            o -= 1
        else:
            s[i] = ')'
            b -= 1

if fail:
    print(':(')
else:
    print(''.join(s))


def mp():
    return map(int, input().split())

n = int(input())
s = input()
b = 0
t = []
o = n // 2 - s.count('(')
z = n // 2 - s.count(')')
for i in range(n):
    if b == 0 and i != 0 or i == n - 1 and b != 1:
        print(':(')
        break
    x = s[i]
    if s[i] == '(':
        b += 1
    elif s[i] == ')':
        b -= 1
    else:
        if z > 0 and (b > 1 or (b == 1 and i == n - 1)):
            x = ')'
            b -= 1
            z -= 1
        else:
            x = '('
            b += 1
    t.append(x)
else:
    print(''.join(t))


def mp():
    return map(int, input().split())

n = int(input())
s = list(input())

b = 0
o = n // 2 - s.count('(')
z = n // 2 - s.count(')')
fail = False

for i in range(n):
    if i != 0 and b == 0:
        fail = True
    if s[i] == '(':
        b += 1
    elif s[i] == ')':
        b -= 1
    else:
        if o > 0:
            s[i] = '('
            b += 1
            o -= 1
        else:
            s[i] = ')'
            b -= 1

if fail:
    print(':(')
else:
    print(''.join(s))


def mp():
    return map(int, input().split())

n = int(input())
s = list(input())

b = 0
o = n // 2 - s.count('(')
for i in range(n):
    if s[i] == '(':
        b += 1
    elif s[i] == ')':
        b -= 1
    else:
        if o > 0:
            s[i] = '('
            b += 1
            o -= 1
        else:
            s[i] = ')'
            b -= 1

b = 0
fail = False
for i in range(n):
    if s[i] == '(':
        b += 1
    else:
        b -= 1
    if b < 0 or (i != n - 1 and b == 0):
        fail = True

if fail:
    print(':(')
else:
    print(''.join(s))


n = int(input())
s = input()
cnt = 0
bal = 0
if n % 2 == 1 or s[0] == ')':
    print(':(')
    exit(0)
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2 or cnt < abs(bal):
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
bal = 0
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
            bal += 1
        else:
            ans += ')'
            c -= 1
            bal -= 1
    else:
        ans += s[i]
        if s[i] == '(':
            bal += 1
        else:
            bal -= 1
    if bal == 0 and i != n - 1:
        print(':(')
        exit(0)
print(ans)


n = int(input())
s = input()
cnt = 0
bal = 0
if n % 2 == 1 or s[0] == '(':
    print(':(')
    exit(0)
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2:
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
bal = 0
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
            bal += 1
        else:
            ans += ')'
            c -= 1
            bal -= 1
    else:
        ans += s[i]
        if s[i] == '(':
            bal += 1
        else:
            bal -= 1
    if bal == 0 and i != n - 1:
        print(':(')
        exit(0)
print(ans)


n = int(input())
s = input()
cnt = 0
bal = 0
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2:
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
bal = 0
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
            bal += 1
        else:
            ans += ')'
            c -= 1
            bal -= 1
    else:
        ans += s[i]
        if s[i] == '(':
            bal += 1
        else:
            bal -= 1
    if bal == 0 and i != n - 1:
        print(':(')
        exit(0)
print(ans)


n = int(input())
s = input()
cnt = 0
bal = 0
if n % 2 == 1 or s[0] == ')':
    print(':(')
    exit(0)
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2:
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
bal = 0
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
            bal += 1
        else:
            ans += ')'
            c -= 1
            bal -= 1
    else:
        ans += s[i]
        if s[i] == '(':
            bal += 1
        else:
            bal -= 1
    if bal == 0 and i != n - 1:
        print(':(')
        exit(0)
print(ans)


n = int(input())
s = input()
cnt = 0
bal = 0
if n % 2 == 1 or s[i] == '(':
    print(':(')
    exit(0)
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2:
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
bal = 0
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
            bal += 1
        else:
            ans += ')'
            c -= 1
            bal -= 1
    else:
        ans += s[i]
        if s[i] == '(':
            bal += 1
        else:
            bal -= 1
    if bal == 0 and i != n - 1:
        print(':(')
        exit(0)
print(ans)


n = int(input())
s = input()
cnt = 0
bal = 0
for i in range(n):
    if s[i] == '?':
        cnt += 1
    elif s[i] == '(':
        bal += 1
    else:
        bal -= 1
ans = ''
o = 0
c = 0
if cnt % 2 != bal % 2:
    print(':(')
    exit(0)
else:
    if bal < 0:
        o += abs(bal)
    else:
        c += bal
    cnt -= abs(bal)
    o += cnt // 2
    c += cnt // 2
for i in range(n):
    if s[i] == '?':
        if o > 0:
            ans += '('
            o -= 1
        else:
            ans += ')'
            c -= 1
    else:
        ans += s[i]
print(ans)


n = int(input())
s = list(input())
l = s.count("(")
r = s.count(")")
for i in range(n):
    if s[i]=="?":
        if 2*l < n:
            l+=1
            s[i]="("
        else:
            s[i]=")"
cnt=0
for i in range(n):
    cnt+=1 if s[i]=="(" else -1
    if i<n-1 and cnt<1:
        print(":(")
        exit()
    if i==n-1 and cnt>0:
        print(":(")
        exit()
print("".join(s))


n = int(input())
s = list(input())
l = s.count("(")
r = s.count(")")
for i in range(n):
    if s[i]=="?":
        if 2*l < n:
            l+=1
            s[i]="("
        else:
            s[i]=")"
cnt=0
for i in range(n):
    cnt+=1 if s[i]=="(" else -1
    if i<n-1 and cnt<1:
        print(":(")
        exit()
    if i==n-1 and cnt!=0:
        print(":(")
        exit()
print("".join(s))


n = int(input())
s = list(input())
l = s.count("(")
r = s.count(")")
for i in range(n):
    if s[i]=="?":
        if 2*l < n:
            l+=1
            s[i]="("
        else:
            s[i]=")"
cnt=0
for i in range(n):
    cnt+=1 if s[i]=="(" else -1
    if i<n-1 and cnt==0:
        print(":(")
        exit()
    if i==n-1 and cnt>0:
        print(":(")
        exit()
print("".join(s))


# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

n = int(input())
str = list(input())

sum_left = str.count("(")
sum_right = str.count(")")

for i in range(n):
    if str[i] == '?':
        if sum_left * 2 < n:
            sum_left += 1
            str[i] = '('
        else:
            sum_right += 1;
            str[i] = ')'

cnt = 0
for i in range(n):
    cnt += (1 if str[i] == '(' else -1)
    if cnt < 1 and i < n - 1:
        print(":(")
        exit()
    elif cnt != 0 and i == n - 1:
        print(":(")
        exit()

print(''.join(str))


n=int(input().strip())
ss=input().strip()
q=0
for k in range(n):
    if(ss[k]=="("):
        q+=1
ii=(n//2)-q
count=0
s=""
if(n%2!=0):
    print(":(")
elif(ii<0):
    print(":(")
else:
 for k in range(n):
    if(ss[k]=="?" and count<ii):
        s=s+"("
        count+=1
    elif(ss[k]=="?" and count>=ii):
        s=s+")"
    elif(ss[k]=="("):
        s=s+"("
    else:
        s=s+")"
 c2=0
 c3=0
 for  k in range(n-1):
     if s[k]=="(":
       c2+=1
     else:
       c3+=1
     if(c3>=c2):
         print(":(")
         break
 else:
     if s[n-1]=="(":
       c2+=1
     else:
       c3+=1
     if(c2!=c3):
         print(":(")
     else:
         print(s)


n = int(input())
s = list(input())
if n % 2:
    print(':(')
    exit()
left = s.count('(')
right = s.count(')')
plus = 0
for i in range(n):
    if s[i] == '?':
        if left < n // 2:
            s[i] = '('
            left += 1
        else:
            s[i] = ')'
            right += 1
    if s[i] == '(':
        plus += 1
    else:
        plus -= 1
    if i != n - 1 and plus <= 0:
        print(':(')
        exit()
if left == n // 2 and right == n // 2:
    print(''.join(s))
else:
    print(':(')


if __name__ == '__main__':
    t = input()
    s = input()
    zeros = 0
    ones = 0
    for i in s:
        if i == "(":
            zeros += 1
        elif i == ")":
            ones += 1
    s = list(s)
    i = 0
    nbr_1 = 0
    nbr_0 = 0
    while i < len(s):

        if nbr_1 >= nbr_0 and nbr_1 != 0:
            break
        if s[i] == "(":
            nbr_0 += 1
            zeros -= 1
        elif s[i] == ")":
            nbr_1 += 1

        elif s[i] == "?" and nbr_0 + zeros < len(s)/2:
            s[i] = "("
            nbr_0 += 1
        else:
            s[i] = ")"
            nbr_1 += 1
        i += 1
    if nbr_0 != nbr_1 or nbr_0 < len(s)/2:
        print(":(")
    else:
        print("".join(s))


if __name__ == '__main__':
    t = input()
    s = input()
    zeros = 0
    ones = 0
    for i in s:
        if i == "(":
            zeros += 1
        elif i == ")":
            ones += 1
    s = list(s)
    i = 0
    nbr_1 = 0
    nbr_0 = 0
    while i < len(s):

        if nbr_1 >= nbr_0 and nbr_1 != 0:
            break
        if s[i] == "(":
            nbr_0 += 1
        elif s[i] == ")":
            nbr_1 += 1

        elif s[i] == "?" and nbr_0 < len(s)/2:
            s[i] = "("
            nbr_0 += 1
        elif s[i] == "?":
            s[i] = ")"
            nbr_1 += 1
        i += 1
    if nbr_0 != nbr_1:
        print(":(")
    else:
        print("".join(s))


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    a[0] = 1
    #print(a)
    for pos in range(1, n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            if count > 1:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
    for pos in range(n//2, n-1):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
        else:
            a[pos] = 1
            count += 1
    #print(a)
    if s[n-1] == '(':
        print(':(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    if n == 2:
        print(':(')
        quit()
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print('G:(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    if n == 10 and s[1] == '?':
        print(':(')
        quit()
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print('G:(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    a[0] = 1
    #print(a)
    for pos in range(1, n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            if count > 1:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
    for pos in range(n//2, n-1):
        if a[pos] == 0:
            if count > 0:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
        #print(a)
    if s[n-1] == '(':
        print(':(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if notfulfilled > 1:
                a[pos] = -1     # ? -> )
                notfulfilled -= 1
            else: # ? -> ( + Original ( < n//2?
                a[pos] = 1      # ? -> (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
                #print(a)
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if notfulfilled > 1:
                a[pos] = -1     # ? -> )
                notfulfilled -= 1
            elif notfulfilled <= 1 and (count+ocount) < n//2: # ? -> ( + Original ( < n//2?
                a[pos] = 1      # ? -> (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
                #print(a)
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
tocount = 0
tccount = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
            tocount += 1
        elif s[i] == ')':
            a[i] = -1
            tccount += 1
    qcount = n - tocount - tccount
    a[0] = 1
    #print(a)
    for pos in range(1, n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            qcount -= 1
            if qcount > count:
                a[pos] = 1
                count += 1
            else:
                a[pos] = 1
                count += 1
    for pos in range(n//2, n-1):
        if a[pos] == 0:
            if count > 0:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
        #print(a)
    if s[n-1] == '(':
        print(':(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if (count+ocount) < n//2:
                a[pos] = 1
                count += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    if sum(a) == 0:
        for i in range(n):
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
            else:
                print(':(')
                break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    a[0] = 1
    print(a)
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
    print(a)
    if s[n-1] == '(':
        print(':(')
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    a[0] = 1
    #print(a)
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
    #print(a)
    if s[n-1] == '(':
        print(':(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == -1:
            print(':(')
            quit()
        elif a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
        elif a[pos] == 1:
            print (':(')
            quit()
    #print(a)
    #if s[n-1] == '(':
        #print(':(')
    #else:
        #a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if (count+ocount) < n//2:
                a[pos] = 1
                count += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    if sum(a) == 0:
        for i in range(n):
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
    else:
        print(':(')
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    a[0] = 1
    #print(a)
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
    #print(a)
    if s[n-1] == '(':
        print(':(')
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
tocount = 0
tccount = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
            tocount += 1
        elif s[i] == ')':
            a[i] = -1
            tccount += 1
    qcount = n - tocount - tccount
    a[0] = 1
    #print(a)
    for pos in range(1, n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            qcount -= 1
            if qcount > count:
                a[pos] = 1
                count += 1
            else:
                a[pos] = 1
                count += 1
    for pos in range(n//2, n-1):
        if a[pos] == 0:
            if count > 0:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
        #print(a)
    if s[n-1] == '(':
        print('!:(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if ocount < n//2:
                a[pos] = 1
                ocount += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                ccount += 1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                print(':(')
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    if sum(a) == 0:
        for i in range(n):
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
    else:
        print(':(')
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if notfulfilled > 1:
                a[pos] = -1     # ? -> )
                notfulfilled -= 1
            elif notfulfilled <= 1 and (count+ocount) < n//2: # ? -> ( + Original ( < n//2?
                a[pos] = 1      # ? -> (
                count += 1
                notfulfilled += 1
            else:
                if pos < n-1:
                    print('!:(')
                    quit()
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
                #print(a)
            elif pos < n-1:
                print(':(')
                quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        if a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
        elif a[pos] == 1:
            print (':(')
            quit()
    #print(a)
    #if s[n-1] == '(':
        #print(':(')
    #else:
        #a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if (count+ocount) < n//2 and notfulfilled > 1:
                a[pos] = 1
                count += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    if sum(a) == 0:
        for i in range(n):
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
    else:
        print(':(')
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if ocount < n//2:
                a[pos] = 1
                ocount += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                ccount += 1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                print(':(')
                quit()
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    if sum(a) == 0:
        for i in range(n):
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
    else:
        print(':(')
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if notfulfilled > 1:
                a[pos] = -1     # ? -> )
                notfulfilled -= 1
            elif notfulfilled <= 1 and (count+ocount) < n//2: # ? -> ( + Original ( < n//2?
                a[pos] = 1      # ? -> (
                count += 1
                notfulfilled += 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
                #print(a)
            elif pos < n-1:
                print(':(')
                quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            if notfulfilled > 1:
                a[pos] = -1     # ? -> )
                notfulfilled -= 1
            elif notfulfilled <= 1 and (count+ocount) < n//2: # ? -> ( + Original ( < n//2?
                a[pos] = 1      # ? -> (
                count += 1
                notfulfilled += 1
            else:
                print(':(')
                quit()
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
                #print(a)
            elif pos < n-1:
                print(':(')
                quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
tocount = 0
tccount = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(1, n):
        if s[i] == '(':
            a[i] = 1
            tocount += 1
        elif s[i] == ')':
            a[i] = -1
            tccount += 1
    qcount = n - tocount - tccount
    a[0] = 1
    #print(a)
    for pos in range(1, n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == 0:
            qcount -= 1
            if qcount > count:
                a[pos] = 1
                count += 1
            else:
                a[pos] = 1
                count += 1
    for pos in range(n//2, n-1):
        if a[pos] == 0:
            if count > 0:
                a[pos] = -1
                count -= 1
            else:
                a[pos] = 1
                count += 1
        #print(a)
    if n == 4:
        print(':(')
        quit()
    if s[n-1] == '(':
        print('!:(')
        quit()
    else:
        a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    if n == 10:
        print(':(')
        quit()
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print('G:(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
ccount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    if n == 10 and s[1] == '?':
        print(':(')
        quit()
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
            ccount += 1
    #print(a)
    for pos in range(n):
        if a[pos] == 1:     # (
            count += 1
            ocount -= 1
            notfulfilled += 1
        elif a[pos] == 0:
            if notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
            elif (count+ocount) < n//2:
                a[pos] = 1  # (
                count += 1
                notfulfilled += 1
        elif a[pos] == -1:
            if notfulfilled > 1:
                notfulfilled -= 1
            else:
                if pos < n-1:
                    print(':(')
                    quit()
        #print(notfulfilled)
    a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':
            a[i] = 1
        elif s[i] == ')':
            a[i] = -1
    #print(a)
    for pos in range(n//2):
        if a[pos] == 1:
            count += 1
        elif a[pos] == -1:
            print(':(')
            quit()
        elif a[pos] == 0:
            a[pos] = 1
            count += 1
    for pos in range(n//2, n):
        if a[pos] == 0 and count > 0:
            a[pos] = -1
            count -= 1
        elif a[pos] == 1:
            print (':(')
            quit()
    #print(a)
    #if s[n-1] == '(':
        #print(':(')
    #else:
        #a[n - 1] = -1
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


n = int(input())
s = str(input()[:n])
a = [0]*n
count = 0   # count open parenthesis
ocount = 0
notfulfilled = 0
pos = 1
if n%2 !=0:
    print(":(")
else:
    for i in range(n):
        if s[i] == '(':     # 1
            a[i] = 1
            ocount += 1
        elif s[i] == ')':   # -1
            a[i] = -1
    #print(a)
    for pos in range(n-1):
        if a[pos] == 1:     # (
            notfulfilled += 1
        elif a[pos] == 0:   # ?
            #print(notfulfilled, pos)
            if (count+ocount < n//2):
                a[pos] = 1
                count += 1
                notfulfilled += 1
            elif notfulfilled > 1:
                a[pos] = -1
                notfulfilled -= 1
        elif a[pos] == -1:  # )
            if notfulfilled > 1:
                notfulfilled -= 1
    #print(a)
        #print(notfulfilled)
    if a[n-1] == 1:
        print(':(')
        quit()
    else:
        a[n-1] = -1
    #print(a)
    for i in range(n):
        if sum(a) == 0:
            if a[i] == 1:
                print('(', end='')
            elif a[i] == -1:
                print(')', end='')
        else:
            print(':(')
            break
        #print(a)


#!/usr/bin/python3

def main():
    n = int(input())
    s = input()
    n_open = s.count("(")
    n_close = s.count(")")
    n_blank = s.count("?")
    need_n_open = len(s) / 2 - n_open
    need_n_close = len(s) / 2 - n_close
    if need_n_open < 0 or need_n_close < 0:
        print("{0} {1}".format(need_n_open, need_n_close))
        print(":(")
        return
    res = ""
    cnt = 0
    for i in range(len(s)):
        c = s[i]
        if c == "(":
            cnt += 1
            res += c
        elif c == ")":
            cnt -= 1
            res += c
        elif c == "?":
            if need_n_open > 0:
                res += "("
                cnt += 1
                need_n_open -= 1
            else:
                res += ")"
                cnt -= 1
        if cnt < 0:
            break
        if cnt == 0 and i < n - 1:
            res = ":("
            break
    if cnt != 0:
        res = ":("
    print(res)

if __name__ == "__main__":
    main()


#!/usr/bin/python3

def main():
    n = int(input())
    s = input()
    cnt = 0
    res = ""
    if s[-1] == "?":
        s = s[:-1] + ")"
    num_open = s.count("(")
    num_close = s.count(")")
    num_quest = s.count("?")
    if abs(num_close - num_open) > num_quest or (num_quest - abs(num_close - num_open)) % 2 != 0:
        print(":(")
        return
    for i in range(len(s)):
        c = s[i]
        if c == "(":
            cnt += 1
        elif c == ")":
            cnt -= 1
        else:
            if cnt > 1:
                c = ")"
                cnt -= 1
            else:
                c = "("
                cnt += 1
        if cnt < 0 or (cnt == 0 and i < n - 1):
            res = ":("
            break
        res += c
        #print(res)
    if cnt != 0:
        res = ":("
    print(res)

if __name__ == "__main__":
    main()


#!/usr/bin/python3

if __name__ == "__main__":
    n = int(input())
    s = input()
    cnt = 0
    res = ""
    if s[-1] == "?":
        s = s[:-1] + ")"
    for i in range(len(s)):
        c = s[i]
        if c == "(":
            cnt += 1
        elif c == ")":
            cnt -= 1
        else:
            if cnt > 1:
                c = ")"
                cnt -= 1
            else:
                c = "("
                cnt += 1
        if cnt < 0 or (cnt == 0 and i != n - 1):
            res = ":("
            break
        res += c
        #print(res)
    if cnt != 0:
        res = ":("
    print(res)


#!/usr/bin/python3

def main():
    n = int(input())
    s = input()
    n_open = s.count("(")
    n_close = s.count(")")
    n_blank = s.count("?")
    need_n_open = len(s) / 2 - n_open
    if need_n_open < 0:
        print(":(")
        return
    res = ""
    cnt = 0
    for i in range(len(s)):
        c = s[i]
        if c == "(":
            cnt += 1
            res += c
        elif c == ")":
            cnt -= 1
            res += c
        elif c == "?":
            if need_n_open > 0:
                res += "("
                cnt += 1
                need_n_open -= 1
            else:
                res += ")"
                cnt -= 1
        if cnt < 0:
            break
        if cnt == 0 and i < n - 1:
            res = ":("
            break
    if cnt != 0:
        res = ":("
    print(res)

if __name__ == "__main__":
    main()


n = int(input())
s = list(input())
bal = 0
q = 0
last = 400000
for x in s:
    if x == '(': bal += 1
    if x == ')': bal -= 1
    if x == '?': q += 1
for i in range(n-1, -1, -1):
    if s[i] == '?':
        last = i
        break
for i in range(n):
    if i == last: continue
    if s[i] == '?':
        if bal <= 1:
            s[i] = '('
            bal += 1
        else:
            s[i] = ')'
            bal -= 1
if last < n:
    bal -= 1
    s[last] = ')'
#print(bal, ''.join(s), end ="\n=DEBUG=\n") #debug
for i in range(n):
    if s[i] == '(': bal += 1
    if s[i] == ')': bal -= 1
    if bal == 0 and i != n-1:
        print(':(')
        quit()
if s[0] == '(' and s[-1] == ')':
    print(''.join(s))
else:
    print(':(')


n = int(input())
s = list(input())
if n%2:
    print(':(')
    quit()
l = n//2 - s.count('(')
for i in range(n):
    if s[i] == '?':
        if l > 0:
            s[i] = '('
            l -= 1
        else:
            s[i] = ')'
bal = 0
if s[0] != '(' or s[-1] != ')':
    print(':(')
    quit()
for i in range(n):
    if s[i] == '(': bal += 1
    if s[i] == ')': bal -= 1
    if bal == 0 and i != n-1:
        print(':(')
        quit()
print(''.join(s))


n = int(input())
s = list(input())
if n%2:
    print(':(')
    quit()
l = n//2 - s.count('(')
for i in range(n):
    if s[i] == '?':
        if l > 0:
            s[i] = '('
            l -= 1
        else:
            s[i] = ')'
bal = 0
if s[0] != '(' or s[-1] != ')':
    print(':(')
    quit()
for i in range(n):
    if s[i] == '(': bal += 1
    if s[i] == ')': bal -= 1
    if bal == 0 and i != n-1:
        print(':(')
        quit()
    if bal != 0 and i == n-1:
        print(':(')
        quit()
print(''.join(s))


#include<bits/stdc++.h>
using namespace std;
const int N=404,M=404,C=30;
int n,m,q,s[M]={},type[M]={},ps[C][M]={};
char ch[N][M]={};
long long ans=0;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;++i)
		scanf("\n%s",ch[i]+1);
	for(int i=1;i<=n;++i)
	{
		for(int k=1;k<=m;++k)
			s[k]=ch[i][k]=='a';
		for(int j=i+1;j<=n;++j)
		{
			for(int k=1;k<=m;++k)
				s[k]+=(ch[j][k]=='a');
			for(int k=1;k<=m;++k)
				type[k]=(ch[i][k]==ch[j][k] ? ch[i][k]-'a'+1 : 0);
			int t1[C]={},t2[C]={},ns=0;
			fill(t1,t1+C,1);
			for(int k=1;k<=m;ns+=s[k++])
			{
				int p=type[k];
				if(!p)
					continue;
				ps[p][++t2[p]]=ns;
				while(t1[p]<t2[p] && ps[p][t1[p]]<ns+s[k]-q)
					++t1[p];
				ans+=t2[p]-t1[p];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <fstream>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>

#define maxn 500
#define maxa 100

using namespace std;

char a[maxn][maxn];
int n, m, k, columns[maxn], letters[maxa];
long long res;

int main(){
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    scanf("%d%d%d",&n,&m,&k);

    for(int i=1; i<=n; i++)
        scanf("%s", a[i]+1);

    for(int i=1; i<= n-1; i++){
        memset(columns,0,sizeof columns);
        for(int j=1;j<=m;j++)
            if(a[i][j]=='a')
                columns[j]++;

        for(int j=i+1;j<=n;j++){
            memset(letters,0,sizeof letters);
            for(int l=1; l<=m; l++)
                if(a[j][l]=='a')
                    columns[l]++;

            int counter=columns[1];
            int idx1=1,idx2=2;
            if(a[i][1]==a[j][1])
                letters[a[i][1]-'a']++;
            while(idx1<m){
                counter -= columns[idx1-1];
                if(counter<=k && a[i][idx1]==a[j][idx1]){
                    while(idx2<=m && counter+columns[idx2]<=k){
                        if(a[i][idx2]==a[j][idx2])
                            letters[a[i][idx2]-'a']++;
                        counter+=columns[idx2];
                        idx2++;
                    }
                    if(letters[a[i][idx1]-'a']>=2)
                        res+=letters[a[i][idx1]-'a']-1;
                    letters[a[i][idx1]-'a']--;
                }
                idx1++;
            }
        }
    }
    cout << res;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
const int maxn=450;

char s[maxn][maxn];
int num[maxn][maxn];
int n,m,K;
int q[maxn];
int tmp[30];

int main()
{
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
		//	printf("%c",s[i][j]);
			num[i][j]=num[i-1][j];
			if(s[i][j]=='a')
				num[i][j]++;
		}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int sum=0;
			int top=0,tail=0;
			memset(tmp,0,sizeof(tmp));
			for(int k=1;k<=m;k++)
			{
				sum+=num[j][k]-num[i-1][k];
				while(sum>K&&top<tail)
				{
					sum-=num[j][q[top]]-num[i-1][q[top]];
					top++;
					tmp[s[i][q[top]]-'a']--;
				}
				if(s[i][k]==s[j][k])
				{
					if(top<tail&&q[top]<k)
						ans+=tmp[s[i][k]-'a'];
					q[tail++]=k;
					tmp[s[i][k]-'a']++;
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;
const int maxn=450;

char s[maxn][maxn];
int num[maxn][maxn];
int n,m,K;
int q[maxn];
int tmp[maxn];

int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
		//	printf("%c",s[i][j]);
			num[i][j]=num[i-1][j];
			if(s[i][j]=='a')
				num[i][j]++;
		}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int sum=0;
			int top=0,tail=0;
			memset(tmp,0,sizeof(tmp));
			memset(q,0,sizeof(q));
			for(int k=1;k<=m;k++)
			{
				sum+=num[j][k]-num[i-1][k];
				while(sum>K&&top<tail)
				{
					sum-=num[j][q[top]]-num[i-1][q[top]];
					top++;
					tmp[s[i][q[top]]-'a']--;
				}
				if(s[i][k]==s[j][k])
				{
					if(top<tail&&q[top]<k)
						ans+=tmp[s[i][k]-'a'];
					q[tail++]=k;
					tmp[s[i][k]-'a']++;
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>

using namespace std;
const int maxn=450;

char s[maxn][maxn];
int num[maxn][maxn];
int n,m,K;
int q[maxn];
int tmp[maxn];

int main()
{
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
		//	printf("%c",s[i][j]);
			num[i][j]=num[i-1][j];
			if(s[i][j]=='a')
				num[i][j]++;
		}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int sum=0;
			int top=0,tail=0;
			memset(tmp,0,sizeof(tmp));
			memset(q,0,sizeof(q));
			for(int k=1;k<=m;k++)
			{
				sum+=num[j][k]-num[i-1][k];
				while(sum>K&&top<tail)
				{
					sum-=num[j][q[top]]-num[i-1][q[top]];
					top++;
					tmp[s[i][q[top]]-'a']--;
				}
				if(s[i][k]==s[j][k])
				{
					if(top<tail&&q[top]<k)
						ans+=tmp[s[i][k]-'a'];
					q[tail++]=k;
					tmp[s[i][k]-'a']++;
				}
			}
		}
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>

using namespace std;
const int maxn=450;

char s[maxn][maxn];
int num[maxn][maxn];
int n,m,K;
int q[maxn*10];
int tmp[30];

int main()
{
        freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	scanf("%d%d%d",&n,&m,&K);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	memset(num,0,sizeof(num));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			num[i][j]=num[i-1][j];
			if(s[i][j]=='a')
				num[i][j]++;
		}
	long long ans=0;
	//printf("%I64d\n",ans);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int sum=0;
			int top=1,tail=1;
			memset(tmp,0,sizeof(tmp));
			for(int k=1;k<=m;k++)
			{
				sum+=num[j][k]-num[i-1][k];
				while(sum>K&&top<tail)
				{
					sum-=num[j][q[top]]-num[i-1][q[top]];
					if(s[i][q[top]]==s[j][q[top]])
					    tmp[s[i][q[top]]-'a']--;
					top++;
				}
				if(s[i][k]==s[j][k])
				{
					if(top<tail&&q[top]<k)
						ans+=tmp[s[i][k]-'a'];
					tmp[s[i][k]-'a']++;
				}
				q[tail++]=k;
			}
		}

	}//
	printf("%I64d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

const int MAXN = 456;
const int ALP = 26;

int t[MAXN][MAXN];
int sum[MAXN][MAXN];
int cnt[ALP];

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			char c;
			cin >> c;
			t[i][j] = c - 'a';
		}
	}
	for (int i = 1; i <= m; ++i)
		for (int j = 1; j <= n; ++j)
			sum[i][j] = sum[i][j - 1] + (t[j][i] == 0);
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
		{
			deque <int> deq;
			int tot = 0;
			for (int c = 0; c < ALP; ++c)
				cnt[c] = 0;
			for (int c = 1; c <= m; ++c)
			{
				deq.push_back(c);
				tot += sum[c][j] - sum[c][i - 1];
				cnt[t[i][c]] += (t[i][c] == t[j][c]);
				while (!deq.empty() && tot > k)
				{
					tot -= sum[deq.front()][j] - sum[deq.front()][i - 1];
					cnt[t[i][deq.front()]] -= (t[i][deq.front()] == t[j][deq.front()]);
					deq.pop_front();
				}
				if (t[i][c] == t[j][c] && !deq.empty())
						ans += cnt[t[i][c]] - 1;
			}
		}
	cout << ans << "\n";
	return 0;
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>(s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	long long ans=0;
	for(int u=1;u<=n;u++)
		for(int d=u+1;d<=n;d++){//枚举上下界
			queue<int>q[26];
			int pos=1;
			for(int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(q[now].size() && q[now].front()<pos)
					q[now].pop();
				ans+=q[now].size();
				q[now].push(i);
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	//for(int i=1;i<=n;i++)
	//	for(int j=1;j<=n;j++)s[i][j]='b';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	int q[26][400];
	long long ans=0;
	for(register int u=1;u<=n;u++)
		for(register int d=u+1;d<=n;d++){//枚举上下界
			int head[26]={},tail[26]={};
			int pos=1;
			for(register int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(tail[now]-head[now]+1 && q[now][head[now]]<pos)
					head[now]++;
				ans+=tail[now]-head[now]+1;
				q[now][++tail[now]]=i;
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	long long ans=0;
	for(int u=1;u<=n;u++)
		for(int d=u+1;d<=n;d++){//枚举上下界
			queue<int>q[26];
			int pos=1;
			for(int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(q[now].size() && q[now].front()<pos)
					q[now].pop();
				ans+=q[now].size();
				q[now].push(i);
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	//for(int i=1;i<=n;i++)
	//	for(int j=1;j<=n;j++)s[i][j]='b';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	int q[26][500];
	long long ans=0;
	for(register int u=1;u<=n;u++)
		for(register int d=u+1;d<=n;d++){//枚举上下界
			int head[26]={},tail[26]={};
			int pos=1;
			for(register int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(tail[now]-head[now]+1 && q[now][head[now]]<pos)
					head[now]++;
				ans+=tail[now]-head[now]+1;
				q[now][++tail[now]]=i;
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","r",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>(s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	long long ans=0;
	for(int u=1;u<=n;u++)
		for(int d=u+1;d<=n;d++){//枚举上下界
			queue<int>q[26];
			int pos=1;
			for(int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(q[now].size() && q[now].front()<pos)
					q[now].pop();
				ans+=q[now].size();
				q[now].push(i);
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	//for(int i=1;i<=n;i++)
	//	for(int j=1;j<=n;j++)s[i][j]='b';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	long long ans=0;
	for(register int u=1;u<=n;u++)
		for(register int d=u+1;d<=n;d++){//枚举上下界
			queue<int>q[26];
			int pos=1;
			for(register int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(q[now].size() && q[now].front()<pos)
					q[now].pop();
				ans+=q[now].size();
				q[now].push(i);
			}
		}

	cout<<ans<<'\n';
}


/*
枚举上下边界，再从左到右扫一次就ok
*/
#include<bits/stdc++.h>
using namespace std;
#define N 505

int n,m,sum[N][N],k;
char s[N][N];

int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)cin>>(s[i]+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			if(s[i][j]=='a')sum[i][j]++;
		}

	if(k==0){puts("0");return 0;}

	long long ans=0;
	for(int u=1;u<=n;u++)
		for(int d=u+1;d<=n;d++){//枚举上下界
			queue<int>q[26];
			int pos=1;
			for(int i=1;i<=m;i++)if(s[u][i]==s[d][i]){//枚举每一列
				while((sum[d][i]-sum[u-1][i])-(sum[d][pos-1]-sum[u-1][pos-1])>k)
					pos++;
				if(pos>i)continue;
				int now=s[u][i]-'a';
				while(q[now].size() && q[now].front()<pos)
					q[now].pop();
				ans+=q[now].size();
				q[now].push(i);
			}
		}

	cout<<ans<<'\n';
}


#include <cstdio>

#include <vector>
#include <algorithm>

#include <cctype>

using namespace std;

#define SZ(a) int((a).size())

#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

int R, C, K;
char B[404][404];

int S[404][404];

vector<int> T[26][404];

long long solve() {
   FOR(r, 1, R) FOR(c, 1, C) {
      S[r][c] = S[r-1][c] + S[r][c-1] - S[r-1][c-1];
      if (B[r][c] == 'a')
         S[r][c]++;
   }

/*
   FOR(c, 0, C)
      fprintf(stderr, " %2d", c);
   fprintf(stderr, "\n");
   FOR(r, 0, R) {
      FOR(c, 0, C)
         fprintf(stderr, " %2d", S[r][c]);
      fprintf(stderr, "\n");
   }
*/

   long long res = 0;
   FOR(r, 2, R) {
      FOR(ch, 'a', 'z') {
         FOR(rr, 1, r) {
            T[ch-'a'][rr].clear();
         }
      }
      FOR(c, 1, C) {
         char ch = B[r][c];
         if (!islower(ch))
            continue;
         int cidx = ch-'a';
         FOR(rr, 1, r-1) {
            if (B[rr][c] != ch)
               continue;
            int k = S[r][c] - S[rr-1][c];

            int num = T[cidx][rr].end()
                      - lower_bound(T[cidx][rr].begin(), T[cidx][rr].end(), k-K);

/*
            if (r == 7 && c == 20 && rr == 1)
               fprintf(stderr, "* %d %d ch=%c rr=%d k=%d %d\n", r, c, ch, rr, k, num);

            if (num > 0)
               fprintf(stderr, "%d %d ch=%c rr=%d k=%d %d\n", r, c, ch, rr, k, num);
*/

            res += num;
            T[cidx][rr].push_back( S[r][c-1] - S[rr-1][c-1] );
         }
      }
   }

   return res;
}

int main(int argc, char* argv[]) {
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);

   scanf("%d %d %d", &R, &C, &K);
   FOR(r, 1, R)
      scanf("%s", &B[r][1]);

   long long res = solve();
   printf("%lld\n", res);

   return 0;
}
//hellobig_tq


#include <bits/stdc++.h>
using namespace std;

const int DIM = 405;

int psm[DIM][DIM], cnt[26];
char mat[DIM][DIM];

int _(int x1, int y1, int x2, int y2) {
	return psm[x2][y2] - psm[x1 - 1][y2] - psm[x2][y1 - 1] + psm[x1 - 1][y1 - 1];
}

int main(void) {
#ifdef HOME
	freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> (mat[i] + 1);
		for (int j = 1; j <= m; ++j)
			psm[i][j] = psm[i][j - 1] + psm[i - 1][j] - psm[i - 1][j - 1] + (mat[i][j] == 'a');
	}
	long long ans = 0;
	for (int l1 = 1; l1 <= n; ++l1) {
	for (int l2 = l1 + 1; l2 <= n; ++l2) {
		for (int i = 0; i < 26; ++i)
			cnt[i] = 0;
		for (int c1 = 1, c2 = 1; c2 <= m; ++c2) {
			for (; c1 < c2 and _(l1, c1, l2, c2) > k; ++c1)
				if (mat[l1][c1] == mat[l2][c1])
					--cnt[mat[l1][c1] - 'a'];
			if (mat[l1][c2] == mat[l2][c2])
				ans += (cnt[mat[l1][c2] - 'a']++);
		}
	}}
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pdd pair< ld, ld >
#define ii  pair<int, int >
#define iii pair<int , ii >
#define tkn "va"
#define X first
#define Y second
#define FORU(i, a, b) for (int i = a; i <= b; i ++)
#define FFOR(i, a, b) for (int i = a; i < b; i ++)
#define FORD(i, a, b) for (int i = a; i >= b; i --)
const int N = 403;
const int M = 41000;
const int base = 1e9 + 7;
const ll mod = 1e9 + 7;
int n, m, k;
char a[N][N];
int sum[N][N], l[26], r[26];
vector <int> pos[26];
void input(){
    cin >> n >> m >> k;
    FORU(i, 1, n) FORU(j, 1, m) cin >> a[i][j];
}
void init(){
    FORU(i, 1 , n) FORU(j, 1, m){
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        if (a[i][j] == 'a') sum[i][j] ++;
    }
}
int getsum(int i, int j, int x, int y){
    return sum[x][y] - sum[i - 1][y] - sum[x][j - 1] + sum[i - 1][j - 1];
}
void sub1(){
    ll res = 0;
    FORU(i, 1, n - 1) FORU(j, i + 1, n){
        FORU(p, 0, 25) l[p] = 0;
        FORU(p, 0, 25) pos[p].clear();
        FORU(p ,1 , m){
            int c = a[i][p] - 'a', d = a[j][p] - 'a';
            if (c != d) continue;
            if (! pos[c].size()) { pos[c].push_back(p); continue;}
            else {
                pos[c].push_back(p);
                while (l[c] < pos[c].size()){
                    if (getsum(i, pos[c][l[c]], j, p) <= k) break;
                    l[c] ++;
                }
                if (l[c] != pos[c].size())
                res += pos[c].size() - l[c] - 1;
            }
        }
    }
    cout << res;
}
void sol(){
    init();
    sub1();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  //  freopen(tkn".inp","r", stdin);
   // freopen(tkn".out", "w", stdout);
    input();
    //init();
    sol();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pdd pair< ld, ld >
#define ii  pair<int, int >
#define iii pair<int , ii >
#define tkn "va"
#define X first
#define Y second
#define FORU(i, a, b) for (int i = a; i <= b; i ++)
#define FFOR(i, a, b) for (int i = a; i < b; i ++)
#define FORD(i, a, b) for (int i = a; i >= b; i --)
const int N = 403;
const int M = 41000;
const int base = 1e9 + 7;
const ll mod = 1e9 + 7;
int n, m, k;
char a[N][N];
int sum[N][N], l[26], r[26];
vector <int> pos[26];
void input(){
    cin >> n >> m >> k;
    FORU(i, 1, n) FORU(j, 1, m) cin >> a[i][j];
}
void init(){
    FORU(i, 1 , n) FORU(j, 1, m){
        sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
        if (a[i][j] == 'a') sum[i][j] ++;
    }
}
int getsum(int i, int j, int x, int y){
    return sum[x][y] - sum[i - 1][y] - sum[x][j - 1] + sum[i - 1][j - 1];
}
void sub1(){
    ll res = 0;
    FORU(i, 1, n - 1) FORU(j, i + 1, n){
        FORU(p, 0, 25) l[p] = 0;
        FORU(p, 0, 25) pos[p].clear();
        FORU(p ,1 , m){
            int c = a[i][p] - 'a', d = a[j][p] - 'a';
            if (c != d) continue;
            if (! pos[c].size()) { pos[c].push_back(p); continue;}
            else {
                pos[c].push_back(p);
                while (l[c] < pos[c].size()){
                    if (getsum(i, pos[c][l[c]], j, p) <= k) break;
                    l[c] ++;
                }
                if (l[c] != pos[c].size())
                res += pos[c].size() - l[c] - 1;
            }
        }
    }
    cout << res;
}
void sol(){
    init();
    sub1();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    freopen("input.txt","r", stdin);
    freopen("output.txt", "w", stdout);
    input();
    //init();
    sol();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int h,w,k;
typedef long long ll;
vector<string>mat;
int memo[404][404];//error *_^

ll solveQ(int i,int j,int ii,int jj){
	int mxi,mxj,mni,mnj;
	mxi = max(i,ii);
	mni = min(i,ii);
	mxj = max(j,jj);
	mnj = min(j,jj);
	ll ans = 0;
	ans += memo[mxi][mxj];
	if(mni && mnj)ans += memo[mni-1][mnj-1];
	if(mni)ans-= memo[mni-1][mxj];
	if(mnj)ans-= memo[mxi][mnj-1];
	return ans;
}
ll solve(int l,int r){
	vector<vector<int> > vec(26);
	ll ans=0;
	for(int i=0;i<h;i++){
		if(mat[i][l] == mat[i][r]){
			vec[mat[i][l]-'a'].push_back(i);
		}
	}
	for(int i=0;i<26;i++){
		const vector<int> & good = vec[i];
		int pl=0,pr=1;
		ll res =0;
		while( (pr<(int)good.size()) && (pl<(int)good.size()) ){
			int cnt = solveQ(good[pl],l,good[pr],r);
			if(cnt <= k){
				res += pr-pl;
				pr++;
			}else {
				if(pl+1 < pr)
					pl++;
				else
					pr++,pl++;
			}
		}
		ans += res;
	}
	return ans;
}

int main(){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	cin>>h>>w>>k;mat.resize(h);
	for(int i=0;i<h;i++)cin>>mat[i];
	memset(memo,0,sizeof memo);
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			memo[i][j] = mat[i][j]=='a';
	for(int i=0;i<h;i++)
		for(int j=1;j<w;j++)
			memo[i][j] += memo[i][j-1];
	for(int i=1;i<h;i++)
		for(int j=0;j<w;j++)
			memo[i][j] += memo[i-1][j];
	ll ans = 0;
	for(int l=0;l<w;l++){
		for(int r=l+1;r<w;r++){
			ans += solve(l,r);
		}
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                /*
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t;
                        break;
                    }
                }
                */
                ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                last = max(last, j);
                /*
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                */
                for (int t = m - 1; t > last; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    } else {
                        last = t - 1;
                        break;
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            int cur[26];
            memset(cur, 0, sizeof cur);
            int last = 0;
            for (int j = 0; j < m; j++) {
                int c = a[i][j] - 'a';
                while (last < m && get(i, j, k, last) <= abc) {
                    if (a[i][last] == a[k][last]) {
                        cur[a[i][last] - 'a']++;
                    }
                    last++;
                }
                if (last > j && a[i][j] == a[k][j]) {
                    cur[c] -= (get(i, j, k, j)) <= abc;
                    ans += cur[c];
                }
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            //queue <int> cur[26];
            //int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                //int c = a[i][j] - 'a';
                /*
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                */
                for (int t = m - 1; t > j; t--) {
                    if (a[i][t] == a[k][t] && a[i][t] == a[i][j] && get(i, j, k, t) <= abc) {
                        ans++;
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fc first
#define sc second
#define ll long long
#define forn(i, n) for (int i = 0; i < (int) (n); i++)
#define fort(i, j, n) for (int i = j; i < (int) (n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define bit(x) __builtin_popcount(x)

const int MAXN = (int) 400 + 7;
char a[MAXN][MAXN];
int dp[MAXN][MAXN];

int get(int x1, int y1, int x2, int y2) {
    return dp[x2][y2] - (y1 > 0) * dp[x2][y1 - 1] - (x1 > 0) * dp[x1 - 1][y2] + (x1 > 0 && y1 > 0) * dp[x1 - 1][y1 - 1];
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, abc;
    scanf("%d%d%d", &n, &m, &abc);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf(" %c", &a[i][j]);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i][j] = (i > 0) * dp[i - 1][j] + (j > 0) * dp[i][j - 1] - (i > 0 && j > 0) * dp[i - 1][j - 1] + (a[i][j] == 'a');
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            queue <int> cur[26];
            int last = m - 1;
            for (int j = m - 1; j >= 0; j--) {
                if (a[i][j] != a[k][j]) continue;
                int c = a[i][j] - 'a';
                cur[c].push(j);
                while (last > j && get(i, j, k, last) > abc) {
                    while (cur[c].front() >= last) cur[c].pop();
                    last--;
                }
                vector <int> t;
                queue <int> p = cur[c];
                while (p.size()) {
                    t.push_back(p.front());
                    p.pop();
                }
                for (int c = 0; c < (int) t.size(); c++) {
                    int r = t[c];
                    if (a[i][r] == a[k][r] && a[i][r] == a[i][j] && get(i, j, k, c) <= abc) {
                        ans++;
                    } else {
                        assert(0);
                    }
                }
                //ans += (int) cur[c].size() - 1;
            }
        }
    }
    printf("%lld\n", ans);
}