File size: 12,277 Bytes
ecf8d4f
1
["s = input()\nn = len(s)\nind = -1\nf = False\nfor i in range(n):\n    if s[i] == '[':\n        f = True\n    elif s[i] == ':':\n        if f:\n            ind = i\n            break\nbind = -1\nf = False\nfor i in range(n-1,-1,-1):\n    if s[i] == ']':\n        f = True\n    elif s[i] == ':':\n        if f:\n            bind = i\n            break\n# print(ind,bind)\nif ind == -1 or bind == -1:\n    print(-1)\nelif ind >= bind:\n    print(-1)\nelse:\n    ans = 4\n    for i in range(ind+1,bind):\n        if s[i] == '|':\n            ans += 1\n    print(ans)\n", "def main():\n    s = input()\n    \n    if s.count('[') == 0 or s.count(']') == 0:\n        print(-1)\n        return\n    \n    t = s[s.find('['):s.rfind(']')+1]\n    \n    if t.count(':') < 2:\n        print(-1)\n        return\n    \n    t = t[t.find(':'):t.rfind(':')+1]\n    print(4 + t.count('|'))\n\nmain()", "s = input()\nif '[' in s:\n    s = s[s.find('[') + 1:]\n    if ']' in s:\n        s = s[:s.rfind(']')]\n        if s.count(':') >= 2:\n            s = s[s.find(':') + 1 : s.rfind(':')]\n            print(s.count('|') + 4)\n\n        else:\n            print(-1)\n    else:\n        print(-1)\nelse:\n    print(-1)", "import sys\ns = input()\nst = s.find('[')\nif st==-1: print((-1)); return\ns = s[st+1:]\n#print(s)\nst = s.find(':')\nif st==-1: print((-1)); return\ns = s[st+1:]\n#print(s)\ns = s[::-1]\nst = s.find(']')\nif st==-1: print((-1)); return\ns = s[st+1:]\n#print(s)\nst = s.find(':')\nif st==-1: print((-1)); return\ns = s[st+1:]\n#print(s)\nx = s.count('|')\nprint(x+4 if x>=0 else -1)\n", "s = input()\n\nsb,eb,sc,ec = -1, -1, -1, -1\n\nfor i in range(len(s)):\n\tif s[i] == '[' and sb == -1:\n\t\tsb = i\n\telif s[i] == ']':\n\t\teb = i\n\telif s[i] == ':' and sc == -1 and sb!=-1:\n\t\tsc = i\n\nif eb <= sb or sc>eb:\n\tprint(-1)\nelif sb ==-1 or eb==-1 or sc==-1:\n\tprint(-1)\nelse:\n\tfor i in range(sc+1, eb):\n\t\tif s[i] == ':':\n\t\t\tec = i\n\tif ec == -1:\n\t\tprint(-1)\n\telse:\n\t\tcnt = 0\n\t\tfor i in range(sc,ec):\n\t\t\tif (s[i] == '|'):\n\t\t\t\tcnt += 1\n\t\tprint(cnt+4)", "s = input()\nt_d = 0\ntry:\n    left = -1\n    was_b = False\n    for i in range(len(s)):\n        if s[i] == '[' and not was_b:\n            was_b = True\n            continue\n        if s[i] == ':' and was_b:\n            left = i\n            break\n        t_d += 1\n    if left == -1:\n        raise ArithmeticError()\n    right = -1\n    was_b = False\n    for i in range(len(s) - 1, -1, -1):\n        if s[i] == ']' and not was_b:\n            was_b = True\n            continue\n        if s[i] == ':' and was_b:\n            right = i\n            break\n        t_d += 1\n    if right == -1 or right <= left:\n        raise ArithmeticError()\n    for i in range(left + 1, right):\n        if s[i] != '|':\n            t_d += 1\n    print(len(s) - t_d)\nexcept:\n    print(-1)\n        \n", "s = input()\n\nmode = 0\nl = len(s)\nr = -1\nfor i in range(len(s)):\n    if mode == 0:\n        if s[i] == \"[\":\n            mode = 1\n    if mode == 1:\n        if s[i] == \":\":\n            l = i\n            break\n\nmode = 0\nfor i in range(len(s)-1, -1, -1):\n    if mode == 0:\n        if s[i] == \"]\":\n            mode = 1\n    if mode == 1:\n        if s[i] == \":\":\n            r = i\n            break\n    \nif l >= r:\n    print(-1)\nelse:\n    c = 0\n    for i in range(l+1, r):\n        if s[i] == \"|\":\n            c += 1\n    print(c+4)\n", "s = input()\n\nf1 = False\nf2 = False\nl1 = -1\nfor l in range(len(s)):\n    if f1 == False and s[l] == '[':\n        f1 = True\n    elif f1 == True and s[l] == ':':\n        f2 = True\n        l1 = l\n        break\ng1 = False\ng2 = False\nr1 = -1\nfor r in range(len(s) - 1, -1, -1):\n    if g1 == False and s[r] == ']':\n        g1 = True\n    elif g1 == True and s[r] == ':':\n        g2 = True\n        r1 = r\n        break\nif (l1 == -1 or r1 == -1) or (r1 <= l1):\n    print(-1)\n    \nelse:\n    ans = 4\n    for i in range(l1 + 1, r1):\n        if s[i] == '|': ans += 1\n    print(ans)", "s=input()\npos1=-1\npos2=-1\npos3=-1\npos4=-1\nfor i in range(0,len(s)):\n    if(s[i]=='['):\n        pos1=i\n        break\nfor i in range(len(s)-1,pos1,-1):\n    if(s[i]==']'):\n        pos2=i\n        break\nfor i in range(pos1,pos2+1):\n    if(s[i]==':'):\n        pos3=i\n        break\nfor i in range(pos2,pos3,-1):\n    if(s[i]==':'):\n        pos4=i\n        break\n    \nif(pos1==-1 or pos2==-1 or pos3==-1 or pos4==-1 or len(s)<4):\n    print('-1')\nelse:\n    c=0\n    for j in range(pos3,pos4):\n        if(s[j]=='|'):\n            c=c+1\n    print(c+4)\n", "def ii():\n    return int(input())\ndef mi():\n    return list(map(int, input().split()))\ndef li():\n    return list(mi())\n\ns = input().strip()\nn = len(s)\nans = -1\nfb = s.find('[')\nif fb >= 0:\n    fc = s.find(':', fb)\n    if fc >= 0:\n        lb = s.rfind(']')\n        if lb > fc:\n             lc = s.rfind(':', 0, lb)\n             if lc > fc:\n                ans = 4 + s[fc:lc].count('|')\nprint(ans)\n", "s = input()\n\ndef sovle(s):\n\n    i1 = s.find('[')\n    if i1 == -1:\n        return -1\n    s = s[i1+1:]\n    i2 = s.find(':')\n    if i2 == -1:\n        return -1\n\n    s = s[i2+1 :]\n    i1 = s.rfind(']')\n    if i1 == -1:\n        return -1\n    s = s[:i1]\n    i2 = s.rfind(':')\n    if i2 == -1:\n        return -1\n    s = s[:i2]\n    x = s.count('|')\n    return x+4\n\nprint(sovle(s))", "def solve(s):\n    if s.find('[') == -1:\n        return -1\n    s = s[s.find('['):]\n    #print(s)\n    if s.find(':') == -1:\n        return -1\n    s = s[s.find(':') + 1:]\n    #print(s)\n    if s.find(']') == -1:\n        return -1\n    s = s[:s.rfind(']')]\n    #print(s)\n    if s.find(':') == -1:\n        return -1\n    s = s[:s.rfind(':')]\n    #print(s)\n    return s.count('|') + 4\n\ns = input()\nprint(solve(s))", "s=input()\ni=s.find('[')\nif i==-1:\n    print(-1)\n    return\ns=s[i:]\ni=s.rfind(']')\n\nif i==-1:\n    print(-1)\n    return\ns=s[:i+1]\nl,h=0,0\nfor i,d in enumerate(s):\n    if d==':':\n        l=i\n        break\nfor i,d in enumerate(s):\n    if d==':':\n        h=i\nif l==h:\n    print(-1)\n    return\nc=0\nfor i in range(l+1,h):\n    if s[i]=='|':\n        c+=1\nprint(c+4)\n", "from sys import stdin\ns=stdin.readline().strip()\nx=-1\nfor i in range(len(s)):\n    if s[i]==\"[\":\n        x=i\n        break\ny=-1\nfor i in range(len(s)-1,-1,-1):\n    if s[i]==\"]\":\n        y=i\n        break\nif x==-1 or y==-1 or y<x:\n    print(-1)\n    return\nx1=-1\nfor i in range(x,y):\n    if s[i]==\":\":\n        x1=i\n        break\ny1=-1\nfor i in range(y-1,x,-1):\n    if s[i]==\":\":\n        y1=i\n        break\nif x1==-1 or y1==-1 or y1<=x1:\n    print(-1)\n    return\nans=4\nfor i in range(x1,y1):\n    if s[i]==\"|\":\n        ans+=1\nprint(ans)\n", "s = str(input().strip())\ni = 0\nn = len(s)\nwhile i < n and s[i] != '[':\n    i+=1\nif(i == n):\n    print(-1)\n    return\nj = n-1\nwhile j > i and s[j] != ']':\n    j-=1\nif(j <= i):\n    print(-1)\n    return\nwhile i < j and s[i] != ':':\n    i+=1\nif(i == j):\n    print(-1)\n    return\nwhile j > i and s[j] != ':':\n    j-=1\nif(j == i):\n    print(-1)\n    return\nk = i+1\nc = 0\nwhile k < j:\n    if(s[k] == '|'):\n        c+=1\n    k+=1\nprint(c+4)\n", "import sys\ns = input()\nl = len(s)\ns_list = [x for x in s]\n\ncounter = 0\ntry:\n\ta = s_list.index('[')\n\tcounter += a\n\ts_list = s_list[a + 1:]\nexcept:\n\tprint(-1)\n\treturn\n\ntry:\n\ta = s_list.index(':')\n\tcounter += a\n\ts_list = s_list[a + 1:]\nexcept:\n\tprint(-1)\n\treturn\n\ns_list_rev = s_list.copy()\ns_list_rev.reverse()\n\ntry:\n\tb = s_list_rev.index(']')\n\tcounter += b\n\ts_list_rev = s_list_rev[b+1:]\nexcept:\n\tprint(-1)\n\treturn\n\ntry:\n\tb = s_list_rev.index(':')\n\tcounter += b\n\ts_list_rev = s_list_rev[b+1:]\nexcept:\n\tprint(-1)\n\treturn\ns_list_rev = [x for x in s_list_rev if x != '|']\ncounter += len(s_list_rev)\nprint(l - counter)", "MOD = 10**9 + 7\nI = lambda:list(map(int,input().split()))\n\ns = input()\nres = 0\nn = len(s)\nst = -1\ne = -1\nfor i in range(n):\n    if s[i] == '[':\n        st = i\n        break\nfor i in range(n-1, -1, -1):\n    if s[i] == ']':\n        e = i\n        break\n# print(st , e)\nif st > e or st == -1 or e == -1:\n    print(-1)\n    return\na = -1\nb = -1\nfor i in range(st, e):\n    if s[i] == ':':\n        a = i\n        break\nfor i in range(e, st, -1):\n    if s[i] == ':':\n        b = i\n        break\nif a == b or a == -1 or b == -1:\n    print(-1)\n    return\ncount = 0\nfor i in range(a, b):\n    if s[i] == '|':\n        count += 1\nprint(4 + count)", "s=input()\nst=\"\"\nidx=-1\nfor i in range(len(s)):\n    if s[i]=='[':\n        idx=i\n        break\nif idx==-1:\n    print(-1)\n    return\nidxl=-1\nfor i in range(len(s)-1,-1,-1):\n    if s[i]==']' and i>idx:\n        idxl=i\n        break\nif idxl==-1:\n    print(-1)\n    return\ncol=col2=-1\nfor i in range(len(s)):\n    if s[i]==':' and i>idx and i<idxl:\n        col=i\n        break\nif col==-1:\n    print(-1)\n    return\nfor i in range(len(s)-1,-1,-1):\n    if s[i]==':' and i>col and i<idxl:\n        col2=i\n        break\nif col2==-1:\n    print(-1)\n    return\nans=0\nfor i in range(col+1,col2):\n    if s[i]=='|':\n        ans+=1\nprint(4+ans)\n    \n\n\n", "s = input()\nrev = s[::-1]\n\nleft = s.find(\"[\")\nif left != -1:\n    left = s.find(\":\", left)\n\nright = rev.find(\"]\")\nif right != -1:\n    right = rev.find(\":\", right)\n\nif left == -1 or right == -1:\n    print(-1)\n    return\nright = len(s)-right-1\nif left >= right:\n    print(-1)\n    return\n\nprint(4 + s[left:right].count(\"|\"))\n", "def ba(s):\n    c1 = s.find('[')\n    c2 = s.find(':', c1+1)\n    c3 = s.rfind(']', c2+1)\n    c4 = s.rfind(':', c2+1, c3)\n    if -1 in [c1, c2, c3, c4]:\n        return -1\n    return s.count('|', c2, c4)+4\n\n\nprint(ba(input()))\n\n", "s = input()\nif '[' in s and ']' in s:\n    a = s.index('[') + 1\n    b = len(s)-s[::-1].index(']') - 1\nelse:\n    print(-1)\n    return\ns = s[a:b]\nif s.count(':') >= 2:\n    a = s.index(':')+1\n    b = len(s)-s[::-1].index(':')-1\nelse:\n    print(-1)\n    return\nc = 0\nfor el in s[a:b]:\n    if el =='|':\n        c += 1\nprint(4 + c)", "s = input()\n\nb = [0]*len(s)\n\nob = 0\ncc = 0\np = -1\nq = -1\n\ncount = 0\n\nfor ind,c in enumerate(s):\n    if c == '[':\n        ob = 1\n    elif c == ':' and p >= 0:\n        q = ind\n    elif c == ':' and ob == 1 and p < 0:\n        p = ind\n    elif c == ']' and q >= 0:\n        cc = q\n    elif c == '|':\n        count += 1\n    b[ind] = count\n\nif cc > 0:\n    print( 4 + b[cc]-b[p])\nelse:\n    print(-1)\n", "s = input()\nif '[' in s and ']' in s and ':' in s:\n  e = s.count(':')\n  if e<2:\n    print(-1)\n  else:\n    a = s.index('[')\n    b = len(s)-1-s[::-1].index(']')\n    if b<a:\n      print(-1)\n    else:\n      if s[a+1:b].count(':')<2:\n        print(-1)\n      else:\n        st1 = True\n        count = 0\n        for i in range(a+1, b):\n          if st1 and s[i]==':':\n            pos1 = i\n            st1 = False\n          if s[i]==':':\n            pos2 = i\n      \n        for i in range(pos1+1, pos2):\n          if s[i]=='|':\n            count+=1\n      \n        print(count+4)\nelse:\n  print(-1) ", "s=input()\ni1=-1\ni2=-1\nk1=-1\nk2=-1\nc=0\nfor i in range(len(s)):\n  if(s[i]=='['):\n    i1=i\n    break\nfor i in range(len(s)-1,-1,-1):\n  if(s[i]==']'):\n    i2=i\n    break\nfor i in range(i1,i2+1):\n  if(s[i]==':'):\n    k1=i\n    break\nfor i in range(i2,i1-1,-1):\n  if(s[i]==':'):\n    k2=i\n    break\nfor i in range(k1,k2+1):\n  if(s[i]=='|'):\n    c+=1\n\nif(i1==-1 or i2==-1 or i1>=i2 or k1==-1 or k2==-1 or k1==k2):\n  print(-1)\nelse:\n  print(4+c)", "s = input()\nl = 0\nend = 0\ni = 1\n\nwhile i <= len(s):\n    if l == 0 and s[-i] == ']':\n        l += 1\n    elif l == 1 and s[-i] == ':':\n        l += 1\n        end = len(s) - i\n        break\n    i += 1\n\nif l < 2:\n    print(-1)\n    return\n\nfor i in range(0, end):\n    if l >= 4 and s[i] == '|':\n        l += 1\n    elif l == 2 and s[i] == '[':\n        l += 1\n    elif l == 3 and s[i] == ':':\n        l += 1\n\nif l >= 4:\n    print(l)\nelse:\n    print(-1)"]