An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, and a closing bracket (ASCII code $093$). The length of the accordion is the number of characters in it.

For example, [::], [:||:] and [:|||:] are accordions having length $4$, $6$ and $7$. (:|:), {:||:}, [:], ]:||:[ are not accordions. 

You are given a string $s$. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from $s$, and if so, what is the maximum possible length of the result?


-----Input-----

The only line contains one string $s$ ($1 \le |s| \le 500000$). It consists of lowercase Latin letters and characters [, ], : and |.


-----Output-----

If it is not possible to obtain an accordion by removing some characters from $s$, print $-1$. Otherwise print maximum possible length of the resulting accordion.


-----Examples-----
Input
|[a:b:|]

Output
4

Input
|]:[|:]

Output
-1

Difficulty: interview

Starter code:

Solutions:
s = input()
n = len(s)
ind = -1
f = False
for i in range(n):
    if s[i] == '[':
        f = True
    elif s[i] == ':':
        if f:
            ind = i
            break
bind = -1
f = False
for i in range(n-1,-1,-1):
    if s[i] == ']':
        f = True
    elif s[i] == ':':
        if f:
            bind = i
            break
# print(ind,bind)
if ind == -1 or bind == -1:
    print(-1)
elif ind >= bind:
    print(-1)
else:
    ans = 4
    for i in range(ind+1,bind):
        if s[i] == '|':
            ans += 1
    print(ans)


def main():
    s = input()
    
    if s.count('[') == 0 or s.count(']') == 0:
        print(-1)
        return
    
    t = s[s.find('['):s.rfind(']')+1]
    
    if t.count(':') < 2:
        print(-1)
        return
    
    t = t[t.find(':'):t.rfind(':')+1]
    print(4 + t.count('|'))

main()

s = input()
if '[' in s:
    s = s[s.find('[') + 1:]
    if ']' in s:
        s = s[:s.rfind(']')]
        if s.count(':') >= 2:
            s = s[s.find(':') + 1 : s.rfind(':')]
            print(s.count('|') + 4)

        else:
            print(-1)
    else:
        print(-1)
else:
    print(-1)

import sys
s = input()
st = s.find('[')
if st==-1: print((-1)); return
s = s[st+1:]
#print(s)
st = s.find(':')
if st==-1: print((-1)); return
s = s[st+1:]
#print(s)
s = s[::-1]
st = s.find(']')
if st==-1: print((-1)); return
s = s[st+1:]
#print(s)
st = s.find(':')
if st==-1: print((-1)); return
s = s[st+1:]
#print(s)
x = s.count('|')
print(x+4 if x>=0 else -1)


s = input()

sb,eb,sc,ec = -1, -1, -1, -1

for i in range(len(s)):
	if s[i] == '[' and sb == -1:
		sb = i
	elif s[i] == ']':
		eb = i
	elif s[i] == ':' and sc == -1 and sb!=-1:
		sc = i

if eb <= sb or sc>eb:
	print(-1)
elif sb ==-1 or eb==-1 or sc==-1:
	print(-1)
else:
	for i in range(sc+1, eb):
		if s[i] == ':':
			ec = i
	if ec == -1:
		print(-1)
	else:
		cnt = 0
		for i in range(sc,ec):
			if (s[i] == '|'):
				cnt += 1
		print(cnt+4)

s = input()
t_d = 0
try:
    left = -1
    was_b = False
    for i in range(len(s)):
        if s[i] == '[' and not was_b:
            was_b = True
            continue
        if s[i] == ':' and was_b:
            left = i
            break
        t_d += 1
    if left == -1:
        raise ArithmeticError()
    right = -1
    was_b = False
    for i in range(len(s) - 1, -1, -1):
        if s[i] == ']' and not was_b:
            was_b = True
            continue
        if s[i] == ':' and was_b:
            right = i
            break
        t_d += 1
    if right == -1 or right <= left:
        raise ArithmeticError()
    for i in range(left + 1, right):
        if s[i] != '|':
            t_d += 1
    print(len(s) - t_d)
except:
    print(-1)
        


s = input()

mode = 0
l = len(s)
r = -1
for i in range(len(s)):
    if mode == 0:
        if s[i] == "[":
            mode = 1
    if mode == 1:
        if s[i] == ":":
            l = i
            break

mode = 0
for i in range(len(s)-1, -1, -1):
    if mode == 0:
        if s[i] == "]":
            mode = 1
    if mode == 1:
        if s[i] == ":":
            r = i
            break
    
if l >= r:
    print(-1)
else:
    c = 0
    for i in range(l+1, r):
        if s[i] == "|":
            c += 1
    print(c+4)


s = input()

f1 = False
f2 = False
l1 = -1
for l in range(len(s)):
    if f1 == False and s[l] == '[':
        f1 = True
    elif f1 == True and s[l] == ':':
        f2 = True
        l1 = l
        break
g1 = False
g2 = False
r1 = -1
for r in range(len(s) - 1, -1, -1):
    if g1 == False and s[r] == ']':
        g1 = True
    elif g1 == True and s[r] == ':':
        g2 = True
        r1 = r
        break
if (l1 == -1 or r1 == -1) or (r1 <= l1):
    print(-1)
    
else:
    ans = 4
    for i in range(l1 + 1, r1):
        if s[i] == '|': ans += 1
    print(ans)

s=input()
pos1=-1
pos2=-1
pos3=-1
pos4=-1
for i in range(0,len(s)):
    if(s[i]=='['):
        pos1=i
        break
for i in range(len(s)-1,pos1,-1):
    if(s[i]==']'):
        pos2=i
        break
for i in range(pos1,pos2+1):
    if(s[i]==':'):
        pos3=i
        break
for i in range(pos2,pos3,-1):
    if(s[i]==':'):
        pos4=i
        break
    
if(pos1==-1 or pos2==-1 or pos3==-1 or pos4==-1 or len(s)<4):
    print('-1')
else:
    c=0
    for j in range(pos3,pos4):
        if(s[j]=='|'):
            c=c+1
    print(c+4)


def ii():
    return int(input())
def mi():
    return list(map(int, input().split()))
def li():
    return list(mi())

s = input().strip()
n = len(s)
ans = -1
fb = s.find('[')
if fb >= 0:
    fc = s.find(':', fb)
    if fc >= 0:
        lb = s.rfind(']')
        if lb > fc:
             lc = s.rfind(':', 0, lb)
             if lc > fc:
                ans = 4 + s[fc:lc].count('|')
print(ans)


s = input()

def sovle(s):

    i1 = s.find('[')
    if i1 == -1:
        return -1
    s = s[i1+1:]
    i2 = s.find(':')
    if i2 == -1:
        return -1

    s = s[i2+1 :]
    i1 = s.rfind(']')
    if i1 == -1:
        return -1
    s = s[:i1]
    i2 = s.rfind(':')
    if i2 == -1:
        return -1
    s = s[:i2]
    x = s.count('|')
    return x+4

print(sovle(s))

def solve(s):
    if s.find('[') == -1:
        return -1
    s = s[s.find('['):]
    #print(s)
    if s.find(':') == -1:
        return -1
    s = s[s.find(':') + 1:]
    #print(s)
    if s.find(']') == -1:
        return -1
    s = s[:s.rfind(']')]
    #print(s)
    if s.find(':') == -1:
        return -1
    s = s[:s.rfind(':')]
    #print(s)
    return s.count('|') + 4

s = input()
print(solve(s))

s=input()
i=s.find('[')
if i==-1:
    print(-1)
    return
s=s[i:]
i=s.rfind(']')

if i==-1:
    print(-1)
    return
s=s[:i+1]
l,h=0,0
for i,d in enumerate(s):
    if d==':':
        l=i
        break
for i,d in enumerate(s):
    if d==':':
        h=i
if l==h:
    print(-1)
    return
c=0
for i in range(l+1,h):
    if s[i]=='|':
        c+=1
print(c+4)


from sys import stdin
s=stdin.readline().strip()
x=-1
for i in range(len(s)):
    if s[i]=="[":
        x=i
        break
y=-1
for i in range(len(s)-1,-1,-1):
    if s[i]=="]":
        y=i
        break
if x==-1 or y==-1 or y<x:
    print(-1)
    return
x1=-1
for i in range(x,y):
    if s[i]==":":
        x1=i
        break
y1=-1
for i in range(y-1,x,-1):
    if s[i]==":":
        y1=i
        break
if x1==-1 or y1==-1 or y1<=x1:
    print(-1)
    return
ans=4
for i in range(x1,y1):
    if s[i]=="|":
        ans+=1
print(ans)


s = str(input().strip())
i = 0
n = len(s)
while i < n and s[i] != '[':
    i+=1
if(i == n):
    print(-1)
    return
j = n-1
while j > i and s[j] != ']':
    j-=1
if(j <= i):
    print(-1)
    return
while i < j and s[i] != ':':
    i+=1
if(i == j):
    print(-1)
    return
while j > i and s[j] != ':':
    j-=1
if(j == i):
    print(-1)
    return
k = i+1
c = 0
while k < j:
    if(s[k] == '|'):
        c+=1
    k+=1
print(c+4)


import sys
s = input()
l = len(s)
s_list = [x for x in s]

counter = 0
try:
	a = s_list.index('[')
	counter += a
	s_list = s_list[a + 1:]
except:
	print(-1)
	return

try:
	a = s_list.index(':')
	counter += a
	s_list = s_list[a + 1:]
except:
	print(-1)
	return

s_list_rev = s_list.copy()
s_list_rev.reverse()

try:
	b = s_list_rev.index(']')
	counter += b
	s_list_rev = s_list_rev[b+1:]
except:
	print(-1)
	return

try:
	b = s_list_rev.index(':')
	counter += b
	s_list_rev = s_list_rev[b+1:]
except:
	print(-1)
	return
s_list_rev = [x for x in s_list_rev if x != '|']
counter += len(s_list_rev)
print(l - counter)

MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

s = input()
res = 0
n = len(s)
st = -1
e = -1
for i in range(n):
    if s[i] == '[':
        st = i
        break
for i in range(n-1, -1, -1):
    if s[i] == ']':
        e = i
        break
# print(st , e)
if st > e or st == -1 or e == -1:
    print(-1)
    return
a = -1
b = -1
for i in range(st, e):
    if s[i] == ':':
        a = i
        break
for i in range(e, st, -1):
    if s[i] == ':':
        b = i
        break
if a == b or a == -1 or b == -1:
    print(-1)
    return
count = 0
for i in range(a, b):
    if s[i] == '|':
        count += 1
print(4 + count)

s=input()
st=""
idx=-1
for i in range(len(s)):
    if s[i]=='[':
        idx=i
        break
if idx==-1:
    print(-1)
    return
idxl=-1
for i in range(len(s)-1,-1,-1):
    if s[i]==']' and i>idx:
        idxl=i
        break
if idxl==-1:
    print(-1)
    return
col=col2=-1
for i in range(len(s)):
    if s[i]==':' and i>idx and i<idxl:
        col=i
        break
if col==-1:
    print(-1)
    return
for i in range(len(s)-1,-1,-1):
    if s[i]==':' and i>col and i<idxl:
        col2=i
        break
if col2==-1:
    print(-1)
    return
ans=0
for i in range(col+1,col2):
    if s[i]=='|':
        ans+=1
print(4+ans)
    




s = input()
rev = s[::-1]

left = s.find("[")
if left != -1:
    left = s.find(":", left)

right = rev.find("]")
if right != -1:
    right = rev.find(":", right)

if left == -1 or right == -1:
    print(-1)
    return
right = len(s)-right-1
if left >= right:
    print(-1)
    return

print(4 + s[left:right].count("|"))


def ba(s):
    c1 = s.find('[')
    c2 = s.find(':', c1+1)
    c3 = s.rfind(']', c2+1)
    c4 = s.rfind(':', c2+1, c3)
    if -1 in [c1, c2, c3, c4]:
        return -1
    return s.count('|', c2, c4)+4


print(ba(input()))



s = input()
if '[' in s and ']' in s:
    a = s.index('[') + 1
    b = len(s)-s[::-1].index(']') - 1
else:
    print(-1)
    return
s = s[a:b]
if s.count(':') >= 2:
    a = s.index(':')+1
    b = len(s)-s[::-1].index(':')-1
else:
    print(-1)
    return
c = 0
for el in s[a:b]:
    if el =='|':
        c += 1
print(4 + c)

s = input()

b = [0]*len(s)

ob = 0
cc = 0
p = -1
q = -1

count = 0

for ind,c in enumerate(s):
    if c == '[':
        ob = 1
    elif c == ':' and p >= 0:
        q = ind
    elif c == ':' and ob == 1 and p < 0:
        p = ind
    elif c == ']' and q >= 0:
        cc = q
    elif c == '|':
        count += 1
    b[ind] = count

if cc > 0:
    print( 4 + b[cc]-b[p])
else:
    print(-1)


s = input()
if '[' in s and ']' in s and ':' in s:
  e = s.count(':')
  if e<2:
    print(-1)
  else:
    a = s.index('[')
    b = len(s)-1-s[::-1].index(']')
    if b<a:
      print(-1)
    else:
      if s[a+1:b].count(':')<2:
        print(-1)
      else:
        st1 = True
        count = 0
        for i in range(a+1, b):
          if st1 and s[i]==':':
            pos1 = i
            st1 = False
          if s[i]==':':
            pos2 = i
      
        for i in range(pos1+1, pos2):
          if s[i]=='|':
            count+=1
      
        print(count+4)
else:
  print(-1) 

s=input()
i1=-1
i2=-1
k1=-1
k2=-1
c=0
for i in range(len(s)):
  if(s[i]=='['):
    i1=i
    break
for i in range(len(s)-1,-1,-1):
  if(s[i]==']'):
    i2=i
    break
for i in range(i1,i2+1):
  if(s[i]==':'):
    k1=i
    break
for i in range(i2,i1-1,-1):
  if(s[i]==':'):
    k2=i
    break
for i in range(k1,k2+1):
  if(s[i]=='|'):
    c+=1

if(i1==-1 or i2==-1 or i1>=i2 or k1==-1 or k2==-1 or k1==k2):
  print(-1)
else:
  print(4+c)

s = input()
l = 0
end = 0
i = 1

while i <= len(s):
    if l == 0 and s[-i] == ']':
        l += 1
    elif l == 1 and s[-i] == ':':
        l += 1
        end = len(s) - i
        break
    i += 1

if l < 2:
    print(-1)
    return

for i in range(0, end):
    if l >= 4 and s[i] == '|':
        l += 1
    elif l == 2 and s[i] == '[':
        l += 1
    elif l == 3 and s[i] == ':':
        l += 1

if l >= 4:
    print(l)
else:
    print(-1)