problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p03355 | u335295553 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nK = int(input())\nls = []\nfor i in range(1,len(s)+1):\n for j in range(i,len(s)+1):\n tmp = s[i:j]\n if tmp != "":\n ls.append(s[i:j])\nprint(sorted(list(set(ls)))[K-1])', 's = input()\nK = int(input())\nprint(sorted(set([s[j:j+i] for j in range(len(s)) for i in range(1,K+1)]))[K-1])\n'] | ['Runtime Error', 'Accepted'] | ['s544533987', 's938235783'] | [3060.0, 4980.0] | [2350.0, 32.0] | [203, 110] |
p03355 | u340515675 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input("string:")\nK = int(input("K:"))\n# substrings = {}\nsubstrings = []\nfor i in range(1,len(s)+1):\n for j in range(0,len(s)):\n if s[j:j+i] not in substrings:\n \n substrings.append(s[j:j+i])\nprint(sorted(substrings)[K-1])', 's = input()\nK = int(input())\n# substrings = {}\nsubstrings = []\nfor i in range(1,6:\n for j in range(0,len(s)):\n if s[j:j+i] not in substrings:\n \n substrings.append(s[j:j+i])\nprint(sorted(substrings)[K-1])', 's = input("string:")\nK = int(input("K:"))\n# substrings = {}\nsubstrings = []\nfor i in range(1,len(s)+1):\n for j in range(0,len(s)):\n if s[j:j+i] not in substrings:\n \n substrings.append(s[j:j+i])\nprint(sorted(substrings)[K-1])', 's = input()\nK = int(input())\n# substrings = {}\nsubstrings = []\nfor i in range(1,6):\n for j in range(0,len(s)):\n if s[j:j+i] not in substrings:\n \n substrings.append(s[j:j+i])\nprint(sorted(substrings)[K-1])\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s670878004', 's706238134', 's802514872', 's008144001'] | [4196.0, 2940.0, 4196.0, 4072.0] | [2104.0, 17.0, 2104.0, 1535.0] | [285, 264, 285, 266] |
p03355 | u355853184 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s= input()\nK = int(input())\n\nans_list = []\nfor i in range(len(s)-K+1):\n for j in range(i+1,i+K+1):\n ans_list.append(s[i:j])\n\nans_set = set(ans_list)\nans_list_min = sorted(list(ans_set))\nprint(ans_list_min[K-1])', 's= input()\nK = int(input())\n\nans_list = []\nfor i in range(len(s)):\n for j in range(i+1,i+K+1):\n if j < len(s)+1:\n ans_list.append(s[i:j])\n\nans_set = set(ans_list)\nans_list_min = sorted(list(ans_set))\n#print(ans_list_min)\nprint(ans_list_min[K-1])'] | ['Runtime Error', 'Accepted'] | ['s195664852', 's368889381'] | [11148.0, 11160.0] | [43.0, 48.0] | [220, 266] |
p03355 | u367130284 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nn=int(input())\nl=[]\nfor t in range(1,len(s)+3):\n for r in range(len(s)-t+1):\n l.append(s[r:r+t])\nprint(sorted(sorted(set(l)),key=lambda x:len(x))[n-1])', 's=input();print(sorted(set(s[t:t+i]for t in range(9)for i in range(1,9)))[int(input())-1])', 's=input();print(sorted(set(s[t:t+i]for t in range(len(s))for i in range(1,9)))[int(input())-1])'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s031553571', 's223164048', 's675691969'] | [1993136.0, 3060.0, 7144.0] | [2288.0, 19.0, 48.0] | [171, 90, 95] |
p03355 | u395672550 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nK = int(input())\nL = []\nM = []\ncon = 0\nfor i in s:\n L.append(i)\nL = list(set(L))\nL.sort()\nfor j in range(len(s)):\n if s[j] == L[0]:\n for k in range(1,6):\n if j + k >=len(s):\n M.append(s[j:])\n break\n else:\n M.append(s[j:j+k])\n\nfor l in range(len(s)):\n if s[l] == L[1]:\n for m in range(1,6):\n if l + m >= len(s):\n M.append(s[l:])\n break\n else:\n M.append(s[l:l+m]) \nif len(M) < K:\n for n in range(len(s)):\n if s[n] == L[2]:\n for o in range(1,6):\n if n + o >=len(s):\n M.append(s[n:])\n break\n else:\n M.append(s[n:n+o])\nM = list(set(M))\nM.sort()\nprint(M)\nprint(M[K - 1]) \n \n', 's = str(input())\nK = int(input())\nL = []\nM = []\ncon = 0\nfor i in s:\n L.append(i)\nL = list(set(L))\nL.sort()\nfor j in range(len(s)):\n if s[j] == L[0]:\n for k in range(1,6):\n if j + k >=len(s):\n M.append(s[j:])\n break\n else:\n M.append(s[j:j+k])\nif len(L) != 1:\n for l in range(len(s)):\n if s[l] == L[1]:\n for m in range(1,6):\n if l + m >= len(s):\n M.append(s[l:])\n break\n else:\n M.append(s[l:l+m]) \nif len(M) < K:\n for n in range(len(s)):\n if s[n] == L[2]:\n for o in range(1,6):\n if n + o >=len(s):\n M.append(s[n:])\n break\n else:\n M.append(s[n:n+o])\nM = list(set(M))\nM.sort()\nprint(M[K - 1]) \n '] | ['Runtime Error', 'Accepted'] | ['s923432022', 's139733537'] | [10356.0, 10084.0] | [40.0, 42.0] | [730, 751] |
p03355 | u405483159 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nN = len( s )\nK = int( input() )\n\ns_set = set()\nfor i in range( N - K + 1 ):\n for j in range( 1, K + 1 ):\n t = s[ i : i + j ]\n s_set.add(t)\n\nprint( sorted( list( s_set ) )[ K - 1 ] )', 's = input()\nN = len( s )\nK = int( input() )\n\ns_set = set()\nfor j in range( 1, K + 1 ):\n for i in range( N - j + 1 ):\n t = s[ i : i + j ]\n s_set.add(t)\n\nprint( sorted( list( s_set ) )[ K - 1 ] )'] | ['Runtime Error', 'Accepted'] | ['s084339686', 's164500065'] | [4592.0, 4592.0] | [36.0, 34.0] | [200, 200] |
p03355 | u413165887 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nk = int(input())\nresult = []\nfor i in range(1, k+1):\n for j in range(len(s)-i):\n result.append(s[j:j+i])\nr = set(result)\nout = list(r)\nout.sort()\nprint(out[k-1])', "def main():\n s = str(input())\n s += '0'\n k = int(input())\n result = set()\n for i in range(1, 6):\n for j in range(len(s)-i):\n result.add(s[j:j+i])\n out = list(result)\n out.sort()\n print(out[k-1])\nif __name__ =='__main__':\n main()"] | ['Runtime Error', 'Accepted'] | ['s014080452', 's882755672'] | [5068.0, 4464.0] | [35.0, 32.0] | [188, 273] |
p03355 | u419963262 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["s = input()\nK = int(input())\nans_lis = []\ns_length = len(s)\nlis = [[] for i in range(26)]\n\nfor i in range(s_length):\n lis[ord(s[i]) - ord('a')].append(i)\n\n\nfor i in range(26):\n k = 1\n while k <= s_length:\n for j in lis[i]:\n ans_lis.append(s[j:j + k + 1])\n k += 1\n ans_lis = sorted(list(set(ans_lis)))\n if len(ans_lis) >= K:\n print(ans_lis[K - 1])\n exit()\n", "s = input()\nK = int(input())\nans_lis = []\ns_length = len(s)\nlis = [[] for i in range(26)]\n\nfor i in range(s_length):\n lis[ord(s[i]) - ord('a')].append(i)\n\n\nfor i in range(26):\n k = 1\n while k <= s_length:\n for j in lis[i]:\n ans_lis.append(s[j:j + k + 1])\n k += 1\n ans_lis = sorted(list(set(ans_lis)))\n if len(ans_lis) >= K:\n print(ans_lis[K - 1])\n exit()\n", "s = input()\nK = int(input())\nans_lis = []\ns_length = len(s)\nlis = [[] for i in range(26)]\n\nfor i in range(s_length):\n lis[ord(s[i]) - ord('a')].append(i)\n\n\nfor i in range(26):\n k = 1\n while k <= K:\n for j in lis[i]:\n ans_lis.append(s[j:j + k])\n k += 1\n ans_lis = sorted(list(set(ans_lis)))\n if len(ans_lis) >= K:\n print(ans_lis[K - 1])\n exit()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s316454005', 's822048998', 's162912557'] | [22092.0, 9500.0, 9444.0] | [2206.0, 106.0, 37.0] | [413, 425, 402] |
p03355 | u442030035 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["s = input()\nK = int(input())\n\nct = 0\nalp = 'abcdefghijklmnopqrstuvwxyz'\nfor i in alp:\n ct += s.count(i)\n if ct >= K:\n key = i\n break\n\nlist_rank = []\nfor i in range(len(s)):\n if s[i] > key:\n continue\n if i < len(s) - K + 1:\n for j in range(K):\n if s[i:i+j+1] not in list_rank:\n list_rank.append(s[i:i+j+1])\n else:\n for j in range(len(s)-i):\n if s[i:i+j+1] not in list_rank:\n list_rank.append(s[i:i+j+1])\n\nlist_rank.sort()\nprint(list_rank[K-1])\n", "s = input()\nK = int(input())\n\nct = 0\nalp = 'abcdefghijklmnopqrstuvwxyz'\nfor i in alp:\n ct += s.count(i)\n if ct >= K:\n break\n\nkey = i\n\nlist_rank = []\nfor i in range(len(s)):\n if s[i] > key:\n continue\n if i < len(s) - K + 1:\n for j in range(K):\n if s[i:i+j+1] not in list_rank:\n list_rank.append(s[i:i+j+1])\n else:\n for j in range(len(s)-i):\n if s[i:i+j+1] not in list_rank:\n list_rank.append(s[i:i+j+1])\n\nlist_rank.sort()\nprint(list_rank[K-1])\n"] | ['Runtime Error', 'Accepted'] | ['s656044730', 's921808407'] | [3064.0, 3064.0] | [29.0, 28.0] | [545, 538] |
p03355 | u445624660 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['\ns = input()\nk = int(input())\nans = []\nfor i in range(len(s)):\n for j in range(i + 1, min(len(s), i + 5 + 1)):\n t = "".join(s[i:j])\n if t not in ans:\n ans.append("".join(s[i:j]))\n ans = sorted(ans)[:5]\nprint(ans[k - 1])\n', ',\ns = input() + " "\nk = int(input())\nans = []\nfor i in range(len(s)):\n for j in range(i + 1, min(len(s), i + 5 + 1)):\n t = "".join(s[i:j])\n if t not in ans:\n ans.append(t)\n ans = sorted(ans)[:6]\nprint(ans[k - 1])\n', 's = input()\nk = int(input())\nlis = []\n\nfor i in range(len(s)):\n for j in range(k):\n lis.append("".join(s[i:i + j + 1]))\nlis = sorted(list(set(lis)))\n\nprint(lis[k - 1])\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s114865752', 's351379541', 's399815975'] | [9188.0, 8892.0, 11192.0] | [58.0, 23.0, 48.0] | [338, 331, 178] |
p03355 | u452786862 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['# n = int(input())\n# a, b = map(int, input().split())\n# c = list(map(int, input().split()))\n# d = [list(map(int, input().split())) for _ in range(n)]\n\nalphabet = "abcdefghijklnmopqrstuvwxyz"\ns = input()\nk = int(input())\ns_set = set(s)\nans = set()\n\nif k == 1:\n s_set_list = list(s_set)\n s_set_list.sort()\n print(s_set_list[0])\n\nelif k >= 2:\n for c in alphabet:\n for i in range(len(s)):\n if c == s[i]:\n ans.add(c)\n if i == len(s[i]):\n break\n for j in range(i+1, i+k+1):\n if j > len(s):\n break\n ans.add(s[i:j])\n if len(ans) >= k:\n break\n\n\n ans_list = list(ans)\n ans_list.sort()\n print(ans_list)\n print(ans_list[k - 1])', '# n = int(input())\n# a, b = map(int, input().split())\n# c = list(map(int, input().split()))\n# d = [list(map(int, input().split())) for _ in range(n)]\n\nalphabet = "abcdefghijklnmopqrstuvwxyz"\ns = input()\nk = int(input())\ns_set = set(s)\nans = set()\n\nif k == 1:\n s_set_list = list(s_set)\n s_set_list.sort()\n print(s_set_list[0])\n\nelif k >= 2:\n for c in alphabet:\n for i in range(len(s)):\n if c == s[i]:\n ans.add(c)\n if i == len(s):\n break\n for j in range(i+1, i+k+2):\n if j > len(s):\n break\n ans.add(s[i:j])\n if len(ans) > k:\n break\n\n\n ans_list = list(ans)\n ans_list.sort()\n print(ans_list[k - 1])'] | ['Wrong Answer', 'Accepted'] | ['s993052598', 's200757194'] | [3188.0, 3188.0] | [32.0, 45.0] | [800, 776] |
p03355 | u455696302 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["s = list(input())\nk = int(input())\nsub = []\nsub += s[:]\n \nfor j in range(2,K+1):\n charGram = [''.join(s[i:i+j]) for i in range(len(s)-1)]\n sub += charGram\nsub = list(set(sub))\nprint(sorted(sub)[k-1])", "s = list(input())\nk = int(input())\nsub = []\nsub += s[:]\n \nfor j in range(2,k+1):\n charGram = [''.join(s[i:i+j]) for i in range(len(s)-1)]\n sub += charGram\nsub = list(set(sub))\nprint(sorted(sub)[k-1])"] | ['Runtime Error', 'Accepted'] | ['s276181751', 's486053050'] | [3188.0, 5196.0] | [18.0, 35.0] | [205, 205] |
p03355 | u533039576 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nn = int(input())\n\ncand = [s[0]]\nfor i in range(len(s)):\n if s[i] > cand[len(cand)-1]:\n continue\n for j in range(i, len(s)):\n tmp = s[i:j+1]\n #print(i,j, tmp, cand)\n if tmp in cand:\n continue\n cand += [tmp]\n if len(cand) > n:\n cand = sorted(cand)\n cand.pop()\n\n\nprint(cand.pop())\n', 's = str(input())\nn = int(input())\n\nfor i in range(len(s)):\n print(i, s[i])\n\ncand = [str(s[0])]\nfor i in range(len(s)):\n if len(cand) == n and s[i] > cand[-1]:\n continue\n for j in range(i, len(s)):\n tmp = str(s[i:j+1])\n #print(i,j, tmp, cand)\n if tmp in cand:\n continue\n cand += [tmp]\n cand = sorted(cand)\n if len(cand) > n:\n cand.pop()\n\n\nprint(cand.pop())\n', 's = str(input())\nn = int(input())\n\ncand = [str(s[0])]\nfor i in range(len(s)):\n if s[i] > cand[-1]:\n continue\n for j in range(i, len(s)):\n tmp = s[i:j+1]\n #print(i,j, tmp, cand)\n if tmp in cand:\n continue\n cand += [tmp]\n #cand = sorted(cand)\n cand.sort()\n if len(cand) > n:\n cand.pop()\n\n\nprint(cand.pop())\n', 's = input()\nk = int(input())\n\nsubstr = []\nfor n in range(1, k+1):\n for i in range(len(s)-n+1):\n substr.append(s[i:i+n])\n\nsubstr = list(set(substr))\nsubstr.sort()\nprint(substr[k-1])\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s229066722', 's415955041', 's484454504', 's708110851'] | [3060.0, 3444.0, 3060.0, 5084.0] | [2104.0, 2104.0, 2104.0, 33.0] | [376, 436, 389, 191] |
p03355 | u543954314 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nk = int(input())\nsub = set()\nfor i in range(n):\n for j in range(1,k):\n sub.add(s[i:i+j])\nprint(sorted(list(sub))[k-1])', 'n,m = map(int, input().split())\np = list(map(int,input().split()))\nd = [list() for _ in range(n+1)]\ncnt = 0\nfor _ in range(m):\n x,y = map(int, input().split())\n d[x].append(y)\n d[y].append(x)\ngr = [0]*(n+1)\ngr[0] = -1\ngn = 0\nfor x in range(1,n+1):\n if gr[x] == 0:\n gn += 1\n gr[x] = gn\n l = [x]\n while l:\n cur = l.pop()\n for i in d[cur]:\n if i not in l and gr[i] == 0:\n gr[i] = gn\n l.append(i)\nfor i in range(n):\n if gr[i+1] == gr[p[i]]:\n cnt += 1\nprint(cnt)', 's = input()\nk = int(input())\nsub = set()\nfor i in range(len(s)):\n for j in range(1,k+1):\n sub.add(s[i:i+j])\nprint(sorted(list(sub))[k-1])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s540721667', 's726444305', 's407504681'] | [3060.0, 3064.0, 4592.0] | [17.0, 18.0, 35.0] | [134, 512, 141] |
p03355 | u623687794 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nn=int(input())\nlst=[]\nfor i in range(len(s)):\n for j in range(i+1,min(i+n+1,len(s)+1)):\n lst.append(s[i:j])\nsub=set(lst)\nsub.sort()\nprint(sub[n-1])', 's=input()\nn=int(input())\nlst=[]\nfor i in range(len(s)):\n for j in range(i+1,min(i+n+1,len(s)+1)):\n lst.append(s[i:j])\nsub=set(lst)\nsub=sorted(sub)\nprint(sub[n-1])\n'] | ['Runtime Error', 'Accepted'] | ['s944920932', 's270506824'] | [4980.0, 5084.0] | [30.0, 37.0] | [161, 167] |
p03355 | u648881683 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n N, A, B, C, D = LI()\n A -= 1\n B -= 1\n C -= 1\n D -= 1\n S = SS()\n\n \n if '##' in S[A:C+1] or '##' in S[B:D+1]:\n print('No')\n else:\n \n if C < D:\n print('Yes')\n \n else:\n \n if '...' in S[B:D+1]:\n print('Yes')\n else:\n print('No')\n\nif __name__ == '__main__':\n resolve()\n", "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n s = SS()\n K = I()\n\n l = [[] for _ in range(26)]\n for i in range(len(s)):\n l[ord(s[i])-ord('a')].append(i)\n\n for i in l:\n tmp = set()\n for j in i:\n for k in range(5):\n if j + k <= len(s) - 1:\n tmp.add(s[j:j+k+1])\n tmp = list(tmp)\n tmp.sort()\n if len(tmp) >= K:\n print(tmp[K-1])\n break\n else:\n K -= len(tmp)\n\nif __name__ == '__main__':\n resolve()\n"] | ['Runtime Error', 'Accepted'] | ['s308365969', 's195152459'] | [10140.0, 10140.0] | [36.0, 45.0] | [1092, 949] |
p03355 | u651952230 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['S = str(input())\nK = int(input())\n\nsub = set()\nfor i in range(1,min(K, len(S))+1):\n for j in range(len(S)-K+1):\n sub.add(S[j:j+i])\nm=list(sub)\nm.sort()\nprint(m[K-1])', 'S = str(input())\nK = int(input())\n \nsub = set()\nfor i in range(1,min(K, len(S))+1):\n for j in range(len(S)-i+1):\n sub.add(S[j:j+i])\n print(S[j:j+i])\nm=list(sub)\nm.sort()\nprint(m)\nprint(m[K-1])', 'S = str(input())\nK = int(input())\n \nsub = set()\nfor i in range(1,min(K, len(S))+1):\n for j in range(len(S)-i+1):\n sub.add(S[j:j+i])\nm=list(sub)\nm.sort()\nprint(m[K-1])'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s391366381', 's698202971', 's754142065'] | [4464.0, 5096.0, 4464.0] | [33.0, 55.0, 33.0] | [175, 209, 176] |
p03355 | u663710122 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["import heapq\n\nS = input()\nK = int(input())\n\nq = []\n\nfor i in range(len(S)):\n for j in range(i, len(S) + 1):\n heapq.heappush(q, S[i:j])\n\nlast = ''\nprint(q)\nwhile K > 0:\n s = heapq.heappop(q)\n if s != last:\n K -= 1\n last = s\n\nprint(last)\n", "import heapq\n\nS = input()\nK = int(input())\n\nq = []\n\nfor i in range(len(S)):\n for j in range(i, min(len(S), i + K) + 1):\n heapq.heappush(q, S[i:j])\n\nlast = ''\nwhile K > 0:\n s = heapq.heappop(q)\n if s != last:\n K -= 1\n last = s\n\nprint(last)\n"] | ['Wrong Answer', 'Accepted'] | ['s656672326', 's485316650'] | [3188.0, 4552.0] | [2342.0, 46.0] | [266, 269] |
p03355 | u667024514 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nk = str(input())\nlis = []\nans = "zzz"\nli = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nfor k in range(6):\n\tfor i in range(len(s)):\n\t\ttry:\n\t\t\tif s[i:i+k] == "":\n\t\t\t\tcontinue\n\t\t\tif s[i:i+k] not in lis:\n\t\t\t\tlis.append(s[i:i+k])\n\t\texcept:\n\t\t\tcontinue\nlis.sort()\n\nfor i in range(k-1):\n\tlis.remove(lis[0])\n\nprint(lis[0])', 's = str(input())\nk = str(input())\nlis = []\nfor u in range(6):\n\tfor i in range(len(s)):\n\t\ttry:\n\t\t\tif s[i:i+u] == "":\n\t\t\t\tcontinue\n\t\t\tif s[i:i+u] not in lis:\n\t\t\t\tlis.append(s[i:i+u])\n\t\texcept:\n\t\t\tcontinue\nlis.sort()\nprint(lis[k-1])', 's = str(input())\nk = int(input())\nlis = []\nfor u in range(6):\n\tfor i in range(len(s)):\n\t\ttry:\n\t\t\tif s[i:i+u] == "":\n\t\t\t\tcontinue\n\t\t\tif s[i:i+u] not in lis:\n\t\t\t\tlis.append(s[i:i+u])\n\t\texcept:\n\t\t\tcontinue\nlis.sort()\nprint(lis[k-1])\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s360258200', 's972518843', 's568652283'] | [3932.0, 3932.0, 3932.0] | [1530.0, 1531.0, 1794.0] | [393, 229, 230] |
p03355 | u669696235 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nK=int(input())\nl=len(s)\nd=[[s[i],l-i] for i in range(len(s))]\nd=sorted(d)\nh=dict()\nans=0\nca=d[0][0] \n\nfor i in d:\n if(i[0]!=i[0][0]):\n break\n z=min(i[1]+1,6)\n for j in range(1,z):\n if(s[l-i[1]:l-i[1]+j] not in h):\n ans+=1\n h.update({s[l-i[1]:l-i[1]+j]:1})\n else:\n pass\n\n\nh=sorted(h)', 's=input()\nK=int(input())\nl=len(s)\nd=[[s[i],l-i] for i in range(len(s))]\nd=sorted(d)\nh=dict()\nans=0\nca=d[0][0] \n\nfor i in d:\n if(i[0]!=i[0][0]):\n break\n z=min(i[1]+1,6)\n for j in range(1,z):\n if(s[l-i[1]:l-i[1]+j] not in h):\n ans+=1\n h.update({s[l-i[1]:l-i[1]+j]:1})\n else:\n pass\n\n\nh=sorted(h)\nprint(h[K-1])'] | ['Wrong Answer', 'Accepted'] | ['s378409167', 's043186982'] | [5648.0, 5656.0] | [59.0, 54.0] | [357, 371] |
p03355 | u673338219 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nk = int(input())\nsub = []\nc = 5\nif len(s) < 5:\n c = len(s)\nfor i in range(c):\n for j in range(len(s)-i-1):\n sub.append(s[j:j+i+1])\n\nsub = list(set(sub))\nsub.sort()\nprint(sub[k-1])\n', 's = str(input())\nk = int(input())\nsub = []\nc = 5\nif len(s) < 5:\n c = len(s)\nfor i in range(c):\n for j in range(len(s)-i):\n sub.append(s[j:j+i+1])\n\nsub = list(set(sub))\nsub.sort()\nprint(sub[k-1])\n'] | ['Runtime Error', 'Accepted'] | ['s716657199', 's794378631'] | [5084.0, 5068.0] | [34.0, 33.0] | [203, 201] |
p03355 | u723180465 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["s = input().strip()\nk = int(input())\n\nss = set()\nfor i in range(len(s)):\n for j in range(i, len(s)):\n ss.add(s[i:j+1])\n\nprint('test')", 'def all_index(s, c):\n ins = []\n for i in range(len(s)):\n if s[i] == c:\n ins.append(i)\n\n return ins\n\n\ns = input().strip()\nk = int(input())\n\nss = set()\nalphabets = sorted(list(set(s)))\nfor c in alphabets:\n ins = all_index(s, c)\n for i in ins:\n for j in range(i, len(s)):\n if (j+1 - i) > k:\n break\n\n ss.add(s[i:j+1])\n\n if len(ss) >= k:\n break\n\nprint(sorted(list(ss))[k-1])'] | ['Wrong Answer', 'Accepted'] | ['s404716797', 's172795772'] | [1882972.0, 3188.0] | [2217.0, 34.0] | [143, 456] |
p03355 | u733608212 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nK = int(input())\nl = [chr(i) for i in range(97, 97+26)]\nselected = []\nfor i in l:\n if i in s:\n index = []\n for ind, j in enumerate(s):\n if i == j:\n index.append(ind)\n print(index)\n for j in index:\n for k in range(len(s)):\n if j+k == len(s):\n break\n selected.append(s[j:j+k+1])\n selected=list(set(selected))\n selected.sort()\n if len(selected)>=K:\n print(selected[K-1])\n break\n', 's = input()\nK = int(input())\nl = [chr(i) for i in range(97, 97+26)]\nselected = []\nfor i in l:\n if i in s:\n index = []\n for ind, j in enumerate(s):\n if i == j:\n index.append(ind)\n for j in index:\n temp = []\n for k in range(len(s)):\n if j+k == len(s) or len(temp)>=K:\n selected+= temp\n break\n temp.append(s[j:j+k+1])\n selected=list(set(selected))\n selected.sort()\n if len(selected)>=K:\n print(selected[K-1])\n break\n', 's = input()\nK = int(input())\nl = [chr(i) for i in range(97, 97+26)]\nselected = []\nfor i in l:\n if i in s:\n index = []\n for ind, j in enumerate(s):\n if i == j:\n index.append(ind)\n for j in index:\n for k in range(K):\n if j+k == len(s):\n break\n selected.append(s[j:j+k+1])\n selected=list(set(selected))\n selected.sort()\n if len(selected)>=K:\n print(selected[K-1])\n break\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s826536394', 's892157466', 's698741120'] | [935652.0, 4576.0, 4568.0] | [2329.0, 41.0, 33.0] | [459, 496, 437] |
p03355 | u760171369 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["import sys\n\ns = input()\nK = int(input())\n\nchars = sorted(set(s))\nn = len(s)\n\nfor j in range(min(3, len(chars))):\n ans = chars[j]\n K -= 1\n if K == 0:\n print(ans)\n break\n while True:\n places = []\n index = -1\n while True:\n index = s.find(ans, index+1)\n if index == -1:\n break\n places.append(index)\n\n print(places, ans, K)\n if len(ans) == len(s) - places[0]:\n break\n\n next_char = 'z' * 6\n for k in places:\n if k >= len(s)-len(ans):\n break\n next_char = min(next_char, s[k+len(ans)])\n\n ans += next_char\n K -= 1\n if K == 0:\n print(ans)\n sys.exit()", "import sys\n\ns = input()\nK = int(input())\n\nchars = sorted(set(s))\nn = len(s)\n\nfor j in range(min(3, len(chars))):\n ans = chars[j]\n K -= 1\n if K == 0:\n print(ans)\n break\n while True:\n places = []\n index = -1\n while True:\n index = s.find(ans, index+1)\n if index == -1:\n break\n places.append(index)\n \n if len(ans) == len(s) - places[0]:\n break\n\n next_char = 'z' * 6\n for k in places:\n if k >= len(s)-len(ans):\n break\n next_char = min(next_char, s[k+len(ans)])\n\n ans += next_char\n K -= 1\n if K == 0:\n print(ans)\n sys.exit()"] | ['Wrong Answer', 'Accepted'] | ['s100921363', 's131487110'] | [3316.0, 3188.0] | [37.0, 37.0] | [634, 614] |
p03355 | u767664985 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['from collections import Counter\n\ns = input()\nK = int(input())\nc = Counter(s)\n\nkey = sorted(c.keys())\nans = []\nqueue = []\n\nwhile (len(ans) < K):\n if queue:\n queue = sorted(list(set(queue)))\n res = queue.pop(0)\n ans.append(res)\n ans = list(set(ans))\n else:\n c = key.pop(0)\n queue.append(c)\n ind = [i for i in range(len(s)) if s[i] == c]\n for i in ind:\n for j in range(min(5, len(s) - i - 1)):\n queue.append(s[i:i+j+1])\n\nprint(ans[K-1])\n', 'from collections import Counter\n\ns = input()\nK = int(input())\nc = Counter(s)\n\nkey = sorted(c.keys())\nans = []\nqueue = []\n\nwhile (len(ans) < K):\n if queue:\n \n queue = sorted(list(set(queue)))\n res = queue.pop(0)\n ans.append(res)\n ans = list(set(ans))\n else:\n c = key.pop(0)\n #print("pop", c)\n queue.append(c)\n ind = [i for i in range(len(s)) if s[i] == c]\n for i in ind:\n for j in range(min(5, len(s) - i)):\n queue.append(s[i:i+j+1])\n\nprint(ans[K-1])\n', 'from heapq import heappush, heappop\n\ns = input()\nK = int(input())\n\nmin_index = [n for n, v in enumerate(s) if v == min(s)]\n\nans_list = [min(s)]\nqueue = []\ni = 2\n\nwhile len(ans_list) < K:\n \n for m in min_index:\n for i in range(1, 6):\n if m + i < len(s):\n heappush(queue, s[m:m+i])\n while queue:\n c = heappop(queue)\n if c not in ans_list:\n ans_list.append(c)\n\nprint(ans_list[K-1])\n', 'from collections import Counter\n\ns = input()\nK = int(input())\nc = Counter(s)\n\nkey = sorted(c.keys())\nans = []\nqueue = []\n\nwhile (len(ans) < K):\n if queue:\n queue = sorted(list(set(queue)))\n res = queue.pop(0)\n ans.append(res)\n ans = list(set(ans))\n else:\n c = key.pop(0)\n queue.append(c)\n ind = [i for i in range(len(s)) if s[i] == c]\n for i in ind:\n for j in range(len(s) - i - 1):\n queue.append(s[i:i+j+1])\n\nprint(ans[K-1])\n', 'from heapq import heappush, heappop\n\ns = input()\nK = int(input())\n\nmin_index = [n for n, v in enumerate(s) if v == min(s)]\n\nans_list = [min(s)]\nqueue = []\ni = 2\n\nwhile len(ans_list) < K:\n print("hello", i)\n \n for m in min_index:\n for i in range(1, 6):\n if m + i < len(s):\n heappush(queue, s[m:m+i])\n while queue:\n c = heappop(queue)\n if c not in ans_list:\n ans_list.append(c)\n\nprint(ans_list[K-1])\n', 'from collections import Counter\n\ns = input()\nK = int(input())\nc = Counter(s)\n\nkey = sorted(c.keys())\nans = []\nqueue = []\n\nwhile (len(ans) < K):\n if queue:\n queue = sorted(list(set(queue)))\n res = queue.pop(0)\n ans.append(res)\n else:\n c = key.pop(0)\n queue.append(c)\n ind = [i for i in range(len(s)) if s[i] == c]\n for i in ind:\n for j in range(1, len(s) - i - 1):\n queue.append(s[i:i+j+1])\n\nprint(ans[K-1])\n', 'from collections import Counter\n\ns = input()\nK = int(input())\nc = Counter(s)\n\nkey = sorted(c.keys())\nans = []\nqueue = []\n\nwhile (len(ans) < K):\n if queue:\n \n queue = sorted(list(set(queue)))\n res = queue.pop(0)\n ans.append(res)\n ans = list(set(ans))\n else:\n c = key.pop(0)\n #print("pop", c)\n queue.append(c)\n ind = [i for i in range(len(s)) if s[i] == c]\n for i in ind:\n for j in range(min(5, len(s) - i)):\n queue.append(s[i:i+j+1])\n\nprint(sorted(ans)[K-1])\n'] | ['Runtime Error', 'Wrong Answer', 'Time Limit Exceeded', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s152887808', 's265228777', 's391424157', 's505537457', 's848408024', 's865754432', 's205732878'] | [4844.0, 4844.0, 4716.0, 935524.0, 10288.0, 935524.0, 4844.0] | [34.0, 34.0, 2104.0, 2367.0, 2104.0, 3147.0, 34.0] | [522, 570, 463, 514, 485, 488, 578] |
p03355 | u777923818 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['# -*- coding: utf-8 -*-\ndef inpl(): return map(int, input().split())\nN = int(input())\nballs = [input().replace(" ", "") for _ in range(2*N)] + ["END"]\n\nB = ["END"] + ["B{}".format(i) for i in range(1, N+1)[::-1]]\nW = ["END"] + ["W{}".format(i) for i in range(1, N+1)[::-1]]\n\nans = 0\nfor i in range(2*N):\n b = balls.index(B[-1])\n w = balls.index(W[-1])\n if b < w:\n if b != i:\n ans += b-i\n del balls[b]\n balls.insert(i, B[-1])\n B.pop()\n else:\n if w != i:\n ans += w-i\n del balls[w]\n balls.insert(i, W[-1])\n W.pop()\n\nprint(ans)', '# -*- coding: utf-8 -*-\ndef inpl(): return map(int, input().split())\nS = input()\nK = int(input())\nans = set()\n\nfor s in sorted(set(S)):\n if len(ans) >= K:\n break\n for i in range(len(S)):\n if S[i] == s:\n for k in range(K):\n ans.add(S[i:i+k+1])\n\nprint(sorted(ans)[K-1])'] | ['Runtime Error', 'Accepted'] | ['s116651294', 's288498388'] | [3188.0, 3064.0] | [19.0, 29.0] | [629, 313] |
p03355 | u784022244 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['from numba import njit\ns=input()\nK=int(input())\n\nN=len(s)\nL=[]\n@njit\ndef solve():\n for i in range(N):\n for j in range(i,N):\n L.append(s[i:j+1])\nL=sorted(list(set(L)))\nprint(L[K-1])', '\nN=len(s)\nL=[]\nflag=False\nfor a in abc:\n for i in range(N):\n if s[i]==a:\n L.append(s[i:])\n \n if flag:\n break\nL=sorted(L)\n#print(L)\nans=[]\nfor l in L:\n n=len(l)\n for i in range(n):\n t=l[:i+1]\n if t not in ans:\n ans.append(l[:i+1])\n if len(ans)>=K:\n break\n#print(ans)\nprint(ans[K-1])\n\n\n', 's=input()\nK=int(input())\nabc=list("abcdefghijklmnopqrstuvwxyz")\n\nN=len(s)\nL=[]\nflag=False\nfor a in abc:\n for i in range(N):\n if s[i]==a:\n L.append(s[i:])\n \n if flag:\n break\nL=sorted(L)\n#print(L)\nans=[]\nfor l in L:\n n=len(l)\n for i in range(n):\n t=l[:i+1]\n if t not in ans:\n ans.append(l[:i+1])\n if len(ans)>=K:\n break\n#print(ans)\nprint(ans[K-1])\n\n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s481178928', 's752965507', 's157158164'] | [3064.0, 3064.0, 24688.0] | [18.0, 17.0, 195.0] | [201, 367, 431] |
p03355 | u785205215 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['import math\nimport itertools\nfrom heapq import heapify, heappop, heappush\nfrom sys import stdin, stdout, setrecursionlimit\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import defaultdict, deque\n\n\n\n\n# inf = float("inf")\n\n\n\ndef LM(t, r): return list(map(t, r))\ndef R(): return stdin.readline()\ndef RS(): return R().split()\ndef I(): return int(R())\ndef F(): return float(R())\ndef LI(): return LM(int,RS())\ndef LF(): return LM(float,RS())\ndef ONE_SL(): return list(input())\ndef ONE_IL(): return LM(int, ONE_SL())\ndef ALL_IL(): return LM(int,stdin)\n\n##### tools #####\ndef ap(f): return f.append\ndef pll(li): print(\'\\n\'.join(LM(str,li)))\ndef pljoin(li, s): print(s.join(li))\n\n\n##### Library ####\n\n\n\n##### main #####\ndef main():\n input_S = input()\n K = I() - 1\n\n len_S = len(input_S)\n lis = set()\n\n if len_S == 1:\n print(input_S)\n else:\n for i in range(len_S - 1):\n for j in range(len_S - i-1):\n s = input_S[j:j+i+1]\n lis.add(s)\n\n print(sorted(lis)[K])\n\nif __name__ == \'__main__\':\n\tmain()\n\n', 'import math\nimport itertools\nfrom heapq import heapify, heappop, heappush\nfrom sys import stdin, stdout, setrecursionlimit\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import defaultdict, deque\n\n\n\n\n# inf = float("inf")\n\n\n\ndef LM(t, r): return list(map(t, r))\ndef R(): return stdin.readline()\ndef RS(): return R().split()\ndef I(): return int(R())\ndef F(): return float(R())\ndef LI(): return LM(int,RS())\ndef LF(): return LM(float,RS())\ndef ONE_SL(): return list(input())\ndef ONE_IL(): return LM(int, ONE_SL())\ndef ALL_IL(): return LM(int,stdin)\n\n##### tools #####\ndef ap(f): return f.append\ndef pll(li): print(\'\\n\'.join(LM(str,li)))\ndef pljoin(li, s): print(s.join(li))\n\n\n##### Library ####\n\n\n\n##### main #####\ndef main():\n input_S = input()\n K = I() - 1\n\n # input_S = "abcde" * 1000\n # K = 4\n \n len_S = len(input_S)\n lis = set()\n min_s = \'z\'\n if len_S == 1:\n print(input_S)\n\n else:\n for i in range(len_S):\n for j in range(len_S):\n\n if input_S[j] > min_s:\n continue\n \n s = input_S[j:j+i+1]\n lis.add(s)\n\n min_s = sorted(lis)[K]\n\n print(sorted(set(lis))[K])\n\nif __name__ == \'__main__\':\n main()\n\n', 'import sys\nimport math\nimport itertools\nfrom heapq import heapify, heappop, heappush\nfrom sys import stdin, stdout, setrecursionlimit\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import defaultdict, deque\n\n\n\n\n# inf = float("inf")\n\n\n\ndef LM(t, r): return list(map(t, r))\ndef R(): return stdin.readline()\ndef RS(): return R().split()\ndef I(): return int(R())\ndef F(): return float(R())\ndef LI(): return LM(int,RS())\ndef LF(): return LM(float,RS())\ndef ONE_SL(): return list(input())\ndef ONE_IL(): return LM(int, ONE_SL())\ndef ALL_IL(): return LM(int,stdin)\n\n##### tools #####\ndef ap(f): return f.append\ndef pll(li): print(\'\\n\'.join(LM(str,li)))\ndef pljoin(li, s): print(s.join(li))\n\n\n##### Library ####\n\n\n##### main #####\ndef main():\n\n input_S = input()\n K = I() - 1\n\n # input_S = \'abcaa\'\n # K = 2\n\n len_S = len(input_S)\n unique_S = len(set(input_S))\n \n lis = set()\n min_s = \'z\'\n\n if len_S == 1:\n print(input_S)\n\n else:\n for i in range(5):\n for j in range(len_S):\n if input_S[j] > min_s:\n continue\n\n s = input_S[j:j+i+1]\n lis.add(s)\n\n print(sorted(lis)[K])\n\n \nif __name__ == \'__main__\':\n main()\n\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s449292817', 's832327083', 's004615870'] | [1219672.0, 11068.0, 4848.0] | [2175.0, 2104.0, 153.0] | [1158, 1350, 1323] |
p03355 | u803848678 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['def cut_kouho(s, char):\n ret = []\n for i in range(s.count(char)):\n ind = s.find(char)\n ret.append(s[ind:])\n if ind == len(s) -1 :\n break\n s = s[ind+1:]\n print(ret)\n return ret\n\ns = input()\nk = int(input())\n\nif len(s) < 51 and False:\n tmp = []\n for i in range(len(s)):\n for j in range(i,len(s)):\n tmp.append(s[i:j+1])\n a = list(set(tmp))\n a.sort()\n print(a[k-1])\nelse:\n char = list(set(list(s)))\n char.sort()\n #print(char)\n nokori = k\n for c in char:\n kouho = cut_kouho(s, c)\n \n kouho = [i[:min(nokori, len(i))] for i in kouho]\n \n \n tmp = []\n for string in kouho:\n for i in range(len(string)):\n for j in range(i,len(string)):\n tmp.append(string[i:j+1])\n a = list(set(tmp))\n a.sort()\n if len(a) >= nokori:\n print(a[nokori-1])\n exit()\n else:\n nokori -= len(a)\n', 'def cut_kouho(s, char):\n ret = []\n for i in range(s.count(char)):\n ind = s.find(char)\n ret.append(s[ind:])\n if ind == len(s) -1 :\n break\n s = s[ind+1:]\n #print(ret)\n return ret\n\ns = input()\nk = int(input())\n\nif len(s) < 51 and False:\n tmp = []\n for i in range(len(s)):\n for j in range(i,len(s)):\n tmp.append(s[i:j+1])\n a = list(set(tmp))\n a.sort()\n print(a[k-1])\nelse:\n char = list(set(list(s)))\n char.sort()\n #print(char)\n nokori = k\n for c in char:\n kouho = cut_kouho(s, c)\n \n kouho = [i[:min(nokori, len(i))] for i in kouho]\n \n \n tmp = []\n for string in kouho:\n for i in range(len(string)):\n tmp.append(string[:i+1])\n a = list(set(tmp))\n a.sort()\n #print(a)\n if len(a) >= nokori:\n print(a[nokori-1])\n exit()\n else:\n nokori -= len(a)'] | ['Wrong Answer', 'Accepted'] | ['s644565120', 's380418628'] | [52472.0, 16624.0] | [117.0, 36.0] | [1069, 1034] |
p03355 | u808585569 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nK=int(input())\nD=[]\nfor i in range(len(s)):\n for j in range(len(s)-i-1):\n D.append(s[i:i+j+1])\nD = sorted(list(set(D)))\nprint(D[K-1])', 's=input()\nK=int(input())\nD=[]\nfor i in range(len(s)+1):\n for j in range(min(len(s)-i,5)):\n D.append(s[i:i+j+1])\nD = sorted(list(set(D)))\n#print(D)\nprint(D[K-1])'] | ['Runtime Error', 'Accepted'] | ['s904645142', 's748431608'] | [3060.0, 5068.0] | [2598.0, 37.0] | [147, 164] |
p03355 | u814781830 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nK = int(input())\n\nsub = []\nfor i in range(1, len(s)+1):\n for k in range(len(s)-i+1):\n sub.append(s[k:k+i])\n\nsub = list(set(sub))\nsub.sort()\nprint(sub[k-1])\n', 's = input()\nK = int(input())\n\nsub = []\nfor i in range(1, len(s)+1):\n for k in range(len(s)-i+1):\n sub.append(s[k:k+i])\n\nsub = list(set(sub))\nsub.sort()\nprint(sub[k+1])\n', 's = input()\nK = int(input())\n\nsub = []\nfor i in range(1, K+1):\n for k in range(len(s)-i+1):\n sub.append(s[k:k+i])\n\nsub = list(set(sub))\nsub.sort()\nprint(sub[K-1])\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s174100308', 's331981094', 's567559956'] | [3060.0, 2051888.0, 5068.0] | [2272.0, 2284.0, 34.0] | [178, 178, 173] |
p03355 | u814986259 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['import collections\ns = input()\nK = int(input())\n\nabc = collections.defaultdict(list)\n\nfor i in range(len(s)):\n for j in range(1,K+1):\n if i+j < len(s):\n abc[s[i:i+j]].append(i)\n\n\nabc = list(abc.items())\nabc.sort(key=lambda x: x[0])\n\n\nprint(abc[K][0])\n', 'import collections\ns = input()\nK = int(input())\n\nabc = collections.defaultdict(list)\n\nfor i in range(len(s)):\n if i > len(s) - 5:\n abc[s[i:]].append(i)\n else:\n abc[s[i:i+5]].append(i)\n\nabc = list(abc.items())\nabc.sort(key=lambda x: x[0])\n\n\nprint(abc[0][0])\n', 'import collections\ns = input()\nK = int(input())\n\nabc = collections.defaultdict(list)\n\nfor i in range(len(s)):\n for j in range(1,K+1):\n if i+j <= len(s):\n abc[s[i:i+j]].append(i)\n\n\nabc = list(abc.items())\nabc.sort(key=lambda x: x[0])\n\nprint(abc[K-1][0])\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s427131362', 's926907607', 's756905660'] | [7852.0, 4852.0, 7844.0] | [58.0, 29.0, 58.0] | [262, 277, 264] |
p03355 | u859897687 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nk=int(input())\nl=[]\nfor i in range(len(s)-1):\n for j in range(i+1,min(len(s),i+5)):\n if s[i:j] not in l:\n l.append(s[i:j])\nl.sort()\nprint(l[k-1])', 's=input()\nk=int(input())\nl=[]\nfor i in range(len(s)):\n for j in range(i+1,min(len(s),i+k)+1):\n if s[i:j] not in l:\n l.append(s[i:j])\nl.sort()\nprint(l[k-1])\n'] | ['Runtime Error', 'Accepted'] | ['s574463378', 's529426673'] | [3692.0, 3944.0] | [908.0, 1761.0] | [164, 165] |
p03355 | u941407962 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['def sub_k(string, I, K):\n temp = []\n for i in range(len(string)):\n if i-1+I == len(string):\n continue\n temp.append(string[i:i+I])\n return sorted(set(temp))[0:K]\n\ndef main(string, K):\n for i in range(K):\n print(sub_k(string, i+1, K-i))\n\nstring = input()\nK = int(input())\nmain(string, K)', 'def sub_k(string, I, K):\n temp = []\n for i in range(len(string)):\n if i-1+I == len(string):\n continue\n temp.append(string[i:i+I])\n return sorted(set(temp))[0:K]\n\ndef main(string, K):\n for i in range(K):\n print(sub_k(string, i+1, K-i))\n\nstring = input()\nK = input()\nmain(string, K)', 'def sub_k(string, I, K):\n temp = []\n for i in range(len(string)):\n if i-1+I == len(string):\n break\n temp.append(string[i:i+I])\n return sorted(set(temp))[0:K]\n\ndef main(string, K):\n result = []\n for i in range(K):\n result += sub_k(string, i+1, K-i)\n print(sorted(set(result))[K-1])\n\nstring = input()\nK = int(input())\nmain(string, K)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s117614590', 's603625665', 's717019912'] | [3536.0, 3064.0, 3528.0] | [31.0, 17.0, 31.0] | [329, 324, 381] |
p03355 | u941884460 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input().rstrip()\nk = int(input())\nresult = []\nfor i in range(len(s)):\n for j in range(i+1,i+k):\n if i+k <= len(s):\n result.append(s[i:j])\nresult.sort()\nprint(result[k-1])', 's = input().rstrip()\nk = int(input())\nresult = []\nfor i in range(len(s)):\n for j in range(i+1,i+k+1):\n if j <= len(s) and s[i:j] not in result:\n result.append(s[i:j])\nresult.sort()\nprint(result[k-1])'] | ['Runtime Error', 'Accepted'] | ['s756682116', 's564659704'] | [4084.0, 3944.0] | [35.0, 1794.0] | [183, 208] |
p03355 | u944209426 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["s = input()\nk = int(input())\n\nx = ['a', 'b', 'ab', 'ba', 'aba']\na=[]\nm = min(s)\nfor i in range(len(s)):\n a.append(s[i])\n if s[i]==m:\n a.append(s[i:min(len(s)-1,i+2)])\n a.append(s[i:min(len(s)-1,i+3)])\n a.append(s[i:min(len(s)-1,i+4)])\n a.append(s[i:min(len(s)-1,i+5)])\na=list(set(a))\na.sort()\nif a[0]=='':\n a=a[1:]\nprint(a[k-1])", "s = input()\nk = int(input())\n\nx = ['a', 'b', 'ab', 'ba', 'aba']\na=[]\nm = min(s)\nfor i in range(len(s)):\n a.append(s[i])\n a.append(s[i:min(len(s),i+2)])\n a.append(s[i:min(len(s),i+3)])\n a.append(s[i:min(len(s),i+4)])\n a.append(s[i:min(len(s),i+5)])\na=list(set(a))\na.sort()\nif a[0]=='':\n a=a[1:]\nprint(a[k-1])"] | ['Runtime Error', 'Accepted'] | ['s297270337', 's709074893'] | [4324.0, 5052.0] | [31.0, 39.0] | [365, 325] |
p03355 | u987164499 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['from sys import stdin\nfrom sys import setrecursionlimit\nsetrecursionlimit(10 ** 7)\n\ns = stdin.readline().rstrip()\nk = int(stdin.readline().rstrip())\n\n\nfinish = set()\nS = len(s)\n\nfor i in range(S):\n for j in range(1,6):\n finish.add(s[i:i+j])\n\nfinish = list(finish)\n\nprint(finish[k-1])', 's = input()\nS = len(s)\nk = int(input())\n\nse = set()\n\ndef string(now,num):\n if now+num == s or num == k:\n return\n se.add(s[now:now+num+1])\n num += 1\n return string(now,num)\n\nfor i in range(S):\n string(i,0)\n\nse = list(se)\nse.sort()\n\nprint(se[k-1])'] | ['Wrong Answer', 'Accepted'] | ['s482495388', 's030575705'] | [4464.0, 4464.0] | [29.0, 39.0] | [293, 267] |
p03356 | u023229441 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ["from subprocess import*\ncall(('pypy3','-c',))\n", 'n,m=map(int,input().split())\nP=[i-1 for i in list(map(int,input().split()))]\n\nclass UnionFind():\n def __init__(self,num):\n self.n = num \n self.parents = [-1 for i in range(self.n)]\n \n\n \n def find(self,x):\n if self.parents[x]<0:\n return x\n else:\n self.parents[x]=self.find(self.parents[x]) \n \n return self.parents[x]\n\n \n \n def union(self,x,y):\n xx=self.find(x) \n yy=self.find(y) \n if xx==yy:\n return \n else:\n size_xx=abs(self.parents[xx]) \n size_yy=abs(self.parents[yy]) \n if size_xx>size_yy:\n xx,yy=yy,xx \n\n self.parents[yy]+=self.parents[xx] \n self.parents[xx]=yy \n\n \n def size(self,x):\n xx=self.find(x)\n return abs(self.parents[xx])\n\n \n def same(self,x,y):\n return 1 if self.find(x)==self.find(y) else 0\n\n \n def members(self,x):\n xx=self.find(x)\n return [i for i in range(self.n) if self.find(i)==xx]\n \n\n \n def roots(self):\n return [i for i,x in enumerate(self.parents) if x < 0]\n \n\n \n def all_group_members(self):\n return {r:self.members(r) for r in self.roots()}\n\n \n def state_grouping(self):\n return list(self.all_group_members().values())\n\n\nuf=UnionFind(n)\nfor i in range(m):\n a,b=map(int,input().split())\n a-=1;b-=1\n uf.union(a,b)\nans=0\nfor i in range(n):\n ans+= uf.same(i,P[i])\nprint(ans)'] | ['Time Limit Exceeded', 'Accepted'] | ['s240548938', 's462510086'] | [154516.0, 20416.0] | [2206.0, 435.0] | [3126, 2689] |
p03356 | u094191970 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['from sys import stdin\nnii=lambda:map(int,stdin.readline().split())\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\nn,m=nii()\np=list(nii())\n\nuf=UnionFind(n+1)\n\nfor i in range(m):\n x,y=nii()\n uf.union(x,y)\n\ncnt=0\nfor i in range(n):\n if not uf.same(i,p[i]):\n cnt+=1\n\nprint(n-cnt)', 'from sys import stdin\nnii=lambda:map(int,stdin.readline().split())\n\nclass UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\nn,m=nii()\np=list(nii())\n\nuf=UnionFind(n)\n\nfor i in range(m):\n x,y=nii()\n x-=1\n y-=1\n uf.union(x,y)\n\ncnt=0\nfor i in range(n):\n if not uf.same(i,p[i]-1):\n cnt+=1\n\nprint(n-cnt)'] | ['Wrong Answer', 'Accepted'] | ['s409317655', 's902887388'] | [13876.0, 14516.0] | [485.0, 493.0] | [765, 779] |
p03356 | u106778233 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ["\nn,m=map(int,input().split())\nroot=[i for i in range(n+1)]\nrank=[0]*(n+1)\ndef find(x):\n if x==root(x):\n return x \n else:\n return find(root[x])\n\ndef union(x,y):\n x=find(x)\n y=find(y)\n if rank[x]>rank[y]:\n root[y]=x \n else rank[x]<rank[y]:\n root[x]=y\n if rank[x]==rank[y]:\n rank[y]+=1\ndef k_sub():\n \n p=list(map(int,input().split()))\n p=[-1]+p \n for _ in range(m):\n x,y=map(int,input().split())\n union(x,y)\n d=[[] for i in range(n+1)]\n u=[[] for i in range(n+1)]\n for i in range(1,n+1):\n d[find[i]].append(i)\n u[find[i]].append(p[i])\n cnt=0\n for i in range(n):\n for candidate in d[i]:\n if candidate in u[i]:\n cnt+=1\n print(cnt)\nif __name__=='__main__':\n k_sub()\n ", "n,m=map(int,input().split())\np=list(map(int,input().split()))\nuf={i:i for i in range(1,n+1)}\ndef get_p(i):\n lst=[]\n while uf[i]!=i:\n lst.append(i)\n i=uf[i]\n for l in lst[:-1]:\n uf[l]=i \n return i \n\ndef unite(i,j):\n uf[get_p(i)]=get_p(j)\ndef same(i,j):\n return get_p(i)==get_p(j)\n\ndef main():\n for i in range(m):\n x,y=map(int,input().split())\n unite(x,y)\n cnt=0\n for i in range(1,n+1):\n cnt+=same(p[i-1],uf[i])\n print(cnt) \nif __name__=='__main__':\n main() "] | ['Runtime Error', 'Accepted'] | ['s773779095', 's121454950'] | [2940.0, 20704.0] | [17.0, 725.0] | [822, 535] |
p03356 | u218843509 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['class UnionFind():\n\tdef __init__(self, size):\n\t\tself.table = [-1 for _ in range(size)]\n\n\tdef find(self, x):\n\t\twhile self.table[x] >= 0:\n\t\t\tx = self.table[x]\n\t\treturn x\n\n\tdef union(self, x, y):\n\t\ts1 = self.find(x)\n\t\ts2 = self.find(y)\n\t\tif s1 == s2:\n\t\t\treturn\n\t\telif:\n\t\t\tif self.table[s1] > self.table[s2]:\n\t\t\t\tself.table[s2] = s1\n\t\t\telif self.table[s1] < self.table[s2]:\n\t\t\t\tself.table[s1] = s2\n\t\t\telse:\n\t\t\t\tself.table[s1] = s2\n\t\t\t\tself.table[s2] -= 1\n\n\nn, m = map(int, input().split())\np = list(map(int, input().split()))\n\nuf = UnionFind(n)\n\nfor i in range(m):\n\tx, y = map(int, input().split())\n\tuf.union(x - 1, y - 1)\n\nans = 0\nfor i, pp in enumerate(p):\n\tif pp - 1 == i:\n\t\tans += 1\n\telif uf.find(pp - 1) == uf.find(i):\n\t\tans += 1\n\nprint(ans)', 'class UnionFind():\n\tdef __init__(self, size):\n\t\tself.table = [-1 for _ in range(size)]\n\n\tdef find(self, x):\n\t\tif self.table[x] < 0:\n\t\t\treturn x\n\t\telse:\n\t\t\tself.table[x] = self.find(self.table[x]) \n\t\t\treturn self.table[x]\n\n\tdef union(self, x, y):\n\t\ts1 = self.find(x)\n\t\ts2 = self.find(y)\n\t\tif s1 == s2:\n\t\t\treturn\n\t\telse:\n\t\t\tst1 = self.table[s1]\n\t\t\tst2 = self.table[s2]\n\t\t\tif st1 > st2:\n\t\t\t\tself.table[s2] = s1\n\t\t\telif st1 < st2:\n\t\t\t\tself.table[s1] = s2\n\t\t\telse:\n\t\t\t\tself.table[s1] = s2\n\t\t\t\tself.table[s2] -= 1\n\n\nn, m = map(int, input().split())\np = list(map(int, input().split()))\n\nuf = UnionFind(n)\n\nfor i in range(m):\n\tx, y = map(int, input().split())\n\tuf.union(x - 1, y - 1)\n\nans = 0\nfor i, pp in enumerate(p):\n\tif pp - 1 == i:\n\t\tans += 1\n\telif uf.find(pp - 1) == uf.find(i):\n\t\tans += 1\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s305666754', 's985879822'] | [2940.0, 13812.0] | [17.0, 720.0] | [742, 830] |
p03356 | u348868667 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ["class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return '\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nN,M = map(int,input().split())\np = list(map(lambda x : int(x)-1,input().split()))\ncount = 0\nuf = UnionFind(N)\nfor _ in range(M):\n i,j = map(lambda x : int(x)-1,input().split())\n uf.union(i,j)\ndic = uf.all_group_members()\nprint(dic)\nfor i in range(N):\n if uf.same(p[i],i):\n count += 1\nprint(count)", 'class UnionFind():\n def __init__(self, x):\n self.x=x\n self.root=[-1]*(N+1)\n self.rnk=[0]*(N+1)\n \n def Find_root(self, x):\n if self.root[x]<0:\n return x\n else:\n self.root[x]=self.Find_root(self.root[x])\n return self.root[x]\n \n def Unite(self, x, y):\n x = self.Find_root(x)\n y = self.Find_root(y)\n if x==y:\n return\n elif self.rnk[x]>self.rnk[y]:\n self.root[x] += self.root[y]\n self.root[y] = x\n else:\n self.root[y] += self.root[x]\n self.root[x] = y\n if self.rnk[x]==self.rnk[y]:\n self.rnk[y]+=1\n \n def isSameGroup(self, x, y):\n return self.Find_root(x)==self.Find_root(y)\n \n def Count(self, x):\n return -self.root[self.Find_root(x)]\n\nN,M = map(int,input().split())\np = list(map(lambda x : int(x)-1,input().split()))\ncount = 0\nuf = UnionFind(N)\nfor _ in range(M):\n i,j = map(lambda x : int(x)-1,input().split())\n uf.Unite(i,j)\nfor i in range(N):\n if uf.isSameGroup(p[i],i):\n count += 1\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s084260141', 's345620739'] | [14308.0, 13812.0] | [2104.0, 725.0] | [1459, 1010] |
p03356 | u367130284 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['class UNION_FIND(object):\n def __init__(self,n):\n \n \n \n self.parent=[-1 for i in range(n)]\n \n def root(self,x):\n \n if self.parent[x]<0:\n return x\n else:\n self.parent[x]=self.root(self.parent[x]) \n return self.parent[x]\n \n def size(self,x):\n \n return -self.parent[self.root(x)] \n \n def union(self,x,y):\n \n \n #print(self.parent)\n x=self.root(x)\n y=self.root(y)\n #print(x,y)\n if x==y: \n return False\n \n \n \n if self.size(x)<self.size(y):\n x,y=y,x\n self.parent[x]+=self.parent[y] \n self.parent[y]=x \n return True\n\n\na,b=map(int,input().split())\n*p,=map(int,input().split())\nu=UNION_FIND(a)\nd=defaultdict(list)\n\np=array(p)\nfor i in range(b):\n x,y=map(int,input().split())\n u.union(x-1,y-1)\nfor i in range(a):\n ans+=(u.root(i)==u.root(p[i]))\nprint(ans)\n', 'class UNION_FIND(object):\n def __init__(self,n):\n \n \n \n self.parent=[-1 for i in range(n)]\n \n def root(self,x):\n \n if self.parent[x]<0:\n return x\n else:\n self.parent[x]=self.root(self.parent[x]) \n return self.parent[x]\n \n def size(self,x):\n \n return -self.parent[self.root(x)] \n \n def union(self,x,y):\n \n \n #print(self.parent)\n x=self.root(x)\n y=self.root(y)\n #print(x,y)\n if x==y: \n return False\n \n \n \n if self.size(x)<self.size(y):\n x,y=y,x\n self.parent[x]+=self.parent[y] \n self.parent[y]=x \n return True\n\n\na,b=map(int,input().split())\n*p,=map(int,input().split())\nu=UNION_FIND(a)\n\nfor i in range(b):\n x,y=map(int,input().split())\n u.union(x-1,y-1)\nans=0\nfor i in range(a):\n ans+=(u.root(i)==u.root(p[i]-1))\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s000610698', 's383450962'] | [14320.0, 13812.0] | [45.0, 722.0] | [1697, 1674] |
p03356 | u371787528 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['n, m = map(int, input().split())\np = list(map(int, input().split()))\n\npar = {x:x for x in range(1, n+1)}\n\ndef root(node):\n if par[node] == node:\n return node\n par[node] = root(par[node])\n return par[node]\n\nfor _ in range(m):\n x, y = map(int, input().split())\n par[root[x]] = root[y]\n \nans = 0\nfor i in range(1, n+1):\n if root[i] == root(p[i]):\n ans += 1\n\nprint(ans)\n ', 'n, m = map(int, input().split())\np = list(map(int, input().split()))\n\npar = {x:x for x in range(1, n+1)}\n\ndef root(node):\n if par[node] == node:\n return node\n par[node] = root(par[node])\n return par[node]\n\nfor _ in range(m):\n x, y = map(int, input().split())\n par[root[x]] = root[y]\n \nans = 0\nfor i in range(1, n+1):\n if root[i] == root(p[i-1]):\n ans += 1\n\nprint(ans)', 'n, m = map(int, input().split())\np = list(map(int, input().split()))\n\npar = {x:x for x in range(1, n+1)}\n\ndef root(node):\n if par[node] == node:\n return node\n par[node] = root(par[node])\n return par[node]\n\nfor _ in range(m):\n x, y = map(int, input().split())\n par[root(x)] = root(y)\n \nans = 0\nfor i in range(1, n+1):\n if root(i) == root(p[i-1]):\n ans += 1\n\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s024910191', 's546412298', 's518407809'] | [20704.0, 20704.0, 20704.0] | [52.0, 52.0, 668.0] | [406, 403, 403] |
p03356 | u379692329 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0]*n\n \n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n \n def union(self, x, y):\n x = self.find[x]\n y = self.find[y]\n \n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n \n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n\nN, M = map(int, input().split())\np = [0] + [int(_) for _ in input().split()]\npair = [[int(_) for _ in input().split()] for _ in range(M)]\nuf = UnionFind(N+1)\nans = 0\n\nfor i in pair:\n uf.union(i[0], i[1])\n\nfor i in range(1, N+1):\n if uf.find(i) == uf.find(p[i]):\n ans += 1\n\nprint(ans)', 'class UnionFind:\n def __init__(self, n):\n self.par = [i for i in range(n)]\n self.rank = [0]*n\n \n def find(self, x):\n if self.par[x] == x:\n return x\n else:\n self.par[x] = self.find(self.par[x])\n return self.par[x]\n \n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n \n if self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n \n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n \n def same_check(self, x, y):\n return self.find(x) == self.find(y)\n\n\nN, M = map(int, input().split())\np = [0] + [int(_) for _ in input().split()]\npair = [[int(_) for _ in input().split()] for _ in range(M)]\nuf = UnionFind(N+1)\nans = 0\n\nfor i in pair:\n uf.union(i[0], i[1])\n\nfor i in range(1, N+1):\n if uf.find(i) == uf.find(p[i]):\n ans += 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s146670571', 's671859468'] | [30216.0, 30176.0] | [349.0, 681.0] | [943, 943] |
p03356 | u497046426 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ["class UnionFind:\n def __init__(self, N):\n # negative value: represents the root of a tree; its absolute value is the size of the tree\n # positive value: the parent's index\n self.vertices = [-1 for _ in range(N)]\n self.rank = [0] * N\n \n def find(self, v):\n if self.vertices[v] < 0: # v is a root\n return v\n else:\n # path compression: reconnect v to the root\n self.vertices[v] = self.find(self.vertices[v])\n return self.vertices[v]\n \n def union(self, u, v):\n s1 = self.find(u) # the root of the tree including vertex u\n s2 = self.find(v) # the root of the tree including vertex v\n \n if s1 == s2: # u and v is in the same tree\n return False\n \n if self.rank[s1] > self.rank[s2]: # the tree including u is taller\n self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree\n self.vertices[s2] = s1\n else: # the tree including v is taller\n self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree\n self.vertices[s1] = s2\n if self.rank[s1] == self.rank[s2]:\n self.rank[s2] += 1\n return True\n \n def is_connected(self, u, v):\n return self.find(u) == self.find(v)\n \n def size(self, v):\n return -self.vertices[self.find(v)]\n\nN, M = map(int, input().split())\nP = list(map(int, input().split()))\nuf = UnionFind(N)\nfor _ in range(M):\n x, y = map(int, input().split())\n uf.union(x, y)\nans = 0\nfor i in range(N):\n if uf.is_connected(i, P[i]-1):\n ans += 1\nprint(ans)", "class UnionFind:\n def __init__(self, N):\n # negative value: represents the root of a tree; its absolute value is the size of the tree\n # positive value: the parent's index\n self.vertices = [-1 for _ in range(N)]\n self.rank = [0] * N\n \n def find(self, v):\n if self.vertices[v] < 0: # v is a root\n return v\n else:\n # path compression: reconnect v to the root\n self.vertices[v] = self.find(self.vertices[v])\n return self.vertices[v]\n \n def union(self, u, v):\n s1 = self.find(u) # the root of the tree including vertex u\n s2 = self.find(v) # the root of the tree including vertex v\n \n if s1 == s2: # u and v is in the same tree\n return False\n \n if self.rank[s1] > self.rank[s2]: # the tree including u is taller\n self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree\n self.vertices[s2] = s1\n else: # the tree including v is taller\n self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree\n self.vertices[s1] = s2\n if self.rank[s1] == self.rank[s2]:\n self.rank[s2] += 1\n return True\n \n def is_connected(self, u, v):\n return self.find(u) == self.find(v)\n \n def size(self, v):\n return -self.vertices[self.find(v)]\n\nN, M = map(int, input().split())\nP = list(map(int, input().split()))\nuf = UnionFind(N)\nfor _ in range(M):\n x, y = map(int, input().split())\n uf.union(x-1, y-1)\nans = 0\nfor i in range(N):\n if uf.is_connected(i, P[i]-1):\n ans += 1\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s518853951', 's462235833'] | [14452.0, 13812.0] | [511.0, 677.0] | [1676, 1680] |
p03356 | u572142121 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['N,M=map(int, input().split()) \nP=list(map(int,input().split()))\npar=[i for i in range(N+1)]\nrank=[0]*(N+1)\n\n\ndef find(x):\n if par[x]==x:\n return x\n else:\n par[x]==find(par[x])\n return par[x]\n\n\ndef same(x,y):\n return find(x)==find(y)\n\ndef union(x,y):\n x=find(x)\n y=find(y)\n if x==y:\n return 0\n if rank[x]<rank[y]:\n par[x]=y\n else:\n par[y]=x\n if rank[x]==rank[y]:\n rank[x]+=1\n\nfor i in range(M):\n a,b=map(int,input().split())\n union(a,b)\n\n\nprint(par)\nprint(rank) \n \nans=0\nfor i in range(1,N+1):\n print(i,P[i-1])\n if same(P[i-1],i):\n ans+=1\nprint(ans)', 'N,M=map(int, input().split()) \nP=list(map(int,input().split()))\npar=[i for i in range(N+1)]\nrank=[0]*(N+1)\n\ndef find(x):\n if x==par[x]:\n return x\n else:\n par[x]=find(par[x])\n return par[x]\n \ndef find(x):\n if x == par[x]:\n return x\n par[x] = find(par[x])\n return par[x]\n \n\ndef same(x,y):\n return find(x)==find(y)\n\ndef union(x,y):\n x=find(x)\n y=find(y)\n if x==y:\n return 0\n if rank[x]<rank[y]:\n par[x]=y\n else:\n par[y]=x\n if rank[x]==rank[y]:\n rank[x]+=1\n\nfor i in range(M):\n a,b=map(int,input().split())\n union(a,b)\n\nans=0\nfor i in range(1,N+1):\n if same(P[i-1],i):\n ans+=1\nprint(ans)\n '] | ['Runtime Error', 'Accepted'] | ['s966338545', 's900119937'] | [15844.0, 13812.0] | [829.0, 548.0] | [629, 669] |
p03356 | u704284486 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['from sys import stdin\nfrom collections import defaultdict\nimport heapq\nclass UnionFind:\n def __init__(self,n):\n self.parent = [i for i in range(n)]\n self.rank = [0]*n\n self.n = n\n def find(self,x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x == y:return\n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n else:\n self.parent[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self,x,y):\n return bool(self.find(x)==self.find(y))\n\n def allset(self):\n d = defaultdict(list)\n for i in range(self.n):\n d[self.find(i)] += [i]\n t = list(d.keys())\n for i in t:\n heapq.heapify(d[i])\n return d\n\ndef main():\n N,M = map(int,stdin.readline().split())\n uf = UnionFind(N)\n p = list(map(int,stdin.readline().split()))\n ans = 0\n for _ in range(M):\n x,y = map(int,stdin.readline().split())\n x -= 1\n y -= 1\n uf.union(x,y)\n d = uf.allset()\n for i in range(N):\n p[i] -= 1\n for i in range(N):\n tmp = p[i]\n r = uf.find(tmp)\n if uf.same(r,i):\n pre = int(p[i])\n new = heapq.heappop(d[r])\n swap = p.index(new)\n p[i] = new\n p[swap] = pre\n for i in range(N):\n if p[i] == i:ans += 1\n print(ans)\nif __name__ == "__main__":\n main()', 'from sys import stdin\nclass UnionFind:\n def __init__(self,n):\n self.parent = [i for i in range(n)]\n self.rank = [0]*n\n self.n = n\n def find(self,x):\n if self.parent[x] == x:\n return x\n else:\n self.parent[x] = self.find(self.parent[x])\n return self.parent[x]\n def union(self,x,y):\n x = self.find(x)\n y = self.find(y)\n if x == y:return\n if self.rank[x] < self.rank[y]:\n self.parent[x] = y\n else:\n self.parent[y] = x\n if self.rank[x] == self.rank[y]:\n self.rank[x] += 1\n def same(self,x,y):\n return bool(self.find(x)==self.find(y))\n\ndef main():\n N,M = map(int,stdin.readline().split())\n uf = UnionFind(N)\n p = list(map(int,stdin.readline().split()))\n ans = 0\n for _ in range(M):\n x,y = map(int,stdin.readline().split())\n x -= 1\n y -= 1\n uf.union(x,y)\n for i in range(N):\n tmp = p[i]-1\n if not uf.same(tmp,i):continue\n else:ans += 1\n print(ans)\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s688275176', 's094356976'] | [33724.0, 18544.0] | [2104.0, 522.0] | [1631, 1118] |
p03356 | u747703115 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['import sys\nreadline = sys.stdin.readline\n\nclass UnionFind(object):\n def __init__(self, n):\n self._par = list(range(n))\n self.size = [1]*n\n\n def root(self, v):\n if self._par[v] == v:\n return v\n self._par[v] = self.root(self._par[v])\n return self._par[v]\n \n def unite(self, u, v):\n u, v = self.root(u), self.root(v)\n if u==v:\n return False\n if self.size[u] > self.size[v]:\n u, v = v, u\n self.size[v] += self.size[u]\n self._par[u] = v\n\n def is_connected(self, u, v):\n return self.root(u)==self.root(v)\n\nn, m = map(int, readline().split())\nP = list(map(lambda x:int(x)-1, readline().split()))\nuf = UnionFind(n)\nfor _ in range(m):\n x, y = map(lambda x:int(x)-1, readline().split())\n uf,unite(x,y)\n\nans = 0\nfor i in range(n):\n if uf.is_connected(i, p[i]):\n ans += 1\nprint(ans)', 'import sys\nfrom collections import deque\nreadline = sys.stdin.readline\nn, m = map(int, readline().split())\nP = list(map(lambda x:int(x)-1, readline().split()))\nG = [set() for _ in range(n)]\nfor i in range(m):\n x, y = map(lambda x:int(x)-1, readline().split())\n G[x].add(y)\n G[y].add(x)\n\nD = {}\ncnt = 0\nV = [-1]*n\nfor i in range(n):\n if V[i]!=-1: continue\n V[i] = cnt\n que = deque([i])\n D[cnt] = set([P[i]])\n while que:\n nw = que.popleft()\n for nx in G[nw]:\n if V[nx] != -1: continue\n D[cnt].add(P[nx])\n V[nx] = cnt\n que.append(nx)\n cnt += 1\nprint(sum([int(i in D[V[i]]) for i in range(n)]))'] | ['Runtime Error', 'Accepted'] | ['s243028433', 's683588428'] | [20332.0, 89772.0] | [58.0, 483.0] | [911, 675] |
p03356 | u762540523 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ["class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return r'\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nn,m=map(int,input().split())\nu=UnionFind(n)\nans=0\np=list(map(lambda x:int(x-1),input().split()))\nfor i in range(m):\n a,b=map(lambda x:x-1,map(int,input().split()))\n u.union(a,b)\nfor i in range(n):\n if u.same(i,p[i]):\n ans+=1\nprint(ans)", "class UnionFind():\n def __init__(self, n):\n self.n = n\n self.parents = [-1] * n\n\n def find(self, x):\n if self.parents[x] < 0:\n return x\n else:\n self.parents[x] = self.find(self.parents[x])\n return self.parents[x]\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n\n if x == y:\n return\n\n if self.parents[x] > self.parents[y]:\n x, y = y, x\n\n self.parents[x] += self.parents[y]\n self.parents[y] = x\n\n def size(self, x):\n return -self.parents[self.find(x)]\n\n def same(self, x, y):\n return self.find(x) == self.find(y)\n\n def members(self, x):\n root = self.find(x)\n return [i for i in range(self.n) if self.find(i) == root]\n\n def roots(self):\n return [i for i, x in enumerate(self.parents) if x < 0]\n\n def group_count(self):\n return len(self.roots())\n\n def all_group_members(self):\n return {r: self.members(r) for r in self.roots()}\n\n def __str__(self):\n return r'\\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())\n\nn,m=map(int,input().split())\nu=UnionFind(n)\nans=0\np=list(map(lambda x:int(x)-1,input().split()))\nfor i in range(m):\n a,b=map(lambda x:x-1,map(int,input().split()))\n u.union(a,b)\nfor i in range(n):\n if u.same(i,p[i]):\n ans+=1\nprint(ans)\n"] | ['Runtime Error', 'Accepted'] | ['s138240476', 's259482710'] | [11316.0, 14708.0] | [27.0, 737.0] | [1389, 1390] |
p03356 | u763115743 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['group_id = 0\ngroups = []\n\ndef solve(graphs, ps):\n global group_id, groups\n groups = [-1] * (len(ps) + 1)\n\n for key in range(1, len(ps) + 1):\n if key < len(graphs) and groups[key] == -1:\n group_id += 1\n dfs(graphs, key)\n\n ans = 0\n for key, value in enumerate(ps, 1):\n if key < len(groups) and value < len(groups) and groups[key] == groups[value]:\n ans += 1\n return ans\n\ndef dfs(graphs, key):\n if key >= len(groups):\n return\n\n global groups\n groups[key] = group_id\n\n for graph_key in graphs[key]:\n if graph_key < len(groups) and groups[graph_key] == -1:\n dfs(graphs, graph_key)\n\ndef main():\n n, m = map(int, input().split())\n ps = list(map(int, input().split()))\n\n \n graphs = [[] for i in range(n + 1)]\n for i in range(m):\n x, y = map(int, input().split())\n graphs[x].append(y)\n graphs[y].append(x)\n\n ans = solve(graphs, ps)\n print(ans)\n\nif __name__ == "__main__":\n main()\n', 'class UnionFind:\n def __init__(self, size):\n self.parent = list(range(size))\n self.rank = [0] * size\n\n def root(self, x):\n if self.parent[x] != x:\n self.parent[x] = self.root(self.parent[x])\n return self.parent[x]\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n\n if x == y:\n return\n\n if self.rank[x] > self.rank[y]:\n self.parent[y] = x\n else:\n self.parent[x] = y\n if self.rank[x] == self.rank[y]:\n self.rank[y] += 1\n\n def same(self, x, y):\n return self.root(x) == self.root(y)\n\n\ndef main():\n n, m = map(int, input().split())\n ps = list(map(int, input().split()))\n\n # 1-origin\n union_find = UnionFind(n + 1)\n for i in range(m):\n x, y = map(int, input().split())\n union_find.unite(x, y)\n\n ans = 0\n for key, value in enumerate(ps, 1):\n if union_find.same(key, value):\n ans += 1\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s759392275', 's602353292'] | [26832.0, 13876.0] | [423.0, 660.0] | [1048, 1049] |
p03356 | u801476312 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['\n\nclass Board:\n\n \n \n \n h = {}\n m = {}\n\n island = 0 \n\n \n def add(self, h, new_item):\n self.h[new_item] = h\n\n \n def merge(self, h1, h2):\n self.m[h2] = self.m[h1]\n\n \n def new_pair(self, x, y):\n new_h = len(self.m) + 1\n self.island += 1\n\n self.h[x] = new_h\n self.h[y] = new_h\n self.m[new_h] = self.island\n\n \n def add_pair(self, x, y):\n \n if x in self.h:\n h_x = self.h[x]\n if y in self.h:\n h_y = self.h[y]\n if self.m[h_x] == self.m[h_y]:\n pass\n else:\n self.merge(h_x, h_y)\n else:\n self.add(h_x, y)\n else:\n if y in self.h:\n self.add(self.h[y], x)\n else:\n self.new_pair(x, y)\n\n \n def movable(self, i, j):\n return i == j \\\n or (i in self.h and j in self.h and self.m[self.h[i]] == self.m[self.h[j]])\n\n def equals(self, *tips):\n result = 0\n\n for i, x in enumerate(tips):\n if self.movable(i, x):\n result += 1\n\n return result\n\n\ndef main():\n n, m = map(int, input().split())\n tips = map(int, input().split())\n board = Board()\n for i in range(m):\n pair = map(int, input().split())\n board.add_pair(*pair)\n print("{0:d}".format(board.equals(*tips)))\n\n\nmain()\n', 'class Elements:\n s = set()\n\n def __init__(self, *elements):\n self.s = set(elements)\n\n def add(self, x):\n self.s.add(x)\n\n def remove(self, x):\n self.s.remove(x)\n\n def union(self, e):\n self.s |= e.s\n\n\nclass Hoge:\n h = {}\n elements_set = set()\n\n def add(self, at, new_item):\n self.h[at].add(new_item)\n self.h[new_item] = self.h[at]\n\n def union(self, x, y):\n if len(self.h[y].s) > len(self.h[x].s):\n x, y = y, x\n\n self.h[x].union(self.h[y])\n self.elements_set.remove(self.h[y])\n for i in self.h[y].s:\n self.h[i] = self.h[x]\n\n def new_pair(self, x, y):\n u = Elements(x, y)\n self.h[x] = u\n self.h[y] = u\n self.elements_set.add(u)\n\n def add_pair(self, x, y):\n if x in self.h:\n if y in self.h:\n if self.h[x] is self.h[y]:\n pass\n else:\n self.union(x, y)\n else:\n self.add(x, y)\n else:\n if y in self.h:\n self.add(y, x)\n else:\n self.new_pair(x, y)\n\n def equals(self, *l):\n result = 0\n\n \n for i, x in enumerate(l):\n if i == x and x not in self.h:\n result += 1\n\n \n for es in self.elements_set:\n s = es.s\n for x in s:\n if l[x] in s:\n result += 1\n\n return result\n\n\ndef main():\n n, m = map(int, input().split())\n l = map(lambda s: int(s)-1, input().split())\n hoge = Hoge()\n for i in range(1, m + 1):\n pair = map(lambda s: int(s)-1, input().split())\n hoge.add_pair(*pair)\n print("{0:d}".format(hoge.equals(*l)))\n\n\nmain()\n'] | ['Wrong Answer', 'Accepted'] | ['s577018766', 's274890579'] | [26448.0, 42544.0] | [585.0, 858.0] | [1955, 1908] |
p03356 | u860002137 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['class UnionFind:\n def __init__(self, n):\n self.root = list(range(n + 1))\n self.size = [1] * (n + 1)\n\n def find(self, x):\n root = self.root\n while root[x] != x:\n root[x] = root[root[x]]\n x = root[x]\n return x\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n sx, sy = self.size[x], self.size[y]\n if sx < sy:\n self.root[x] = y\n self.size[y] += sx\n else:\n self.root[y] = x\n self.size[x] += sy\n\n\nn, m = map(int, input().split())\np = np.array(list(map(int, input().split())))\n\n\nuf = UnionFind(n)\nunion = uf.union\nfind = uf.find\n\n\nfor _ in range(m):\n x, y = map(int, input().split())\n union(x - 1, y - 1)\n\nans = 0\nfor i, x in enumerate(p):\n if find(i) == find(x - 1):\n ans += 1\n\nprint(ans)', 'class UnionFind:\n def __init__(self, n):\n self.root = list(range(n + 1))\n self.size = [1] * (n + 1)\n\n def find(self, x):\n root = self.root\n while root[x] != x:\n root[x] = root[root[x]]\n x = root[x]\n return x\n\n def union(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x == y:\n return\n sx, sy = self.size[x], self.size[y]\n if sx < sy:\n self.root[x] = y\n self.size[y] += sx\n else:\n self.root[y] = x\n self.size[x] += sy\n\n\nn, m = map(int, input().split())\np = list(map(int, input().split()))\n\n\nuf = UnionFind(n)\nunion = uf.union\nfind = uf.find\n\n\nfor _ in range(m):\n x, y = map(int, input().split())\n union(x - 1, y - 1)\n\nans = 0\nfor i, x in enumerate(p):\n if find(i) == find(x - 1):\n ans += 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s259659691', 's423893744'] | [3316.0, 13812.0] | [21.0, 561.0] | [894, 884] |
p03356 | u882868478 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['sys.setrecursionlimit(100000)\n\ndef dfs(i, g, visited):\n visited.add(i)\n for j in g[i]:\n if not (j in visited):\n dfs(j, g, visited)\n\ndef main():\n n, m = map(int, input().split())\n p = (list(map(int, input().split())))\n g = [[] for i in range(n + 1)]\n for i in range(m):\n x, y = map(int, input().split())\n g[x].append(y)\n g[y].append(x)\n seen = [False for i in range(n + 1)]\n ans = 0\n for i in range(1, n):\n if not seen[i]:\n visited = set()\n dfs(i, g, visited)\n for j in visited:\n seen[j] = True\n if p[j - 1] in visited:\n ans += 1\n print(ans)\n\nif __name__ == "__main__":\n main()', 'import sys\nsys.setrecursionlimit(100000)\n\ndef dfs(i, g, visited):\n visited.add(i)\n for j in g[i]:\n if not (j in visited):\n dfs(j, g, visited)\n\ndef main():\n n, m = map(int, input().split())\n p = (list(map(int, input().split())))\n g = [[] for i in range(n + 1)]\n for i in range(m):\n x, y = map(int, input().split())\n g[x].append(y)\n g[y].append(x)\n seen = [False for i in range(n + 1)]\n ans = 0\n for i in range(1, n):\n if not seen[i]:\n visited = set()\n dfs(i, g, visited)\n for j in visited:\n seen[j] = True\n if p[j - 1] in visited:\n ans += 1\n print(ans)\n\nif __name__ == "__main__":\n main()'] | ['Runtime Error', 'Accepted'] | ['s762699259', 's314937569'] | [3064.0, 85732.0] | [17.0, 608.0] | [645, 656] |
p03356 | u921009792 | 2,000 | 1,048,576 | We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation on p as many times as desired so that the number of i (1 ≤ i ≤ N) such that p_i = i is maximized: * Choose j such that 1 ≤ j ≤ M, and swap p_{x_j} and p_{y_j}. Find the maximum possible number of i such that p_i = i after operations. | ['N,M = map(int, input().split())\nP = list(map(int, input().split()))\n\nuf = uf(N)\n\nfor _ in range(1,M+1):\n x,y = map(int, input().split())\n uf.unite(x,y)\n\ncount = 0\nfor n in range(N):\n if uf.is_same_group(P[n-1],n+1):\n count += 1\n\nprint(count)\n', 'class uf():\n def __init__(self,n):\n self.root = [-1] * (n+1)\n\n def findroot(self,x):\n if self.root[x] < 0:\n return x\n else:\n self.root[x] = self.findroot(self.root[x])\n return self.root[x]\n\n def unite(self,x,y):\n rootx = self.findroot(x)\n rooty = self.findroot(y)\n if rootx == rooty:\n return\n else:\n self.root[rootx] += self.root[rooty]\n self.root[rooty] = rootx\n return\n\n def is_same_group(self,x,y):\n return self.findroot(x) == self.findroot(y)\n\nN,M = map(int, input().split())\nP = list(map(int, input().split()))\n\nuf = uf(N)\n\nfor _ in range(M):\n x,y = map(int, input().split())\n uf.unite(x,y)\n\ncount = 0\nfor n in range(N):\n if uf.is_same_group(P[n],n+1):\n count += 1\n\nprint(count)'] | ['Runtime Error', 'Accepted'] | ['s832610511', 's226507011'] | [13880.0, 14452.0] | [41.0, 693.0] | [258, 844] |
p03358 | u340781749 | 2,000 | 1,048,576 | There is a tree with N vertices numbered 1 through N. The i-th edge connects Vertex x_i and y_i. Each vertex is painted white or black. The initial color of Vertex i is represented by a letter c_i. c_i = `W` represents the vertex is white; c_i = `B` represents the vertex is black. A cat will walk along this tree. More specifically, she performs one of the following in one second repeatedly: * Choose a vertex that is adjacent to the vertex where she is currently, and move to that vertex. Then, invert the color of the destination vertex. * Invert the color of the vertex where she is currently. The cat's objective is to paint all the vertices black. She may start and end performing actions at any vertex. At least how many seconds does it takes for the cat to achieve her objective? | ["def first_cut(links, colors):\n tmp_links = links.copy()\n for v, neighbors in tmp_links.items():\n while len(neighbors) == 1 and colors[v]:\n del links[v]\n par = neighbors.pop()\n links[par].remove(v)\n v = par\n neighbors = links[par]\n return links\n\n\ndef solve(links, colors):\n ans = 0\n if all(colors):\n return 0\n\n print(links)\n links = first_cut(links, colors)\n print(links)\n\n while True:\n if len(links) == 1:\n col = [colors[i] for i in links][0]\n if col:\n pass\n else:\n ans -= 1\n return ans\n if len(links) == 2:\n col = [colors[i] for i in links]\n if all(col):\n pass\n elif any(col):\n ans += 1\n else:\n ans += 2\n return ans\n\n tmp_links = links.copy()\n\n for v, neighbors in tmp_links.items():\n if len(neighbors) > 1 or not neighbors:\n continue\n if colors[v]:\n ans += 1\n else:\n ans += 2\n par = neighbors.pop()\n colors[par] ^= 1\n links[par].remove(v)\n del links[v]\n\n\nn = int(input())\nlinks = {i: set() for i in range(n)}\nfor _ in range(n - 1):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n links[x].add(y)\n links[y].add(x)\ncolors = [c == 'B' for c in input()]\n\nprint(solve(links, colors))\n", "from collections import deque\n\n\ndef first_cut(links, colors):\n tmp_links = links.copy()\n for v, neighbors in tmp_links.items():\n while len(neighbors) == 1 and colors[v]:\n del links[v]\n par = neighbors.pop()\n links[par].remove(v)\n v = par\n neighbors = links[par]\n return links\n\n\ndef diameter(links, flags):\n def dfs(s):\n fs = flags[s]\n d, v = 0, 0\n q = deque(sorted((fs + flags[v], v, s) for v in links[s]))\n while q:\n d, v, a = q.popleft()\n for u in links[v]:\n if u == a:\n continue\n fu = flags[u]\n if fu:\n q.append((d + 1, u, v))\n else:\n q.appendleft((d, u, v))\n return d, v\n\n s = next(iter(links))\n _, t = dfs(s)\n d, _ = dfs(t)\n return d\n\n\ndef solve(links, colors):\n if all(colors):\n return 0\n\n links = first_cut(links, colors)\n k = len(links)\n\n if k == 1:\n return 1\n\n flags = {v: colors[v] ^ (len(link) % 2 == 0) for v, link in links.items()}\n euler_tour = 2 * (k - 1) + sum(flags.values())\n return euler_tour - 2 * diameter(links, flags)\n\n\nn = int(input())\nlinks = {i: set() for i in range(n)}\nfor _ in range(n - 1):\n x, y = map(int, input().split())\n x -= 1\n y -= 1\n links[x].add(y)\n links[y].add(x)\ncolors = [c == 'B' for c in input()]\n\nprint(solve(links, colors))\n"] | ['Wrong Answer', 'Accepted'] | ['s166498009', 's121733965'] | [60836.0, 65632.0] | [2106.0, 736.0] | [1519, 1480] |
p03363 | u001024152 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ["from collections import defaultdict\nN = int(input())\na = list(map(int, input().split()))\n\nruiseki = [0]\nfor ai in a:\n ruiseki.append(ruiseki[-1] + ai)\n\nd = defaultdict(lambda:0)\nfor ri in ruiseki:\n d[ri] += 1\n\ndef comb_fermat(n:int, r:int)->int:\n # Fermat's little theorem: O(r)\n # return nCr\n if r > n: return 0\n if r > n-r: return comb_fermat(n, n-r)\n mul,div = 1,1\n for i in range(r):\n mul *= n-i\n div *= i+1\n\n ret = mul * pow(div, MOD-2)\n return ret\n\nans = 0\nfor k in d.keys():\n ans += comb_fermat(d[k], 2)\nprint(ans)\n", 'from collections import defaultdict\nN = int(input())\na = list(map(int, input().split()))\n\nruiseki = [0]\nfor ai in a:\n ruiseki.append(ruiseki[-1] + ai)\n\nd = defaultdict(lambda:0)\nfor ri in ruiseki:\n d[ri] += 1\n\nfrom math import factorial\ndef comb_naive(n:int, r:int)->int:\n if r > n: return 0\n ret = factorial(n) // (factorial(n-r)*factorial(r))\n return ret\n\nans = 0\nfor k in d.keys():\n ans += comb_naive(d[k], 2)\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s628192401', 's722215268'] | [41728.0, 41728.0] | [261.0, 1516.0] | [569, 442] |
p03363 | u004025573 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import math\n\nN = int(input())\n\na = list(map(int, input().split()))\nb = [a[0] for i in range(N)]\n\nfor i in range(1, N):\n b[i] = b[i-1] + a[i]\n \nb.sort()\nc = 1\nans = 0\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r) \n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nif N==1:\n if b[0]==0:\n print(1)\n else:\n print(0)\nelse:\n for i in range(1, N):\n if b[i]==b[i-1]:\n c = c+1\n else:\n if c>1:\n ans = ans + C(c, 2)\n if b[i-1]==0:\n ans = ans + c\n c=1\n else:\n if c>1:\n ans = ans + C(c, 2)\n if b[i-1]==0:\n ans = ans + c\n \n print(ans)', 'import math\n\nN = int(input())\n\na = list(map(int, input().split()))\nb = [a[0] for i in range(N)]\n\nfor i in range(1, N):\n b[i] = b[i-1] + a[i]\n \nb.sort()\nc = 1\nans = 0\n\ndef P(n, r):\n return math.factorial(n)//math.factorial(n-r) \n\ndef C(n, r):\n return P(n, r)//math.factorial(r)\n\nif N==1:\n if b[0]==0:\n print(1)\n else:\n print(0)\nelse:\n for i in range(1, N):\n if b[i]==b[i-1]:\n c = c+1\n else:\n if c>1:\n ans = ans + C(c, 2)\n if b[i-1]==0:\n ans = ans + c\n c=1\n else:\n if c>1:\n ans = ans + C(c, 2)\n if b[i-1]==0:\n ans = ans + c\n \n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s139705729', 's174520894'] | [27268.0, 27268.0] | [2108.0, 1579.0] | [709, 705] |
p03363 | u007808656 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['from itertools import combinations, product\nn=int(input())\ns=[["a" for _ in range(n)] for _ in range(n)]\nfor i in range(n):\n s[i]=list(input())\n\nres=0\nfor a in product(range(n)):\n for i,j in combinations(range(n),2):\n if(s[(i+a)%n][(j)%n]!=s[(j+a)%n][(i)%n]):\n break\n else:\n res+=1\n\nprint(res*n)\n', 'from collections import defaultdict\n\nn=int(input())\ncumsum=0\na=list(map(int,input().split()))\ncounter=defaultdict(int)\n\ncounter[0]+=1\nfor k in a:\n cumsum+=k\n counter[cumsum]+=1\n\nprint(sum(map(lambda v: v*(v-1)//2,counter.values())))\n'] | ['Runtime Error', 'Accepted'] | ['s256040079', 's806057501'] | [506160.0, 39296.0] | [2142.0, 213.0] | [310, 235] |
p03363 | u013617325 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['def main(N,A):\n B=[0]\n count = 0\n for i in range(N):\n T = A[i] + B[i]\n print(B)\n if T in B:\n\n print(\'count:\',count)\n count += B.count(T)\n\n\n \n #\n # count = [ count + 1 for m in range(len(B)) if B[i] - B[i-m] == 0]\n\n # for m in range(len(B)):\n # if T - B[m] == 0:\n # # print(i, m)\n # # print(B[i],B[i-m])\n # # print(T)\n # # print("kore",B[i],B[i-m])\n # count += 1\n B.append(T)\n\n\n #print(count)\n print(B)\n return print(count)\n\nif __name__ == "__main__":\n N=int(input())\n A=list(map(int,input().split()))\n\n main(N,A)', '\n\ndef main(N,A):\n B=[0]\n\n for i in range(int(len(A))):\n T = A[i] + B[i]\n B.append(T)\n count = 0\n for i in range(i+1)):\n for m in range(i+1):\n if i > i-m:\n T = B[i]-B[i-m]\n # print(i, m)\n # print(B[i],B[i-m])\n # print(T)\n if T == 0:\n # print("kore",B[i],B[i-m])\n count += 1\n\n #print(count)\n \n return print(count)\n\n\n\n\nif __name__ == "__main__":\n N=int(input())\n A=list(map(int,input().split()))\n main(N,A)', '\n\ndef main(N,A):\n B=[0]\n\n for i in range(int(len(A))):\n T = A[i] + B[i]\n B.append(T)\n count = 0\n M=0\n for i in range(int(len(B))):\n for m in range(int(i)):\n if i > i-m:\n T = B[i]-B[i-m]\n # print(i, m)\n # print(B[i],B[i-m])\n # print(T)\n if T == 0:\n # print("kore",B[i],B[i-m])\n count += 1\n\n #print(count)\n \n return print(count)\n\n\n\n\nif __name__ == "__main__":\n N=int(input())\n A=list(map(int,input().split()))\n main(N,A)', 'def main(N,A):\n B=[0]\n count = 0\n for i in range(N):\n T = A[i] + B[i]\n for m in range(N+1):\n if T - B[m] == 0:\n # print(i, m)\n # print(B[i],B[i-m])\n # print(T)\n # print("kore",B[i],B[i-m])\n count += 1\n B.append(T)\n\n #print(count)\n \n return print(count)\n\nif __name__ == "__main__":\n N=int(input())\n A=list(map(int,input().split()))\n\n main(N,A)', 'def main(N,A):\n B=[0]\n count = 0\n for i in range(N):\n T = A[i] + B[i]\n\n B.append(T)\n\n\n B = sorted(B)\n \n c = 0\n for i in range(len(B)):\n if i==0:\n continue\n if B[i] == B[i-1]:\n c+=1\n count +=c\n # print(c)\n # \n # print(count)\n else:\n c = 0\n\n return print(count)\n\nif __name__ == "__main__":\n N=int(input())\n A=list(map(int,input().split()))\n\n main(N,A)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s173564642', 's289440721', 's421717642', 's899318218', 's299713485'] | [148348.0, 9000.0, 31552.0, 31616.0, 31680.0] | [2401.0, 22.0, 2206.0, 74.0, 175.0] | [727, 587, 605, 485, 505] |
p03363 | u024383312 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['from collections import Counter\nimport numpy as np\n\nN = int(input())\nA = list(map(int, input().split()))\n\ncumulative_sum = [0] + np.cumsum(A)\ncounts = Counter(cumulative_sum)\nans = 0\nfor v in counts.values():\n ans += v * (v-1) // 2\n \nprint(ans)', 'from collections import Counter\nimport numpy as np\n\nN = int(input())\nA = [0]+list(map(int, input().split()))\n\ncumulative_sum = np.cumsum(A)\nprint(cumulative_sum)\ncounts = Counter(cumulative_sum)\nans = 0\nfor v in counts.values():\n ans += v * (v-1) // 2\n \nprint(ans)', 'from collections import Counter\nfrom scipy.misc import comb\n\nN = int(input())\nA = list(map(int, input().split()))\nans = 0\ncumulative_sum = [0] + [sum(A[:i+1]) for i in range(N)]\ncounts = Counter(cumulative_sum).most_common()\nans = 0\nfor c in counts:\n if c[1] < 2:\n break\n ans += comb(c[1], 2, exact=True)\n \nprint(ans)\n', 'from collections import Counter\nfrom scipy.misc import comb\n\nN = int(input())\nA = list(map(int, input().split()))\nans = 0\ncumulative_sum = [0] + [sum(A[:i+1]) for i in range(N)]\ncounts = Counter(cumulative_sum)\nans = 0\nfor v in counts.values():\n ans += v * (v-1) // 2\n \nprint(ans)\n', 'from collections import Counter\nimport numpy as np\n\nN = int(input())\nA = [0]+list(map(int, input().split()))\n\ncumulative_sum = np.cumsum(A)\ncounts = Counter(cumulative_sum)\nans = 0\nfor v in counts.values():\n ans += v * (v-1) // 2\n \nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s000863649', 's180922157', 's702348716', 's713190832', 's879617950'] | [45916.0, 45920.0, 35720.0, 35712.0, 45916.0] | [334.0, 322.0, 2109.0, 2109.0, 323.0] | [250, 270, 334, 287, 248] |
p03363 | u026788530 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ["N = int(input())\n\nA = raw_input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n", "N = raw_input()\n\nA = raw_input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n", "N = input()\n\nA = raw_input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n", "N = input()\n\nA = raw_input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n", "N = input()\n\nA = input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n", "N = int(input())\n\nA = input().split(' ')\n\ntotal = 0\nB = [0]\ndic = {}\n\nfor i in range(N):\n total += int(A[i])\n B.append(total)\n\nfor b in B:\n if b in dic:\n dic[b] +=1\n else:\n dic[b] = 1\ndef C(n):\n return int(n*(n-1)/2)\n\nans = 0;\n\nfor k,v in dic.items():\n ans += C(v)\n\nprint(ans)\n"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s242845576', 's283930168', 's769094804', 's802753916', 's880212349', 's433387601'] | [3064.0, 3064.0, 3060.0, 3060.0, 19324.0, 47380.0] | [17.0, 17.0, 17.0, 17.0, 37.0, 257.0] | [313, 312, 308, 308, 304, 309] |
p03363 | u029169777 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N=int(input())\nA=list(map(int,input().split()))\nB=[0]\ntotal=0\ncount=1\nanswer=0\n\nfor i in range(len(A)):\n total+=A[i]\n B.append(total) \n\nB.sort() \n\nfor i in range(len(B)-1):\n if B[i]==B[i+1]:\n count+-1\n else:\n answer+=count*(count-1)/2 \n \n \nprint(int(answer))', 'N=int(input())\nA=list(map(int,input().split()))\nB=[0]\ntotal=0\ncount=1\nanswer=0\n\nfor i in range(len(A)):\n total+=A[i]\n B.append(total) \n\nB.sort() \nfor i in range(1,len(B)):\n if B[i]==B[i-1]:\n count+=1\n else:\n answer+=count*(count-1)/2 \n count=1\nanswer+=count*(count-1)/2\n \nprint(int(answer))'] | ['Wrong Answer', 'Accepted'] | ['s018307179', 's922985140'] | [25976.0, 25724.0] | [239.0, 240.0] | [489, 440] |
p03363 | u042802884 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N=int(input())\nA=list(map(int,input().split()))\nd={}\nsum=0\nd[sum]=1\nfor i in range(N):\n sum+=A[i]\n if sum in d:\n d[sum]+=1\n else:\n d[sum]=1\nans=0\nprint(d)\nfor x in d:\n ans+=d[x]*(d[x]-1)//2 # 1*0//2=0\nprint(ans)', 'N=int(input())\nA=list(map(int,input().split()))\nd={}\nsum=0\nd[sum]=1\nfor i in range(N):\n sum+=A[i]\n if sum in d:\n d[sum]+=1\n else:\n d[sum]=1\nans=0\nfor x in d:\n ans+=d[x]*(d[x]-1)//2 # 1*0//2=0\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s680767088', 's624083412'] | [42096.0, 38644.0] | [286.0, 202.0] | [241, 232] |
p03363 | u063896676 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input())\nA = list(map(int, input().split()))\n\nsum_list = [None] * (N+1)\n\nsum_list[0] = 0\nfor i in range(N):\n sum_list[i+1] = sum_list[i] + A[i]\n\noutput = 0\nfor i in range(N+1):\n for j in range(i+1, N+1):\n if sum_list[j] - sum_list[i] == 0:\n print("(", str(i), ",", str(j), ")")\n output += 1\n\nprint(output)', 'N = int(input())\nA = list(map(int, input().split()))\n\nsum_list = [None] * (N+1)\n\nsum_list[0] = 0\nfor i in range(N):\n sum_list[i+1] = sum_list[i] + A[i]\n\noutput = 0\nsum_list_sorted = sorted(sum_list)\ni = 0\nwhile i < N:\n k = 1\n for j in range(i+1, N+1):\n if sum_list_sorted[i] == sum_list_sorted[j]:\n k += 1\n else:\n break\n output += k * (k-1) // 2\n i += k\n \nprint(output)'] | ['Wrong Answer', 'Accepted'] | ['s167950091', 's833501775'] | [27132.0, 27260.0] | [2105.0, 342.0] | [348, 423] |
p03363 | u065446124 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n=int(input())\na=list(map(int,input().split()))\nans=0\ns=0\ndic={}\nfor i in a:\n s+=i\n dic.get(s,0)+=1\n ans+=dic[s]-s!=0\nprint(ans)', 'n=int(input())\na=list(map(int,input().split()))\nans=0\ns=0\ndic={}\nfor i in a:\n s+=i\n dic[s]=dic.get(s,0)+1\n ans+=dic[s]\n if s!=0:\n ans-=1\nprint(ans) '] | ['Runtime Error', 'Accepted'] | ['s111685169', 's657953353'] | [3064.0, 38676.0] | [18.0, 208.0] | [131, 157] |
p03363 | u075304271 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import numpy as np\nimport math\nimport collections\nimport fractions\nimport itertools\n\ndef solve():\n n = int(input())\n a = list(map(int, input().split()))\n ruiseki = [0]\n ans = 0\n for i in range(n-1):\n ruiseki.append(ruiseki[i]+a[i+1])\n if ruiseki[i]+a[i+1] == 0:\n ans += 1\n c = collections.Counter(ruiseki).values()\n for i in c:\n ans += i*(i-1)//2\n print(ans)\n print(ruiseki)\n return 0\n\nif __name__ == "__main__":\n solve()', 'import numpy as np\nimport math\nimport collections\nimport fractions\nimport itertools\n\ndef solve():\n n = int(input())\n a = list(map(int, input().split()))\n ruiseki = [0,a[0]]\n ans = 0\n for i in range(n-1):\n ruiseki.append(ruiseki[i]+a[i+1])\n if ruiseki[i]+a[i+1] == 0:\n ans += 1\n c = collections.Counter(ruiseki).values()\n for i in c:\n ans += i*(i-1)//2\n print(ans)\n return 0\n\nif __name__ == "__main__":\n solve()', 'def solve():\n n = int(input())\n a = list(map(int, input().split()))\n ruiseki = [0,a[0]]\n ans = 0\n for i in range(n-1):\n ruiseki.append(ruiseki[i]+a[i+1])\n if ruiseki[i]+a[i+1] == 0:\n ans += 1\n c = collections.Counter(ruiseki).values()\n for i in c:\n ans += i*(i-1)//2\n print(ans)\n return 0\n\nif __name__ == "__main__":\n solve()', 'import numpy as np\nimport math\nimport collections\nimport fractions\nimport itertools\n\ndef solve():\n n = int(input())\n a = list(map(int, input().split()))\n ruiseki = [a[0]]\n ans = 0\n for i in range(n):\n ruiseki.append(ruiseki[i-1]+a[i])\n if ruiseki[i-1]+a[i] == 0:\n ans += 1\n c = collections.Counter(ruiseki).values()\n for i in c:\n if i > 0:\n ans += i*(i-1)//2\n print(ans)\n print(ruiseki)\n return 0\n\nif __name__ == "__main__":\n solve()', "import math\nimport collections\nimport fractions\nimport itertools\n\ndef solve():\n n = int(input())\n a = list(map(int, input().split()))\n ruiseki = [0]\n ans = 0\n for i in range(n):\n ruiseki.append(ruiseki[i]+a[i])\n c = collections.Counter(ruiseki)\n for i in c:\n ans += (c[i]*(c[i]-1)//2)\n print(ans)\n return 0\n\nif __name__ == '__main__':\n solve()"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s052579911', 's542834711', 's674111079', 's697819457', 's286454951'] | [53388.0, 51332.0, 26000.0, 53544.0, 45400.0] | [334.0, 312.0, 128.0, 339.0, 180.0] | [486, 472, 387, 509, 387] |
p03363 | u077025302 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\na = list(map(int,input().split()))\nlist_S = [0]\nans = 0\nfor i in range(n):\n list_S.append(list_S[i] + a[i])\n\ndict_S = {}\nfor i in list_S:\n if i in dict_S:\n dict_S[i] = 1\n else:\n dict_S[i] += 1\n\nfor v in dict_S.values():\n ans += v * (v-1) // 2\n\nprint(ans)', 'n = int(input())\na = list(map(int,input().split()))\nlist_S = [0]\nans = 0\nfor i in range(n):\n list_S.append(list_S[i] + a[i])\n\ndict_S = {} \nfor i in list_S: \n if i in dict_S: \n dict_S[i] += 1\n else: \n dict_S[i] = 1\n\nfor v in dict_S.values(): \n ans += v * (v-1) // 2\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s355107823', 's391178348'] | [26716.0, 41196.0] | [123.0, 207.0] | [297, 458] |
p03363 | u099918199 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\nlist_a = list((map(int, input().split())))\nmemo = 0\nmemo_dict = {0:1}\nfor i in range(0,n):\n memo += list_a[i]\n if memo in memo_dict:\n memo_dict[memo] += 1\n else:\n memo_dict[memo] = 1\nprint(memo_dict)\nans = 0\nfor number in memo_dict.values():\n ans += number * (number-1) / 2\nprint(int(ans))\n', 'n = int(input())\nlist_a = list((map(int, input().split())))\nmemo = 0\nmemo_list = [0]\nmemo_dict = {}\nfor i in range(0,n):\n memo += list_a[i]\n memo_list.append(memo)\n if memo in memo_dict:\n memo_dict[memo] += 1\n else:\n memo_dict[memo] = 1\nans = 0\nfor number in memo_dict.values():\n ans += number * (number-1) / 2\nprint(int(ans))\n', 'n = int(input())\nlist_a = list((map(int, input().split())))\nmemo = 0\nmemo_dict = {0:1}\nfor i in range(0,n):\n memo += list_a[i]\n if memo in memo_dict:\n memo_dict[memo] += 1\n else:\n memo_dict[memo] = 1\nans = 0\nfor number in memo_dict.values():\n ans += number * (number-1) / 2\nprint(int(ans))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s086379236', 's842704676', 's011506512'] | [42096.0, 38644.0, 39532.0] | [234.0, 210.0, 196.0] | [333, 356, 316] |
p03363 | u102242691 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['\nn = int(input())\na = list(map(int,input().split()))\nb = [0]\nfor i in range(n):\n b.append(b[-1] + a[i])\n\nans = 0\nb.sort()\n\nfor i in range(n+1):\n if i == 0:\n x = b[0]\n m = 1\n else:\n if x == b[i]:\n m += 1\n if i == n:\n ans += m*(m-1)//2\n else:\n if m != 1:\n ans += m*(m-1)//2\n m = 1\nprint(ans)\n', 'n=int(input())\na=list(map(int,input().split()))\nb=[0]\nfor i in range(n):\n b.append(b[-1]+a[i])\n#print(b)\nans = 0\nb.sort()\nfor i in range(n+1):\n if i == 0:\n x=b[0]\n m=1\n else:\n if x==b[i]:\n m+=1\n if i==n:\n ans += m*(m-1)//2\n else:\n if m!=1:\n ans += m*(m-1)//2\n m=1\n x=b[i]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s740606819', 's759180903'] | [25976.0, 25724.0] | [217.0, 231.0] | [421, 338] |
p03363 | u104282757 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input()) - 1\n\nLARGE = 10**9+7\n\ndef ex_euclid(x, y):\n c0, c1 = x, y\n a0, a1 = 1, 0\n b0, b1 = 0, 1\n \n while c1 != 0:\n m = c0 % c1\n q = c0 // c1\n \n c0, c1 = c1, m\n a0, a1 = a1, (a0 - q * a1)\n b0, b1 = b1, (b0 - q * b1)\n \n return c0, a0, b0\n\nfac_list = [1]*(N+1)\nfac = 1\nfor i in range(1, N+1):\n fac = (fac * i) % LARGE\n fac_list[i] = fac\n \nfac_inv_list = [1]*(N+1)\nfor i in range(N+1):\n fac_inv_list[i] = pow(fac_list[i], LARGE-2, LARGE)\n \ndef nCr(n, r):\n return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE\n\ndef pat(n, r):\n return (((fac_list[n] * fac_inv_list[r]) % LARGE) * fac_inv_list[n-r]) % LARGE\n\n\npat = 0\nscore = 0\n\nfor k in range(N+1):\n if k-1 >= N-k:\n res = (((fac_list[k-1]*fac_list[k]) % LARGE) * fac_inv_list[k-1-N+k]) % LARGE\n score = (score + (res - pat) * k) % LARGE\n # print(k, pat, res)\n pat = res\nprint(score)', '# A\nN = int(input())\nA_list = list(map(int, input().split()))\n\ncumsum_list = list()\ncumsum_dict = dict()\nr = 0\nfor a in A_list:\n r += a\n if r not in cumsum_dict.keys():\n cumsum_dict[r] = 0\n cumsum_dict[r] += 1\n cumsum_list.append(r)\nres = 0\nif 0 in cumsum_dict.keys():\n res += cumsum_dict[0]\n \nfor i in range(N):\n r = cumsum_list[i]\n cumsum_dict[r] -= 1\n res += cumsum_dict[r]\n \nprint(res)'] | ['Wrong Answer', 'Accepted'] | ['s877626008', 's272945568'] | [20916.0, 39544.0] | [964.0, 267.0] | [976, 426] |
p03363 | u105210954 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['from collections import Counter\nfrom math import factorial\n\n\nn = int(input())\na = list(map(int, input().split()))\n\ns = [0]\ns_elem = 0\n\nfor ai in a:\n \n s_elem += ai\n s.append(s_elem)\n\nans = 0\nfor c in Counter(s).values():\n if c > 1:\n ans += i*(i-1)//2\n \nprint(ans)', 'from collections import Counter\nfrom math import factorial\n\n\nn = int(input())\na = list(map(int, input().split()))\n\ns = [0]\ns_elem = 0\n\nfor ai in a:\n \n s_elem += ai\n s.append(s_elem)\n\nans = 0\nfor c in Counter(s).values():\n ans += c*(c-1)//2\n \nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s311809919', 's554957251'] | [41728.0, 41720.0] | [152.0, 169.0] | [273, 259] |
p03363 | u112902287 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['\u2028\u2028\u2028def solve(A):\n cumsum = [0]\n for elem in A:\n cumsum.append(cumsum[-1]+elem)\n d = dict()\n for i in cumsum:\n try:\n d[i] += 1\n except:\n d[i] = 1\n res = 0\n for value in d.values():\n res += (value * (value - 1)) // 2\n return res\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n res = solve(A)\n print(res)\n\nmain()', 'def solve(A):\n cumsum = [0]\n for elem in A:\n cumsum.append(cumsum[-1]+elem)\n d = dict()\n for i in cumsum:\n try:\n d[i] += 1\n except:\n d[i] = 1\n res = 0\n for value in d.values():\n res += (value * (value - 1)) // 2\n return res\n\ndef main():\n N = int(input())\n A = list(map(int, input().split()))\n res = solve(A)\n print(res)\n\nmain()'] | ['Runtime Error', 'Accepted'] | ['s293224602', 's699776881'] | [2940.0, 41108.0] | [17.0, 192.0] | [419, 410] |
p03363 | u118642796 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import bisect\n \nN = int(input())\nA = [int(i) for i in input().split()]\n \nB = {}\nB[0] = 1\n\ns = 0\nans = 0\n\nfor a in A:\n s += a\n ans += B.get(a,0)\n B[a] = B.get(a,0) + 1\n\nprint(ans)\n ', 'inport bisect\n\nN = int(input())\nA = [int(i) for i in input().split()]\n\nB = [0]\nX = [0]\nans = 0\n\nfor i in range(N):\n X.append(X[i]+A[i])\n insert_index = bisect.bisect_left(B,X[i+1])\n for j in range(insert_index,i+1):\n if B[j] == X[i+1]:\n ans += 1\n else:\n break\n\n B.insert(insert_index,X[i+1])\n\nprint(ans)', 'N = int(input())\nA = [int(i) for i in input().split())]\n\nans = 0\n\nfor i in range(0,N-1):\n for j in range(i+1,N):\n if sum(A[i:j])==0:\n ans +=1\n\nprint(ans)', 'N = int(input())\nA = [int(i) for i in input().split()]\n\nans = 0\n\nfor i in range(0,N-1):\n for j in range(i+1,N):\n if sum(A[i:j])==0:\n ans +=1\n\nprint(ans)', 'import bisect\n\nN = int(input())\nA = [int(i) for i in input().split()]\n \nB = [0]\nfor i in range(N):\n x = B[i]+A[i]\n insert_index = bisect.bisect_left(B,x)\n B.insert(insert_index, x)\n\nans = 0\nfor i in range(N):\n for j in range(i+1,N+1):\n if B[i] == B[j]:\n ans += 1\n else:\n break\n \nprint(ans)', 'import bisect\n\nN = int(input())\nA = [int(i) for i in input().split()]\n \nB = [0]\nX = [0]\nans = 0\nfor i in range(N):\n X.append(X[i]+A[i])\n insert_index = bisect.bisect_left(B,X[i+1])\n ans += bisect.bisect_right(B,X[i+1])-insert_incex\n B.insert(insert_index,X[i+1])\n \nprint(ans)', 'N = int(input())\nA = [int(i) for i in input().split()]\n\nB = {}\nB[0] = 1\n\ns = 0\nans = 0\n\nfor a in A:\n s += a\n ans += B.get(s,0)\n B[s] = B.get(s,0)+1\n\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s106285370', 's139857974', 's508607216', 's689971069', 's710999868', 's785703402', 's621142311'] | [33652.0, 2940.0, 2940.0, 25724.0, 25604.0, 26608.0, 39540.0] | [205.0, 17.0, 17.0, 2104.0, 2104.0, 80.0, 203.0] | [193, 351, 156, 155, 337, 287, 168] |
p03363 | u123543140 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import collections\n\n#n=int(input())\n#a=list(map(int,input().split(" ")))\nn=5\na=[1,-2,3,-4,5]\nb=[0 for i in range(n+1)]\ns=[0 for i in range(n+1)]\nfor i in range(1,n+1):\n s[i]=s[i-1]+a[i-1]\nc=collections.Counter(s).most_common()\nd=0\nfor i in c:\n if i[1]<2:\n break\n d+=i[1]*(i[1]-1)//2\nprint(d)', 'import collections\n\nn=int(input())\na=list(map(int,input().split(" ")))\n#n=5\n#a=[1,-2,3,-4,5]\ns=[0 for i in range(n+1)]\nfor i in range(1,n+1):\n s[i]=s[i-1]+a[i-1]\nc=collections.Counter(s).most_common()\nd=0\nfor i in c:\n if i[1]<2:\n break\n d+=i[1]*(i[1]-1)//2\nprint(d)'] | ['Wrong Answer', 'Accepted'] | ['s786706522', 's217560230'] | [3316.0, 48668.0] | [21.0, 241.0] | [297, 271] |
p03363 | u134387396 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\nnums = input()\nA =[int(x.strip()) for x in nums.split()]\n\nS = [0]\nfor i in range(n):\n S.append(S[i]+A[i])\n\nS.sort()\n# print(S)\n\nans = 0\nfor i in range(n):\n for j in range(n-i):\n print(i,i+j+1)\n if S[i] == S[i+j+1]:\n ans += 1\n if S[i] < S[j+1]:\n break\nprint(ans)\n', 'from collections import Counter\nn = int(input())\nnums = input()\nA =[int(x.strip()) for x in nums.split()]\n\nS = [0]\nfor i in range(n):\n S.append(S[i]+A[i])\n\nco = Counter(S)\n# print(S)\n# print(co)\n\nans = 0\nfor i in co.values():\n if i > 1:\n ans += i*(i-1) /2\n\nprint(int(ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s969184350', 's403461267'] | [34980.0, 43508.0] | [2110.0, 193.0] | [328, 286] |
p03363 | u143492911 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n=int(input())\na=list(map(int,input().split()))\nimport math\ns=[0]*(n+1)\na.insert(0,0)\nfor i in range(1,n+1):\n s[i]=s[i-1]+a[i]\nprint(s)\nfrom collections import Counter\ndata=Counter(s)\ndef combination_cout(n,r):\n return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))\nans=[]\nfor i in data.values():\n if 2<=i:\n ans.append(i)\ntotal=0\nfor i in ans:\n total+=combination_cout(i,2)\nprint(total)\n ', 'n=int(input())\na=list(map(int,input().split()))\nfrom collections import Counter\na.insert(0,0)\ns=[0]*(n+1)\nfor i in range(1,n+1):\n s[i]=s[i-1]+a[i]\ndata=Counter(s)\ncnt=[]\nfor i in data.values():\n if 2<=i:\n cnt.append(i)\ndef combination_cnt(n):\n return n*(n-1)//2\nans=0\nfor i in range(len(cnt)):\n ans+=combination_cnt(cnt[i])\nprint(ans)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s366380684', 's513275717'] | [44588.0, 41428.0] | [1532.0, 191.0] | [508, 356] |
p03363 | u149260203 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input())\nA = [int(i) for i in input().split()]\nca = [A[0]] + [0]*(N-1)\n\nfor i in range(1,N):\n ca[i] = ca[i-1] + A[i]\n\ncount = 0\nfor i in list(set(ca)):\n if i == 0:\n count += sum([1 if j == 0 else 0 for j in ca])\n number = sum([1 if j == i else 0 for j in ca])\n count += number * (number-1) /2\n\n\nprint(count)', "N = int(input())\nA = [int(i) for i in input().split()]\nca = [A[0]] + [0]*(N-1)\n\nfor i in range(1,N):\n ca[i] = ca[i-1] + A[i]\n\ncount = 1\nnumber = 0\nnumber += ca.count(0)\nsca = sorted(ca) + ['hoge']\nprint(sca)\nfor i in range(1,N+1):\n if sca[i] == sca[i-1]:\n count += 1\n else:\n number += count*(count - 1)/2\n count = 1\n\n\nprint(int(number))", 'import scipy.misc as scm\nN = int(input())\nA = [int(i) for i in input().split()]\nca = [A[0]] + [0]*(N-1)\n\nfor i in range(1,N):\n ca[i] = ca[i-1] + A[i]\n\ncount = 0\nfor i in list(set(ca)):\n if i == 0:\n count += sum([1 if j == 0 else 0 for j in ca])\n count += scm.comb(\n sum([1 if j == i else 0 for j in ca])\n ,2,1)\n\n\nprint(count)', 'N = int(input())\nA = [int(i) for i in input().split()]\n\ndic = {}\nS = 0\ndic[0] = 1\n\nfor i in range(N):\n S += A[i]\n if S in dic:\n dic[S] += 1\n else:\n dic[S] = 1\n\nnumber = 0\n\nfor i in dic:\n N = dic[i]\n number += N * (N - 1) / 2\n\nprint(int(number))\n'] | ['Wrong Answer', 'Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s161615627', 's524517994', 's735612119', 's934507407'] | [33396.0, 34712.0, 44028.0, 39508.0] | [2105.0, 292.0, 2110.0, 226.0] | [334, 366, 351, 274] |
p03363 | u170201762 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input())\na = list(map(int,input().split()))\ns = [0]*(len(a)+1)\nfor i in range(len(a)):\n s[i+1] = s[i] + a[i]\ns.sort()\nn = 0\nfor x in set(s):\n l = s.count(x)\n n += l*(l-1)/2\nprint(n)', 'a = list(map(int,input().split()))\nn = 0\nfor i in range(1,N+1):\n for j in range(N+1-i):\n S = 0\n for x in a[j:j+i]:\n S += x\n if S == 0:\n n += 1\nprint(n)', 'N = int(input())\na = list(map(int,input().split()))\ns = [0]*(len(a)+1)\nfor i in range(len(a)):\n s[i+1] = s[i] + a[i]\nb = {}\nfor x in s:\n if str(x) not in b:\n b[str(x)] = 1\n else:\n b[str(x)] += 1\nn = 0\nfor x in b:\n n += b[x]*(b[x]-1)/2\nprint(int(n))'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s112583043', 's751728867', 's623043255'] | [32824.0, 3060.0, 52488.0] | [2105.0, 18.0, 354.0] | [198, 197, 274] |
p03363 | u182249053 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input())\nA = list(int(i) for i in input().split())\nB = []\nB.append(0)\nn = 1\ncnt = 0\n\nfor i in A:\n B[0] += i\n B.append(B[0])\nB[0] = 0\nB.sort()\n\nfor i in range(1,N+1):\n if B[i] == B[i-1]:\n n += 1\n else:\n cnt += int(n*(n-1)/2)\n n = 1\n\ncnt += int(n*(n-1)/2)6\n\nprint(cnt)', 'N = int(input())\nA = list(int(i) for i in input().split())\nB = []\nB.append(0)\nn = 1\ncnt = 0\n\nfor i in A:\n B[0] += i\n B.append(B[0])\nB[0] = 0\nB.sort()\n\nfor i in range(1,N+1):\n if B[i] == B[i-1]:\n n += 1\n else:\n cnt += int(n*(n-1)/2)\n n = 1\n\ncnt += int(n*(n-1)/2)\n\nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s364903918', 's245397267'] | [3064.0, 26136.0] | [17.0, 268.0] | [307, 306] |
p03363 | u187894032 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N = int(input())\nA = list(map(int, input().split()))\n\nC = [0 for _ in A]\nC[0] = A[0]\nfor i in range(1, len(A)):\n C[i] = C[i-1] + A[i]\n\nfrom collections import Counter\nimport scipy.misc as scm\n\ncount = Counter(C)\n\nli = list(count.values())\n\nres = 0\nfor l in li:\n if l == 1:\n pass\n else:\n res += scm.comb(l, 2)\nres += count[0]\n\nprint(int(res))', 'N = int(input())\nA = list(map(int, input().split()))\n\nC = [0 for _ in A]\nC[0] = A[0]\nfor i in range(1, len(A)):\n C[i] = C[i-1] + A[i]\n\nfrom collections import Counter\n\ncount = Counter(C)\n\nli = list(count.values())\n\nres = 0\nfor l in li:\n if l == 1:\n pass\n else:\n res += l * (l - 1) / 2\nres += count[0]\n\nprint(int(res))'] | ['Wrong Answer', 'Accepted'] | ['s673026711', 's757236676'] | [51224.0, 41540.0] | [664.0, 182.0] | [364, 340] |
p03363 | u215743476 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\na = list(map(int, input().split()))\n\nans = 0\nfor i in range(n):\n sum = 0\n for j in range(i, n):\n sum += a[i]\n if sum == 0:\n ans += 1\n\nprint(ans)', 'from collections import Counter\n\nn = int(input())\na = list(map(int, input().split()))\n\nl_sum = [0]\ns= 0\nfor i in range(n):\n s += a[i]\n l_sum.append(s)\n\nc_sum = Counter(l_sum)\n\n# print(c_sum)\nans = 0\nfor i in c_sum:\n if c_sum[i] > 1:\n ans += c_sum[i] * (c_sum[i] - 1) // 2\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s115563201', 's132914738'] | [26720.0, 41696.0] | [2104.0, 207.0] | [192, 299] |
p03363 | u218843509 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\na = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(n):\n sum_list = [sum(a[i:j]) for j in range(i + 1, n + 1)]\n print(sum_list)\n ans += sum_list.count(0)\n \nprint(ans)', 'from collections import Counter\nn = int(input())\na = list(map(int, input().split()))\nb = 0\nc = Counter([0])\nans = 0\nfor i in range(n):\n b += a[i]\n ans += c[b]\n c[b] += 1\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s097286120', 's366890200'] | [25976.0, 39264.0] | [2104.0, 329.0] | [204, 183] |
p03363 | u223646582 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['N, P = map(int, input().split())\nodd = sum([int(i) % 2 for i in input().split()])\neven = N-odd\n\nif odd == 0:\n if P == 0:\n print(2**even)\n else: # P==1\n print(0)\nelse:\n print(2**even * (2**odd//2))\n', 'N = int(input())\nA = [int(i) for i in input().split()]\n\ns = [0]\nsum = 0\nfor i in range(N):\n sum += A[i]\n s.append(sum)\ns = sorted(s)\n\nans = 0\nfor r in set(s):\n if s.count(r) >= 2:\n ans += r*(r-1)//2\n\nprint(ans)\n', 'import collections\nN = int(input())\nA = [int(i) for i in input().split()]\n\nS = [0]\nfor a in A:\n S.append(S[-1]+a)\n\nC = collections.Counter(S)\n\nans = 0\nfor v in C.values():\n if v >= 2:\n ans += v*(v-1)//2\nprint(ans)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s383436757', 's707612765', 's715261983'] | [3060.0, 35156.0, 41472.0] | [17.0, 2105.0, 165.0] | [221, 227, 227] |
p03363 | u223904637 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n=int(input())\nl=list(map(int,input().split()))\nr[0]*(n+1)\nfor i in range(n):\n r[i+1]=r[i]+l[i]\nr.sort()\nr.append(100000000000)\nf=1\nans=0\nfor i in range(n+1):\n if r[i]==r[i+1]:\n f+=1\n else:\n ans+=f*(f-1)//2\n f=1\nprint(ans)', 'n=int(input())\nl=list(map(int,input().split()))\nr=[0]*(n+1)\nfor i in range(n):\n r[i+1]=r[i]+l[i]\nr.sort()\nr.append(100000000000)\nf=1\nans=0\nfor i in range(n+1):\n if r[i]==r[i+1]:\n f+=1\n else:\n ans+=f*(f-1)//2\n f=1\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s628353233', 's377211611'] | [26716.0, 25720.0] | [69.0, 243.0] | [252, 254] |
p03363 | u227082700 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import math\ndef aPb(a,b):return(math.factorial(a)//math.factorial(a-b))\ndef aCb(a,b):return(aPb(a,b)//math.factorial(b))\ndef ex(X):\n b=X[:]\n b.append("null")\n a=[]\n for i in range(len(X)):\n if b[i]!=b[i+1]:a.append(b[i])\n return a\nn,a=int(input()),list(map(int,input().split()));b=[0]\nfor i in a:b.append(b[-1]+i)\nb.sort();d=ex(b)\nc=0;ans=0\nfor i in d:ans+=aCb(b.count(i),2)\nprint(ans)', 'from collections import defaultdict\nn=int(input())\na=list(map(int,input().split()))\nb=[0]\nfor i in a:b.append(b[-1]+i)\nd=defaultdict(int)\nfor i in b:d[i]+=1\nans=0\nfor i in set(b):ans+=d[i]*(d[i]-1)//2\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s924110532', 's811690158'] | [27268.0, 47484.0] | [2105.0, 277.0] | [393, 211] |
p03363 | u228759454 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import numpy as np\n\nN = int(input())\na_list = list(map(int, input().split()))\n\ni_sum_list = []\nzero_cnt = 0\nfor i in range(2, N + 1):\n if i == 2:\n for j in range(0, N - i + 1):\n if j < N - i:\n i_sum_list.append(sum(a_list[j:j + i]))\n\n if j == N - i:\n i_sum_list.append(sum(a_list[j:]))\n\n zero_cnt += sum(x == 0 for x in i_sum_list)\n i_sum_list = np.array(i_sum_list)\n a_list = np.array(a_list)\n else:\n i_sum_list = i_sum_list[:-1] + a_list[i-1:]\n\n zero_cnt += sum(x == 0 for x in i_sum_list) \n\nprint(i_sum_list)\n\n\n', 'N = int(input())\na_list = map(int, input().split())\n\nB = dict()\nB[0] = 1\nans = 0\ns = 0\n\nfor a in a_list:\n s += a\n ans += B.get(s, 0)\n B[s] = B.get(s, 0) + 1\n\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s634774136', 's752814065'] | [34592.0, 45036.0] | [2109.0, 207.0] | [614, 177] |
p03363 | u232429509 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['#include <bits/stdc++.h>\n \nusing namespace std;\n \n#define rep(i,n) for(int i=0;i<n;i++)\n#define REP(i,s,n) for(int i=(s);i<(n);i++)\n#define repr(i,n) for(int i=n-1;i>=0;i--)\n#define REPR(i,s,n) for(int i=(s);i>=(n);i--)\n#define all(a) (a).begin(),(a).end()\n\n\n\n#define pb push_back\n#define pf push_front\n#define mod 1e9+7\n \ntypedef vector<int> vi;\ntypedef vector<string> vs;\ntypedef long long ll;\ntypedef vector<ll> vll;\n\nconst double pi = acos(-1.0);\n \nll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }\nll lcm(ll x, ll y) { return x / gcd(x, y) * y; }\n\nbool IsPrime(int num)\n{\n if (num < 2) return false;\n else if (num == 2) return true;\n else if (num % 2 == 0) return false;\n\n double sqrtNum = sqrt(num);\n for (int i = 3; i <= sqrtNum; i += 2)\n {\n if (num % i == 0)\n {\n return false;\n }\n }\n return true;\n}\n\nint main()\n{\n\tint n,cnt=0;\n\tll ans=0;\n\tcin >> n;\n\tll v[n+1];\n\tv[0]=0;\n\tfor(int i=1;i<=n;i++){\n\t\tcin >> v[i];\n\t\tv[i]+=v[i-1];\n\t}\n\tsort(v,v+n+1);\n\trep(i,n+1){\n\t\tcnt++;\n\t\tif(v[i]!=v[i+1] || i==n){\n\t\t\tans+=(cnt*(cnt-1)/2);\n\t\t\tcnt=0;\n\t\t}\n\t}\n\tcout << ans << endl;\n\treturn 0;\n}', 'from collections import defaultdict\n\nn = int(input())\na = list(map(int, input().split()))\na = [0] + a\n\nans = 0\nd = defaultdict(int)\nd[0] += 1\n\nfor i in range(n):\n \n a[i + 1] += a[i]\n \n ans += d[a[i + 1]]\n \n d[a[i + 1]] += 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s096025594', 's254567175'] | [2940.0, 39208.0] | [18.0, 213.0] | [1298, 319] |
p03363 | u257974487 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\nnums = list(map(int,input().split()))\n\nS = [0]\n\nfor i in range(n):\n S.append(S[i] + nums[i])\n\nS.sort()\nprint(S)\n\nans = 0\n\nfor i in range(n):\n for j in range(i+1, n+1):\n if S[i] == S[j]:\n ans += 1\n elif S[i] > S[j]:\n break\n\nprint(ans)', 'n = int(input())\nnums = list(map(int,input().split()))\n\nS = [0]\n\nfor i in range(n):\n S.append(S[i] + nums[i])\n\nS.sort()\nprint(S)\n\nans = 0\n\nfor i in range(n):\n for j in range(i+1, n+1):\n if S[i] == S[j]:\n ans += 1\n elif S[i] < S[j]:\n break\n\nprint(ans)', 'from collections import Counter\nn = int(input())\nnums = list(map(int,input().split()))\n\nS = [0]\n\nfor i in range(n):\n S.append(S[i] + nums[i])\n\nS.sort()\nans = 0\np = S[0]\nc = Counter(S)\n\nfor i in range(1, n+1):\n if i == n or S[i] != p:\n x = c[p]\n ans += x * (x-1) // 2\n p = S[i]\n\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s059996268', 's082338703', 's685247011'] | [30040.0, 30040.0, 41696.0] | [2105.0, 2105.0, 349.0] | [292, 292, 316] |
p03363 | u268792407 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n=int(input())\na=list(map(int,input().split()))\nb=[]\nfor i in range(n):\n if i==0:\n b.append(a[0])\n else:\n b.append(b[-1]+a[i])\nans = b.count(0)\nbp = [i for i in b if i>0]\nbm = [i for i in b if i<0]\nfor i in bp:\n ans += bm.count(-i)\nprint(ans)', 'n=int(input())\na=list(map(int,input().split()))\nb=[0]\nfor i in range(n):\n b.append(b[-1]+a[i])\n#print(b)\nans = 0\nb.sort()\nfor i in range(n+1):\n if i == 0:\n x=b[0]\n m=1\n else:\n if x==b[i]:\n m+=1\n if i==n:\n ans += m*(m-1)//2\n else:\n if m!=1:\n ans += m*(m-1)//2\n m=1\n x=b[i]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s393394212', 's268843729'] | [26720.0, 26136.0] | [2105.0, 230.0] | [251, 338] |
p03363 | u268793453 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\ns = [input() for i in range(n)]\n\ncnt = 0\n\nfor i in range(n):\n i_ = (n+i)%n\n for k in range(n):\n for l in range(n):\n if s[(i_+k)%n][l] != s[(i_+l)%n][k]:\n break\n else:\n continue\n break\n else:\n cnt += 1\n\nprint(cnt*n)', 'from collections import defaultdict\n\nn = int(input())\na = [int(i) for i in input().split()]\n\ns = 0\nd = defaultdict(int)\nans = 0\nd[0] = 1\n\nfor i in a:\n s += i\n ans += d[s]\n d[s] += 1\n\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s018000774', 's714438497'] | [8024.0, 39040.0] | [22.0, 216.0] | [305, 202] |
p03363 | u278430856 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ["if __name__ == '__main__':\n N, numbers = get_input()\n s = [0]\n for i in range(N):\n s.append(s[-1] + numbers[i])\n s.sort()\n print(s)\n count = 1\n result = 0\n for i in range(N):\n if(s[i] == s[i+1]):\n count += 1\n else:\n result += count * (count -1 ) // 2\n count = 1\n result += count * (count -1 ) // 2\n print(result)", "def get_input():\n N = int(input())\n numbers = [int(i) for i in input().split()]\n return N, numbers\n\ndef DPsolve(N, numbers):\n count = 0\n dp = [[1 for i in range(len(numbers))] for j in range(len(numbers))]\n for i in range(N):\n for j in range(N-i):\n if j == 0:\n dp[i][j] = numbers[i]\n else:\n dp[i][j] = dp[i][j-1] + numbers[i+j]\n if dp[i][j] == 0:\n count += 1\n return dp, count\n\nif __name__ == '__main__':\n N, numbers = get_input()\n s = [0]\n for i in range(N):\n s.append(s[-1] + numbers[i])\n s.sort()\n count = 1\n result = 0\n for i in range(N):\n if(s[i] == s[i+1]):\n count += 1\n else:\n result += count * (count -1 ) // 2\n count = 1\n result += count * (count -1 ) // 2\n print(result)"] | ['Runtime Error', 'Accepted'] | ['s848720711', 's777532847'] | [3064.0, 25724.0] | [17.0, 245.0] | [396, 867] |
p03363 | u312025627 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import itertools\nimport collections\nn = int(input())\na = list(map(int,input().split()))\n\nb = [0] + a\ns = list(itertools.accumulate(b))\n\n\nc = collections.Counter(s)\ncm = c.most_common()\nprint(cm)\ncnt = 0\nfor v in cm:\n if v[1] > 1:\n cnt += (v[1]*(v[1]-1) // 2) \nprint(cnt)', "def main():\n from itertools import accumulate\n from collections import Counter\n N = int(input())\n A = [int(i) for i in input().split()]\n S = list(accumulate([0] + A))\n # print(S)\n c = Counter(S)\n ans = 0\n for v in c.values():\n ans += v*(v-1)//2\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s046070654', 's600169462'] | [60156.0, 41620.0] | [349.0, 140.0] | [280, 334] |
p03363 | u314057689 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['import sys\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nimport numpy as np\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\n\n\ndef solve():\n N = int(input())\n A = list(map(int, input().split()))\n\n CS = [0]*(N+1)\n\n for n in range(N):\n if n >= 1:\n CS[n+1] = CS[n] + A[n]\n else:\n CS[n+1] = A[n]\n\n res = 0\n for v in Counter(CS).values():\n if v >= 2:\n res += v*(v-1)//2\n\n print(res)\n\nif __name__ == "__main__":\n local_test()\n solve()\n\n', '#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nIN = \'sample-1.in\' # sample case for local test\ndef local_test():\n try:\n from pcm.utils import set_stdin\n import sys\n if len(sys.argv) == 1:\n set_stdin(os.path.dirname(__file__) + \'/test/\' + IN)\n except:\n pass\n\n\nimport sys\nimport os\nimport time\nimport re\nfrom pydoc import help\nimport string\nimport math\nimport numpy as np\nfrom operator import itemgetter\nfrom collections import Counter\nfrom collections import deque\nfrom collections import defaultdict as dd\nimport fractions\nfrom heapq import heappop, heappush, heapify\nimport array\nfrom bisect import bisect_left, bisect_right, insort_left, insort_right\nfrom copy import deepcopy as dcopy\nimport itertools\nsys.setrecursionlimit(10**7)\nINF = 10**20\nGOSA = 1.0 / 10**10\nMOD = 10**9+7\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef DP(N, M, first): return [[first] * M for n in range(N)]\ndef DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]\n\n\ndef solve():\n N = int(input())\n A = list(map(int, input().split()))\n\n CS = [0]*(N+1)\n\n for n in range(N):\n if n >= 1:\n CS[n+1] = CS[n] + A[n]\n else:\n CS[n+1] = A[n]\n\n res = 0\n for v in Counter(CS).values():\n if v >= 2:\n res += v*(v-1)//2\n\n print(res)\n sys.stdout.flush()\n \n\nif __name__ == "__main__":\n local_test()\n solve()\n'] | ['Runtime Error', 'Accepted'] | ['s755819497', 's070322073'] | [15284.0, 52864.0] | [269.0, 389.0] | [1381, 1717] |
p03363 | u325264482 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = []\n\nfor i, a in enumerate(S):\n S.append(S[0] + a)\n\nS.sort()\na = Counter(S).most_common()\n\ncnt = 0\n\nfor i in range(len(a)):\n cnt += ((a[i][1]-1)*a[i][1])//2\n\nprint(cnt)\n', 'from itertools import accumulate\nimport collections\n\n\nN = int(input())\nA = list(map(int, input().split()))\n\n\nB = [0] + A\nB = list(accumulate(B))\n\n\nc = collections.Counter(B)\ncm = c.most_common()\n\ncnt = 0\nfor v in cm:\n if v[1] > 1:\n cnt += (v[1]*(v[1]-1)//2)\n\nprint(cnt)\n'] | ['Wrong Answer', 'Accepted'] | ['s448449940', 's585709233'] | [27508.0, 48272.0] | [78.0, 213.0] | [265, 311] |
p03363 | u327248573 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ["import numpy\nN = int(input())\nary = list(map(int, input().split(' ')))\ncount = 0\nzero_count = 0\nfor i in range(N):\n if ary[0] == 0:\n zero_count += 1\n ary.pop(0)\n continue\n elif ary[0] == ary[1]:\n ary.pop(0)\n continue\n else:\n if zero_count != 0:\n count += zero_count * (zero_count + 1) / 2\n zero_count = 0\n ary_int = numpy.cumsum(ary)\n count += ary_int.tolist().count(0)\n ary.pop(0)\nif zero_count != 0:\n count += zero_count * (zero_count + 1) / 2\n zero_count = 0\n\nprint(int(count))", "import numpy\nN = int(input())\nary = list(map(int, input().split(' ')))\ncount = 0\nzero_count = 0\nfor i in range(N):\n print('roop!')\n if ary[0] == 0:\n zero_count += 1\n ary.pop(0)\n continue\n elif len(ary)>=2 and ary[0] == ary[1]:\n ary.pop(0)\n continue\n else:\n if zero_count != 0:\n count += zero_count * (zero_count + 1) / 2\n zero_count = 0\n ary_int = numpy.cumsum(ary)\n zero_tmp = ary_int.tolist().count(0)\n zero_ary = numpy.where(ary_int == 0)\n if zero_tmp:\n count += zero_tmp\n ary = ary[zero_ary[0][0]:]\n elif len(ary)>=2:\n ary.pop(0)\n else: break\n\nif zero_count != 0:\n count += zero_count * (zero_count + 1) / 2\n zero_count = 0\n\nprint(int(count))", "import numpy\nN = int(input())\nary = list(map(int, input().split(' ')))\nary_int = numpy.cumsum(ary).tolist()\nary_int.sort()\nary_int.append(float('inf'))\n\ncount = 0\nsame_count = 0\nfor i in range(N):\n if ary_int[i] == ary_int[i+1]:\n same_count += 1\n else:\n count += same_count * (same_count + 1) // 2\n same_count = 0\ncount += ary_int.count(0)\nprint(int(count))"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s503895557', 's617078913', 's837900286'] | [34664.0, 34660.0, 34652.0] | [2109.0, 2109.0, 354.0] | [580, 803, 384] |
p03363 | u363074342 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n = int(input())\na = list(map(int,input().split()))\ndic_S = {0:[0]}\nS = 0\nans = 0\nfor i in range(n):\n S += a[i]\n if S not in dic_S:\n dic_S[S] = []\n else:\n pass\n dic_S[S].append(a[i])\n \n\nfor k in dic_S.keys():\n I = len(dic_S[k])\n if 3 <= I:\n ans += (I*(I-1))// *2\n elif I == 2:\n ans += 1\n else:\n pass\nprint(ans)\n', 'n = int(input())\na = list(map(int,input().split()))\ndic_S = {0:[0]}\nS = 0\nans = 0\nfor i in range(n):\n S += a[i]\n if S not in dic_S:\n dic_S[S] = []\n else:\n pass\n dic_S[S].append(a[i])\n \n\nfor k in dic_S.keys():\n I = len(dic_S[k])\n if 3 <= I:\n ans += (I*(I-1))// 2\n elif I == 2:\n ans += 1\n else:\n pass\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s842965425', 's818204419'] | [2940.0, 54780.0] | [17.0, 424.0] | [373, 372] |
p03363 | u367130284 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['from itertools import*\nfrom collections import*\nfrom operator import mul\nfrom functools import reduce\n \ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n \n \nn,*a=map(int,open(0).read().split())\nb=accumulate(a)\nprint(sum(cmb(v,2)for k,v in Counter(b).items() if v>1)+list(b).count(0))\n', 'from itertools import*\nfrom collections import*\nfrom operator import mul\nfrom functools import reduce\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\n\nn,*a=map(int,open(0).read().split())\na=accumulate(a)\nprint(sum(cmb(v,2)for k,v in Counter(a).items() if v>1)+list(a).count(0))', 'from itertools import*\nfrom collections import*\nfrom operator import mul\nfrom functools import reduce\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\n\nn,*a=map(int,open(0).read().split())\na=accumulate(a)\nprint(sum(cmb(v,2)for k,v in Counter(accumulate(a)).items() if v>1)+list(a).count(0))', 'n,*a=map(int,open(0).read().split())\nprint(q)\nans=0\nfor t in range(2,n):\n for s in range(n):\n try:\n if s+t>n:\n break\n # print(q[s:s+t])\n if sum(q[s:s+t])==0:\n ans+=1\n except:\n break\nprint(ans)', 'from itertools import*\nfrom operator import mul\nfrom functools import reduce\nfrom collections import*\n\nn,*a=map(int,open(0).read().split())\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\nb=list(accumulate(a))\nprint(sum(cmb(v,2)for k,v in Counter(b).items()if v>1)+b.count(0))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s100846488', 's233631259', 's622405680', 's861391971', 's641052388'] | [39172.0, 39176.0, 39908.0, 25108.0, 41568.0] | [135.0, 129.0, 137.0, 71.0, 138.0] | [401, 397, 409, 282, 396] |
p03363 | u371467115 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['n=int(input())\na=list(map(int,input().split()))\ncnt=0\nn=[]\nfor i in range(len(a)):\n for j in range(i+1,len(a)):\n if n[i-1]==0:\n continue\n elif sum(a[i:j])==0:\n cnt+=1\nprint(cnt)', 'from collections import Counter\nn=int(input())\na = [int(i) for i in input().split()]\nb=[0]\ns=0\nfor i in a:\n s+=i\n b.append(s)\nc= Counter(b)\nans=0\nfor i in c:\n ans+=int(c[i]*(c[i]-1)/2)\nprint(ans)\n#copy code'] | ['Runtime Error', 'Accepted'] | ['s974274957', 's322550063'] | [26720.0, 41472.0] | [72.0, 284.0] | [194, 209] |
p03363 | u372345564 | 2,000 | 262,144 | We have an integer sequence A, whose length is N. Find the number of the non-empty **contiguous** subsequences of A whose sums are 0. Note that we are counting **the ways to take out subsequences**. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions. | ['def main():\n N = int(input())\n A = [int(i) for i in input().split()]\n \n result = 0\n s = [0]\n for i in range(N):\n s.append(s[-1] + A[i])\n \n s.sort()\n print(s)\n \n count = 1\n for i in range(N):\n if(s[i] == s[i+1]):\n count += 1\n else:\n result += count * (count -1 ) // 2\n count = 1\n result += count * (count -1 ) // 2\n print(result)\n \nif __name__=="__main__":\n main()', 'def main():\n N = int(input())\n A = [int(i) for i in input().split()]\n \n result = 0\n s = [0]\n for i in range(N):\n s.append(s[-1] + A[i])\n \n s.sort()\n# print(s)\n \n count = 1\n for i in range(N):\n if(s[i] == s[i+1]):\n count += 1\n else:\n result += count * (count -1 ) // 2\n count = 1\n result += count * (count -1 ) // 2\n print(result)\n \nif __name__=="__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s421597736', 's723271156'] | [30552.0, 26720.0] | [226.0, 196.0] | [469, 470] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.