forked from salesforce/CodeRL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70f83e4
commit d3f4635
Showing
1 changed file
with
1 addition
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"0": {"code": ["import sys\n\ndef main():\n\ts = sys.stdin.readline().strip()\n\tif not s:\n\t\treturn 0\n\tl = len(s)\n\tif l % 4 == 1:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"|\":\n\t\t\tcnt += 1\n\t\telif c == \":\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"[\":\n\t\t\tcnt += 1\n\t\telif c == \"]\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"|\":\n\t\t\tcnt += 1\n\t\telif c == \":\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"|\":\n\t\t\tcnt += 1\n\t\telif c == \"[\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"|\":\n\t\t\tcnt += 1\n\t\telif c == \":\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:\n\t\tprint(-1)\n\t\treturn 0\n\t\n\tcnt = 0\n\tfor c in s:\n\t\tif c == \"|\":\n\t\t\tcnt += 1\n\t\telif c == \"[\":\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\tbreak\n\t\n\tif cnt > 0:", "import sys\n\ndef solve(s):\n\tif len(s) % 3!= 0:\n\t\tprint(-1)\n\t\treturn\n\n\tif len(s) == 0:\n\t\tprint(0)\n\t\treturn\n\n\t# Remove all\n\ts = [c for c in s if c in \"|:\"]\n\n\t# Try to get length\n\t# 0 - len(s)\n\t# 1 - len(s) - 1\n\tstart = 0\n\tend = 1\n\tlength = 1\n\twhile end < len(s):\n\t\t# print(start, end, length)\n\t\tif s[start:end + 1] == s[start + 1:end + 2]:\n\t\t\tend += 2\n\t\t\tlength += 1\n\t\telif s[start:end + 1] == s[start + 2:end + 3]:\n\t\t\tend += 3\n\t\t\tlength += 1\n\t\telse:\n\t\t\t# print(-1)\n\t\t\treturn -1\n\t\tstart += 1\n\n\t# print(start, end, length)\n\treturn length\n\ndef main():\n\tsys.setrecursionlimit(100000)\n\tinput = sys.stdin.readline\n\tsolve(input())\n\nmain()\n", "import sys\n\ndef main():\n\ts = sys.stdin.readline().strip()\n\tl = len(s)\n\tif s[l//2]!= \"|\" or s[l//2-1]!= \":\":\n\t\tprint(-1)\n\t\treturn\n\tl -= 1\n\tcnt = 0\n\tmax_cnt = 0\n\tfor i in range(l//2):\n\t\tif s[i]!= s[l+i-1]:\n\t\t\tcnt += 1\n\t\telse:\n\t\t\tif cnt > max_cnt:\n\t\t\t\tmax_cnt = cnt\n\t\t\tcnt = 0\n\tif cnt > max_cnt:\n\t\tmax_cnt = cnt\n\tprint(max_cnt)\n\ndef __starting_point():\n\tmain()\n\n__starting_point()\n", "import sys\n\ndef main():\n\ts = sys.stdin.readline().strip()\n\tif len(s) % 4!= 0:\n\t\tprint(-1)\n\t\treturn\n\t\n\tstart = 0\n\tend = 0\n\tresult = -1\n\tfor i in s:\n\t\tif i == \"|\":\n\t\t\tif result == -1:\n\t\t\t\tresult = end - start + 1\n\t\t\t\tstart += 1\n\t\t\telse:\n\t\t\t\tresult = max(result, end - start + 1)\n\t\t\t\tstart += 1\n\t\t\t\tend += 1\n\t\telif i == \":\":\n\t\t\tif result == -1:\n\t\t\t\tresult = end - start + 1\n\t\t\t\tstart += 1\n\t\t\telse:\n\t\t\t\tresult = max(result, end - start + 1)\n\t\t\t\tstart += 1\n\t\t\t\tend += 1\n\t\telse:\n\t\t\tstart += 1\n\t\t\tend += 1\n\t\t\n\tprint(result)\n\nmain()\n", "import sys\ndef I():\n\treturn sys.stdin.readline().rstrip()\n\ndef main():\n\ts = I()\n\tif len(s)%2:\n\t\tprint(-1)\n\t\treturn\n\tl = len(s)\n\tif l==1:\n\t\tprint(1)\n\t\treturn\n\tans = 0\n\tstart = 0\n\tfor i in range(1,l):\n\t\tif s[start:i]!= s[i:l-i]:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tstart = i\n\tprint(l-i)\n\treturn\n\ndef __starting_point():\n\tmain()\n__starting_point()\n", "import sys\n\ndef solve(s):\n\tif not s:\n\t\treturn 0\n\tl = len(s)\n\tif l % 4 == 0:\n\t\tif s[0] == ':':\n\t\t\tif s[1] == '|':\n\t\t\t\tif s[2] == ':':\n\t\t\t\t\treturn 1\n\t\t\t\tif s[3] == ':':\n\t\t\t\t\treturn 2\n\t\t\t\treturn 3\n\t\t\treturn 1\n\t\tif s[1] == '|':\n\t\t\tif s[2] == ':':\n\t\t\t\treturn 2\n\t\t\tif s[3] == ':':\n\t\t\t\treturn 3\n\t\t\treturn 4\n\t\tif s[2] == ':':\n\t\t\treturn 1\n\t\tif s[3] == ':':\n\t\t\treturn 2\n\t\tif s[4] == '|':\n\t\t\tif s[5] == ':':\n\t\t\t\treturn 1\n\t\t\tif s[6] == ':':\n\t\t\t\treturn 2\n\t\t\treturn 3\n\t\tif s[5] == '|':\n\t\t\tif s[6] == ':':\n\t\t\t\treturn 3\n\t\t\tif s[7] == ':':\n\t\t\t\treturn 2\n\t\t\treturn 4\n\t\tif s[6] == ':':\n\t\t\treturn 2\n\t\tif s[7] == ':':\n\t\t\treturn 1\n\t\tif s[8] == '|':\n\t\t\tif s[9] == ':':\n\t\t\t\treturn 1\n\t\t\tif s[10] == ':':\n\t\t\t\treturn 2\n\t\t\treturn 3\n\t\tif s[9] == ':':\n\t\t\treturn 1\n\t\tif s[10] == ':':\n\t\t\treturn 2\n\t\tif s[8] == '|':\n\t\t\tif s[11] == ':':\n\t\t\t\treturn 3\n\t\t\tif s[12] == ':':\n\t\t\t\treturn 4\n\t\t\treturn 5\n\t\tif s[11] == ':':\n\t\t\treturn 1\n\t\tif s[12] == ':':\n\t\t\treturn 2\n\t\tif s[8] == '|':\n\t\t\tif s[10] == ':':\n\t\t\t\treturn 3\n\t\t\tif s[11] == ':':\n\t\t\t\t", "import sys\n\ndef main():\n\ts = sys.stdin.readline().rstrip()\n\tif not s:\n\t\treturn 0\n\t\n\t# [::, :||:][:][|:]\n\t# [::, :||:][:][|:][:][:][|:][:][|:][:][:][|:][:][:][|:][:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|:][:][|", "import sys\n\ns = sys.stdin.readline().rstrip()\n\nif len(s) % 2!= 0:\n\tprint(-1)\n\treturn\n\nstart = 0\nend = 0\n\nfor i in s:\n\tif i == \"|\":\n\t\tif end > start:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tend += 1\n\telif i == \":\":\n\t\tif start > end:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tstart = end\n\t\tend = 0\n\telif i == \"[\":\n\t\tif start > end:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tstart = 0\n\t\tend += 1\n\telif i == \"]\":\n\t\tif start > end:\n\t\t\tprint(-1)\n\t\t\treturn\n\t\tstart += 1\n\t\tend = 0\n\nprint(end - start)\n", "import sys\n\n\ndef main():\n\ts = sys.stdin.readline()\n\tif not s:\n\t\treturn 0\n\tlen_s = len(s)\n\tif len_s % 4 == 1:\n\t\tprint(-1)\n\t\treturn 0\n\tcnt = 0\n\tfor c in s:\n\t\tif c == '|':\n\t\t\tcnt += 1\n\t\telif c == ':':\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\treturn -1\n\t\tcnt -= 1\n\tif cnt!= 0:\n\t\tprint(-1)\n\t\treturn 0\n\tcnt = 0\n\tfor c in s:\n\t\tif c == '[':\n\t\t\tcnt += 1\n\t\telif c == ']':\n\t\t\tcnt += 1\n\t\telif cnt == 0:\n\t\t\treturn -1\n\t\tcnt -= 1\n\tif cnt!= 0:\n\t\tprint(-1)\n\t\treturn 0\n\tres = 0\n\tfor i in range(1, len_s // 4 + 1):\n\t\tif len_s - 4 * i == 4 * cnt:\n\t\t\tres = max(res, 4 * cnt - i)\n\t\telse:\n\t\t\tres = max(res, 4 * cnt - i)\n\tprint(res)\n\n\ndef __starting_point():\n\tmain()\n__starting_point()\n", "import sys\nreadline = sys.stdin.readline\n\nS = readline().strip()\n\nif len(S) % 4!= 0:\n\tprint(-1)\n\treturn\n\n# \u5168\u90e8\u683c\u5b50\u306e\u6587\u5b57\u3092\u53d6\u5f97\u3059\u308b\nlen_s = len(S)\n\n# \u30db\u30c6\u30eb\u304b\u3089\u30010~9\u306b\u306a\u308b\u7121\u843d\u3059\u308b\nMIN_LEN = 1 << (len_s - 1)\n# \u30db\u30c6\u30eb\u304b\u30899~15\u306b\u306a\u308b\u7121\u843d\u3059\u308b\nMAX_LEN = min(9, 15)\n\n# \u30db\u30c6\u30eb\u304b\u3089\u5165\u308c\u308b\u51e6\u7406\ndef make_accordion(s):\n\tl_s = len(s)\n\tl_accordion = len(S) // 4\n\tl_open = 0\n\tl_close = 0\n\tl_pos = 0\n\tl_cnt = 0\n\tfor i in range(len_s):\n\t\tif s[i] == s[i + 1]:\n\t\t\tl_cnt += 1\n\t\telse:\n\t\t\tif l_cnt > 0:\n\t\t\t\tl_open += 1\n\t\t\tif l_open > l_close:\n\t\t\t\tl_close = l_open\n\t\t\tl_cnt = 0\n\t\t\tl_pos = i + 1\n\t\tl_pos %= 4\n\t# \u30db\u30c6\u30eb\u304b\u3089\u5165\u308c\u308b\u51e6\u7406\n\tl_open -= 1\n\tl_close -= 1\n\tl_accordion += l_cnt // 2\n\treturn [l_accordion, l_open, l_close, l_pos]\n\n# \u30db\u30c6\u30eb\u304b\u3089\u5165\ufffd"], "prompt": "\nQUESTION:\nAn 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.\n\nFor example, [::], [:||:] and [:|||:] are accordions having length $4$, $6$ and $7$. (:|:), {:||:}, [:], ]:||:[ are not accordions. \n\nYou 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?\n\n\n-----Input-----\n\nThe only line contains one string $s$ ($1 \\le |s| \\le 500000$). It consists of lowercase Latin letters and characters [, ], : and |.\n\n\n-----Output-----\n\nIf 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.\n\n\n-----Examples-----\nInput\n|[a:b:|]\n\nOutput\n4\n\nInput\n|]:[|:]\n\nOutput\n-1\nUse Standard Input format\nANSWER:\n"}} |