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
p03675
u077019541
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['n = int(input())\nAs= list(map(int,input().split()))\nback = As[::-2]\nif n%2==0:\n forward = As[::2]\nelse:\n forward = As[1::2]\nprint(back+forward)', 'n = int(input())\nAs= list(map(int,input().split()))\nback = As[::-2]\nif n%2==0:\n forward = As[::2]\nelse:\n forward = As[1::2]\nans = back+forward\nprint(" ".join(map(str,ans)))']
['Wrong Answer', 'Accepted']
['s867711262', 's332823591']
[26180.0, 30404.0]
[94.0, 112.0]
[149, 178]
p03675
u118642796
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['N = int(input())\nA = [int(a) for a in input().split()]\n\nprint(*([A[i] for i in range(N-1,-1,-2)]+[A[i] for i in range(2,N,2)])) \n', 'N = int(input())\nA = [int(a) for a in input().split()]\n\nprint(*([A[i] for i in range(N-1,-1,-2)]+[A[i] for i in range(N%2,N,2)])) ']
['Wrong Answer', 'Accepted']
['s972744960', 's513312941']
[26360.0, 26020.0]
[201.0, 192.0]
[130, 134]
p03675
u123648284
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['from collections import deque\n\nN = int(input())\nA = list(map(int, input().split()))\n\nq = deque()\nq.append(A[0])\nq.append(A[1])\nfor i in range(2, N):\n a = A[i]\n if i % 2 == 1:\n q.appendleft(a)\n else:\n q.append(a)\n\nprint(" ".join(map(str, q)))\n', 'from collections import deque\n\nN = int(input())\nA = list(map(int, input().split()))\n\nq = deque()\nfor i in range(N):\n a = A[i]\n if i > 1 and i % 2 == 0:\n q.appendleft(a)\n else:\n q.append(a)\n\nif N % 2 == 0:\n q.reverse()\nprint(" ".join(map(str, q)))\n']
['Runtime Error', 'Accepted']
['s209552425', 's868025272']
[29124.0, 29124.0]
[168.0, 175.0]
[251, 257]
p03675
u243492642
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['import collections\nn = int(input())\na = list(map(int, input().split()))\nb = collections.deque(list)\nif n % 2 == 0:\n for i, ele in enumerate(a):\n if i % 2 == 0:\n b.append(ele)\n else:\n b.appendleft(ele)\nelse:\n for i, ele in enumerate(a):\n if i % 2 == 0:\n b.appendleft(ele)\n else:\n b.append(ele)\n\nprint(" ".join(b))', '# coding: utf-8\nimport array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time\n\nsys.setrecursionlimit(10 ** 7)\nINF = 10 ** 20\nMOD = 10 ** 9 + 7\n\n\ndef II(): return int(input())\ndef ILI(): return list(map(int, input().split()))\ndef IAI(LINE): return [ILI() for __ in range(LINE)]\ndef IDI(): return {key: value for key, value in ILI()}\n\n\ndef read():\n n = II()\n a = list(map(str, input().split()))\n return n, a\n\n\ndef solve(n, a):\n b = collections.deque([])\n if n % 2 == 0:\n for i, ele in enumerate(a):\n if i % 2 == 0:\n b.append(ele)\n else:\n b.appendleft(ele)\n else:\n for i, ele in enumerate(a):\n if i % 2 == 0:\n b.appendleft(ele)\n else:\n b.append(ele)\n\n ans = " ".join(list(b))\n return ans\n\n\ndef main():\n params = read()\n print(solve(*params))\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s455151426', 's471674337']
[25412.0, 30176.0]
[70.0, 151.0]
[390, 960]
p03675
u364386647
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['n = int(input())\na = list(map(int, input().split()))\n\nb = []\n\nfor i in range(n):\n if i % 2 != n % 2:\n b.insert(0, a[i])\n else:\n b.append(a[i])\n\nfor i in range(n):\n print(b[i], end=" ")\n', 'n = int(input())\na = list(map(int, input().split()))\n\nb = []\n\nfor i in range(n):\n b.append(a[i])\n b = b[::-1]\n\nfor i in range(n):\n print(b[i], end = " ")\n', 'n = int(input())\na = list(map(int, input().split()))\n\nb = []\n\nfor i in range(n):\n b.append(a[i])\n b = b[::-1]\n\nprint(b)\n', 'from collections import deque\n\nn = int(input())\na = list(map(int, input().split()))\n\nb = deque()\n\nfor i in range(n):\n if i % 2 != n % 2:\n b.appendleft(a[i])\n else:\n b.append(a[i])\n\nprint(" ".join(map(str, b)))\n']
['Time Limit Exceeded', 'Time Limit Exceeded', 'Wrong Answer', 'Accepted']
['s496491776', 's725102268', 's839933888', 's931581469']
[26020.0, 26020.0, 26180.0, 29128.0]
[2104.0, 2104.0, 2104.0, 171.0]
[208, 163, 126, 230]
p03675
u375616706
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['N = int(input())\nA = list(map(int, input().split()))\n\nans = []\n\nl1 = A[0::2]\nl2 = A[1::2]\nif N % 2 == 0:\n l2 = l2[::-1]\n ans = l2+l1\nelse:\n l1 = l1[::-1]\n ans = l1+l2\n\nprint(" ".join(ans))\n', 'N = int(input())\nA = list(input().split())\n\nans = []\n\nl1 = A[0::2]\nl2 = A[1::2]\nif N % 2 == 0:\n l2 = l2[::-1]\n ans = l2+l1\nelse:\n l1 = l1[::-1]\n ans = l1+l2\n\nprint(" ".join(ans))\n']
['Runtime Error', 'Accepted']
['s206826702', 's369085332']
[26360.0, 27204.0]
[77.0, 61.0]
[201, 191]
p03675
u382748202
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['from operator import mul\nfrom functools import reduce\n\nn = int(input())\na = list(map(int, input().split()))\n\ndef com(n, k):\n if n == 0 or k == 0:\n return 1\n return int(reduce(mul, range(n + 1 - k, n + 1)) / reduce(mul, range(1, k + 1)))\n\nidx_list = [-1] * (n + 2)\nl = 0\nr = 0\nfor i, a_i in enumerate(a):\n if idx_list[a_i] < 0:\n idx_list[a_i] = i\n else:\n l = idx_list[a_i]\n r = n - i\n break\n\nfor k in range(1, n + 2):\n m = k - 1\n dup = 0\n for l_n in range(0, m + 1):\n r_n = m - l_n\n if l_n > l or r_n > r:\n continue\n l_c = com(l, l_n)\n r_c = com(r, r_n)\n dup += l_c * r_c\n ans = (com(n + 1, k) - dup) % (10 ** 9 + 7)\n print(ans)', "n = int(input())\na = list(map(int, input().split()))\n\nb = []\nif n % 2 == 0:\n for i in reversed(range(1, n, 2)):\n b.append(str(a[i]))\n for i in range(0, n, 2):\n b.append(str(a[i]))\nelse:\n for i in reversed(range(0, n + 1, 2)):\n b.append(str(a[i]))\n for i in range(1, n, 2):\n b.append(str(a[i]))\n\nans = ' '.join(b)\nprint(ans)"]
['Runtime Error', 'Accepted']
['s958433426', 's451615077']
[25776.0, 31944.0]
[79.0, 147.0]
[735, 363]
p03675
u482969053
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['n = input()\nan = list(map(int, input().split()))\nb = []\n\nfor i in an:\n b.append(i)\n b.reverse()\n\nprint(b)\n', 'n = int(input())\na = list(input().split())\nif n == 1:\n print(a[0])\nelif n % 2:\n print(*(a[-1::-2] + a[1::2]))\nelse:\n print(*(a[-1::-2] + a[0::2]))\n']
['Wrong Answer', 'Accepted']
['s405737159', 's892091541']
[25156.0, 23332.0]
[2104.0, 116.0]
[112, 156]
p03675
u500297289
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
["n = int(input())\na = list(map(int, input().split()))\n\nb = []\nfor aa in a:\n b.append(aa)\n b.reverse()\n\nans = ''\nfor bb in b:\n ans += bb + ' '\n\nprint(ans[:-1])\n", "from collections import deque\n\nn = int(input())\na = list(input().split())\n\nb = deque()\nfor i in range(n):\n if i % 2 == 0:\n b.append(a[i])\n else:\n b.appendleft(a[i])\nif n % 2 == 1:\n b.reverse()\n\nprint(' '.join(b))\n"]
['Runtime Error', 'Accepted']
['s107945912', 's397813296']
[25156.0, 26564.0]
[2106.0, 107.0]
[167, 236]
p03675
u536113865
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['f = lambda: list(map(int,input().split()))\nn = int(input())\na = f()\nif n&1:\n b = a[::-2]+a[1::2]\nelse:\n b = a[::-1]+a[::2]\nprint(*b)\n', 'ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\n\nn = int(input())\na = ai()\nMOD = 10**9+7\n\nfrom collections import Counter\ndup = list(Counter(sorted(a)).values()).index(2)+1\nant = a.index(dup)\npost = a[::-1].index(dup)\n\n\ndef nCb(n, r):\n fac = [1, 1] + [0] * n\n finv = [1, 1] + [0] * n\n inv = [0, 1] + [0] * n\n for i in range(2, n + 2):\n fac[i] = fac[i - 1] * i % MOD\n inv[i] = -inv[MOD % i] * (MOD // i) % MOD\n finv[i] = finv[i - 1] * inv[i] % MOD\n \n if n < r: return 0\n if n < 0 or r < 0: return 0\n return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD\n\n\nfor k in range(1,n+2):\n if k == 1:\n print(n)\n else:\n ans = nCb(n+1,k)\n if ant+post+1 >= k:\n ans -= nCb(ant+post,k-1)\n print(ans)\n', 'f = lambda: list(map(int,input().split()))\nn = int(input())\na = f()\nif n&1:\n b = a[::-2]+a[1::2]\nelse:\n b = a[::-2]+a[::2]\nprint(*b)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s339529501', 's987702829', 's670681365']
[25156.0, 35648.0, 26020.0]
[221.0, 202.0, 171.0]
[139, 823, 139]
p03675
u667084803
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['import math\nN=int(input())\na=list(map(int,input().split()))\nc=[]\nfor i in range(N+1):\n if a[i] in c:\n b=a[i]\n j=c.index(a[i])\n k=i\n L=j+N-k\n break\n c+=[a[i]]\nBase=N+1\nMinu=1\nfor i in range(0,min(L+1,N+1)):\n print((Base-Minu)%(10**9+7))\n Base=int(Base*(N-i)/(i+2))\n Minu=int(Minu*(L-i)/(i+1))\n \nfor i in range(L+1,N+1):\n print(Base%(10**9+7))\n Base=int(Base*(N-i)/(i+2))', "N=int(input())\na=list(map(int,input().split()))\nb=[]\nif N%2==0:\n for i in range(int(N/2)):\n b+=[a[N-1-2*i]]\n for i in range(int(N/2)):\n b+=[a[2*i]]\nelse:\n for i in range(int((N+1)/2)):\n b+=[a[N-1-2*i]]\n for i in range(int((N-1)/2)):\n b+=[a[2*i+1]]\nprint(' '.join(map(str, b)))"]
['Runtime Error', 'Accepted']
['s769623945', 's352034971']
[25156.0, 29768.0]
[2104.0, 171.0]
[524, 292]
p03675
u676264453
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['n = int(input())\nl = list(map(int, input().split()))\nk = []\n\nfor i in range(n):\n k.append(l[i])\n k = list(reversed(k))\n\nprint(",".join(map(str, k)))', 'from collections import deque\n\nn = int(input())\nl = list(map(int, input().split()))\nd = deque()\n\nfor i in range(n):\n if (i % 2 == 0):\n d.appendleft(l[i])\n else:\n d.append(l[i])\n\nif (n % 2 == 0):\n d = reversed(d)\n\nprint(" ".join(map(str, d)))\n']
['Wrong Answer', 'Accepted']
['s910540744', 's057285957']
[26180.0, 29252.0]
[2105.0, 161.0]
[150, 251]
p03675
u751717561
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
["n = int(input())\nx = list(input().split()) \na = ''.join(x)\n\nif n == 1:\n print(a)\n exit()\n\ns1 = a[::2] \ns2 = a[1::2] \n\ns2 = s2[::-1]\n\ns = s2 + s1\n\nif n%2 == 1:\n s = s[::-1]\n\nfor i in s:\n print(int(i), end=' ')\n", 'n = int(input())\na = list(map(int,input().split()))\nb = []\nc = []\nfor i in range(n):\n if i % 2 == 0:\n b.append(a[i])\n if i % 2 == 1:\n c.append(a[i])\nc.reverse()\nc += b\nif n % 2 == 1:\n c.reverse()\nprint(*c)']
['Wrong Answer', 'Accepted']
['s547516279', 's393877958']
[30004.0, 26020.0]
[2105.0, 223.0]
[254, 228]
p03675
u780475861
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
["import sys\nn, *alst = map(int, sys.stdin.read().split())\nlst1 = alst[::2]\nlst2 = alst[1::2]\nif n % 2:\n lst1.reverse()\n print(''.join(lst1 + lst2))\nelse:\n lst2.reverse()\n print(''.join(lst2 + lst1))", "n = int(input())\nalst = input().split()\nlst1 = alst[::2]\nlst2 = alst[1::2]\nif n % 2:\n lst1.reverse()\n print(' '.join(lst1 + lst2))\nelse:\n lst2.reverse()\n print(' '.join(lst2 + lst1))\n"]
['Runtime Error', 'Accepted']
['s735511894', 's414107710']
[25180.0, 26616.0]
[71.0, 49.0]
[201, 187]
p03675
u970449052
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
['n=int(input())\na=list(map(int,input().split()))\na1=[]\nfor i in range(n-1,-1,-2):\n a1.append(a[i])\na2=[]\nfor i in range(n-2,-1,-2):\n a2.append(a[i])\na2.reverse\na1+=a2\nprint(*a1)', 'n=int(input())\na=list(map(int,input().split()))\na1=[]\nfor i in range(n-1,-1,-2):\n a1.append(a[i])\na2=[]\nfor i in range(n-2,-1,-2):\n a2.append(a[i])\na2.reverse()\na1+=a2\nprint(*a1)']
['Wrong Answer', 'Accepted']
['s318483060', 's112113933']
[26360.0, 26356.0]
[196.0, 198.0]
[182, 184]
p03675
u985443069
2,000
262,144
You are given an integer sequence of length n, a_1, ..., a_n. Let us consider performing the following n operations on an empty sequence b. The i-th operation is as follows: 1. Append a_i to the end of b. 2. Reverse the order of the elements in b. Find the sequence b obtained after these n operations.
["import sys\n\n\n\n\n\ndef read_int_list():\n return list(map(int, input().split()))\n\n\ndef read_int():\n return int(input())\n\n\ndef read_str_list():\n return input().split()\n\n\ndef read_str():\n return input()\n\n\ndef solve():\n n = read_int()\n a = read_int_list()\n b = [0] * n\n p = 0\n q = n - 1\n for i in range(n):\n if i % 2 == (n - 1) % 2:\n b[p] = a[i]\n p += 1\n else:\n b[q] = a[i]\n q += -1\n return ' '.join(map(str, b))\n\n\ndef main():\n res = solve()\n print(res)\n\n\nif __name__ == '__main__':\n main()\n", "import sys\n\n\n\n\n\ndef read_int_list():\n return list(map(int, input().split()))\n\n\ndef read_int():\n return int(input())\n\n\ndef read_str_list():\n return input().split()\n\n\ndef read_str():\n return input()\n\n\ndef solve():\n n = read_int()\n a = read_int_list()\n b = [0] * n\n p = 0\n q = n - 1\n for i in range(n-1, -1, -1):\n if i % 2 == (n-1) % 2:\n b[p] = a[i]\n p += 1\n else:\n b[q] = a[i]\n q += -1\n return ' '.join(map(str, b))\n\n\ndef main():\n res = solve()\n print(res)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s366915217', 's887793573']
[29216.0, 29344.0]
[153.0, 152.0]
[611, 619]
p03676
u218843509
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['MOD = (10 ** 9) + 7\n\nf_list = [1] * 100001\nf_r_list = [1] * 100001\n\nfor i in range(100000):\n\tf_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)\n\ndef power(n, x):\n\tif x == 1:\n\t\treturn n\n\telif x % 2 == 0:\n\t\treturn power(int((n * n) % MOD), int(x / 2))\n\telse:\n\t\treturn int((n * power(n, x - 1)) % MOD)\n\nf_r_list[-1] = power(f_list[-1], MOD - 2)\n\nfor i in range(2, 100002)\n\tf_r_list[-i] = int((f_r_list[-i + 1] * (100003 - i)) % MOD)\n\ndef comb(n, r):\n\tif n == 0 or r == 0 or n == r:\n\t\treturn 1\n\telse:\n\t\treturn (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD \n\nn = int(input())\na = list(map(int, input().split()))\na_r = list(reversed(a))\n\n\ndoubled = sum(a) - n * (n + 1) / 2\nx = a.index(doubled)\ny = a_r.index(doubled)\nnum = x + y\n\nprint(n)\n\nfor i in range(2, n + 2):\n\tif num >= i - 1:\n\t\tprint(int((comb(n + 1, i) - comb(num, i - 1)) % MOD))\n\telse:\n\t\tprint(comb(n + 1, i))', 'MOD = (10 ** 9) + 7\n\nf_list = [1] * 100001\nf_r_list = [1] * 100001\n\nfor i in range(100000):\n\tf_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)\n\ndef power(n, x):\n\tif x == 1:\n\t\treturn n\n\telif x % 2 == 0:\n\t\treturn power(int((n * n) % MOD), int(x / 2))\n\telse:\n\t\treturn int((n * power(n, x - 1)) % MOD)\n\nf_r_list[-1] = power(f_list[-1], MOD - 2)\n\nfor i in range(2, 100002):\n\tf_r_list[-i] = int((f_r_list[-i + 1] * (100003 - i)) % MOD)\n\ndef comb(n, r):\n\tif n == 0 or r == 0 or n == r:\n\t\treturn 1\n\telse:\n\t\treturn (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD \n\nn = int(input())\na = list(map(int, input().split()))\na_r = list(reversed(a))\n\n\ndoubled = sum(a) - n * (n + 1) / 2\nx = a.index(doubled)\ny = a_r.index(doubled)\nnum = x + y\n\nprint(n)\n\nfor i in range(2, n + 2):\n\tif num >= i - 1:\n\t\tprint(int((comb(n + 1, i) - comb(num, i - 1)) % MOD))\n\telse:\n\t\tprint(comb(n + 1, i))']
['Runtime Error', 'Accepted']
['s095134310', 's056555186']
[3064.0, 21748.0]
[17.0, 374.0]
[889, 890]
p03676
u329749432
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['from scipy.misc import comb\n\nn=int(input())\ns=[int(i) for i in input().split()]\nfor i in range(1,n+1):\n k=s.count(i)\n if k==2:\n a=s.index(i)\n b=s.index(i,a+1)\n\nfor i in range(1,n+2):\n print(comb(n+1,i,1)-comb(a+n-b,i-1,1))\n', 'import scipy.misc as scm\nfrom collections import Counter\n\nn=int(input())\ns=[int(i) for i in input().split()]\nc = Counter(s)\nj=-1\nfor i in range(1, n + 1):\n if c[i] == 2:\n j = i\n break\na,b = [i for i in range(n + 1) if s[i] == j]\n\nfor i in range(1,n+2):\n print(scm.comb(n+1,i,1)-scm.comb(a+n-b,i-1,1))\n', 'import scipy.misc as scm\nimport sys\n\nn=int(input())\ns=[int(i) for i in input().split()]\nfor i in range(1,n+1):\n k=s.count(i)\n if k==2:\n a=s.index(i)\n b=s.index(i,a+1)\n print(a,b)\n\nfor i in range(1,n+2):\n print(scm.comb(n+1,i,1)-scm.comb(a+n-b,i-1,1))\n', 'import scipy.misc as scm\nimport sys\n\nn=int(input())\ns=[int(i) for i in input().split()]\nfor i in range(1,n+1):\n k=s.count(i)\n if k==2:\n a=s.index(i)\n b=s.index(i,a+1)\n print(a,b)\nz=a+n-b\nprint(z)\nif n==1:\n print(1)\n print(1)\n sys.exit()\nif n==2:\n print(2)\n print(scm.comb(n+1,i,1)-z)\n print(1)\n sys.exit()\n\nfor i in range(1,n+1):\n ans=scm.comb(n+1,i,1)\n if z>=i-1:\n ans=ans-scm.comb(z,i-1,1)\n fa=ans%(10**9+7)\n print(fa)', 'n = int(input())\na = list(map(int, input().split()))\noccur = [0 for i in range(n + 1)]\nMOD = 1000000007\nfor i in range(n + 1):\n if occur[a[i]] > 0: val = n - 1 - i + occur[a[i]]\n else: occur[a[i]] = i + 1\ninv = [0 if i > 2 else 1 for i in range(n + 2)]\npinv = [0 if i > 2 else 1 for i in range(n + 2)]\nperm = [0 if i > 2 else 1 for i in range(n + 2)]\nfor i in range(2, n + 2):\n inv[i] = -int(MOD / i) * inv[MOD % i] + MOD\n pinv[i] = pinv[i - 1] * inv[i] % MOD\n perm[i] = perm[i - 1] * i % MOD\ndef C(n, m):\n return (perm[m] * pinv[n] % MOD) * pinv[m - n] % MOD if n <= m else 0\nfor i in range(1, n + 2):\n temp = C(i, n + 1) - C(i - 1, val)\n if temp < 0: temp += MOD\n print(temp)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s251382568', 's299725596', 's716773520', 's730519912', 's208168923']
[23992.0, 28196.0, 23992.0, 23904.0, 27752.0]
[2109.0, 2112.0, 2109.0, 2109.0, 456.0]
[246, 321, 281, 487, 704]
p03676
u458486313
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['import sys\n\nstdin = sys.stdin\n\nns = lambda: stdin.readline()\nni = lambda: int(ns())\nna = lambda: list(map(int,stdin.readline().split()))\n\nMOD = 10**9+7\n\nclass Comb:\n def __init__(self, size):\n self.fact = [0 for i in range(size + 1)]\n self.inv_fact = [0 for i in range(size + 1)]\n self.factrical(size)\n\n def nCr(self, n,r):\n ret = self.fact[n]\n ret *= self.inv_fact[n-r]\n ret %= MOD\n ret *= self.inv_fact[r]\n ret %= MOD\n return ret\n\n def factrical(self, N):\n self.fact[0] = 1\n self.inv_fact[0] = 1\n for i in range(1,N+1):\n self.fact[i] = i * self.fact[i-1] % MOD\n self.inv_fact[i] = self.inv(self.fact[i]) % MOD\n\n def inv(self, a):\n return pow(a, MOD-2, MOD)\n\nN = ni()\na = na()\nc = [-1 for i in range (N)]\nindex = [-1,-1]\n\nfor i, x in enumerate(a):\n if (c[x-1]!=-1):\n index[0] = c[x-1]\n index[1] = i\n break\n\n c[x-1] = i\n\nco = Comb(N+1)\nprint (co.fact[N])\nfor i in range(1, N+2):\n ans = co.nCr(N+1,i)\n if ((N-index[1]) + (index[0])>=i-1 ):\n ans -= co.nCr((N-index[1]) + (index[0]),i-1) \n \n print (ans) \n \n\n', 'import sys\n\nstdin = sys.stdin\n\nns = lambda: stdin.readline()\nni = lambda: int(ns())\nna = lambda: list(map(int,stdin.readline().split()))\n\nMOD = 10**9+7\n\nclass Comb:\n def __init__(self, size):\n self.fact = [0 for i in range(size + 1)]\n self.inv_fact = [0 for i in range(size + 1)]\n self.factrical(size)\n\n def nCr(self, n,r):\n ret = self.fact[n]\n ret *= self.inv_fact[n-r]\n ret %= MOD\n ret *= self.inv_fact[r]\n ret %= MOD\n return ret\n\n def factrical(self, N):\n self.fact[0] = 1\n self.inv_fact[0] = 1\n for i in range(1,N+1):\n self.fact[i] = i * self.fact[i-1] % MOD\n self.inv_fact[i] = self.inv(self.fact[i]) % MOD\n\n def inv(self, a):\n return pow(a, MOD-2, MOD)\n\nN = ni()\na = na()\nc = [-1 for i in range (N)]\nindex = [-1,-1]\n\nfor i, x in enumerate(a):\n if (c[x-1]!=-1):\n index[0] = c[x-1]\n index[1] = i\n break\n\n c[x-1] = i\n\nco = Comb(N+1)\nfor i in range(1, N+2):\n ans = co.nCr(N+1,i)\n if ((N-index[1]) + (index[0])>=i-1 ):\n ans -= co.nCr((N-index[1]) + (index[0]),i-1) \n \n print (ans%MOD) \n \n\n']
['Wrong Answer', 'Accepted']
['s038538593', 's615987718']
[20528.0, 20456.0]
[758.0, 760.0]
[1191, 1180]
p03676
u497046426
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['# ARC 77 D\nMOD = 10**9 + 7\nn = int(input())\nA = list(map(int, input().split()))\n\nfact = {i: None for i in range(n+1)} # n!\ninverse = {i: None for i in range(1, n+1)} # inverse of n in the field Z/(MOD)Z\nfact_inverse = {i: None for i in range(n+1)} # inverse of n! in the field Z/(MOD)Z\n\nfact[0] = fact[1] = 1\nfact_inverse[0] = fact_inverse[1] = 1\ninverse[1] = 1\nfor i in range(2, n+1):\n fact[i] = i * fact[i-1] % MOD\n inverse[i] = - inverse[MOD % i] * (MOD // i) % MOD\n fact_inverse[i] = inverse[i] * fact_inverse[i-1] % MOD\n\ndef combination(n, r):\n if n < r or n < 0 or r < 0:\n return 0\n else:\n return fact[n] * (fact_inverse[r] * fact_inverse[n-r] % MOD) % MOD\n\ndup_num = sum(A) - n*(n+1)//2\ndup_idx = []\nfor i, a in enumerate(A):\n if a == dup_num:\n dup_idx.append(i)\n \nleft, right = dup_idx[0], dup_idx[1]\n \nfor k in range(1, n+2):\n print((combination(n+1, k) - combination(n + 1 - (right - left + 1), k - 1)) % MOD)', 'MOD = 10**9 + 7\n\nfact = {i: None for i in range(10**6+1)} # n!\ninverse = {i: None for i in range(1, 10**6+1)} # inverse of n in the field Z/(MOD)Z\nfact_inverse = {i: None for i in range(10**6+1)} # inverse of n! in the field Z/(MOD)Z\n\nfact[0] = fact[1] = 1\nfact_inverse[0] = fact_inverse[1] = 1\ninverse[1] = 1\nfor i in range(2, 10**6+1):\n fact[i] = i * fact[i-1] % MOD\n inverse[i] = - inverse[MOD % i] * (MOD // i) % MOD\n fact_inverse[i] = inverse[i] * fact_inverse[i-1] % MOD\n\ndef combination(n, r):\n if n < r or n < 0 or r < 0:\n return 0\n else:\n return fact[n] * (fact_inverse[r] * fact_inverse[n-r] % MOD) % MOD\n\nn = int(input())\nA = list(map(int, input().split()))\n\ndup_num = sum(A) - n*(n+1)//2\ndup_idx = []\nfor i, a in enumerate(A):\n if a == dup_num:\n dup_idx.append(i)\n \nleft, right = dup_idx[0], dup_idx[1]\n \nfor k in range(1, n+2):\n print((combination(n+1, k) - combination(n + 1 - (right - left + 1), k - 1)) % MOD)', "class BinomialCoefficient:\n def __init__(self, N, mod):\n '''\n Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)\n over the finite field Z/(mod)Z.\n Input:\n N (int): maximum n\n mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.\n '''\n self.mod = mod\n self.fact = {i: None for i in range(N+1)} # n!\n self.inverse = {i: None for i in range(1, N+1)} # inverse of n in the field Z/(MOD)Z\n self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z\n \n # preprocess\n self.fact[0] = self.fact[1] = 1\n self.fact_inverse[0] = self.fact_inverse[1] = 1\n self.inverse[1] = 1\n for i in range(2, N+1):\n self.fact[i] = i * self.fact[i-1] % self.mod\n q, r = divmod(self.mod, i)\n self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod\n self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod\n \n def binom(self, n, r):\n if n < r or n < 0 or r < 0:\n return 0\n else:\n return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod\n \nN = int(input())\nA = list(map(int, input().split()))\nMOD = 10**9 + 7\n\ndup_num = sum(A) - N*(N+1)//2\ndup_num_idx = sorted([i+1 for i, a in enumerate(A) if a == dup_num])\nl, r = dup_num_idx[0], dup_num_idx[1]\n\nbc = BinomialCoefficient(N+1, MOD)\nfor k in range(1, N+2):\n print((bc.binom(N+1, k) - bc.binom(N+1 - (r - l + 1), k - 1)) % MOD)"]
['Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s770826903', 's842641173', 's497102205']
[50780.0, 351360.0, 51804.0]
[216.0, 2117.0, 509.0]
[998, 1004, 1647]
p03676
u536113865
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\nn = int(input())\na = ai()\n\ndup = sum(a)-n*(n+1)//2\nant = a.index(dup)\npost = a[::-1].index(dup)\nprint(ant,post)\n\nmod = 10**9+7\nfactorial = [1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i %mod)\n\ninverse = [0]*(n+2)\ninverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)\nfor i in range(n+2-2, -1, -1):\n inverse[i] = inverse[i+1] * (i+1) % mod\n\n\ndef nCr(n,r):\n if n<r or n==0 or r==0:\n return 0\n return factorial[n] * inverse[r] * inverse[n-r] % mod\n\n\nfor k in range(1,n+2):\n if k == 1:\n print(n)\n else:\n ans = nCr(n+1,k) - nCr(ant+post,k-1)\n if ans < 0:\n ans += mod\n print(ans)\n', 'ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\n\nn = int(input())\na = ai()\n\nfrom collections import Counter\ndup = list(Counter(sorted(a)).values()).index(2)+1\nant = a.index(dup)\npost = a[::-1].index(dup)\n\n\nmod = 10**9+7\nfactorial = [1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i %mod)\n\ninverse = [0]*(n+2)\ninverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)\nfor i in range(n+2-2, -1, -1):\n inverse[i] = inverse[i+1] * (i+1) % mod\n\n\ndef nCr(n,r):\n if n<r or n==0 or r==0:\n return 0\n return factorial[n] * inverse[r] * inverse[n-r] % mod\n\n\nfor k in range(1,n+2):\n ans = nCr(n+1,k) - nCr(ant+post,k-1)\n print(ans)\n', 'ai = lambda: list(map(int,input().split()))\nai_ = lambda: [int(x)-1 for x in input().split()]\n\nn = int(input())\na = ai()\n\ndup = sum(a)-n*(n+1)//2\nant = a.index(dup)\npost = a[::-1].index(dup)\n\nmod = 10**9+7\nfactorial = [1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i %mod)\n\ninverse = [0]*(n+2)\ninverse[n+2-1] = pow(factorial[n+2-1], mod-2,mod)\nfor i in range(n+2-2, -1, -1):\n inverse[i] = inverse[i+1] * (i+1) % mod\n\n\ndef nCr(n,r):\n if n<r or n==0 or r==0:\n return 0\n return factorial[n] * inverse[r] * inverse[n-r] % mod\n\n\nfor k in range(1,n+2):\n if k == 1:\n print(n)\n else:\n ans = nCr(n+1,k) - nCr(ant+post,k-1)\n if ans < 0:\n ans += mod\n print(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s140177456', 's518593985', 's798095520']
[16484.0, 20064.0, 16484.0]
[307.0, 367.0, 322.0]
[744, 696, 728]
p03676
u559823804
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['from operator import mul\nfrom functools import reduce\nmod=10**9+2\ndef cmb(n,r):\n if r>n: return 0\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=int(input())\na=list(map(int,input().split()))\nsums=0\nfor aa in a:\n sums+=aa\n\nsames=[i for i,x in enumerate(a) if x==sums-(n*(n+1)//2)]\nsame_len = sames[0]+(32-sames[1])\n\nprint(n)\n\nfor i in range(1,n):\n print((cmb((n+1),(i+1))-cmb(same_len,i))%mod)\nprint(1)', 'from collections import Counter\nmod=10**9+7\nN=10**5+11\nfac,finv,inv = [0]*N,[0]*N,[0]*N\n \ndef cmb_init():\n fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1\n for i in range(2,N):\n fac[i] = fac[i-1]*i%mod\n inv[i] = mod-inv[mod%i] * (mod//i) % mod\n finv[i] = finv[i-1] * inv[i] % mod\n \n \ndef cmb_mod(n,k):\n if n<k : return 0\n return fac[n]*(finv[k]*finv[n-k]%mod)%mod\n \nn=int(input())\na=list(map(int,input().split()))\nac = Counter(a).most_common()[0][0]\nsames=[i for i,x in enumerate(a) if x==ac]\nsame_len = sames[0]+(n-sames[1])\ncmb_init()\nprint(n)\n \nfor i in range(1,n):\n nums = cmb_mod(n+1,i+1) - cmb_mod(same_len,i)\n if nums < 0: nums+=mod\n print(nums)\nprint(1)']
['Wrong Answer', 'Accepted']
['s270764510', 's238590196']
[14436.0, 24404.0]
[2104.0, 404.0]
[525, 746]
p03676
u766684188
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import Counter\nmod=10**9+7\nn=int(input())\nA=list(map(int,input().split()))\nfactorial=[1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i%mod)\ninverse=[0]*(n+2)\ninverse[n+1]=pow(factorial[n+1],mod-2,mod)\nfor i in range(n,-1,-1):\n inverse[i]=inverse[i+1]*(i+1)%mod\ndef comb(n,r):\n if n<r or n==0 or r==0:\n return 0\n return factorial[n]*inverse[r]*inverse[n-r]%mod\nC=Counter(A)\ni=C.most_common()[0][0]\nidx=[k for k, x in enumerate(A) if x==i]\nfor k in range(1,n+2):\n print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)', 'import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import Counter\nmod=10**9+7\nn=int(input())\nA=list(map(int,input().split()))\nfactorial=[1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i%mod)\ninverse=[0]*(n+2)\ninverse[n+1]=pow(factorial[n+1],mod-2,mod)\nfor i in range(n,-1,-1):\n inverse[i]=inverse[i+1]*(i+1)% mod\ndef comb(n,r):\n if n<r or n==0 or r==0:\n return 0\n return factorial[n]*inverse[r]*inverse[n-r]%mod\nC=Counter(A)\ni=C.most_common()[0][0]\nidx=[k for k, x in enumerate(A) if x==i]\nfor k in range(1,n+2):\n print((comb(n+1,k)%mod-comb(n+idx[0]-idx[1],k-1)%mod)%mod)', '#077-D\nimport sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import Counter\nmod=10**9+7\nn=int(input())\nA=list(map(int,input().split()))\nfactorial=[1]\nfor i in range(1,n+2):\n factorial.append(factorial[i-1]*i%mod)\ninverse=[0]*(n+2)\ninverse[n+1]=pow(factorial[n+1],mod-2,mod)\nfor i in range(n,-1,-1):\n inverse[i]=inverse[i+1]*(i+1)%mod\ndef comb(n,r):\n if n<r:\n return 0\n return factorial[n]*inverse[r]*inverse[n-r]%mod\nC=Counter(A)\ni=C.most_common()[0][0]\nidx=[k for k, x in enumerate(A) if x==i]\nfor k in range(1,n+2):\n print((comb(n+1,k)-comb(n+idx[0]-idx[1],k-1))%mod)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s177891024', 's246471968', 's318437561']
[29980.0, 29972.0, 29980.0]
[374.0, 371.0, 367.0]
[628, 637, 619]
p03676
u777923818
2,000
262,144
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n. It is known that each of the n integers 1,...,n appears at least once in this sequence. For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.
['# -*- coding: utf-8 -*-\nfrom math import factorial\nfrom scipy.misc import comb\ndef inpl(): return tuple(map(int, input().split()))\n\ndef combination(n, r):\n if n < r:\n return 0\n else:\n return factorial(n)//(factorial(r) * factorial(n-r))\n\nn = int(input())\nA = inpl()\nC = ["" for i in range(n+1)]\n\nfor l, a in enumerate(A):\n if type(C[a]) == int:\n i, j = C[a], l\n break\n else:\n C[a] = l\n\nprint(n)\n\nfor k in range(2, n+2):\n total = comb(n+1, k, 1)\n b = comb(n+i-j, k-1, 1)\n res = (total-b)%(10**9 + 7)\n print(res)', '# -*- coding: utf-8 -*-\ndef inpl(): return tuple(map(int, input().split()))\n\nn = int(input())\nA = inpl()\nmod = 10**9 + 7\n\nfct = [1]\ninv = [1]\n\nfor i in range(1, n+2):\n fct.append((fct[-1]*i)%mod)\n inv.append((pow(fct[i], mod-2, mod)))\n\ndef comb(n, k):\n if k < 0 or k > n:\n return 0\n return (fct[n] * inv[n - k] * inv[k]) % mod \n\nC = ["" for i in range(n+1)]\n\nfor l, a in enumerate(A):\n if type(C[a]) == int:\n i, j = C[a], l\n break\n else:\n C[a] = l\n\nprint(n)\n\nfor k in range(2, n+2):\n total = comb(n+1, k)\n b = comb(n+i-j, k-1)\n res = (total-b)%(mod)\n print(res)']
['Time Limit Exceeded', 'Accepted']
['s337479455', 's829851129']
[24004.0, 21024.0]
[2109.0, 679.0]
[569, 622]
p03684
u059586440
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
['n = int(input())\nxs = []\nys = []\n\nfor i in range(n):\n x, y = map(int, input().split())\n xs.append((x, i))\n ys.append((y, i))\n\n\nxs.sort()\nys.sort()\n\nes = []\n\nfor i in range(n-1):\n es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))\n es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))\n\nes.sort()\nprint(0)\nexit()\n\nclass UF:\n def __init__(self):\n self.p = {}\n def find(self, x):\n if x not in self.p:\n self.p[x] = x\n if x == self.p[x]:\n return x\n self.p[x] = self.find(self.p[x])\n return self.p[x]\n def merge(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.p[x] = y\n\n\nuf= UF()\nans = 0\nfor d, i0, i1 in es:\n c0 = uf.find(i0)\n c1 = uf.find(i1)\n if c0 == c1:\n continue\n ans += d\n uf.merge(i0, i1)\nprint(ans)\n', 'n = int(input())\nxs = []\nys = []\n\nfor i in range(n):\n x, y = map(int, input().split())\n xs.append((x, i))\n ys.append((y, i))\n\n\nxs.sort()\nys.sort()\n\nes = []\n\nfor i in range(n-1):\n es.append((xs[i+1][0] - xs[i][0], xs[i][1], xs[i+1][1]))\n es.append((ys[i+1][0] - ys[i][0], ys[i][1], ys[i+1][1]))\n\nes.sort()\n\nclass UF:\n def __init__(self):\n self.p = {}\n def find(self, x):\n if x not in self.p:\n self.p[x] = x\n if x == self.p[x]:\n return x\n self.p[x] = self.find(self.p[x])\n return self.p[x]\n def merge(self, x, y):\n x = self.find(x)\n y = self.find(y)\n if x != y:\n self.p[x] = y\n\n\nuf = UF()\nans = 0\ntry:\n for d, i0, i1 in es:\n c0 = uf.find(i0)\n c1 = uf.find(i1)\n if c0 == c1:\n continue\n ans += d\n uf.merge(i0, i1)\n print(ans)\nexcept:\n print(0)\n']
['Wrong Answer', 'Accepted']
['s033808910', 's262063616']
[50248.0, 58356.0]
[1016.0, 1720.0]
[865, 908]
p03684
u104282757
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
['# D\nimport numpy as np\nN = int(input())\nX = np.zeros(N, dtype=int)\nY = np.zeros(N, dtype=int)\n\nfor i in range(N):\n x, y = map(int, input().split())\n X[i] = x\n Y[i] = y\n\n# edges\nX_s = np.argsort(X)\nY_s = np.argsort(Y)\n\nedge_list = []\nedge_weight = []\nfor i in range(N-1):\n edge_list.append([X_s[i], X_s[i+1]])\n edge_weight.append(min(abs(X[X_s[i+1]] - X[X_s[i]]), abs(Y[X_s[i+1]] - Y[X_s[i]])))\n edge_list.append([Y_s[i], Y_s[i+1]])\n edge_weight.append(min(abs(X[Y_s[i+1]] - X[Y_s[i]]), abs(Y[Y_s[i+1]] - Y[Y_s[i]])))\n \n\nsel = np.argsort(np.array(edge_weight))\n\n# union find tree\nuf = dict()\nfor i in range(N):\n uf[i] = i\n\nres = 0\nflg = np.zeros(N)\n\nfor s in sel:\n m, n = edge_list[s]\n # find union\n gr_m = m\n gr_m_list = []\n gr_n = n\n gr_n_list = []\n while gr_m != uf[gr_m]:\n gr_m_list.append(gr_m)\n for m_ in gr_m_list:\n uf[m_] = gr_m\n while gr_n != uf[gr_n]:\n gr_n_list.append(gr_n)\n for n_ in gr_n_list:\n uf[n_] = gr_n\n if gr_m == gr_n:\n pass\n else:\n res += edge_weight[s]\n if dep_m > dep_n:\n uf[gr_n] = gr_m\n elif dep_m > dep_n:\n uf[gr_n] = gr_m\n else:\n uf[gr_m] = gr_n\nprint(res)', '# D\nimport numpy as np\nN = int(input())\nX = np.zeros(N, dtype=int)\nY = np.zeros(N, dtype=int)\n\nfor i in range(N):\n x, y = map(int, input().split())\n X[i] = x\n Y[i] = y\n\n# edges\nX_s = np.argsort(X)\nY_s = np.argsort(Y)\n\nedge_list = []\nedge_weight = []\nfor i in range(N-1):\n edge_list.append([X_s[i], X_s[i+1]])\n edge_weight.append(min(abs(X[X_s[i+1]] - X[X_s[i]]), abs(Y[X_s[i+1]] - Y[X_s[i]])))\n edge_list.append([Y_s[i], Y_s[i+1]])\n edge_weight.append(min(abs(X[Y_s[i+1]] - X[Y_s[i]]), abs(Y[Y_s[i+1]] - Y[Y_s[i]])))\n \n\nsel = np.argsort(np.array(edge_weight))\n\n# union find tree\nuf = dict()\nfor i in range(N):\n uf[i] = i\n\nres = 0\nflg = np.zeros(N)\n\nfor s in sel:\n m, n = edge_list[s]\n # find union\n gr_m = m\n gr_m_list = []\n gr_n = n\n gr_n_list = []\n while gr_m != uf[gr_m]:\n gr_m_list.append(gr_m)\n gr_m = uf[gr_m]\n for m_ in gr_m_list:\n uf[m_] = gr_m\n \n while gr_n != uf[gr_n]:\n gr_n_list.append(gr_n)\n gr_n = uf[gr_n]\n \n for n_ in gr_n_list:\n uf[n_] = gr_n\n if gr_m == gr_n:\n pass\n else:\n res += edge_weight[s]\n if dep_m > dep_n:\n uf[gr_n] = gr_m\n elif dep_m > dep_n:\n uf[gr_n] = gr_m\n else:\n uf[gr_m] = gr_n\nprint(res)', '# D\nimport numpy as np\nN = int(input())\nX = []\nY = []\n\nfor i in range(N):\n x, y = map(int, input().split())\n X.append(x)\n Y.append(y)\n\n# edges\nX_s = np.argsort(np.array(X))\nY_s = np.argsort(np.array(Y))\n\nedge_list = []\nedge_weight = []\nfor i in range(N-1):\n edge_list.append([X_s[i], X_s[i+1]])\n edge_weight.append(X[X_s[i+1]] - X[X_s[i]])\n edge_list.append([Y_s[i], Y_s[i+1]])\n edge_weight.append(Y[Y_s[i+1]] - Y[Y_s[i]])\n \n\nsel = np.argsort(np.array(edge_weight))\n\n# union find tree\nuf = np.arange(N)\n\n\nres = 0\nflg = np.zeros(N)\n\nfor s in sel:\n m, n = edge_list[s]\n # find union\n gr_m = m\n gr_m_list = []\n gr_n = n\n gr_n_list = []\n while gr_m != uf[gr_m]:\n gr_m_list.append(gr_m)\n gr_m = uf[gr_m]\n for m_ in gr_m_list:\n uf[m_] = gr_m\n \n while gr_n != uf[gr_n]:\n gr_n_list.append(gr_n)\n gr_n = uf[gr_n]\n for n_ in gr_n_list:\n uf[n_] = gr_n\n \n if gr_m == gr_n:\n pass\n else:\n res += edge_weight[s]\n uf[gr_n] = gr_m\nprint(res)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s380072078', 's799959648', 's425422743']
[78600.0, 75548.0, 74088.0]
[1391.0, 1347.0, 1986.0]
[1255, 1321, 1073]
p03684
u231685196
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
['\n\n\nclass uf_tree():\n\n def __init__(self,n):\n self.n = n\n self.par = [i for i in range(n)]\n\n def indep(self):\n dep =0\n for i in range(self.n):\n if i == self.par[i]:\n dep += 1\n\n return dep\n\n def unite(self,child,mas):\n if self.root(child) == self.root(mas):\n return\n else:\n self.par[self.root(child)] = self.root(mas)\n\n def root(self,i):\n if self.par[i] == i:\n return i\n else:\n self.par[i] = self.root(self.par[i])\n return self.par[i]\n\n def same(self,x,y):\n if self.root(x) == self.root(y):\n return True\n else:\n return False\ndef kruscal(n,edge_arr):\n edge_arr.sort(key=lambda x:x[2])\n ans = []\n tree = uf_tree(n)\n for e in edge_arr:\n s = e[0]-1\n g = e[1]-1\n if tree.same(s,g):\n continue\n else:\n ans.append(e)\n tree.unite(s,g)\n return ans\n\ndef main():\n n = int(input())\n p = [[0,0,0] for i in range(n)]\n edge = []\n for i in range(n):\n x,y = map(int,input().split())\n p[i][0] = x\n p[i][1] = y\n p[i][2] = i+1\n\n p.sort(key = lambda x:x[0])\n for i in range(n-1):\n cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))\n edge.append([p[i][2],p[i+1][2],cost])\n\n p.sort(key = lambda x:x[1])\n for i in range(n-1):\n cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))\n edge.append([p[i][2],p[i+1][2],cost])\n\n ans = kruscal(n,edge)\n tot = 0\n for e in ans:\n tot += e[2]\n print(tot)', '\nclass uf_tree():\n\n def __init__(self,n):\n self.n = n\n self.par = [i for i in range(n)]\n self.rank = [0 for i in range(n)]\n\n def indep(self):\n dep =0\n for i in range(self.n):\n if i == self.par[i]:\n dep += 1\n\n return dep\n\n def unite(self,x,y):\n if self.root(x) == self.root(y):\n return\n else:\n rootx = self.root(x)\n rooty = self.root(y)\n if self.rank[rootx] < self.rank[rooty]:\n self.par[rootx] = rooty\n else:\n self.par[rooty] = rootx\n if self.rank[rootx] == self.rank[rooty]:\n self.rank[rootx] += 1\n def root(self,i):\n if self.par[i] == i:\n return i\n else:\n self.par[i] = self.root(self.par[i])\n return self.par[i]\n\n def same(self,x,y):\n return self.root(x) == self.root(y)\n\ndef kruscal(n,edge_arr):\n edge_arr.sort(key=lambda x:x[2])\n ans = []\n tree = uf_tree(n)\n for e in edge_arr:\n s = e[0]-1\n g = e[1]-1\n if tree.same(s,g):\n continue\n else:\n ans.append(e)\n tree.unite(s,g)\n return ans\n\np = []\nedge = []\nn = int(input())\nfor i in range(n):\n x,y = map(int,input().split())\n p.append([x,y,i+1])\n\np.sort(key = lambda x:x[0])\nfor i in range(n-1):\n cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))\n edge.append([p[i][2],p[i+1][2],cost])\n\np.sort(key = lambda x:x[1])\nfor i in range(n-1):\n cost = min(abs(p[i+1][0]-p[i][0]),abs(p[i+1][1]-p[i][1]))\n edge.append([p[i][2],p[i+1][2],cost])\n\nans = kruscal(n,edge)\ntot = 0\nfor e in ans:\n tot += e[2]\nprint(tot)']
['Wrong Answer', 'Accepted']
['s568673150', 's989482792']
[3192.0, 55196.0]
[18.0, 1602.0]
[1646, 1726]
p03684
u497046426
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
["from collections import defaultdict\nfrom heapq import *\n\ndef prim(V, E):\n '''\n Input:\n V = list(range(N))\n E = {i: defaultdict(int) for i in range(N)}\n Output:\n the edges of the minimum weight tree and its weight\n '''\n N = len(V)\n weight = 0; edges = [];\n used = [False]*N; used[0] = True; n_used = 1;\n heap = [(c, 0, v) for v, c in E[0].items()]; heapify(heap)\n while heap and n_used < N:\n c, u, v = heappop(heap)\n if used[v]: continue\n used[v] = True; n_used += 1; edges.append((u, v))\n weight += c\n for w, d in E[v].items():\n if not used[w]: heappush(heap, (d, v, w))\n return edges, weight\n\nN = int(input())\ncities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]\nsorted_x, sorted_y = sorted(cities, key=lambda x:x[0]), sorted(cities, key=lambda x:x[1])\nE = {i: defaultdict(int) for i in range(N)}\nfor i in range(N-1):\n (a1, _, u), (a2, _, v) = sorted_x[i], sorted_x[i+1]\n E[u][v], E[v][u] = a2 - a1, a2 - a1\n (_, b1, u), (_, b2, v) = sorted_y[i], sorted_y[i+1]\n E[u][v], E[v][u] = min(b2 - b1, E[u][v]), min(b2 - b1, E[v][u])\nV = list(range(N))\n_, ans = prim(V, E)\nprint(ans)", "from heapq import *\n\ndef prim(V, E):\n '''\n Input:\n V = list(range(N))\n E = {i: defaultdict(int) for i in range(N)}\n Output:\n the edges of the minimum weight tree and its weight\n '''\n N = len(V)\n weight = 0; edges = [];\n used = [False]*N; used[0] = True; n_used = 1;\n heap = [(c, 0, v) for v, c in E[0].items()]; heapify(heap)\n while heap and n_used < N:\n c, u, v = heappop(heap)\n if used[v]: continue\n used[v] = True; n_used += 1; edges.append((u, v))\n weight += c\n for w, d in E[v].items():\n if not used[w]: heappush(heap, (d, v, w))\n return edges, weight\n\nN = int(input())\ncities = [(a, b, i) for i, (a, b) in enumerate([tuple(map(int, input().split())) for _ in range(N)])]\nsorted_x, sorted_y = sorted(cities, key=lambda x:x[0]), sorted(cities, key=lambda x:x[1])\nE = {i: {} for i in range(N)}\nfor i in range(N-1):\n (a1, _, u), (a2, _, v) = sorted_x[i], sorted_x[i+1]\n E[u][v] = min(a2 - a1, E[u][v]) if E[u].get(v) is not None else a2 - a1\n E[v][u] = E[u][v]\n (_, b1, u), (_, b2, v) = sorted_y[i], sorted_y[i+1]\n E[u][v] = min(b2 - b1, E[u][v]) if E[u].get(v) is not None else b2 - b1\n E[v][u] = E[u][v]\nV = list(range(N))\n_, ans = prim(V, E)\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s667371077', 's661137869']
[88592.0, 87180.0]
[1309.0, 1419.0]
[1234, 1272]
p03684
u835482198
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
['s UnionFind(object):\n\n def __init__(self, n):\n self.n = n\n self.par = list(range(n))\n self.rank = [1] * n\n\n def is_same(self, a, b):\n return self.root(a) == self.root(b)\n\n def root(self, x):\n if self.par[x] == x:\n return x\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.rank[x] > self.rank[y]:\n self.par[y] = x\n elif self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n self.rank[x] += 1\n\n\nN = int(input())\nX = []\nY = []\nfor i in range(N):\n x, y = map(int, input().split())\n X.append((x, i))\n Y.append((y, i))\n\nX = sorted(X)\nY = sorted(Y)\ngraph = []\nfor i in range(N - 1):\n graph.append((X[i + 1][0] - X[i][0], X[i][1], X[i + 1][1]))\n graph.append((Y[i + 1][0] - Y[i][0], Y[i][1], Y[i + 1][1]))\n\ngraph.sort()\nuf = UnionFind(N)\n\ntotal_cost = 0\nfor cost, a, b in graph:\n if not uf.is_same(a, b):\n uf.unite(a, b)\n total_cost += cost\n\nprint(total_cost)\n', 'class UnionFind(object):\n\n def __init__(self, n):\n self.n = n\n self.par = list(range(n))\n self.rank = [1] * n\n\n def is_same(self, a, b):\n return self.root(a) == self.root(b)\n\n def root(self, x):\n if self.par[x] == x:\n return x\n self.par[x] = self.root(self.par[x])\n return self.par[x]\n\n def unite(self, x, y):\n x = self.root(x)\n y = self.root(y)\n if x == y:\n return\n if self.rank[x] > self.rank[y]:\n self.par[y] = x\n elif self.rank[x] < self.rank[y]:\n self.par[x] = y\n else:\n self.par[y] = x\n self.rank[x] += 1\n\n\nN = int(input())\nX = []\nY = []\nfor i in range(N):\n x, y = map(int, input().split())\n X.append((x, i))\n Y.append((y, i))\n\nX = sorted(X)\nY = sorted(Y)\ngraph = []\nfor i in range(N - 1):\n graph.append((X[i + 1][0] - X[i][0], X[i][1], X[i + 1][1]))\n graph.append((Y[i + 1][0] - Y[i][0], Y[i][1], Y[i + 1][1]))\n\ngraph.sort()\nuf = UnionFind(N)\n\ntotal_cost = 0\nfor cost, a, b in graph:\n if not uf.is_same(a, b):\n uf.unite(a, b)\n total_cost += cost\n\nprint(total_cost)\n']
['Runtime Error', 'Accepted']
['s119362788', 's860787010']
[2940.0, 54544.0]
[17.0, 1464.0]
[1170, 1174]
p03684
u884087839
2,000
262,144
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates. You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads. Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?
["#!/usr/bin/env python3\nimport sys\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 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\n\nclass UnionFindLabel(UnionFind):\n def __init__(self, labels):\n assert len(labels) == len(set(labels))\n \n self.n = len(labels)\n self.parents = [-1] * self.n\n self.d = {x: i for i, x in enumerate(labels)}\n self.d_inv = {i: x for i, x in enumerate(labels)}\n \n def find_label(self, x):\n return self.d_inv[super().find(self.d[x])]\n \n def union(self, x, y):\n super().union(self.d[x], self.d[y])\n \n def size(self, x):\n return super().size(self.d[x])\n \n def same(self, x, y):\n return super().same(self.d[x], self.d[y])\n \n def members(self, x):\n root = self.find(self.d[x])\n return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]\n \n def roots(self):\n return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]\n\ndef main():\n N = int(input())\n nodes = []\n for _ in range(N):\n x, y = map(int, input().split())\n nodes.append((x, y))\n\n ufl = UnionFindLabel(nodes)\n nodes_sorted_by_x = sorted(nodes)\n nodes_sorted_by_y = sorted(nodes, key=lambda i: i[1])\n\n # edges = []\n \n \n \n # cost = min(dx, dy)\n \n\n \n \n \n # cost = min(dx, dy)\n \n\n # edges.sort()\n \n # ans = 0\n # for edge in edges:\n # w, s, t = edge\n # if not ufl.same(s, t):\n # ans += w\n \n # print(ans)\n\n print(nodes_sorted_by_x)\n print(nodes_sorted_by_y)\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\nimport sys\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 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\n\nclass UnionFindLabel(UnionFind):\n def __init__(self, labels):\n assert len(labels) == len(set(labels))\n \n self.n = len(labels)\n self.parents = [-1] * self.n\n self.d = {x: i for i, x in enumerate(labels)}\n self.d_inv = {i: x for i, x in enumerate(labels)}\n \n def find_label(self, x):\n return self.d_inv[super().find(self.d[x])]\n \n def union(self, x, y):\n super().union(self.d[x], self.d[y])\n \n def size(self, x):\n return super().size(self.d[x])\n \n def same(self, x, y):\n return super().same(self.d[x], self.d[y])\n \n def members(self, x):\n root = self.find(self.d[x])\n return [self.d_inv[i] for i in range(self.n) if self.find(i) == root]\n \n def roots(self):\n return [self.d_inv[i] for i, x in enumerate(self.parents) if x < 0]\n\ndef main():\n N = int(input())\n nodes = []\n for _ in range(N):\n x, y = map(int, input().split())\n nodes.append((x, y))\n\n ufl = UnionFindLabel(nodes)\n nodes_sorted_by_x = sorted(nodes)\n nodes_sorted_by_y = sorted(nodes, key=lambda i: i[1])\n\n edges = []\n for i in range(N - 1):\n dx = abs(nodes_sorted_by_x[i][0] - nodes_sorted_by_x[i + 1][0])\n dy = abs(nodes_sorted_by_x[i][1] - nodes_sorted_by_x[i + 1][1])\n cost = min(dx, dy)\n edges.append((cost, nodes_sorted_by_x[i], nodes_sorted_by_x[i + 1]))\n\n for i in range(N - 1):\n dx = abs(nodes_sorted_by_y[i][0] - nodes_sorted_by_y[i + 1][0])\n dy = abs(nodes_sorted_by_y[i][1] - nodes_sorted_by_y[i + 1][1])\n cost = min(dx, dy)\n edges.append((cost, nodes_sorted_by_y[i], nodes_sorted_by_y[i + 1]))\n\n edges.sort()\n \n print(nodes_sorted_by_x)\n print(nodes_sorted_by_y)\n\n # ans = 0\n # for edge in edges:\n # w, s, t = edge\n # if not ufl.same(s, t):\n # ans += w\n \n # print(ans)\n\n \n \nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python3\nimport sys\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 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\n\n\ndef main():\n N = int(input())\n nodes = []\n for i in range(N):\n x, y = map(int, input().split())\n nodes.append((x, y, i))\n\n uf = UnionFind(N)\n nodes_sorted_by_x = sorted(nodes)\n nodes_sorted_by_y = sorted(nodes, key=lambda i: i[1])\n\n edges = []\n for i in range(N - 1):\n dx = abs(nodes_sorted_by_x[i][0] - nodes_sorted_by_x[i + 1][0])\n dy = abs(nodes_sorted_by_x[i][1] - nodes_sorted_by_x[i + 1][1])\n cost = min(dx, dy)\n edges.append((cost, nodes_sorted_by_x[i][2], nodes_sorted_by_x[i + 1][2]))\n\n for i in range(N - 1):\n dx = abs(nodes_sorted_by_y[i][0] - nodes_sorted_by_y[i + 1][0])\n dy = abs(nodes_sorted_by_y[i][1] - nodes_sorted_by_y[i + 1][1])\n cost = min(dx, dy)\n edges.append((cost, nodes_sorted_by_y[i][2], nodes_sorted_by_y[i + 1][2]))\n\n edges.sort()\n \n ans = 0\n for edge in edges:\n w, s, t = edge\n if not uf.same(s, t):\n ans += w\n uf.union(s, t)\n print(ans)\n\n \n \nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s278127755', 's372303998', 's153342446']
[49320.0, 72408.0, 47320.0]
[601.0, 1122.0, 1430.0]
[3257, 3292, 2369]
p03687
u021548497
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s = input()[:-1]\nalphabet = ["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"]\n\nans = len(s)\nfor i in range(26):\n k = s.count(alphabet[i])\n ans = min(ans, len(s)-k)\nprint(ans)', 's = input()[:-1]\nalphabet = ["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"]\n\nn = len(s)\nans = n\nfor v in alphabet:\n key = [s[i] for i in range(n)]\n for i in range(n):\n for j in range(n-i):\n if key[j] != v:\n break\n if j == n-i-1:\n ans = min(i, ans)\n break\n \n for j in range(n-1-i):\n if key[j] == v or key[j+1] == v:\n key[j] = v\n \n\nprint(ans)', 's = input()\nalphabet = ["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"]\n\nn = len(s)\nans = n\n\nfor v in alphabet:\n key = [s[i] for i in range(n)]\n \n count = 0\n end = False\n while True:\n for i in range(n-count):\n if key[i] != v:\n break\n if i == n-count-1:\n ans = min(ans, count)\n end = True\n if count == n-1:\n break\n \n if end:\n break\n \n count += 1\n for i in range(n-count):\n if key[i] == v or key[i+1] == v:\n key[i] = v\n\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s077413380', 's824150058', 's915377938']
[9024.0, 9096.0, 9112.0]
[29.0, 55.0, 48.0]
[257, 558, 689]
p03687
u039623862
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s = input()\nn = len(s)\nmin_t = float('inf')\nfor i in range(n):\n target = s[i]\n pre = 0\n max_t = 0\n for j in range(n):\n if s[j] == s[i]:\n max_t = max(max_t, j-pre-1)\n pre = j\n max_t = max(max_t, n - pre-1)\n if max_t < min_t:\n min_t = min(min_t, max_t)\nprint(min_t)", "import string\ns = input()\nn = len(s)\n\nmin_cnt = float('inf')\n\nfor c in string.ascii_lowercase:\n if c not in s:\n continue\n cnt = 0\n s_ = s[:]\n while s_:\n m = len(s_) - 1\n is_same = True\n for d in s_:\n if d != c:\n is_same = False\n break\n if is_same:\n min_cnt = min(min_cnt, n - m-1)\n s_next = [''] * m\n for i in range(m):\n if s_[i] == c or s_[i + 1] == c:\n s_next[i] = c\n else:\n s_next[i] = s_[i]\n s_ = s_next\n\nprint(min_cnt)\n"]
['Wrong Answer', 'Accepted']
['s452351236', 's271697239']
[3064.0, 9876.0]
[21.0, 55.0]
[317, 596]
p03687
u057993957
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from collections import Counter\ns = input()\ncnt = Counter(s).most_common()\nprint(cnt)\n\nmins = len(s) - 1\nfor k, v in cnt:\n if v != 1:\n ind = 0\n dist = []\n for i in range(len(s)):\n if k == s[i]:\n dist.append(i-ind+1) \n ind = i\n mins = min(max(dist), mins)\nprint(mins)', 's = input()\n\nans = 1000\nfor c in set(s):\n ans = min(ans, max([len(si) for si in s.split(c)]))\nprint(ans)']
['Wrong Answer', 'Accepted']
['s357799901', 's981377925']
[3316.0, 2940.0]
[21.0, 17.0]
[338, 107]
p03687
u125545880
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['import sys\n\nsys.setrecursionlimit(10**6)\n\ndef handling(string, letter):\n global cnt\n cnt += 1\n for i, r in enumerate(string):\n if r == letter and 0 < i < len(string):\n if string[i-1] != letter:\n string[i-1] = letter\n elif i < len(string)-1:\n string[i+1] = letter\n else:\n pass\n if string[-1] != letter:\n string.pop()\n else:\n string = string[1:]\n if len(set(string)) != 1:\n handling(string, letter)\n\ndef main():\n global cnt\n s = list(input())\n sletter = set(s)\n if len(sletter) == 1:\n print(0)\n return\n ans = 101\n for l in sletter:\n cnt = 0\n t = s.copy()\n handling(t, l)\n ans = min(ans, cnt)\n print(ans)\n\nif __name__ == "__main__":\n main()\n', 'import sys\n\nsys.setrecursionlimit(10**6)\n\ndef handling(string, letter):\n global cnt\n cnt += 1; nxt = []\n for i in range(len(string)-1):\n s1, s2 = string[i], string[i+1]\n if s1 == letter:\n nxt.append(s1)\n elif s2 == letter:\n nxt.append(s2)\n else:\n nxt.append(s1)\n if len(set(nxt)) != 1:\n handling(nxt, letter)\n\ndef main():\n global cnt\n s = list(input())\n sletter = set(s)\n if len(sletter) == 1:\n print(0)\n return\n ans = 101\n for l in sletter:\n cnt = 0\n t = s.copy()\n handling(t, l)\n ans = min(ans, cnt)\n print(ans)\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Accepted']
['s287615260', 's406224046']
[3064.0, 3064.0]
[25.0, 36.0]
[828, 696]
p03687
u151785909
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s = input()\na = [[0] for i in range(26)]\n\nfor i in range(len(s)):\n a[ord(s[i])-ord('a')].append(i)\n\nfor i in range(26):\n a[i].append(len(s)-1)\n\nans = float('inf')\nfor i in range(26):\n ma = 0\n for j in range(1,len(a[i])):\n dis = a[i][j]-a[i][j-1]-1\n ma = max(dis,ma)\n ans = min(ma,ans)\n\nprint(ans)\n", "s = input()\na = [[-1] for i in range(26)]\n\nfor i in range(len(s)):\n a[ord(s[i])-ord('a')].append(i)\n\nfor i in range(26):\n a[i].append(len(s))\n\nans = float('inf')\nfor i in range(26):\n ma = 0\n for j in range(1,len(a[i])):\n dis = a[i][j]-a[i][j-1]-1\n ma = max(dis,ma)\n ans = min(ma,ans)\n\nprint(ans)\n"]
['Wrong Answer', 'Accepted']
['s006979868', 's803437396']
[3064.0, 3064.0]
[18.0, 18.0]
[326, 325]
p03687
u163320134
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["check='abcdefghijklmnopqrstuvwxyz'\ns=input()\nl=len(s)\npos=[0]*26\nfor i in range(l):\n for j in range(26):\n if s[i]==check[j]:\n pos[j].append(i)\nans=10**9:\n for i in range(26):\n tmp=0\n for j in range(len(pos[i])-1):\n tmp=max(tmp,pos[i][j+1]-pos[i][j])\n tmp=max(tmp,(l-1)-pos[i][-1])\n ans=min(ans,tmp)\nprint(ans)", "check='abcdefghijklmnopqrstuvwxyz'\ns=input()\nl=len(s)\npos=[[0] for _ in range(26)]\nfor i in range(l):\n for j in range(26):\n if s[i]==check[j]:\n pos[j].append(i+1)\nans=10**9\nfor i in range(26):\n tmp=0\n for j in range(len(pos[i])-1):\n tmp=max(tmp,pos[i][j+1]-pos[i][j]-1)\n tmp=max(tmp,l-pos[i][-1])\n ans=min(ans,tmp)\nprint(ans)\n"]
['Runtime Error', 'Accepted']
['s852482623', 's477013670']
[2940.0, 3064.0]
[17.0, 18.0]
[336, 342]
p03687
u177481830
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=input()\nprint(s)', 's=input()\n\nminCost=len(s)\nfor char in char_set:\n m=max([len(_) for _ in s.split(char)])\n if m<minCost:\n minCost=m\nprint(minCost)', 's=input()\n\nminCost=len(s)\nchar_set=set(s)\nfor char in char_set:\n m=max([len(_) for _ in s.split(char)])\n if m<minCost:\n minCost=m\nprint(minCost)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s271083404', 's333673249', 's304119948']
[2940.0, 2940.0, 2940.0]
[17.0, 17.0, 17.0]
[18, 172, 188]
p03687
u227082700
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=input()\nans=len(s)\ndef a(s,t):\n ss=""\n a=0\n b=False\n for i in range(len(s)-1):\n if s[i]!=t!=s[i+1]:ss+=s[i];b=True\n else:ss+=t\n if b:a=a(ss,t)\n return a+1\nfor i in s:ans=min(ans,a(s,i))\nprint(ans)', 's=input()\nse=set(list(s))\nx=len(s)\nfor i in se:\n a=b=0\n for j in s:\n if i==j:a=0\n else:a+=1;b=max(a,b)\n x=min(x,b)\nprint(x)']
['Runtime Error', 'Accepted']
['s392724576', 's233852479']
[3064.0, 2940.0]
[17.0, 18.0]
[210, 132]
p03687
u252828980
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s = input()#print(len(s))\nnum = []\n\nli1 = []\nn = 0\nwhile n < len(s):\n \n li2 = []\n for i in range(len(s)):\n if s[i] == s[n]:\n li2.append(i)\n #print(li2)\n if len(li2) == 1:\n num.append(li2[0])\n break\n elif len(li2) >=2: \n idx = li2[0]\n li1 = []\n for i in range(len(li2)-1):\n idx = max(idx,li2[i+1]-li2[i])\n li1.append(idx)\n #print(li1)\n num.append(max(li1))\n n += 1\nprint(min(num))\n \n \n', 'from copy import deepcopy\ns = input()\n\nans = 10**10\nfor i in range(len(s)):\n a = s[i]\n t = deepcopy(s)\n cnt = 0\n \n while len(set(list(t))) !=1:\n \n cnt +=1\n while True:\n S = ""\n for j in range(len(t)-1):\n if (t[j] == a) or (t[j+1] == a):\n S +=a\n #print(t,S,j,t[j],t[j+1],a)\n else:\n S +=t[j]\n\n else:\n t = deepcopy(S)\n #print(S,cnt)\n break\n ans = min(ans,cnt)\n #print(S,t,i,ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s205106235', 's353592391']
[3064.0, 9160.0]
[23.0, 169.0]
[500, 593]
p03687
u256868077
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=input()\nl=len(s)\na=[1]*(l+1)\nc=[]\nx=0\nwhile(x<=l-1):\n if(a[x]==1):\n a[x]=0\n k=0\n b=[x-1]\n t=s+s[x]\n for i in range(x+1,l+1):\n if(t[x]==t[i]):\n b.append(k)\n a[i]=0\n k=0\n else:\n k+=1\n c.append(max(b))\n x+=1\nprint(min(c))', 's=input()\nl=len(s)\na=[1]*(l+1)\nc=[]\nx=0\nwhile(x<=l-1):\n if(a[x]==1):\n a[x]=0\n k=0\n b=[x]\n t=s+s[x]\n for i in range(x+1,l+1):\n if(t[x]==t[i]):\n b.append(k)\n a[i]=0\n k=0\n else:\n k+=1\n c.append(max(b))\n x+=1\nprint(min(c))']
['Wrong Answer', 'Accepted']
['s470576215', 's565407024']
[3064.0, 3064.0]
[18.0, 17.0]
[278, 276]
p03687
u263830634
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s = list(input())\nN = len(s)\nif N == 1:\n print (0)\n exit()\n\n ans = 99\nfor i in range(1, N): \n tmp = 0 \n count = 0 \n for j in range(i):\n if s[j] == s[i]:\n tmp = max(tmp, count)\n count = 0\n else:\n count += 1\n tmp = max(tmp, count)\n ans = min(ans, max(tmp, N - i - 1))\n\nprint (ans)', 's = list(input())\nN = len(s)\nif N == 1:\n print (0)\n exit()\n\nans = 99\nfor i in range(1, N): \n tmp = 0 \n count = 0 \n for j in range(i):\n if s[j] == s[i]:\n tmp = max(tmp, count)\n count = 0\n else:\n count += 1\n tmp = max(tmp, count)\n ans = min(ans, max(tmp, N - i - 1))\n\nprint (ans)']
['Runtime Error', 'Accepted']
['s517012773', 's850335938']
[3064.0, 3064.0]
[17.0, 19.0]
[466, 462]
p03687
u278356323
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s = input()\nprint(s.count('r'))\n\n\ndef calc(s, a):\n if s.count(a) == len(s):\n return 0\n ns = s[:-1]\n for i in range(len(s)-1):\n if s[i] == a or s[i+1] == a:\n ns[i] = a\n return 1+calc(ns, a)\n\n\n# for a in list('abcdefghijklmnopqrstuvwxyz'):\n# print(a)\n", 'from collections import Counter\n\ns = input()\n\n\ndef convert(st, toS, cou):\n if st.count(st[0]) == len(st):\n return cou\n for i in range(len(st)):\n if i+1 < len(st) and st[i+1] == toS:\n st[i] = toS\n return convert(st[:-1], toS, cou+1)\n\n\nans = 200\nfor j in set(s):\n ans = min(ans, convert(list(s), j, 0))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s928774580', 's239120467']
[2940.0, 3316.0]
[17.0, 34.0]
[289, 349]
p03687
u309977459
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['#s = input()\ns = "zzz"\ns = "whbrjpjyhsrywlqjxdbrbaomnw"\nf = {}\ng = {}\n\nchars = [c for c in s]\n#print(chars)\n\nfor char in chars:\n f[char] = []\n f[char].append(-1)\n for i, c in enumerate(s):\n if(c==char):\n f[char].append(i)\n f[char].append(len(s))\n\nmax_len_all = len(s)\nfor char in chars:\n max_len = 0\n for i in range(len(f[char])-1):\n max_len = max(max_len, f[char][i+1]-f[char][i])\n g[char] = max_len\n if(g[char]<max_len_all):\n ans = char\n max_len_all = g[char]\n\n\n\n#print(f)\n#print(g)\nprint(max_len_all-1)\n', 's = input()\nf = {}\ng = {}\n\nchars = [c for c in s]\n#print(chars)\n\nfor char in chars:\n f[char] = []\n f[char].append(-1)\n for i, c in enumerate(s):\n if(c==char):\n f[char].append(i)\n f[char].append(len(s))\n\nmax_len_all = len(s)\nfor char in chars:\n max_len = 0\n for i in range(len(f[char])-1):\n max_len = max(max_len, f[char][i+1]-f[char][i])\n g[char] = max_len\n if(g[char]<max_len_all):\n ans = char\n max_len_all = g[char]\n\n\n\n#print(f)\n#print(g)\nprint(max_len_all-1)\n']
['Wrong Answer', 'Accepted']
['s456105633', 's446011185']
[3064.0, 3064.0]
[17.0, 23.0]
[569, 525]
p03687
u323680411
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['import sys\n\n\ndef next_str() -> str:\n result = ""\n while True:\n tmp = sys.stdin.read(1)\n if tmp.strip() != "":\n result += tmp\n elif tmp != \'\\r\':\n break\n return result\n\n\ndef main() -> None:\n s = next_str()\n dic = [set() for _ in range(len(s))]\n\n flg = False\n\n for i in range(len(s)):\n dic[i].add(s[i])\n\n print(dic)\n\n while True:\n for c in range(ord(\'a\'), ord(\'z\') + 1):\n for i in range(len(dic)):\n if chr(c) not in dic[i]:\n break\n else:\n flg = True\n\n for i in range(len(dic) - 1):\n dic[i] |= dic[i + 1]\n\n if flg: break\n dic = dic[:-1]\n\n print(len(s) - len(dic))\n\n\nif __name__ == \'__main__\':\n main()', 'import sys\n\n\ndef next_str() -> str:\n result = ""\n while True:\n tmp = sys.stdin.read(1)\n if tmp.strip() != "":\n result += tmp\n elif tmp != \'\\r\':\n break\n return result\n\n\ndef main() -> None:\n s = next_str()\n dic = [set() for _ in range(len(s))]\n\n flg = False\n\n for i in range(len(s)):\n dic[i].add(s[i])\n\n while True:\n for c in range(ord(\'a\'), ord(\'z\') + 1):\n for i in range(len(dic)):\n if chr(c) not in dic[i]:\n break\n else:\n flg = True\n\n for i in range(len(dic) - 1):\n dic[i] |= dic[i + 1]\n\n if flg: break\n dic = dic[:-1]\n\n print(len(s) - len(dic))\n\n\nif __name__ == \'__main__\':\n main()']
['Wrong Answer', 'Accepted']
['s157957700', 's598539742']
[3064.0, 3064.0]
[19.0, 19.0]
[789, 773]
p03687
u354638986
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["def main():\n s = input()\n c_set = set(s)\n\n min_c = len(s)\n for i in range(len(s)):\n if s[i] in c_set:\n max_c, f_idx = i, i\n for j in range(i+1, len(s)):\n if s[i] == s[j] or j == len(s) - 1:\n if max_c < j - f_idx - 1:\n max_c = j - f_idx - 1\n\n f_idx = j\n\n if max_c < min_c:\n min_c = max_c\n\n c_set.remove(s[i])\n\n print(min_c)\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n s = input()\n\n dic = {}\n for i in range(len(s)):\n if s[i] in dic:\n dic[s[i]].append(i)\n else:\n dic[s[i]] = [i]\n\n ans = 101\n for k in dic:\n dic[k].append(-1)\n dic[k].append(len(s))\n dic[k].sort()\n\n mx = -1\n for j in range(len(dic[k])-1):\n mx = max(mx, dic[k][j+1]-dic[k][j]-1)\n\n ans = min(ans, mx)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s900588511', 's268000131']
[3064.0, 3064.0]
[18.0, 18.0]
[520, 469]
p03687
u374531474
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from collections import Counter\n\ns = list(input())\n\nc = Counter(s)\nmc = c.most_common()\nlen_s = len(s)\nans = len_s\nfor l, n in mc:\n if n != mc[0][1]:\n break\n prev = 0\n x = 0\n for i in range(len_s):\n if s[i] == l:\n x = max(x, i - prev)\n prev = i + 1\n ans = min(ans, x)\n print(l, n, x)\nprint(ans)\n', 's = input()\nprint(min(max(len(p) for p in s.split(l)) for l in set(list(s))))\n']
['Wrong Answer', 'Accepted']
['s497536388', 's554191079']
[3316.0, 2940.0]
[21.0, 18.0]
[349, 78]
p03687
u405256066
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from sys import stdin\ns= (stdin.readline().rstrip())\nf = lambda a, b: abs(a-b-1)\ndiff = lambda ls: map(f, ls[1:], ls)\n\nans = 100\nfor i in set(s):\n indexes = [j for j,x in enumerate(list(s)) if x == i]\n indexes = [0] + indexes + [len(s)]\n index_diff = list(diff(indexes))\n ans = min(ans,max(max(index_diff),1))\nif len(set(s)) == 1:\n ans = 0\nprint(ans)', 'from sys import stdin\ns= (stdin.readline().rstrip())\nf = lambda a, b: abs(a-b-1)\ndiff = lambda ls: map(f, ls[1:], ls)\n\nans = 100\nfor i in set(s):\n indexes = [j for j,x in enumerate(list(s)) if x == i]\n indexes = [0] + indexes + [len(s)]\n index_diff = list(diff(indexes))\n if i == s[0]:\n ans = min(ans,max(index_diff))\n elif i == s[-1]:\n ans = min(ans,max(index_diff)+1)\n else:\n ans = min(ans,max(index_diff))\nif len(set(s)) == 1:\n ans = 0\nprint(ans)', 'from sys import stdin\ns= (stdin.readline().rstrip())\nf = lambda a, b: abs(a-b-1)\ndiff = lambda ls: map(f, ls[1:], ls)\n\nans = 100\nfor i in set(s):\n ans = min(ans,max([len(j) for j in s.split(i)]))\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s120566953', 's421971274', 's274522662']
[3064.0, 3064.0, 3060.0]
[17.0, 18.0, 17.0]
[363, 483, 209]
p03687
u453642820
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S=input()\nA="abcdefghijklmnopqrstuvwxyz"\nminimum=len(S)//2\nfor a in A:\n maximum=0\n for s in S:\n p=-1\n if a==s:\n maximum=max(p-1,maximum)\n p=0\n else:\n p+=1\n minimum=min(maximum,minimum)\nprint(minimum)', 'S=input()\nA="abcdefghijklmnopqrstuvwxyz"\nminimum=len(S)//2\nfor a in set(S):\n maximum=0\n ans_max=0\n p=0\n for s in S:\n if a==s:\n ans_max=max(p-1,maximum)\n p=0\n else:\n p+=1\n minimum=min(ans_max,minimum)\nprint(minimum)', 'from collections import Counter\nS=input()\ns=Counter(S)\nT=[key for key,value in s.items() if max(s.values())==value]\nminimum=len(S)//2\nfor t in T:\n P=[i for i,x in enumerate(S) if x==t]+[len(S)-1]\n maximum=P[0]\n for j in range(1,len(P)):\n if maximum<P[j]-P[j-1]-1:\n maximum=P[j]-P[j-1]-1\n minimum=min(minimum,maximum)\nprint(minimum)', 'S=input()\nA="abcdefghijklmnopqrstuvwxyz"\nminimum=len(S)//2\nfor a in A:\n ans_max=0\n p=0\n for s in S:\n if a==s:\n ans_max=max(p,ans_max)\n p=0\n else:\n p+=1\n ans_max=max(p,ans_max)\n minimum=min(ans_max,minimum)\nprint(minimum)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s010263432', 's086940338', 's092113759', 's774518824']
[3060.0, 3060.0, 3316.0, 3060.0]
[17.0, 17.0, 21.0, 17.0]
[262, 276, 361, 282]
p03687
u455591217
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["\nimport sys\n\ndef judgeUpper(ansList, var):\n for a in ansList:\n if int(a) > var:\n# print(a + ':' + str(var) + str(True))\n return True\n return False\ndef judgeEqual(ansList, var, N):\n count = ansList.count(str(var))\n# print(str(count) + ':' + str(N-1) + str(count < N - 1))\n return count < N - 1 or (count == N and var * 2 > N and var+1 != N)\ndef judgeLower(ansList, var):\n for a in ansList:\n if int(a) < var - 1:\n# print(a + ':' + str(var-1) + str(True))\n return True\n return False\n \nN = input()\nansList = input().split(' ')\nfor i in range(int(N)):\n var = i + 1\n if judgeUpper(ansList, var):\n continue\n if judgeEqual(ansList, var, int(N)):\n continue\n if judgeLower(ansList, var):\n continue\n print('Yes')\n sys.exit()\nprint('No')", '\ndef convertList(strList, c):\n time = 0\n tmpList = list(strList)\n while tmpList.count(c) != len(tmpList):\n newList = []\n for i in range(len(tmpList[:])-1):\n newList.append(c if (tmpList[i] == c or tmpList[i+1] == c) else tmpList[i])\n tmpList = list(newList)\n time += 1\n return time\n\nS = input()\nstrList = list(S)\nstrSet = set(strList)\nminTime = 1000000 \nfor c in strSet:\n time = convertList(strList, c)\n if minTime > time:\n minTime = time\nprint(minTime)']
['Runtime Error', 'Accepted']
['s785255850', 's587681264']
[3188.0, 3064.0]
[17.0, 38.0]
[853, 517]
p03687
u500297289
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s = input()\nl = set(list(s))\nN = len(s)\nn = len(s)\nans = 0\n\nfor ll in l:\n S = s\n while n > 0:\n tmp = ''\n for i in range(n - 1):\n if S[i] == ll or S[i + 1] == ll:\n tmp += ll\n else:\n tmp += S[i]\n if len(set(tmp)) == 1:\n ans = max(ans, len(tmp))\n break\n n -= 1\n S = tmp\n\nprint(N - ans)\n", "s = input()\nl = list(s)\nN = len(s)\nn = len(s)\nans = 0\n\nfor ll in l:\n S = s\n n = N\n while n > 0:\n tmp = ''\n for i in range(n - 1):\n if S[i] == ll or S[i + 1] == ll:\n tmp += ll\n else:\n tmp += S[i]\n print(tmp)\n if len(set(tmp)) == 1:\n ans = max(ans, len(tmp))\n break\n n -= 1\n S = tmp\n\nprint(N - ans)\n", "s = input()\nl = list(s)\nN = len(s)\nn = len(s)\nans = 0\n\nfor ll in l:\n S = s\n while n > 0:\n tmp = ''\n for i in range(n - 1):\n if S[i] == ll or S[i + 1] == ll:\n tmp += ll\n else:\n tmp += S[i]\n if len(set(tmp)) == 1:\n ans = max(ans, len(tmp))\n break\n n -= 1\n S = tmp\n\nprint(N - ans)\n", "s = input()\nl = list(s)\nN = len(s)\nn = len(s)\nans = 0\n\nif len(set(s)) == 1:\n print(0)\n exit()\n\nfor ll in l:\n S = s\n n = N\n while n > 0:\n tmp = ''\n for i in range(n - 1):\n if S[i] == ll or S[i + 1] == ll:\n tmp += ll\n else:\n tmp += S[i]\n if len(set(tmp)) == 1:\n ans = max(ans, len(tmp))\n break\n n -= 1\n S = tmp\n\nprint(N - ans)\n"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s252460630', 's309511823', 's783768469', 's777046932']
[3064.0, 3444.0, 3064.0, 3064.0]
[19.0, 141.0, 20.0, 136.0]
[398, 422, 393, 449]
p03687
u593567568
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from collections import Counter\n\nS = input()\nuni_s = list(set(list(S)))\n\nans = len(S) - 1\n\n# -1,1\nfor s in uni_s:\n L = len(S)\n T = list(S)\n all_same = [s == t for t in S]\n cnt = 0\n while not all(all_same):\n newT = [False] * (L-1)\n for i in range(L):\n t = T[i]\n if s == t:\n newT[i] = t\n if 0 <= i-1:\n newT[i-1] = t\n else:\n if not newT[i]:\n newT[i] = t\n if 0 <= i-1 and not newT[i-1]:\n newT[i-1] = t\n \n all_same = [s==t for t in newT]\n T = newT\n L = len(T)\n ans = min(ans,cnt)\n\nprint(ans)\n \n ', 'S = input()\nuni_s = list(set(list(S)))\n\nans = len(S) - 1\n\n# -1,1\nfor s in uni_s:\n L = len(S)\n T = list(S)\n all_same = [s == t for t in S]\n cnt = 0\n while not all(all_same):\n newT = [False] * (L-1)\n for i in range(L):\n t = T[i]\n if s == t:\n if i < L-1:\n newT[i] = t\n if 0 <= i-1:\n newT[i-1] = t\n else:\n if i < L-1 and not newT[i]:\n newT[i] = t\n if 0 <= i-1 and not newT[i-1]:\n newT[i-1] = t\n \n all_same = [s==t for t in newT]\n T = newT\n L = len(T)\n ans = min(ans,cnt)\n\nprint(ans)\n \n \n', 'S = input()\nuni_s = list(set(list(S)))\n\nans = len(S) - 1\n\n# -1,1\nfor s in uni_s:\n L = len(S)\n T = list(S)\n all_same = [s == t for t in S]\n cnt = 0\n while not all(all_same):\n cnt += 1\n newT = [False] * (L-1)\n for i in range(L):\n t = T[i]\n if s == t:\n if i < L-1:\n newT[i] = t\n if 0 <= i-1:\n newT[i-1] = t\n else:\n if i < L-1 and not newT[i]:\n newT[i] = t\n if 0 <= i-1 and not newT[i-1]:\n newT[i-1] = t\n \n all_same = [s==t for t in newT]\n T = newT\n L = len(T)\n ans = min(ans,cnt)\n\nprint(ans)\n \n \n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s286421990', 's414024741', 's506562296']
[3316.0, 3064.0, 3192.0]
[21.0, 64.0, 71.0]
[592, 594, 607]
p03687
u594329566
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['def solve (a , d):\n c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n old =a\n a=""\n for i in old:\n c[ord(i)-97]+=1\n if len(old) == max(c):\n return 0\n for i in range(len(old)-2):\n if old[i]==d or old[i+1]==d:\n a+=d\n else :\n a+=old[i]\n print(a+":")\n return solve(a,d)+1\n\na=input()\nb=True\n\nan =9999999999\nc=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nfor i in a:\n c[ord(i)-97]+=1\nindexes = [i for i, x in enumerate(c) if x == max(c)]\nfor i in indexes:\n print(chr(i+97)+"!!")\n t= solve(a,chr(i+97))\n if t<an:\n an=t\n\nprint(an)', 'def solve (a , d):\n c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n old =a\n a=""\n for i in old:\n c[ord(i)-97]+=1\n if len(old) == max(c):\n return 0\n for i in range(len(old)-2):\n if old[i]==d or old[i+1]==d:\n a+=d\n else :\n a+=old[i]\n return solve(a,d)+1\n\na=input()\nb=True\n\nan =9999999999\nc=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nfor i in a:\n c[ord(i)-97]+=1\nindexes = [i for i, x in enumerate(c) if x == max(c)]\nfor i in indexes:\n t= solve(a,chr(i+97))\n if t<an:\n an=t\n\nprint(an)', 'def solve (a , d):\n c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\n old =a\n a=""\n for i in old:\n c[ord(i)-97]+=1\n if len(old) == max(c):\n return 0\n for i in range(len(old)-1):\n if old[i]==d or old[i+1]==d:\n a+=d\n else :\n a+=old[i]\n return solve(a,d)+1\n\na=input()\nb=True\n\nan =9999999999\nc=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]\nfor i in a:\n c[ord(i)-97]+=1\nindexes = [i for i, x in enumerate(c) if x == max(c)]\nfor i in a:\n t= solve(a,i)\n if t<an:\n an=t\n\nprint(an)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s631406502', 's674969615', 's511807277']
[3064.0, 3064.0, 3188.0]
[19.0, 19.0, 116.0]
[636, 593, 579]
p03687
u619819312
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=list(input())\np=[chr(ord("a")+i)for i in range(26)]\nq=100\nif len(list(set(d)))==1:\n print(0)\nelse:\n for i in range(26):\n t=p[i]\n d=s[:]\n c=0\n while len(d)>0:\n c+=1\n for j in range(len(d)-1):\n if d[j]==t or d[j+1]==t:\n d[j]=t\n else:\n d.pop(-1)\n if len(list(set(d)))==1 and d[0]==t:\n break\n q=min(q,c)\n print(q)', 's=list(input())\np=[chr(ord("a")+i)for i in range(26)]\nq=100\nif len(list(set(s)))==1:\n print(0)\nelse:\n for i in range(26):\n t=p[i]\n d=s[:]\n c=0\n while len(d)>0:\n c+=1\n for j in range(len(d)-1):\n if d[j]==t or d[j+1]==t:\n d[j]=t\n else:\n d.pop(-1)\n if len(list(set(d)))==1 and d[0]==t:\n break\n q=min(q,c)\n print(q)']
['Runtime Error', 'Accepted']
['s713923091', 's650419438']
[3064.0, 3064.0]
[18.0, 48.0]
[471, 471]
p03687
u623687794
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=input()\nans=1000\nfor i in range(26):\n if chr(97+i) not in s:continue\n S=s\n cnt=0\n while(len(set(S)))!=1:\n cnt+=1\n t=""\n for j in range(len(S)-1):\n if S[j] == chr(97+i) or S[j+1] == chr(97+i):\n t+=chr(97+i)\n else:\n t+=S[j]\n ans=min(cnt,ans)\nprint(ans)', 's=input()\nans=1000\nfor i in range(26):\n if chr(97+i) not in s:continue\n S=s\n cnt=0\n while(len(set(S)))!=1:\n cnt+=1\n t=""\n for j in range(len(S)-1):\n if S[j] == chr(97+i) or S[j+1] == chr(97+i):\n t+=chr(97+i)\n else:\n t+=S[j]\n S=t\n ans=min(cnt,ans)\nprint(ans)\n']
['Time Limit Exceeded', 'Accepted']
['s678434882', 's505406075']
[3064.0, 3064.0]
[2103.0, 68.0]
[290, 299]
p03687
u624475441
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S = input()\nans = min(max(map(len, S.split(c)))\n for c in [chr(i + 97) for i in range(26)]\n if c not in S))\nprint(ans)', 'S = input()\nans = min(max(map(len, S.split(c)))\n for c in [chr(i + 97) for i in range(26)]\n if c not in S)\nprint(ans)', 'S = input()\nans = min(max(map(len, S.split(c)))\n for c in [chr(i + 97) for i in range(26)]\n if c in S)\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s027369558', 's092047056', 's200444093']
[2940.0, 2940.0, 2940.0]
[18.0, 18.0, 18.0]
[136, 135, 131]
p03687
u626468554
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S = list(input())\ndis = [0 for i in range(26)]\nmm = [0 for i in range(26)]\n\nfor i in range(len(S)):\n wd = ord(S[i])-97\n dis[wd] = max(dis[wd],i-mm[wd]-1)\n mm[wd] = i\n\nfor i in range(26):\n dis[i] = max(dis[i],len(S)-mm[i]-1)\nprint(min(dis))', 'S = list(input())\ndis = [0 for i in range(26)]\nmm = [-1 for i in range(26)]\n\nfor i in range(len(S)):\n wd = ord(S[i])-97\n dis[wd] = max(dis[wd],i-mm[wd]-1)\n mm[wd] = i\n\nfor i in range(26):\n dis[i] = max(dis[i],len(S)-mm[i]-1)\nprint(min(dis))\n# print(dis)']
['Wrong Answer', 'Accepted']
['s082964274', 's520541824']
[3064.0, 3064.0]
[18.0, 17.0]
[251, 265]
p03687
u629350026
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s=str(input())\nimport collections\nc=collections.Counter(s)\ntemp=c.most_common()[0][0]\ntempc=c.most_common()[0][1]\nl=len(s)\na=0\ncnt=0\nfor i in range(l):\n if s[i]!=temp:\n cnt=cnt+1\n else:\n a=max(a,cnt)\n cnt=0\na=max(a,cnt)\nprint(a)', 's=str(input())\nl=len(s)\nans=99999999999\nfor j in s:\n temp=j\n a=0\n cnt=0\n for i in range(l):\n if s[i]!=temp:\n cnt=cnt+1\n else:\n a=max(a,cnt)\n cnt=0\n a=max(a,cnt)\n ans=min(a,ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s265387072', 's130547215']
[3316.0, 3064.0]
[23.0, 19.0]
[239, 214]
p03687
u676264453
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['\nS = str(input())\n\nc = 0\nma = 0\nfor i in S:\n c = 0\n for k,j in enumerate(S):\n if ( k != 0 and k != N-1 and j != i and S[k-1] != a and S[k+1] != a):\n c += 1\n ma = min(ma, c)\n\nprint(ma)\n\n\n', '\n S = str(input())\n\n c = 0\n ma = 0\n for i in S:\n c = 0\n for k,j in enumerate(S):\n if ( k != 0 and k != len(S) and j != i and S[k-1] != a and S[k+1] != a):\n c += 1\n ma = min(ma, c)\n\n print(ma)\n\n', 'def check(s, S):\n for i in S:\n if (i != s):\n return True\n return False\n\nS = str(input())\nT = S\n\nm = 1000\nfor s in S:\n num = 0\n T = S\n while (check(s, T)):\n num += 1\n K = []\n for i in range(0, len(T) - 1):\n if s == T[i+1]:\n K.append(T[i+1])\n else:\n K.append(T[i])\n T = K\n m = min(m, num)\n\nprint(m)\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s700341936', 's720982567', 's974860591']
[2940.0, 2940.0, 3064.0]
[17.0, 18.0, 116.0]
[213, 225, 413]
p03687
u691018832
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\ns = input()\nlen_s = len(s)\ncnt = [0] * 26\nal = [chr(ord('a') + i) for i in range(26)]\nans = [''] * (len_s + 1)\nans[0] = s\nfor i in range(26):\n check = list(s)\n if al[i] in check:\n ans[0] = s\n while any([al[i] != a for a in check]):\n cnt[i] += 1\n for j in range(len_s - cnt[i]):\n if ans[cnt[i] - 1][j + 1] == al[i]:\n ans[cnt[i]] += al[i]\n else:\n ans[cnt[i]] += ans[cnt[i] - 1][j]\n check = list(ans[cnt[i]])\n ans[cnt[i] - 1] = ''\nif all(cnt[i] == 0 for i in range(26)):\n print(0)\nelse:\n s = list(set(s))\n s.sort()\n if s[0] == 0:\n print(s[1])\n else:\n print(s[0])\n", "import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\nsys.setrecursionlimit(10 ** 7)\n\nfrom copy import deepcopy\n\n\ndef moji_list(a, b):\n \n \n \n \n \n \n return [chr(i) for i in range(a, b)]\n\n\ns = list(read().rstrip().decode())\nans = float('inf')\nfor al in moji_list(97, 123):\n cnt = 0\n check_s = deepcopy(s)\n while len(set(check_s)) > 1:\n cnt += 1\n ss = []\n for bf, af in zip(check_s, check_s[1:]):\n ss.append(af if af == al else bf)\n check_s = ss\n ans = min(ans, cnt)\nprint(ans)\n"]
['Wrong Answer', 'Accepted']
['s656850982', 's315987573']
[3064.0, 3436.0]
[82.0, 44.0]
[869, 828]
p03687
u692632484
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s=input()\ns.lower()\n\na=[0 for i in range(26)]\nfor i in s:\n\ta[ord(i)-ord('a')]+=1\ntest=max(a)\n\nprint(len(s)-test)", 's=input()\n\nans=int(len(s)/2)\nfor i in range(26):\n\ttemp=0\n\ttempAns=0\n\tif s.count(chr(i+97))!=0:\n\t\tfor j in s:\n\t\t\tif j==chr(i+97):\n\t\t\t\ttempAns=max(temp,tempAns)\n\t\t\t\ttemp=0\n\t\t\telse:\n\t\t\t\ttemp+=1\n\t\ttempAns=max(temp,tempAns)\n\t\tans=min(ans,tempAns)\n\t\t#print(tempAns)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s921375370', 's631098823']
[2940.0, 3064.0]
[18.0, 18.0]
[112, 270]
p03687
u729133443
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from subprocess import*\nwith open(\'Main.java\',\'w\')as f:f.write(r\'\'\'\nimport java.util.Scanner;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString[] s = sc.next().split("");\n\t\tString[] v = {"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"};\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < 26; i++) {\n\t\t\tint tmp = 0;\n\t\t\tString[] u = s;\n\t\t\tloop: while (true) {\n\t\t\t\tboolean comp = true;\n\t\t\t\tfor (int j = 0; j < u.length; j++)\n\t\t\t\t\tif (!u[j].equals(u[0])) {\n\t\t\t\t\t\tcomp = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (comp) {\n\t\t\t\t\tans = Math.min(ans, tmp);\n\t\t\t\t\tbreak loop;\n\t\t\t\t}\n\t\t\t\tString[] w = new String[u.length - 1];\n\t\t\t\tfor (int j = 0; j < w.length; j++) {\n\t\t\t\t\tif (u[j].equals(v[i]) || u[j + 1].equals(v[i]))\n\t\t\t\t\t\tw[j] = v[i];\n\t\t\t\t\telse\n\t\t\t\t\t\tw[j] = u[j];\n\t\t\t\t}\n\t\t\t\tu = w;\n\t\t\t\ttmp++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n\'\'\')\ncall((\'javac\',\'Main.java\'))\ncall((\'java\',\'Main\'))', 'from subprocess import*\nwith open(\'Main.java\',\'w\')as f:f.write(r"""\nimport java.util.Scanner;\npublic class Main {\n\tpublic static void main(String[] args) {\n\t\tScanner sc = new Scanner(System.in);\n\t\tString[] s = sc.next().split("");\n\t\tString[] v = {"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"};\n\t\tint ans = Integer.MAX_VALUE;\n\t\tfor (int i = 0; i < 26; i++) {\n\t\t\tint tmp = 0;\n\t\t\tString[] u = s;\n\t\t\tloop: while (true) {\n\t\t\t\tboolean comp = true;\n\t\t\t\tfor (int j = 0; j < u.length; j++)\n\t\t\t\t\tif (!u[j].equals(u[0])) {\n\t\t\t\t\t\tcomp = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\tif (comp) {\n\t\t\t\t\tans = Math.min(ans, tmp);\n\t\t\t\t\tbreak loop;\n\t\t\t\t}\n\t\t\t\tString[] w = new String[u.length - 1];\n\t\t\t\tfor (int j = 0; j < w.length; j++) {\n\t\t\t\t\tif (u[j].equals(v[i]) || u[j + 1].equals(v[i]))\n\t\t\t\t\t\tw[j] = v[i];\n\t\t\t\t\telse\n\t\t\t\t\t\tw[j] = u[j];\n\t\t\t\t}\n\t\t\t\tu = w;\n\t\t\t\ttmp++;\n\t\t\t}\n\t\t}\n\t\tSystem.out.println(ans);\n\t}\n}\n""")\ncall((\'javac\',\'Main.java\'))\ncall((\'java\',\'Main\'))', 's=input()\nprint(min(max(map(len,s.split(t)))for t in s))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s338252279', 's781127590', 's711065907']
[58376.0, 58012.0, 2940.0]
[1062.0, 1062.0, 18.0]
[1014, 1014, 56]
p03687
u745087332
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['# coding:utf-8\n\nfrom collections import Counter\n\n\ndef inpl(): return list(map(int, input().split()))\n\n\nS = input()\nC = Counter(S)\nif len(S) == 1:\n print(0)\n exit()\n\nans = 100\nfor key in C.keys():\n prev_S = list(S)\n cnt = 0\n t = len(S) - 1\n while t > 0:\n if all([1 if s == key else 0 for s in prev_S]):\n ans = min(ans, cnt)\n break\n SS = []\n for i in range(t):\n if key in prev_S[i: i + 2]:\n SS.append(key)\n else:\n SS.append(prev_S[i])\n cnt += 1\n t -= 1\n prev_S = SS[:]\n print(cnt, prev_S)\n\nprint(ans)\n', "# coding:utf-8\n\nimport sys\nfrom collections import Counter\n\nINF = float('inf')\nMOD = 10 ** 9 + 7\n\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 LS(): return sys.stdin.readline().split()\ndef II(): return int(sys.stdin.readline())\ndef SI(): return input()\n\n\ndef main():\n s = SI()\n char_cnt = Counter(s)\n\n res = INF\n for c in char_cnt.keys():\n r = s[:]\n cnt = 0\n while len(set(r)) != 1:\n t = ''\n for ss in zip(r[:-1], r[1:]):\n if c in ss:\n t += c\n else:\n t += ss[0]\n cnt += 1\n r = t\n # print(r)\n res = min(res, cnt)\n\n return res\n\n\nprint(main())\n"]
['Wrong Answer', 'Accepted']
['s828904139', 's302984127']
[3316.0, 3316.0]
[61.0, 35.0]
[636, 799]
p03687
u749614185
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S = input()\na = 1000 \nfor i in range (len(S)):\n A = B = 0\n for j in range (1, len(S) + 1):\n if S[i] == S[len(S)-j]:\n A = 0\n else:\n A += 1\n B = max(A,B)\n a = min(A,B)\nprint(a)', 'S = input()\nval = 10**9\n \nvoc = set(S)\nfor c in voc:\n cnt = 0\n tmp = list(S)\n \n while True:\n if all([w == c for w in tmp]):\n val = min(cnt, val)\n break\n cnt += 1\n for u in range(len(tmp)-1):\n tmp[u] = c if tmp[u] == c or tmp[u+1] == c else tmp[u] \n tmp.pop()\n \n \nprint(val)']
['Wrong Answer', 'Accepted']
['s071082103', 's777632509']
[9036.0, 9132.0]
[30.0, 44.0]
[226, 346]
p03687
u757584836
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["s = input()\nc = [0]*26\nv = []\nm = 0\nfor i in range(0, len(s)):\n c[(int)s[i]-'a'] += 1\nfor i in range(0, 26):\n m = max(m, c[i])\nfor i in range(0, 26):\n if c[i] == m:\n v.append((char)'a'+i)\na = 10000\nfor i in range(0, len(c)):\n n = 0\n t = 0\n for j in range(0, len(s)):\n if s[j] != v[i]:\n t += 1\n else:\n n = max(n, (t+1)//2)\n n = max(n, (t+1)//2)\n a = min(a, n)\nprint(a)", 's = input()\na = 10000\nfor i in range(0, 26):\n n = 0\n t = 0\n b = True\n for j in range(0, len(s)):\n if s[j] != chr(ord("a")+i):\n t += 1\n elif b:\n n = max(n, t)\n t = 0\n else:\n n = max(n, (t+1)//2)\n t = 0\n n = max(n, t)\n a = min(a, n)\nprint(a)']
['Runtime Error', 'Accepted']
['s056644039', 's477645947']
[2940.0, 3064.0]
[17.0, 18.0]
[394, 279]
p03687
u785989355
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
["def itoa(i):\n alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',\n 'p','q','r','s','t','u','v','w','x','y','z']\n return alphabet[i]\ns = input()\nscore_list = []\nfor i in range(26):\n c = itoa(i)\n prev = -1\n score = 0\n flag=False\n for j in range(len(s)):\n if c==s[j]:\n score=max(j-prev-1,score)\n flag=True\n prev=j\n score = max(j-prev,score)\n if flag==False:\n score=10**3\n score_list.append(score)\n \nprint(min(score_list))\nprint(score_list)", "def itoa(i):\n alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',\n 'p','q','r','s','t','u','v','w','x','y','z']\n return alphabet[i]\ns = input()\nscore_list = []\nfor i in range(26):\n c = itoa(i)\n prev = 0\n score = 0\n flag=False\n for j in range(len(s)):\n if c==s[j]:\n score=max(j-prev-1,score)\n flag=True\n prev=j\n score = max(j-prev,score)\n if flag==False:\n score=10**3\n score_list.append(score)\n \nprint(min(score_list))", '\ns=input()\nc=[]\nfor i in range(len(s)):\n if not s[i] in c:\n c.append(s[i])\ncount_max_list = []\nfor a in c:\n count=0\n count_max = 0\n for i in range(len(s)):\n if a==s[i]:\n count_max=max(count,count_max)\n count=0\n else:\n count+=1\n count_max=max(count,count_max)\n count_max_list.append(count_max)\nprint(min(count_max_list))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s101701150', 's414748141', 's762420777']
[3064.0, 3064.0, 3064.0]
[19.0, 18.0, 18.0]
[552, 533, 391]
p03687
u794543767
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from collections import Counter\ns = input()\ncounter = Counter(s)\ntarget = counter.most_common()[0][0]\nj = 0\nwhile(1):\n if len(set(s)) == 1:\n break\n new_s = ""\n for i in range(len(s)-1):\n if s[i] == target or s[i+1] == target:\n new_s +=target\n else:\n new_s += s[i]\n j+=1;\n s = new_s\nprint(j)', '\na = input()\n\nfor target in set(s):\n s = a\n j = 0\n min = 10000\n while(1):\n \n if len(set(s)) == 1:\n break\n new_s = ""\n for i in range(len(s)-1):\n if s[i] == target or s[i+1] == target:\n new_s +=target\n else:\n new_s += s[i]\n j+=1;\n s = new_s\n if min > j:\n min = j\nprint(min)', 'from collections import Counter\ns = raw_input()\ncounter = Counter(s)\ntarget = counter.most_common()[0][0]\nj = 0\nwhile(1):\n if len(set(s)) == 1:\n break\n new_s = ""\n for i in range(len(s)-1):\n if s[i] == target or s[i+1] == target:\n new_s +=target\n else:\n new_s += s[i]\n j+=1;\n s = new_s\nprint(j)', 'a = input()\nmin = 10000\nfor target in set(a):\n s = a\n j = 0\n while(1):\n \n if len(set(s)) == 1:\n break\n new_s = ""\n for i in range(len(s)-1):\n if s[i] == target or s[i+1] == target:\n new_s +=target\n else:\n new_s += s[i]\n j+=1;\n if j > min:\n break\n s = new_s\n if min > j:\n min = j\n\nprint(min)']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s133338191', 's508456482', 's682274516', 's597801439']
[3316.0, 3064.0, 3316.0, 3064.0]
[21.0, 24.0, 20.0, 41.0]
[348, 399, 352, 432]
p03687
u817328209
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S = input()\n\nfor c in string.lowercase :\n if c not in S :\n continue\n\n X = S.split(c)\n ans = 0\n for str in X :\n ans = max(ans, len(str))\n\nprint(ans)', 'S = input()\nchars = set(S)\nans = len(S)\n\nfor c in chas :\n m = max(len(_) for _ in S.split(c))\n ans = min(ans, m)\n\nprint(ans)', 'S = input()\nchars = set(S)\nans = len(S)\n\nfor c in chars :\n m = max(len(_) for _ in S.split(c))\n ans = min(ans, m)\n\nprint(ans)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s238955231', 's520588623', 's044578849']
[2940.0, 3060.0, 3060.0]
[17.0, 18.0, 18.0]
[173, 130, 131]
p03687
u861141787
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s = input()\nans = float("inf")\nfor i in range(26):\n c = chr(ord("a")+i)\n if c not in s:\n continue\n temp = s\n count = 0\n while set(temp) != {c}:\n t = ""\n for j in range(len(temp)-1):\n if temp[j] == c or temp[j+1] == c:\n t += c\n else:\n t += "#"\n temp = t\n count += 1\n print(temp)\n ans = min(ans, count)\nprint(ans)', 's = input()\n\nans = float("inf")\nfor i in range (26):\n a = chr(ord("a")+i)\n if s.count(a) == 0 :\n pass\n else:\n tmp = s\n c = 0\n while set(tmp) != {a}:\n t = ""\n for j in range(len(tmp)-1):\n if tmp[j] == a or tmp[j+1] == a:\n t += a\n else:\n t += tmp[j]\n c += 1\n tmp = t\n ans = min(c, ans)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s325087148', 's021840357']
[3064.0, 3060.0]
[47.0, 51.0]
[359, 453]
p03687
u879870653
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['S = input()\nP = list(set(P))\nANS = []\nfor i in range(len(P)) :\n T = list(S.split(P[i]))\n U = []\n for j in range(len(T)) :\n U.append(len(T[j]))\n ANS.append(max(U))\nprint(min(ANS))\n', 'S = input()\nP = list(set(S))\nANS = []\nfor i in range(len(P)) :\n T = list(S.split(P[i]))\n U = []\n for j in range(len(T)) :\n U.append(len(T[j]))\n ANS.append(max(U))\nprint(min(ANS))\n']
['Runtime Error', 'Accepted']
['s857503330', 's346480960']
[2940.0, 2940.0]
[17.0, 17.0]
[198, 198]
p03687
u921773161
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['import statistics\nimport math\n\nl = list(input())\n\nmode = statistics.mode(l)\nmode = l.count(mode)\n\ncheck = 0\n\n\n\nfor i in range(len(l)):\n if mode * (2**i) >= len(l) -i :\n ans = i\n break\n\nprint(ans)', 'import collections\ns = list(input())\n#print(s)\nc = collections.Counter(s)\nl = list(c.items())\nl = sorted(l, key = lambda x : x[1], reverse=True)\n#print(l)\n\nh = []\ntmp = l[0][1]\n\nfor i in range(len(l)):\n h.append(l[i][0])\n\n\n#print(h)\n\nans = []\n\nfor i in range(len(h)):\n tmp = [_ for _, x in enumerate(s) if x == h[i]]\n# print(h[i])\n# print(tmp)\n lll = []\n for j in range(len(tmp)):\n if j == 0:\n lll.append(tmp[j])\n else:\n lll.append(tmp[j] - tmp[j-1] - 1)\n lll.append(len(s) - tmp[len(tmp) - 1] - 1)\n ans.append(max(lll))\n# print(lll)\n\n\n#print(ans)\nprint(min(ans))\n \n \n']
['Runtime Error', 'Accepted']
['s846543027', 's046143067']
[5276.0, 3316.0]
[39.0, 24.0]
[250, 655]
p03687
u945418216
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['from collections import Counter\nss = input()\n\nans = 1000\ncandidates = set(ss)\nfor s in candidates:\n count = 0\n t = list(ss)\n while True:\n t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]\n print(count, s, t)\n if len(set(t))==1:\n ans = min(ans, count)\n break\n count += 1\nprint(ans)', 'from collections import Counter\nss = input()\n\nans = 1000\ncandidates = set(ss)\nfor s in candidates:\n count = 0\n t = list(ss)\n while True:\n t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]\n if len(set(t))==1:\n ans = min(ans, count)\n break\n count += 1\nprint(ans)', 'from collections import Counter\nss = input()\n\nans = 1000\ncandidates = set(ss)\nfor s in candidates:\n count = 0\n t = list(ss)\n while True:\n if len(set(t))==1:\n ans = min(ans, count)\n break\n t = [t[i] if t[i+1] != s else t[i+1] for i in range(len(t)-1)]\n count += 1\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s201544339', 's714704048', 's798669623']
[14392.0, 3316.0, 3316.0]
[2104.0, 2104.0, 37.0]
[352, 325, 325]
p03687
u995062424
2,000
262,144
Snuke can change a string t of length N into a string t' of length N - 1 under the following rule: * For each i (1 ≤ i ≤ N - 1), the i-th character of t' must be either the i-th or (i + 1)-th character of t. There is a string s consisting of lowercase English letters. Snuke's objective is to apply the above operation to s repeatedly so that all the characters in s are the same. Find the minimum necessary number of operations.
['s = input()\nal = set(list(s)) \nans = 100\n\nfor c in al:\n L = list(s.split(c))\n print(L)\n tmp = 0\n for st in L:\n tmp = max(tmp, len(st))\n \n \n ans = min(tmp, ans)\n #print(ans)\nprint(ans)', 's = input()\nal = set(list(s)) \nans = 100\n\nfor c in al:\n L = list(s.split(c))\n tmp = 0\n for st in L:\n tmp = max(tmp, len(st))\n \n \n ans = min(tmp, ans)\n #print(ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s231633314', 's245809492']
[3060.0, 3060.0]
[17.0, 17.0]
[270, 257]
p03688
u021548497
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['import sys\ninput = sys.stdin.readline\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n \n M, m = max(a), min(a)\n c = a.count(m)\n C = a.count(M)\n \n if M == m:\n if n//2 >= m:\n judge = True\n else:\n judge = False\n else:\n if (n-c) >= C*2:\n judge = True\n else:\n judge = False\n \n \n print("Yes" if judge else "No")\n \n \n \nif __name__ == "__main__":\n main()\n', 'import sys\ninput = sys.stdin.readline\n\ndef main():\n n = int(input())\n a = list(map(int, input().split()))\n \n M, m = max(a), min(a)\n c = a.count(m)\n C = a.count(M)\n \n if M == m:\n if n//2 >= m or m == n-1:\n judge = True\n else:\n judge = False\n else:\n if M - m > 1:\n judge = False\n elif M - c <= 0:\n judge = False\n elif n-c >= (M-c)*2:\n judge = True\n else:\n judge = False\n \n \n print("Yes" if judge else "No")\n \n \n \nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Accepted']
['s922098547', 's939066864']
[20668.0, 20796.0]
[57.0, 55.0]
[491, 606]
p03688
u102461423
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["import sys\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN = int(readline())\nA = sorted(map(int, readline().split()))\n\ndef main(A):\n N = len(A)\n if A[0] == A[-1]:\n x = A[0]\n return x == N - 1 or 2 * x <= N\n if A[0] + 1 != A[-1]:\n return False\n a, b = A[0], A[-1]\n full = b\n unique = A.count(a)\n people, color = N - unique, A[-1] - unique\n return color > 1 and 2 * color <= people\n\nprint('Yes' if main(A) else 'No')", "import sys\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN = int(readline())\nA = sorted(map(int, readline().split()))\n\ndef main(A):\n N = len(A)\n if A[0] == A[-1]:\n x = A[0]\n return x == N - 1 or 2 * x <= N\n if A[0] + 1 != A[-1]:\n return False\n a, b = A[0], A[-1]\n full = b\n unique = A.count(a)\n people, color = N - unique, A[-1] - unique\n return color > 0 and 2 * color <= people\n\nprint('Yes' if main(A) else 'No')"]
['Wrong Answer', 'Accepted']
['s943660382', 's527986530']
[18348.0, 18344.0]
[50.0, 51.0]
[520, 520]
p03688
u128646083
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["n=int(input())\na=list(map(int,input().split()))\nb=sorted(a)\nc=0\nif(b[n-1]-b[0]>1):\n print('No')\nelif(b[n-1]-b[0]==0):\n if(1<=b[0]<=n//2 or b[0]==n-1):\n print('Yes')\n else:\n print('No')\nelse:\n for i in range(n-1):\n if(b[i]<b[i+1]):\n c=i\n break\n if(c==n-2):\n print('No')\n elif(c+2<=b[0]<=+1+(n-c-1)//2):\n print('Yes') \n else:\n print('No')", "n=int(input())\na=list(map(int,input().split()))\nb=sorted(a)\nc=0\nif(b[n-1]-b[0]>1):\n print('No')\nelif(b[n-1]-b[0]==0):\n if(1<=b[0]<=n//2 or b[0]==n-1):\n print('Yes')\n else:\n print('No')\nelse:\n for i in range(n-1):\n if(b[i]<b[i+1]):\n c=i\n break\n if(c==n-2):\n print('No')\n elif(c+2<=b[0]<=c+1+(n-c-1)//2):\n print('Yes') \n else:\n print('No')", "n=int(input())\na=list(map(int,input().split()))\nb=sorted(a)\nc=0\nif(b[n-1]-b[0]>1):\n print('No')\nelif(b[n-1]-b[0]==0):\n if(1<=b[0]<=n//2 or b[0]==n-1):\n print('Yes')\n else:\n print('No')\nelse:\n for i in range(n-1):\n if(b[i]<b[i+1]):\n c=i\n break\n if(c==n-2):\n print('No')\n elif(c+1<=b[0]<=c+(n-c-1)//2):\n print('Yes') \n else:\n print('No')"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s116687340', 's118971817', 's154894639']
[14092.0, 14092.0, 14092.0]
[58.0, 58.0, 59.0]
[428, 429, 427]
p03688
u148423304
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n = int(input())\na = list(map(int, input().split()))\nimport collections\nl1 = collections.Counter(a).most_common()\nl1.sort()\nif len(l1) > 2\u3000or l1[1][0] - l1[0][0] > 1:\n print("No")\nelif len(l1) == 1:\n if l1[0][0] * 2 <= n or l1[0][0] == n - 1:\n print("Yes")\n else:\n print("No")\nelse:\n if l1[1][1] >= (l1[1][0] - l1[0][1]) * 2 and l1[1][0] > l1[0][1]:\n print("Yes")\n else:\n print("No")', 'n = int(input())\na = list(map(int, input().split()))\nimport collections\nl1 = collections.Counter(a).most_common()\nl1.sort()\nif len(l1) > 2:\n print("No")\nelif len(l1) == 1:\n if l1[0][0] * 2 <= n or l1[0][0] == n - 1:\n print("Yes")\n else:\n print("No")\nelse:\n if l1[1][0] - l1[0][0] > 1:\n print("No")\n elif l1[1][1] >= (l1[1][0] - l1[0][1]) * 2 and l1[1][0] > l1[0][1]:\n print("Yes")\n else:\n print("No")']
['Runtime Error', 'Accepted']
['s675215058', 's561415250']
[2940.0, 21360.0]
[17.0, 79.0]
[571, 596]
p03688
u163320134
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["n=int(input())\narr=list(map(int,input().split()))\namax=max(arr)\namin=min(arr)\nif amax-amin>=2:\n print('No')\nelif amax-amin==0:\n flag=False\n for i in range(n):\n if arr[i]!=n-1:\n break\n else:\n flag=True\n for i in range(n):\n if 2*arr[i]>n:\n break\n else:\n flag=True\n if flag==True:\n print('Yes')\n else:\n print('No')\nelif amax-amin==1:\n cnt1=0\n cnt2=0\n for i in range(n):\n if arr[i]==amax-1:\n cnt1+=1\n else:\n cnt2+=1\n if cnt1<amax and 2*(amax-cnt1)<cnt2:\n print('Yes')\n else:\n print('No')", "n=int(input())\narr=list(map(int,input().split()))\namax=max(arr)\namin=min(arr)\nif amax-amin>=2:\n print('No')\nelif amax-amin==0:\n flag=False\n for i in range(n):\n if arr[i]!=n-1:\n break\n else:\n flag=True\n for i in range(n):\n if 2*arr[i]>n:\n break\n else:\n flag=True\n if flag==True:\n print('Yes')\n else:\n print('No')\nelif amax-amin==1:\n cnt1=0\n cnt2=0\n for i in range(n):\n if arr[i]==amax:\n cnt1+=1\n else:\n cnt2+=1\n if cnt1<amax and 2*(amax-cnt1)<=cnt2:\n print('Yes')\n else:\n print('No')", "n=int(input())\narr=list(map(int,input().split()))\namax=max(arr)\namin=min(arr)\nif amax-amin>=2:\n print('No')\nelif amax-amin==0:\n flag=False\n for i in range(n):\n if arr[i]!=n-1:\n break\n else:\n flag=True\n for i in range(n):\n if 2*arr[i]>n:\n break\n else:\n flag=True\n if flag==True:\n print('Yes')\n else:\n print('No')\nelif amax-amin==1:\n cnt1=0\n cnt2=0\n for i in range(n):\n if arr[i]==amax:\n cnt1+=1\n else:\n cnt2+=1\n if cnt1<amax and 2*(amax-cnt1)<cnt2:\n print('Yes')\n else:\n print('No')", "n=int(input())\narr=list(map(int,input().split()))\namax=max(arr)\namin=min(arr)\nif amax-amin>=2:\n print('No')\nelif amax-amin==0:\n flag=False\n for i in range(n):\n if arr[i]!=n-1:\n break\n else:\n flag=True\n for i in range(n):\n if 2*arr[i]>n:\n break\n else:\n flag=True\n if flag==True:\n print('Yes')\n else:\n print('No')\nelif amax-amin==1:\n cnt1=0\n cnt2=0\n for i in range(n):\n if arr[i]==amax-1:\n cnt1+=1\n else:\n cnt2+=1\n if cnt1<amax and 2*(amax-cnt1)<=cnt2:\n print('Yes')\n else:\n print('No')"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s044830743', 's080140254', 's117046933', 's093164097']
[14008.0, 14092.0, 14092.0, 14092.0]
[63.0, 62.0, 61.0, 66.0]
[546, 545, 544, 547]
p03688
u227082700
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n=int(input())\na=list(map(int,input().split()))\nif max(a)-2<=min(a):exit(print("No"))\nif len(set(a))==1:\n m=a[0]\n if m==n-1 or 2*m<=n:print("Yes")\n else:print("No")\nelse:\n x=a.count(min(a))\n y=n-x\n if x<max(a) and 2*(max(a)-x)<=y:print("Yes")\n else:print("No")', 'yes="Yes"\nno="No"\nn=int(input())\na=list(map(int,input().split()))\nif max(a)-min(a)>1:exit(print(no))\nif a==[a[0]]*n:\n if a[0]==n-1:print(yes)\n elif 2*a[0]<=n:print(yes)\n else:print(no)\nelse:\n mi=a.count(min(a))\n ma=n-mi\n if mi<max(a) and 2*(max(a)-mi)<=ma:print(yes)\n else:print(no)\n']
['Wrong Answer', 'Accepted']
['s923863261', 's710058601']
[14204.0, 20784.0]
[55.0, 58.0]
[267, 290]
p03688
u257974487
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n = int(input())\ncats = list(map(int,input().split()))\nflag = True\np, q = max(cats), min(cats)\nx = cats.count(p)\ny = cats.count(q)\nif p > q + 1:\n flag = False\nelif p == q:\n if n - p > 1 and p * 2 > n:\n flag = False\nelse:\n if x >= p or (p-x) * 2 > y:\n flag = False\n\nif flag:\n print("Yes")\nelse:\n print("No")', 'n = int(input())\ncats = list(map(int,input().split()))\nflag = True\np, q = max(cats), min(cats)\nx = cats.count(p)\ny = cats.count(q)\nif p - q >= 2:\n flag = False\nelif p == q:\n if p != n - 1 and p * 2 > n:\n flag = False\nelse:\n if y >= p or (p-y) * 2 > x:\n flag = False\n\nif flag:\n print("Yes")\nelse:\n print("No")']
['Wrong Answer', 'Accepted']
['s213430686', 's195382783']
[14092.0, 13964.0]
[46.0, 46.0]
[335, 337]
p03688
u268516119
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['import sys\ndef printans(t):\n print(t)\n sys.exit()\n\nN=int(input())\nA=[int(i) for i in input().split()]\n\nif all([a==A[0] for a in A]):\n shurui=A[0]\n if shurui==N-1 or shurui*2<=N:\n printans("Yes")\n else:printans("No")\nelse:\n maxshurui = max(A)\n if all([a in (maxshurui,maxshurui-1)]):\n unique = A.count(maxshurui-1)\n shurui = maxshurui-unique\n if shurui<=0:\n printans("No")\n if shurui*2<=N-unique:\n printans("Yes")\n else:printans("No")', 'import sys\ndef printans(t):\n print(t)\n sys.exit()\n\nN=int(input())\nA=[int(i) for i in input().split()]\n\nif all([a==A[0] for a in A]):\n shurui=A[0]\n if shurui==N-1 or shurui*2<=N:\n printans("Yes")\n else:printans("No")\nelse:\n maxshurui = max(A)\n if all([a in (maxshurui,maxshurui-1) for a in A]):\n unique = A.count(maxshurui-1)\n shurui = maxshurui-unique\n if shurui<=0:\n printans("No")\n if shurui*2<=N-unique:\n printans("Yes")\n else:printans("No")\n else:printans("No")']
['Runtime Error', 'Accepted']
['s271197245', 's870271858']
[13964.0, 13964.0]
[53.0, 68.0]
[610, 645]
p03688
u284854859
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["n = int(input())\n\na = list(map(int,int(input())))\na_max = max(a)\na_min = min(a)\nif a_max > a_min+1:\n print('No')\n exit()\nk = a_max\nif a_max == a_min:\n if k == n-1 or 2*k <= n:\n print('Yes')\n else:\n print('No')\nelse:\n uni = a.count(k-1)\n if k >= uni + 1 and k <= uni + (n-uni)//2:\n print('Yes')\n else:\n print('No')", "n = int(input())\n\na = list(map(int,input().split()))\na_max = max(a)\na_min = min(a)\nif a_max > a_min+1:\n print('No')\n exit()\nk = a_max\nif a_max == a_min:\n if k == n-1 or 2*k <= n:\n print('Yes')\n else:\n print('No')\nelse:\n uni = a.count(k-1)\n if k >= uni + 1 and k <= uni + (n-uni)//2:\n print('Yes')\n else:\n print('No')"]
['Runtime Error', 'Accepted']
['s544313425', 's209829435']
[4788.0, 14004.0]
[20.0, 44.0]
[362, 365]
p03688
u285891772
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom fractions import gcd\nfrom heapq import heappush, heappop, heapify\nfrom functools import reduce, lru_cache\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float(\'inf\')\nmod = 10**9 + 7\n#from decimal import *\n\nN = INT()\na = LIST()\n\nif len(set(a)) == 1:\n\tif a[0] == N-1 or a[0] <= N//2:\n\t\tprint("Yes")\n\telse:\n\t\tprint("No")\n\nelif len(set(a)) == 2:\n\tp, q = sorted(list(set(a)))\n\tif a.count(p) == p and q == p+1 and p <= N-2:\n\t\tprint("Yes")\n\telse:\n\t\tprint("No")\n\nelse:\n\tprint("No")', 'import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import deepcopy\nfrom string import ascii_lowercase, ascii_uppercase, digits\nfrom bisect import bisect, bisect_left, insort, insort_left\nfrom heapq import heappush, heappop\nfrom functools import reduce, lru_cache\ndef input(): return sys.stdin.readline().strip()\ndef INT(): return int(input())\ndef MAP(): return map(int, input().split())\ndef LIST(): return list(map(int, input().split()))\ndef TUPLE(): return tuple(map(int, input().split()))\ndef ZIP(n): return zip(*(MAP() for _ in range(n)))\nsys.setrecursionlimit(10 ** 9)\nINF = float(\'inf\')\nmod = 10 ** 9 + 7 \n#mod = 998244353\n#from decimal import *\n#import numpy as np\n#decimal.getcontext().prec = 10\n\nN = INT()\na = LIST()\n\nif max(a) - min(a) == 0 and (a[0] == N-1 or a[0] <= N//2):\n\tprint("Yes")\nelif max(a) - min(a) == 1 and a.count(min(a))+1 <= max(a) <= a.count(min(a)) + a.count(max(a))//2:\n\tprint("Yes")\nelse:\n\tprint("No")']
['Wrong Answer', 'Accepted']
['s563134463', 's720747711']
[21988.0, 21556.0]
[65.0, 72.0]
[1162, 1215]
p03688
u333945892
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["from collections import defaultdict,deque\nimport sys,heapq,bisect,math,itertools,string,queue,datetime\nsys.setrecursionlimit(10**8)\nINF = float('inf')\nmod = 10**9+7\neps = 10**-7\ndef inpl(): return list(map(int, input().split()))\ndef inpls(): return list(input().split())\n\nN = int(input())\naa = inpl()\nMIN = min(aa)\nMAX = max(aa)\n\nif MAX-MIN > 1:\n\tprint('No')\nelif MAX == MIN:\n\tif MAX == N-1:\n\t\tprint('Yes')\n\telif MAX <= N//2:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\nelse: #MAX-MIN == 1\n\tn_MIN = n_MAX = 0\n\tfor a in aa:\n\t\tif a == MIN: n_MIN += 1\n\t\tif a == MAX: n_MAX += 1\n\tprint(n_MIN,n_MAX)\n\tx_min = n_MIN + 1\n\tx_max = n_MIN + n_MAX//2\n\tif x_min <= MAX <= x_max:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n", "from collections import defaultdict,deque\nimport sys,heapq,bisect,math,itertools,string,queue,datetime\nsys.setrecursionlimit(10**8)\nINF = float('inf')\nmod = 10**9+7\neps = 10**-7\ndef inpl(): return list(map(int, input().split()))\ndef inpls(): return list(input().split())\n\nN = int(input())\naa = inpl()\nMIN = min(aa)\nMAX = max(aa)\n\nif MAX-MIN > 1:\n\tprint('No')\nelif MAX == MIN:\n\tif MAX == N-1:\n\t\tprint('Yes')\n\telif MAX <= N//2:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\nelse: #MAX-MIN == 1\n\tn_MIN = n_MAX = 0\n\tfor a in aa:\n\t\tif a == MIN: n_MIN += 1\n\t\tif a == MAX: n_MAX += 1\n\tx_min = n_MIN + 1\n\tx_max = n_MIN + n_MAX//2\n\tif x_min <= MAX <= x_max:\n\t\tprint('Yes')\n\telse:\n\t\tprint('No')\n"]
['Wrong Answer', 'Accepted']
['s791540290', 's644145140']
[15600.0, 15596.0]
[74.0, 74.0]
[695, 675]
p03688
u391731808
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['N=int(input())\n*A, = map(int,input().split())\nB = {}\nfor a in A: B[a] = B.get(a,0)+1\nm = min(B)\nM = max(B)\nif m+1<M:\n print("NO")\n exit()\ndef check(n):\n b0 = B.setdefault(n-1,0)\n b1 = B.setdefault(n,0)\n if b1==0:\n return b0==n\n else:\n return 1<= n-b0 <= b1//2\nif m+1==M:\n ans = check(M)\nelse:\n ans = check(m) or check(m+1)\nprint("YES" if ans else "NO")', 'N=int(input())\n*A, = map(int,input().split())\nB = {}\nfor a in A: B[a] = B.get(a,0)+1\nm = min(B)\nM = max(B)\nif m+1<M:\n print("No")\n exit()\ndef check(n):\n b0 = B.setdefault(n-1,0)\n b1 = B.setdefault(n,0)\n if b1==0:\n return b0==n\n else:\n return 1<= n-b0 <= b1//2\nif m+1==M:\n ans = check(M)\nelse:\n ans = check(m) or check(m+1)\nprint("Yes" if ans else "No")']
['Wrong Answer', 'Accepted']
['s989491794', 's182757694']
[18272.0, 17400.0]
[68.0, 71.0]
[390, 390]
p03688
u392319141
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["from collections import Counter\n\nN = int(input())\nA = Counter(map(int, input().split()))\n\nif len(A.keys()) >= 3:\n print('No')\n exit()\n\nif len(A.keys()) == 1:\n p = list(A.keys())[0]\n print('Yes' if 2 * p <= N or p == N - 1 else 'No')\n exit()\n\np1, p2 = sorted(A.keys())\n1 / 0\nprint('Yes' if [p1, p2] == [1, 2] and A[1] == 1 else 'No')\n", "from collections import Counter\n\nN = int(input())\nA = list(map(int, input().split()))\n\ncntA = Counter(A)\ncntA = list(cntA.items())\ncntA.sort()\n\nif len(cntA) >= 3:\n print('No')\nelif len(cntA) == 1:\n if cntA[0][0] == N - 1:\n print('Yes')\n elif N // 2 >= cntA[0][0]:\n print('Yes')\n else:\n print('No')\nelif len(cntA) == 2:\n if cntA[0][0] + 1 == cntA[1][0]:\n if N >= cntA[0][1] + cntA[1][1] * 2:\n print('Yes')\n else:\n print('No')\n else:\n print('No')", "from collections import Counter\n\nN = int(input())\nA = Counter(map(int, input().split()))\n\nif len(A.keys()) >= 3:\n print('No')\n exit()\n\nif len(A.keys()) == 1:\n p = list(A.keys())[0]\n print('Yes' if 2 * p <= N or p == N - 1 else 'No')\n exit()\n\np1, p2 = sorted(A.keys())\nprint('Yes' if [p1, p2] == [1, 2] and A[p1] + A[p2] * 2 <= N else 'No')\n", "from collections import Counter\n\nN = int(input())\nA = Counter(map(int, input().split()))\n\nif len(A.keys()) >= 3:\n print('No')\n exit()\n\nif len(A.keys()) == 1:\n p = list(A.keys())[0]\n print('Yes' if 2 * p <= N or p == N - 1 else 'No')\n exit()\n\np1, p2 = sorted(A.keys())\nprint('Yes' if p2 - p1 == 1 and (A[p1] + 1) == p2 and p2 <= N - 2 else 'No')\n", "from collections import Counter\n\nN = int(input())\nA = Counter(map(int, input().split()))\n\nif len(A.keys()) >= 3:\n print('No')\n exit()\n\nif len(A.keys()) == 1:\n print('Yes' if list(A.keys())[0] == N - 1 or list(A.keys())[0] == 2 else 'No')\n exit()\n\np1, p2 = A.keys()\n1 / 0\nprint('Yes' if abs(p1 - p2) == 1 and max(p1, p2) <= N - 1 and A[min(p1, p2)] == 1 else 'No')\n", "from collections import Counter\n\nN = int(input())\nA = Counter(map(int, input().split()))\n\nif len(A.keys()) >= 3:\n print('No')\n exit()\n\nif len(A.keys()) == 1:\n p = list(A.keys())[0]\n print('Yes' if 2 * p <= N or p == N - 1 else 'No')\n exit()\n\np1, p2 = sorted(A.keys())\nprint('Yes' if p2 - p1 == 1 and (A[p1] + 1) <= p2 <= (A[p1] + A[p2] // 2) else 'No')\n"]
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s290393392', 's343593890', 's826623647', 's849336028', 's998395184', 's094308086']
[22636.0, 21468.0, 22636.0, 22636.0, 22636.0, 22636.0]
[53.0, 70.0, 53.0, 53.0, 53.0, 53.0]
[348, 526, 355, 360, 376, 368]
p03688
u422104747
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n=int(input())\ns=input().split()\nl=[int(s[i]) for i in range(n)]\nl.sort()\nif l[0]==l[-1]:\n if 1<=l[0]<=n//2:\n print("Yes")\n else:\n print("No")\nelif l[-1]-l[0]>1:\n l[10000000]-=1\n print("No")\nelse:\n l[10000000]-=1\n a=l.count(l[0])\n b=l.count(l[-1])\n if a+1<=l[-1]<=a+b//2:\n print("Yes")\n else:\n print("No")\n', 'n=int(input())\ns=input().split()\nl=[int(s[i]) for i in range(n)]\nl.sort()\nif l[0]==l[-1]:\n if l[0]<=n//2 or l[0]==n-1:\n print("Yes")\n else:\n print("No")\nelif l[-1]-l[0]>1:\n print("No")\nelse:\n a=l.count(l[0])\n b=l.count(l[-1])\n if a+1<=l[-1]<=a+b//2:\n print("Yes")\n else:\n print("No")\n']
['Runtime Error', 'Accepted']
['s088973280', 's512498557']
[13964.0, 13964.0]
[50.0, 52.0]
[361, 333]
p03688
u637175065
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\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 S(): return input()\n\n\ndef main():\n n = I()\n a = LI()\n d = collections.defaultdict(int)\n for c in a:\n d[c] += 1\n t = sorted(list(d.keys()))\n if t[-1] - t[0] > 1:\n return 'No'\n if len(t) == 1:\n if t[0] == n - 1:\n return 'Yes'\n if t[0] > n / 2.0:\n return 'No'\n return 'Yes'\n b = t[1] - d[t[0]]\n n2 = d[t[1]]\n print(1/0)\n if n2 == 2 and b == n2 - 1:\n return 'Yes'\n if b < 1:\n return 'No'\n if b >= n2 - 2:\n return 'No'\n\n return 'Yes'\n\n\nprint(main())\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\nmod = 10**9 + 7\n\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 S(): return input()\n\n\ndef main():\n n = I()\n a = LI()\n d = collections.defaultdict(int)\n for c in a:\n d[c] += 1\n t = sorted(list(d.keys()))\n if t[-1] - t[0] > 1:\n return 'No'\n if len(t) == 1:\n if t[0] == n - 1:\n return 'Yes'\n if t[0] > n / 2.0:\n return 'No'\n return 'Yes'\n b = t[1] - d[t[0]]\n n2 = d[t[1]]\n if n2 == 2 and b == n2 - 1:\n return 'Yes'\n if b < 1:\n return 'No'\n if b >= n2 - 2:\n return 'No'\n if b > n2 / 2.0:\n return 'No'\n\n return 'Yes'\n\n\nprint(main())\n"]
['Runtime Error', 'Accepted']
['s762794143', 's973203639']
[20476.0, 20484.0]
[93.0, 95.0]
[1062, 1088]
p03688
u667084803
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['import sys\nN=int(input())\na=[int(i) for i in input().split()]\na.sort()\n\nif a[N-1]-a[0]>1:\n print("No")\n sys.exit()\nif a[0]==N-1:\n print("Yes")\n sys.exit()\nif a[N-1]==1:\n print("Yes")\n sys.exit()\nif a[0]==a[N-1]:\n if 2*a[0]<=N:\n print("Yes")\n else:\n print("No")\n sys.exit()\n\ncount=a.index(a[N-1])\nif count+1<=a[N-1] and a[N-1]<=count+int((N-a[count])/2):\n print("Yes")\nelse:\n print("No")', 'import sys\nN=int(input())\na=[int(i) for i in input().split()]\na.sort()\n\nif a[N-1]-a[0]>1:\n print("No")\n sys.exit()\nif a[0]==N-1:\n print("Yes")\n sys.exit()\nif a[N-1]==1:\n print("Yes")\n sys.exit()\nif a[0]==a[N-1]:\n if 2*a[0]<=N:\n print("Yes")\n else:\n print("No")\n sys.exit()\nprint(a[N])', 'import sys\nN=int(input())\na=[int(i) for i in input().split()]\na.sort()\n\nif a[N-1]-a[0]>1:\n print("No")\n sys.exit()\nif a[0]==N-1:\n print("Yes")\n sys.exit()\nprint(a[N])', 'import sys\nN=int(input())\na=[int(i) for i in input().split()]\na.sort()\n\nif a[N-1]-a[0]>1:\n print("NO")\n sys.exit()\nif a[N-1]>N-1:\n print("NO")\n sys.exit()\nif a[0]==N-1:\n print("YES")\n sys.exit()\nif a[0]==a[N-1]:\n print("YES")\n sys.exit()\nprint(a[N])', 'import sys\nN=int(input())\na=[int(i) for i in input().split()]\na.sort()\n\nif a[N-1]-a[0]>1:\n print("No")\n sys.exit()\nif a[0]==N-1:\n print("Yes")\n sys.exit()\nif a[N-1]==1:\n print("Yes")\n sys.exit()\nif a[0]==a[N-1]:\n if 2*a[0]<=N:\n print("Yes")\n else:\n print("No")\n sys.exit()\n\ncount=a.index(a[N-1])\nif count+1<=a[N-1] and a[N-1]<=count+int((N-count)/2):\n print("Yes")\nelse:\n print("No")']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s011107352', 's674375530', 's729967136', 's864797464', 's262250609']
[13964.0, 13964.0, 13964.0, 13964.0, 13964.0]
[47.0, 69.0, 52.0, 45.0, 49.0]
[403, 299, 170, 257, 400]
p03688
u711245972
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['m=map(int,input().split())\na=[int(i) for i in m]\nd=max(a)-min(a)\nif d>1:\n ans=False\nelif d==0:\n if (max(a)<len(a) and max(a)*2>=len(a)):\n ans=True\n else:\n ans=False\nelse:\n max_num=a.count(max(a))\n min_num=a.count(min(a))\n dif=max(a)-min_num\n if (min_num<max(a) and dif*2<=max_num):\n ans=True\n else:\n ans=False\n \nif ans:\n print("Yes")\nelse:\n print("No")', 'm=map(int,input().split())\na=[int(i) for i in m]\nd=max(a)-min(a)\nif d>1:\n ans=False\nelif d==0:\n if max(a)<len(a):\n ans=True\n else:\n ans=False\nelse:\n max_num=a.count(max(a))\n min_num=a.count(min(a))\n dif=max(a)-min_num\n if (min_num<max(a)):\n if dif*2<=max_num:\n ans=True\n else:\n ans=False\n else:\n ans=False\nif ans:\n print("Yes")\nelse:\n print("No")\n \n', 'n=input()\nm=map(int,input().split())\na=[int(i) for i in m]\nd=max(a)-min(a)\nif d>1:\n ans=False\nelif d==0:\n if (max(a)==len(a)-1 or max(a)*2<=len(a)):\n ans=True\n else:\n ans=False\nelse:\n max_num=a.count(max(a))\n min_num=a.count(min(a))\n dif=max(a)-min_num\n if (min_num<max(a) and dif*2<=max_num):\n ans=True\n else:\n ans=False\n \nif ans:\n print("Yes")\nelse:\n print("No")\n ']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s069370168', 's887195475', 's723621455']
[3064.0, 3064.0, 13964.0]
[17.0, 17.0, 66.0]
[421, 443, 442]
p03688
u729133443
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["print([1/id('hoge')%5%2]*2**28**id('fuga')and'Yes')", "n,a=open(0)\nn=int(n)\na=sorted(map(int,a.split()))\nif a[0]==a[-1]:\n if n-1==a[0]or n//a[0]>=2:\n print('Yes')\n else:\n print('No')\nelif a[-1]-1==a[0]:\n x=a.count(a[0])\n if x<a[-1]and(n-x)//(a[-1]-x)>=2:\n print('Yes')\n else:\n print('No')\nelse:\n print('No')"]
['Time Limit Exceeded', 'Accepted']
['s175227001', 's445356754']
[12324.0, 13992.0]
[2104.0, 42.0]
[51, 270]
p03688
u729707098
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['from collections import Counter\nn = int(input())\na = [int(i) for i in input().split()]\na.sort()\nc = Counter(a)\nif len(c)>2: print("No")\nelif len(c)==1:\n\tif a[0]+1==n or n>=2*a[0]: print("Yes")\n\telse: print("No")\nelif c[a[-1]]>=2*a[-1]: print("Yes")\nelse: print("No")', 'from collections import Counter\nn = int(input())\na = [int(i) for i in input().split()]\na.sort()\nc = Counter(a)\nif len(c)>2 or a[0]+1<a[-1]: print("No")\nelif len(c)==1:\n\tif a[0]+1==n or n>=2*a[0]: print("Yes")\n\telse: print("No")\nelse:\n\tx,y = c[a[-1]],c[a[0]]\n\tif y+1<=a[-1]<=x//2+y: print("Yes")\n\telse: print("No")']
['Wrong Answer', 'Accepted']
['s243236346', 's013219469']
[18656.0, 18656.0]
[56.0, 56.0]
[266, 313]
p03688
u780962115
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n=int(input())\nlists=list(map(int,input().split()))\nfrom collections import Counter\na=dict(Counter(lists))\nif len(a)==1:\n if n>=lists[0]*2 or lists[0]==n-1:\n print("Yes")\n else:\n print("No")\n \nelif len(a)==2:\n P=list(a.keys())\n Q=list(a.values())\n x,y=min(P),max(P) #x=k+l-1,y=k+l\n c,d=a[x],a[y]#c=k,d=?\n if 2*y-c<=n and c>0 and y>c and d+c==y:\n print("Yes")\n else:\n print("No")\n\n \nelse:\n print("No")', 'n=int(input())\nlists=list(map(int,input().split()))\nfrom collections import Counter\na=dict(Counter(lists))\nif len(a)==1:\n if n>=lists[0]*2 or lists[0]==n-1:\n print("Yes")\n else:\n print("No")\n \nelif len(a)==2:\n P=list(a.keys())\n Q=list(a.values())\n x,y=min(P),max(P) #x=k+l-1,y=k+l\n c,d=a[x],a[y]#c=k,d=?\n if 2*y-c<=n and c>0 and y>c and y-x==1:\n print("Yes")\n else:\n print("No")\n\n \nelse:\n print("No")']
['Wrong Answer', 'Accepted']
['s175486758', 's780361359']
[21596.0, 21596.0]
[63.0, 54.0]
[461, 461]
p03688
u813174766
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n=int(input())\na=list(map(int,input().split()))\nM=max(a)\nm=min(a)\nif M>m+1:\n print("No")\nelif M==m+1:\n cntm=a.count(m)\n cntM=n-cntm\n if cntm>m:\n print("No")\n elif cntm+cntM//2<M:\n print("No")\n else:\n print("Yes")\nelif M==m:\n if m<=n//2:\n print("Yes")\n else if m==n-1:\n print("Yes")\n else:\n print("No")', 'n=int(input())\na=list(map(int,input().split()))\nM=max(a)\nm=min(a)\nif M>m+1:\n print("No")\nelif M==m+1:\n cntm=a.count(m)\n cntM=n-cntm\n if cntm>m:\n print("No")\n elif cntm+cntM//2<M:\n print("No")\n else:\n print("Yes")\nelif M==m:\n if m<=n//2:\n print("Yes")\n elif m==n-1:\n print("Yes")\n else:\n print("No")']
['Runtime Error', 'Accepted']
['s765578720', 's799716095']
[3060.0, 14004.0]
[18.0, 44.0]
[328, 325]
p03688
u814986259
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['N = int(input())\na = list(map(int, input().split()))\nM = max(a)\nm = min(a)\nif M > m + 1:\n print("No")\nelse:\n if M == m:\n if M == N-1:\n print("Yes")\n elif M*2 <= N:\n print("Yes")\n else:\n print("No")\n\n else:\n if a.count(M) > 2:\n print(\'No\')\n else:\n \n c = a.count(m)\n if (M - c) * 2 < N-c and c < M: \n print("Yes")\n else:\n print("No")\n', 'N = int(input())\na = list(map(int, input().split()))\nM = max(a)\nm = min(a)\nif M > m + 1:\n print("No")\nelse:\n if M == m:\n if M == N-1:\n print("Yes")\n elif M*2 <= N:\n print("Yes")\n else:\n print("No")\n\n else:\n \n c = a.count(m)\n if (M - c) * 2 <= N-c and c < M: \n print("Yes")\n else:\n print("No")\n']
['Wrong Answer', 'Accepted']
['s809891476', 's169274937']
[20868.0, 20768.0]
[55.0, 54.0]
[688, 600]
p03688
u896741788
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['n=int(input())\n\na=list(map(int,input().split()))\nif len(set(a))==1:\n if n>=2*a[0] or n-1==a[0]:print("Yes")\n else:print("No")\nelif len(set(a))>=3:print("No")\nelse:\n s,S=sorted(list(set(a)))\n if 2*n-a.count(s)<=S:print("Yes")\n else:print("No")', 'n=int(input())\n\na=list(map(int,input().split()))\nif len(set(a))==1:\n if n>=2*a[0] or n-1==a[0]:print("Yes")\n else:print("No")\nelif len(set(a))>=3:print("No")\nelse:\n s,S=sorted(list(set(a)))\n k=a.count(s)\n if S==s+1 and 2*S-n<=k and S>k:print("Yes")\n else:print("No")']
['Wrong Answer', 'Accepted']
['s855909132', 's193511900']
[14564.0, 14208.0]
[52.0, 50.0]
[257, 284]
p03688
u950708010
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["#https://img.atcoder.jp/agc016/editorial.pdf\ndef solve():\n n = int(input())\n a = list(int(i) for i in input().split())\n ans = 'YES'\n alone = 0\n group = 0\n if max(a) - min(a) >= 2: ans = 'NO'\n \n elif max(a) - min(a) == 1:\n for i in a:\n if i == max(a)-1 : alone += 1\n else: group += 1\n if alone < max(a) and 2*(max(a)-alone)<= group: pass\n else: ans = 'NO'\n \n \n elif max(a) - min(a) == 0:\n if a[0] == n-1 or 2*a[0] <= n:\n pass\n else: ans = 'NO'\n return ans\n\nif __name__ == '__main__':\n print(solve())", "#https://img.atcoder.jp/agc016/editorial.pdf\ndef solve():\n n = int(input())\n a = list(int(i) for i in input().split())\n ans = 'Yes'\n alone = 0\n group = 0\n ha = max(a)\n la = min(a)\n if ha - la >= 2: ans = 'No'\n \n elif ha - la == 1:\n for i in a:\n if i == ha-1 : alone += 1\n else: group += 1\n if alone < ha and 2*(ha-alone)<= group: pass\n else: ans = 'No'\n \n \n elif ha - la == 0:\n if a[0] == n-1 or 2*a[0] <= n:\n pass\n else: ans = 'No'\n return ans\n\nif __name__ == '__main__':\n print(solve())"]
['Wrong Answer', 'Accepted']
['s299277385', 's041450316']
[13964.0, 13964.0]
[2104.0, 57.0]
[536, 528]
p03688
u976162616
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['import sys\nif __name__ == "__main__":\n N = int(input())\n evidences = list(map(int, input().split()))\n evidences = list(sorted(evidences))\n unique_evidence = set(evidences)\n if (evidences[-1] - evidences[0] > 1):\n print ("No")\n sys.exit()\n if (len(unique_evidence) == 1):\n group = evidences[0];\n # all unique\n if (group == N - 1):\n print ("Yes")\n sys.exit()\n if (N - 2 * group < 0):\n print ("No")\n sys.exit()\n print ("Yes")\n sys.exit()\n # evidences[-1] - evidences[0] > 1\n min_val = min(evidences)\n max_val = max(evidences)\n\n min_val_cnt = 0\n max_val_cnt = 0\n for val in evidences:\n if (val == min_val):\n min_val_cnt += 1\n else:\n max_val_cnt += 1\n \n if (max_val_cnt <= 1):\n print ("No")\n sys.exit()\n #rest cat\n rest = N\n rest -= min_val_cnt\n\n min_group = min_val_cnt + 1\n max_group = min_val_cnt + (max_val_cnt // 2)\n if min_group <= evidences[-1] and evidences <= max_group:\n print ("Yes")\n sys.exit()\n print ("No")\n', 'import sys\nif __name__ == "__main__":\n N = int(input())\n evidences = list(map(int, input().split()))\n evidences = list(sorted(evidences))\n unique_evidence = set(evidences)\n if (evidences[-1] - evidences[0] > 1):\n print ("No")\n sys.exit()\n if (len(unique_evidence) == 1):\n group = evidences[0];\n # all unique\n if (group == N - 1):\n print ("Yes")\n sys.exit()\n if (N - 2 * group < 0):\n print ("No")\n sys.exit()\n print ("Yes")\n sys.exit()\n # evidences[-1] - evidences[0] > 1\n min_val = min(evidences)\n max_val = max(evidences)\n\n min_val_cnt = 0\n max_val_cnt = 0\n for val in evidences:\n if (val == min_val):\n min_val_cnt += 1\n else:\n max_val_cnt += 1\n \n if (max_val_cnt <= 1):\n print ("No")\n sys.exit()\n #rest cat\n rest = N\n rest -= min_val_cnt\n\n min_group = min_val_cnt + 1\n max_group = min_val_cnt + (max_val_cnt // 2)\n if min_group <= evidences[-1] and evidences[-1] <= max_group:\n print ("Yes")\n sys.exit()\n print ("No")\n']
['Runtime Error', 'Accepted']
['s076321795', 's059415705']
[14660.0, 14300.0]
[62.0, 65.0]
[1163, 1167]
p03688
u985443069
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
["import sys\nfrom collections import Counter\n\nsys.stdin = open('b1.in')\n\n\ndef read_int_list():\n return list(map(int, input().split()))\n\n\ndef read_int():\n return int(input())\n\n\ndef read_str_list():\n return input().split()\n\n\ndef read_str():\n return input()\n\n\nyes, no = 'Yes', 'No'\n\n\ndef solve(n, a):\n s = set(a)\n c = Counter(a)\n if len(s) == 1:\n a = list(s)[0]\n n_colors = a + 1\n if n_colors == n:\n return yes\n n_colors = a\n if 2 * n_colors <= n:\n return yes\n if len(s) == 2:\n a, b = sorted(s)\n if a + 1 == b:\n n_colors = b\n appear_once = c[a]\n appear_twice_or_more = n_colors - appear_once\n if appear_once < n_colors:\n if c[b] >= 2 * appear_twice_or_more:\n return yes\n return no\n\nn = read_int()\na = read_int_list()\nres = solve(n, a)\nprint(res)\n\n", "import sys\nfrom collections import Counter\n\n\n\n\ndef read_int_list():\n return list(map(int, input().split()))\n\n\ndef read_int():\n return int(input())\n\n\ndef read_str_list():\n return input().split()\n\n\ndef read_str():\n return input()\n\n\nyes, no = 'Yes', 'No'\n\n\ndef solve(n, a):\n s = set(a)\n c = Counter(a)\n if len(s) == 1:\n a = list(s)[0]\n n_colors = a + 1\n if n_colors == n:\n return yes\n n_colors = a\n if 2 * n_colors <= n:\n return yes\n if len(s) == 2:\n a, b = sorted(s)\n if a + 1 == b:\n n_colors = b\n appear_once = c[a]\n appear_twice_or_more = n_colors - appear_once\n if appear_once < n_colors:\n if c[b] >= 2 * appear_twice_or_more:\n return yes\n return no\n\nn = read_int()\na = read_int_list()\nres = solve(n, a)\nprint(res)\n\n"]
['Runtime Error', 'Accepted']
['s579875988', 's772356705']
[3316.0, 24280.0]
[21.0, 55.0]
[918, 920]
p03688
u996252264
2,000
262,144
There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
['def ri(): return int(input())\ndef rli(): return list(map(int, input().split()))\ndef ris(): return list(input())\ndef pli(): return "".join(list(map(str, ans)))\n\n\nN = ri()\na = rli()\nif(len(set(a)) >= 3):\n print("No")\nelif(len(set(a)) == 2):\n ma = max(a)\n mi = min(a)\n l_ma = 0\n l_mi = 0\n for i in a:\n if(i == ma): l_ma += 1\n if(i == mi): l_mi += 1\n if(ma >= l_mi + 2*l_ma):\n print("Yes")\n else:\n print("No")\nelse:\n if(a[0] == N-1 or N/a[0] >= 2):\n print("Yes")\n else:\n print("No")\n', 'def ri(): return int(input())\ndef rli(): return list(map(int, input().split()))\ndef ris(): return list(input())\ndef pli(): return "".join(list(map(str, ans)))\n \n \nN = ri()\na = rli()\nma = max(a)\nmi = min(a)\nif(ma - mi > 1):\n print("No")\nelif(ma - mi == 1):\n l_ma = a.count(ma)\n l_mi = a.count(mi)\n if(ma <= l_mi):\n print("No")\n elif(l_mi + l_ma/2 >= ma):\n print("Yes")\n else:\n print("No")\nelse:\n if(a[0] == N-1):\n print("Yes")\n elif(N/a[0] >= 2):\n print("Yes")\n else:\n print("No")']
['Wrong Answer', 'Accepted']
['s183328926', 's705972859']
[14300.0, 14300.0]
[67.0, 47.0]
[551, 548]
p03701
u033407970
2,000
262,144
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well. However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?
["import math as mt\nstore = []\ndef binarysearch(min, max):\n mid = int((max + min)/2)\n if (min == max):\n return mid\n elif count(mid) > mid:\n return binarysearch(mid+1, max)\n else:\n return binarysearch(min, mid)\n\ndef count(x):\n store = [mt.ceil((n - x*b)/a) for n in hp]\n store = [x for x in store if x > 0]\n return sum(store)\n\nst = 0\nmin = 10 ** 18\nmax = 0\nn, a, b = [int(x) for x in input().split(' ')]\nhp = []\nfor i in range(n):\n st = int(input())\n if st < min:\n min = st\n if st > max:\n max = st\n hp.append(st)\nmin, max = mt.ceil(min/a), mt.ceil(max/b)\na = a - b\nprint(binarysearch(min,max))\n", 'n = int(input())\nsum = 0\nsub = 101\nfor i in range(n):\n store = int(input())\n sum += store\n if store % 10 != 0 and store < sub:\n sub = store\nif sum % 10 != 0:\n print(sum)\nelse:\n if sub == 101:\n print(0)\n else:\n print(sum - sub)\n']
['Runtime Error', 'Accepted']
['s981228818', 's518018625']
[3064.0, 2940.0]
[18.0, 17.0]
[659, 266]