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
p03724
u022979415
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['def main():\n vertex, query = map(int, input().split())\n cnt = [0 for _ in range(vertex)]\n answer = "YES"\n for _ in range(query):\n a, b = map(lambda x: int(x) - 1, input().split())\n left = min(a, b)\n right = max(a, b)\n cnt[left] += 1\n if right < vertex - 1:\n cnt[right + 1] -= 1\n for i in range(1, vertex):\n cnt[i] += cnt[i - 1]\n odd_cnt = cnt[0] % 2\n odd_cnt_odd = 0\n for i in range(1, vertex):\n if cnt[i] % 2 == 1:\n odd_cnt += 1\n else:\n if odd_cnt % 2:\n odd_cnt_odd += 1\n odd_cnt = 0\n if odd_cnt_odd % 2 == 0:\n answer = "NO"\n print(answer)\n\n\nif __name__ == \'__main__\':\n main()\n\n', 'def main():\n vertex, query = map(int, input().split())\n cnt = [0 for _ in range(vertex)]\n for _ in range(query):\n a, b = map(lambda x: int(x) - 1, input().split())\n cnt[a] += 1\n cnt[b] += 1\n print("YES" if all(cnt[i] % 2 == 0 for i in range(vertex)) else "NO")\n\n\nif __name__ == \'__main__\':\n main()\n\n']
['Wrong Answer', 'Accepted']
['s167044427', 's724798935']
[7080.0, 4184.0]
[459.0, 355.0]
[734, 335]
p03724
u054106284
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N, M = (int(i) for i in input().split())\nDP[N] = [False]*N\nfor i in range(M):\n a, b = (int(i) for i in input().split())\n for i in (a, b):\n DP[i-1] = not DP[i-1]\nfor i in range(N):\n if DP[i]:\n print(NO)\n break\nelse:\n print(YES)', 'N, M = (int(i) for i in input().split())\nDP = [False]*N\nfor i in range(M):\n a, b = (int(k) for k in input().split())\n for j in (a, b):\n DP[j-1] = not DP[j-1]\nfor i in range(N):\n if DP[i]:\n print(NO)\n break\nelse:\n print(YES)', 'N, M = (int(i) for i in input().split())\nDP[N] = [False]*N\nfor i in range(M):\n a, b = (int(i) for i in input().split())\n for i in (a, b):\n DP[i] = not DP[i]\nfor i in range(N):\n if DP[i]:\n print(NO)\n break\nelse:\n print(YES)', 'N, M = (int(i) for i in input().split())\nDP = [False]*N\nfor i in range(M):\n a, b = (int(i) for i in input().split())\n for j in (a, b):\n DP[j-1] = not DP[j-1]\nfor i in range(N):\n if DP[i]:\n print(NO)\n break\nelse:\n print(YES)', 'N, M = (int(i) for i in input().split())\nDP[N] = [False]*N\nfor i in range(M):\n a, b = (int(i) for i in input().split())\n for j in (a, b):\n DP[j-1] = not DP[j-1]\nfor i in range(N):\n if DP[i]:\n print(NO)\n break\nelse:\n print(YES)', "N, M = (int(i) for i in input().split())\nDP = [False]*N\nfor i in range(M):\n a, b = (int(k) for k in input().split())\n for j in (a, b):\n DP[j-1] = not DP[j-1]\nfor i in range(N):\n if DP[i]:\n print('NO')\n break\nelse:\n print('YES')"]
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s457794533', 's673415900', 's692693354', 's875873162', 's947881406', 's598069444']
[3828.0, 3828.0, 3828.0, 3828.0, 3828.0, 3828.0]
[19.0, 403.0, 18.0, 391.0, 19.0, 395.0]
[239, 236, 235, 236, 239, 240]
p03724
u075595666
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["n,m = map(int,input().split())\nchk = [0]*n\nfor i in range(m):\n a,b = map(int,input().split())\n chk[a-1] += 1\n chk[b-1] += 1\nans = 'Yes'\nfor i in chk:\n if i % 2 == 1:\n ans = 'No'\nprint(ans)", "n,m = map(int,input().split())\nchk = [0]*n\nfor i in range(m):\n a,b = map(int,input().split())\n chk[a-1] += 1\n chk[b-1] += 1\nans = 'YES'\nfor i in chk:\n if i % 2 == 1:\n ans = 'NO'\nprint(ans)"]
['Wrong Answer', 'Accepted']
['s438300318', 's242968506']
[3828.0, 3828.0]
[338.0, 332.0]
[196, 196]
p03724
u095426154
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['# coding: utf-8\nN,M=map(int,input().split())\nNL=[0 for i in range(N)]\nfor i in range(M):\n a,b=map(int,input().split())\n NL[a-1]+=1\n NL[b-1]+=1\n\nflg=True\n\nfor i in range(N):\n if NL[i]%2==1:\n flg=False\n\nif flg:\n print("Yes")\nelse:\n print("No")\n', '# coding: utf-8\nN,M=map(int,input().split())\nNL=[0 for i in range(N)]\nfor i in range(M):\n a,b=map(int,input().split())\n NL[a-1]+=1\n NL[b-1]+=1\n\nflg=True\n\nfor i in range(N):\n if NL[i]%2==1:\n flg=False\n\nif flg:\n print("YES")\nelse:\n print("NO")\n']
['Wrong Answer', 'Accepted']
['s687814306', 's280938456']
[3928.0, 3888.0]
[332.0, 341.0]
[267, 267]
p03724
u102960641
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n,m = map(int, input().split())\nab = list(map(int, input().split()))\ns = [0] * (10 ** 5+1)\nfor a,b in ab:\n s[a] += 1\n s[b] += 1\nif any([s % 2 for i in s]):\n print("NO")\nelse:\n print("YES")\n \n', 'n,m = map(int, input().split())\nab = [list(map(int, input().split())) for i in range(m)]\ns = [0] * (10 ** 5+1)\nfor a,b in ab:\n s[a] += 1\n s[b] += 1\nif any([i % 2 for i in s]):\n print("NO")\nelse:\n print("YES")']
['Runtime Error', 'Accepted']
['s768242287', 's523288008']
[3828.0, 29072.0]
[18.0, 358.0]
[196, 212]
p03724
u134019875
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["n, m = map(int, input().split())\nd = {i: 0 for i in range(1, n)}\nfor _ in range(n):\n a, b = map(int, input().split())\n d[a] += 1\n d[b] += 1\nfor k, v in d.items():\n if v % 2:\n print('NO')\n break\nelse:\n print('YES')\n", "n, m = map(int, input().split())\nd = {i: 0 for i in range(1, n+1)}\nfor _ in range(m):\n a, b = map(int, input().split())\n d[a] += 1\n d[b] += 1\nfor k, v in d.items():\n if v % 2:\n print('NO')\n break\nelse:\n print('YES')\n"]
['Runtime Error', 'Accepted']
['s024907554', 's872641651']
[15084.0, 15084.0]
[334.0, 354.0]
[243, 245]
p03724
u163320134
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["n,m=map(int,input().split())\ng=[[]*for _ in range(n+1)]\nfor _ in range(m):\n u,v=map(int,input().split())\n g[u].append(v)\n g[v].append(u)\nflag=True\nfor i in range(1,n+1):\n if g[i]%2==0:\n continue\n else:\n flag=False\n break\nif flag==True:\n print('YES')\nelse:\n print('NO')", "n,m=map(int,input().split())\ng=[[] for _ in range(n+1)]\nfor _ in range(m):\n u,v=map(int,input().split())\n g[u].append(v)\n g[v].append(u)\nflag=True\nfor i in range(1,n+1):\n if len(g[i])%2==0:\n continue\n else:\n flag=False\n break\nif flag==True:\n print('YES')\nelse:\n print('NO')"]
['Runtime Error', 'Accepted']
['s724987475', 's845602632']
[2940.0, 20656.0]
[17.0, 374.0]
[284, 289]
p03724
u373047809
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['c = [0]*10**5\nfor i in open(0).read().split()[::2]: c[int(i)] ^= 1\nprint("NO" if any(c) else "YES")', 'c = [0]*10**5\nfor i in open(0).read().split()[2:]: c[int(i)-1] ^= 1\nprint("NO" if any(c) else "YES")']
['Runtime Error', 'Accepted']
['s877757969', 's694164204']
[19060.0, 19060.0]
[67.0, 115.0]
[99, 100]
p03724
u375616706
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN, M = int(input())\nnode = [0]*(N+1)\nfor _ in range(M):\n a, b = map(lambda x: int(x)-1, input().split())\n node[a] += 1\n node[b] += 1\n\nif all(x % 2 == 0 for x in node):\n print("YES")\nelse:\n print("NO")\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\nN, M = map(int, input().split())\nnode = [0]*(N)\nfor _ in range(M):\n a, b = map(lambda x: int(x)-1, input().split())\n node[a] ^= 1\n node[b] ^= 1\n\nif any(node):\n print("NO")\nelse:\n print("YES")\n']
['Runtime Error', 'Accepted']
['s441797536', 's060278431']
[3060.0, 3828.0]
[17.0, 206.0]
[315, 305]
p03724
u391819434
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["N,M,*ab=open(0).read().split()\nfrom collections import*\nC=Counter(ab)\nprint('YNeos'[any(v%2 for v in C.values())::2])", "N,M,*ab=open(0).read().split()\nfrom collections import*\nC=Counter(ab)\nprint('YNEOS'[any(v%2 for v in C.values())::2])"]
['Wrong Answer', 'Accepted']
['s288664508', 's122088963']
[28484.0, 28372.0]
[90.0, 89.0]
[117, 117]
p03724
u413165887
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n, m = map(int, input().split())\n\ntree = [0 for _ in range(n+1)]\nfor _i in range(m):\n a, b = map(int, input().split())\n tree[a] += 1\n tree[b] += 1\nif all(i%2==0 for i in tree):\n print("Yes")\nelse:\n print("No")', 'n, m = map(int, input().split())\n\ntree = [0 for _ in range(n+1)]\nfor _i in range(m):\n a, b = map(int, input().split())\n tree[a] += 1\n tree[b] += 1\nif all(i%2==0 for i in tree):\n print("YES")\nelse:\n print("NO")']
['Wrong Answer', 'Accepted']
['s992282698', 's294991444']
[3888.0, 3888.0]
[315.0, 317.0]
[224, 224]
p03724
u426108351
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N, M = map(int, input().split())\nnum = [0] * (N+1)\nfor i in range(M):\n a, b = map(int, input().split())\n num[a] += 1\n num[b] += 1\n\nflag = 1\nfor i in num:\n if i % 2 != 0:\n flag = 0\n\nif flag = 1:\n print("YES")\nelse:\n print("NO")\n', 'N, M = map(int, input().split())\nnum = [0] * (N+1)\nfor i in range(M):\n a, b = map(int, input().split())\n num[a] += 1\n num[b] += 1\n\nflag = 1\nfor i in num:\n if num % 2 != 0:\n flag = 0\n\nif flag = 1:\n print("YES")\nelse:\n print("NO")\n', 'N, M = map(int, input().split())\nnum = [0] * (N+1)\nfor i in range(M):\n a, b = map(int, input().split())\n num[a] += 1\n num[b] += 1\n\nflag = 1\nfor i in num:\n if i % 2 != 0:\n flag = 0\n\nif flag == 1:\n print("YES")\nelse:\n print("NO")\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s417969473', 's660316967', 's486289848']
[3188.0, 2940.0, 3828.0]
[21.0, 17.0, 316.0]
[252, 254, 253]
p03724
u474423089
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["N, M = map(int, input().split(' '))\nl = [0]*(N-1)\nfor i in range(M):\n a, b = map(int, input().split(' '))\n if 1 in [a, b]:\n a, b = sorted([a, b])\n l[b-2] += 1\n else:\n l[a - 2] += 1\n l[b - 2] += 1\nfor i in l:\n if i % 2 != 0:\n print('No')\n exit()\nprint('Yes')", "N, M = map(int, input().split(' '))\nl = [0]*(N-1)\nfor i in range(M):\n a, b = map(int, input().split(' '))\n if 1 in [a, b]:\n a, b = sorted([a, b])\n l[b-2] += 1\n else:\n l[a - 2] += 1\n l[b - 2] += 1\nfor i in l:\n if i % 2 != 0:\n print('NO')\n exit()\nprint('YES')"]
['Wrong Answer', 'Accepted']
['s856544723', 's027795760']
[3828.0, 3828.0]
[351.0, 345.0]
[311, 311]
p03724
u518042385
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n,m=map(int,input().split())\nl=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n l[a-1]+=1\n l[b-1]+=1\nb=True\nfor i in range(m):\n if l[i]%2!=1:\n b=False\nif b:\n print("YES")\nelse:\n print("NO")', 'n,m=map(int,input().split())\nl=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n l[a-1]+=1\n l[b-1]+=1\nb=True\nfor i in range(n):\n if l[i]%2!=1:\n b=False\nif b:\n print("YES")\nelse:\n print("NO")\n', 'n,m=map(int,input().split())\nl=[0]*n\nfor i in range(m):\n a,b=map(int,input().split())\n l[a-1]+=1\n l[b-1]+=1\nb=True\nfor i in range(n):\n if l[i]%2==1:\n b=False\nif b:\n print("YES")\nelse:\n print("NO")\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s288326368', 's913463055', 's789593079']
[3828.0, 3828.0, 3828.0]
[330.0, 332.0, 333.0]
[205, 206, 206]
p03724
u538632589
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n, m = map(int, input().split())\nc_list = [0]*n\nfor _ in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n c_list[a] += 1\n c_list[b] += 1\n\nok = True\nfor c in c_list:\n if c % 2 != 0:\n ok = False\nif ok:\n print("Yes")\nelse:\n print("No")\n', 'n, m = map(int, input().split())\nc_list = [0]*n\nfor _ in range(m):\n a, b = map(int, input().split())\n a -= 1\n b -= 1\n c_list[a] += 1\n c_list[b] += 1\n\nok = True\nfor c in c_list:\n if c % 2 != 0:\n ok = False\nif ok:\n print("YES")\nelse:\n print("NO")\n']
['Wrong Answer', 'Accepted']
['s548504406', 's193206127']
[3828.0, 3828.0]
[330.0, 343.0]
[276, 276]
p03724
u619728370
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['from collections import Counter\n\nn,m = map(int,input().split())\ns = ""\nfor i in range(m):\n s = s + input()\ncounter = Counter(s)\nfor i in range(n+1):\n if counter[str(i)] % 2 != 0:\n print("NO")\n break\nif i == n -1:\n print("YES")', 'from collections import Counter\n\nn,m = map(int,input().split())\ns = ""\nfor i in range(m):\n s += input()\ncounter = Counter(s)\nfor i in range(n+1):\n if counter[str(i)] % 2 != 0:\n print("NO")\n break\nif i == n -1:\n print("YES")', 'from collections import Counter\n\nn,m = map(int,input().split())\ns = ""\nfor i in range(m):\n s = s + input()\ncounter = Counter(s)\nfor i in range(n+1):\n if counter[str(i)] % 2 != 0:\n print("NO")\n break\nif i == n:\n print("YES")']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s002388077', 's556782912', 's222615808']
[4584.0, 4464.0, 4564.0]
[279.0, 281.0, 267.0]
[249, 246, 246]
p03724
u619819312
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['import numpy as np\nn,m=map(int,input().split())\ns=np.zeros(n+1)\nfor i in range(m):\n a,b=map(int,input().split())\n s[a]+=1\n s[b]+=1\nprint(s%2,s)\nprint("NO" if sum(s%2)else"YES")', 'import numpy as np\nn,m=map(int,input().split())\ns=np.zeros(n+1)\nfor i in range(m):\n a,b=map(int,input().split())\n s[a]+=1\n s[b]+=1\nprint("NO" if sum(s%2)else"YES")']
['Wrong Answer', 'Accepted']
['s598858231', 's138719203']
[14028.0, 14028.0]
[886.0, 877.0]
[185, 172]
p03724
u667084803
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\ncount=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q%2==1:\n print("NO")\nelse:\n for j in range(0,M,M/100):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\n else: \n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\ncount=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q%2==1:\n print("NO")\nelse:\n for j in range(1,M,int(M/100)):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\n else: \n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\ncount=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q%2==1:\n print("NO")\nelse:\n for j in range(1,min(10,M)):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\nelif M>10:\n for j in range(M-10,M+1):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\nelse:\n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\ncount=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q%2==1:\n print("NO")\nelse:\n for j in range(1,M,int(M/10)):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\n else: \n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\ncount=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q%2==1:\n print("NO")\nelse:\n for j in range(1,min(10,M)):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\n elif M>10:\n for j in range(M-10,M+1):\n for i in range(0,M):\n if p[i][0]==j or p[i][1]==j:\n count+=1\n if count%2==1:\n print("NO")\n sys.exit()\n else:\n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nq=0\nfor i in range(0,M):\n p.append(list(map(int, input().split())))\nfor i in range(0,M):\n q+=p[i][0]-p[i][1]\nif q[i]%2==1:\n print("NO")\nelse:\n print("YES")', 'import sys\n\nN,M=list(map(int, input().split()))\np=[]\nfor i in range(0,N):\n p.append(0)\nfor i in range(0,M):\n count=list(map(int, input().split()))\n p[count[0]-1]+=1\n p[count[1]-1]+=1\nfor i in range(0,M):\n if p[i]%2==1:\n print("NO")\n sys.exit()\nprint("YES")']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s028793608', 's120420140', 's236626116', 's700103072', 's729042010', 's939461306', 's097208421']
[27368.0, 29396.0, 3064.0, 27368.0, 3064.0, 27364.0, 3888.0]
[378.0, 2105.0, 17.0, 604.0, 17.0, 382.0, 379.0]
[405, 410, 580, 409, 592, 229, 284]
p03724
u668785999
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["N,M = map(int,input().split())\ncntNode = [0]*N\nfor i in range(N):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n cntNode[a] += 1\n cntNode[b] += 1\n\nflag = True\nfor i in range(N):\n if(cntNode[i] % 2 != 0):\n flag = False\n break\nif(flag):\n print('Yes')\nelse:\n print('No')", "N,M = map(int,input().split())\ncntNode = [0]*N\nfor i in range(M):\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n cntNode[a] += 1\n cntNode[b] += 1\n\nflag = True\nfor i in range(N):\n if(cntNode[i] % 2 != 0):\n flag = False\n break\nif(flag):\n print('YES')\nelse:\n print('NO')"]
['Runtime Error', 'Accepted']
['s217484777', 's583992160']
[9632.0, 9468.0]
[221.0, 217.0]
[307, 307]
p03724
u670180528
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n,_,*l=map(int,open(0).read().split())\nc=[0]*-~n\nfor a,b in zip(l[::2],l[1::2]):\n\tc[a]^=1;c[b]^=1\nprint("YNEOS"[any(i for i in l)::2])', 'n,_,*l=map(int,open(0).read().split())\nc=[0]*-~n\nfor a,b in zip(l[::2],l[1::2]):\n\tc[a]^=1;c[b]^=1\nprint("YNEOS"[any(i for i in c)::2])']
['Wrong Answer', 'Accepted']
['s998186129', 's924038993']
[25076.0, 25076.0]
[98.0, 98.0]
[134, 134]
p03724
u708255304
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["N, M = map(int, input().split()) \n\ncounter = [0] * N\n\nfor _ in range(M):\n a, b = map(lambda x: int(x) - 1, input().split())\n counter[a] += 1\n counter[b] += 1\n\nflag = True\nfor i in range(len(counter)):\n if counter[i] % 2 != 0:\n flag = False\n\n\nif flag:\n print('Yes')\nelse:\n print('No')\n", 'from collections import defaultdict\nN, M = map(int, input().split())\nc = defaultdict(int)\nfor _ in range(M):\n a, b = map(int, input().split())\n c[a] += 1\n c[b] += 1\n\nflag = True\nfor k, v in c.items():\n if v % 2 != 0:\n flag = False\nif flag:\n print("YES")\nelse:\n print("NO")\n']
['Wrong Answer', 'Accepted']
['s279059696', 's676189281']
[3828.0, 14660.0]
[389.0, 244.0]
[337, 298]
p03724
u727801592
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
["n,m=map(int,input().split())\ncnt=[]\nfor i in range(n):\n cnt.append(0)\nfor i in range(m):\n a,b=map(int,input().split())\n cnt[a-1]+=1\n cnt[b-1]+=1\nfor i in range(n):\n if cnt[i]%2==1:\n print('NO')\n exit()\nprint('Yes')", "n,m=map(int,input().split())\ncnt=[]\nfor i in range(n):\n cnt.append(0)\nfor i in range(m):\n a,b=map(int,input().split())\n cnt[a-1]+=1\n cnt[b-1]+=1\nfor i in range(n):\n if cnt[i]%2==1:\n print('NO')\n exit()\nprint('YES')"]
['Wrong Answer', 'Accepted']
['s885405240', 's923943950']
[3964.0, 3888.0]
[340.0, 338.0]
[225, 225]
p03724
u736729525
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['def main():\n import sys\n input = sys.stdin.readline\n N, M = map(int, input().split())\n C = [0]*(N+1)\n for i in range(M):\n a, b = map(int, input().split())\n C[a]+=1\n C[b]+=1\n for i in range(N+1):\n if C[i] % 2 == 1:\n return "NO"\n return "YES"\n\nmain()\n', 'def main():\n import sys\n input = sys.stdin.readline\n N, M = map(int, input().split())\n C = [0]*(N+1)\n for i in range(M):\n a, b = map(int, input().split())\n C[a]+=1\n C[b]+=1\n for i in range(N+1):\n if C[i] % 2 == 1:\n return "NO"\n return "YES"\n\nprint(main())\n']
['Wrong Answer', 'Accepted']
['s087704366', 's233595439']
[3828.0, 3828.0]
[144.0, 137.0]
[309, 316]
p03724
u784022244
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N,M=map(int, input().split())\n\n\n\n\n\n\n\nD={} \nfor i in range(N):\n D[i+1]=0\nfor i in range(M):\n a,b=map(int, input().split())\n D[a]+=1\n D[b]+=1\n\nodds=0\nevens=0\nfor v in D.values():\n if v%2==0:\n evens+=1\n else:\n odds+=1\nif odds==0:\n print("Yes")\nelse:\n if evens>=odds*2:\n print("Yes")\n else:\n print("No")', 'N,M=map(int, input().split())\n\nD={} \nfor i in range(N):\n D[i+1]=0\nfor i in range(M):\n a,b=map(int, input().split())\n D[a]+=1\n D[b]+=1\n\nodds=0\nevens=0\nfor v in D.values():\n if v%2==0:\n evens+=1\n else:\n odds+=1\nif odds>0:\n print("NO")\nelse:\n print("YES")']
['Wrong Answer', 'Accepted']
['s749657906', 's916087103']
[15084.0, 15084.0]
[384.0, 359.0]
[545, 282]
p03724
u785578220
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N,M=map(int,input().split())\nimport collections\ne =[]\nfor i in range(N):\n ta,tb =map(int,input().split())\n e.extend([ta,tb])\nc = collections.Counter(e)\nprint(c)\nans = "YES"\nfor i in c:\n if c[i]%2 != 0:\n ans = "NO"\nprint(ans)\n', 'N,M=map(int,input().split())\nimport collections\ne =[]\nfor i in range(M):\n ta,tb =map(int,input().split())\n e.extend([ta,tb])\nc = collections.Counter(e)\n#print(c)\nans = "YES"\nfor i in c:\n if c[i]%2 != 0:\n ans = "NO"\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s110997501', 's373467001']
[27140.0, 16004.0]
[438.0, 363.0]
[241, 242]
p03724
u798818115
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N,M=map(int,input().split())\n\ncount=[0]*N\nfor _ in range(M):\n a,b=map(int,input().split())\n count[a-1]+=1\n count[b-1]+=1\n\nfor c in count:\n if c%2==0:\n print("NO")\n exit()\n\nprint("YES")', 'N,M=map(int,input().split())\n\ncount=[0]*N\nfor _ in range(M):\n a,b=map(int,input().split())\n count[a-1]+=1\n count[b-1]+=1\n\nfor c in count:\n if c%2==1:\n print("NO")\n exit()\n\nprint("YES")']
['Wrong Answer', 'Accepted']
['s760582229', 's162833471']
[3828.0, 3828.0]
[319.0, 325.0]
[210, 210]
p03724
u816116805
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n\n#\n\n"""\nagc014 B\n"""\n\nfrom collections import Counter\nn, m = map(int, input().split())\n\ncnt = Counter()\nfor i in range(m):\n a, b = map(int, input().split())\n cnt[a] += 1\n cnt[b] += 1\n\nfor a in range(1, n+1):\n if cnt[a] % 2 == 1:\n print(\'No\')\n exit()\n\nprint(\'Yes\')\n', '#! /usr/bin/env python\n# -*- coding: utf-8 -*-\n\n#\n\n"""\nagc014 B\n"""\n\nfrom collections import Counter\nn, m = map(int, input().split())\n\ncnt = Counter()\nfor i in range(m):\n a, b = map(int, input().split())\n cnt[a] += 1\n cnt[b] += 1\n\nfor a in range(1, n+1):\n if cnt[a] % 2 == 1:\n print(\'NO\')\n exit()\n\nprint(\'YES\')\n']
['Wrong Answer', 'Accepted']
['s458510426', 's025936879']
[9448.0, 9448.0]
[453.0, 468.0]
[353, 353]
p03724
u854685751
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N = int(input())\n\nl = [0 for i in range(N)]\nad = [[] for i in range(N)]\nde1 = [0 for i in range(N)]\n\nfor i in range(N-1):\n\ta,b = map(int,input().split())\n\tl[a-1] += 1\n\tl[b-1] += 1\n\tad[a-1].append(b-1)\n\tad[b-1].append(a-1)\n\nfor i in range(N):\n\tif l[i] == 1:\n\t\tde1[ad[i][0]] += 1\n\nfor i in range(N):\n\tif de1[i] >= 2:\n\t\tprint("First")\n\t\tbreak\nelse:\n\tprint("Second")\n\n\n\n\n\n', 'N,M = map(int,input().split())\n\nl = [0 for i in range(N)]\n\nfor i in range(M):\n\ta,b = map(int,input().split())\n\tl[a-1] += 1\n\tl[b-1] += 1\n\nfor i in l:\n\tif i%2 == 1:\n\t\tprint("NO")\n\t\tbreak\nelse:\n\tprint("YES")']
['Runtime Error', 'Accepted']
['s103845072', 's747850183']
[3064.0, 3888.0]
[18.0, 324.0]
[368, 204]
p03724
u879870653
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N,M = map(int,input().split())\n\nG = [[] for i in range(N)]\n\nfor i in range(M) :\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n G[a].append(b)\n G[b].append(a)\n\nans = "NO" if any(len(g) for g in G) else "YES"\n\nprint(ans)\n', 'N,M = map(int,input().split())\n\nG = [[] for i in range(N)]\n\nfor i in range(M) :\n a,b = map(int,input().split())\n a -= 1\n b -= 1\n G[a].append(b)\n G[b].append(a)\n\nans = "NO" if any(len(g)%2 for g in G) else "YES"\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s005377981', 's599637550']
[20656.0, 20656.0]
[384.0, 407.0]
[236, 238]
p03724
u886747123
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N, M = map(int, input().split())\nc = [0] * (N+1)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n c[a] += 1\n c[b] += 1\n\nprint("Yes" if all(c[i]%2 == 0 for i in range(N+1)) else "No")', 'N, M = map(int, input().split())\nc = [0] * (N+1)\n\nfor _ in range(M):\n a, b = map(int, input().split())\n c[a] += 1\n c[b] += 1\n\nprint("YES" if all(c[i]%2 == 0 for i in range(N+1)) else "NO")']
['Wrong Answer', 'Accepted']
['s250503278', 's539578850']
[3828.0, 3828.0]
[330.0, 319.0]
[197, 197]
p03724
u896741788
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['n,m=map(int,input().split())\nc=sum([list(map(int,input().split())) for i in range(m)],[])\nfrom collections import Counter as co\nfor i in co(c).values():\n if i%2:print("NO");exit()\n print("YES")', 'n,m=map(int,input().split())\nfrom collections import Counter as co\n\nfrom itertools import chain\nflatten=chain.from_iterable\nprint("YES" if all(i%2==0 for i in co(flatten([list(map(int,input().split())) for i in range(m)])).values()) else "NO")']
['Runtime Error', 'Accepted']
['s774528171', 's129559211']
[2940.0, 31388.0]
[17.0, 244.0]
[197, 243]
p03724
u905582793
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['import sys\nfrom collections import Counter\nn,m=map(int,input().split())\na=list(map(int,read().split()))\nc=Counter(a)\nans="YES"\nfor i in c.values():\n if i%2:\n ans="NO"\nprint(ans)', 'import sys\nfrom collections import Counter\nread=sys.stdin.read\nn,m=map(int,input().split())\na=list(map(int,read().split()))\nc=Counter(a)\nans="YES"\nfor i in c.values():\n if i%2:\n ans="NO"\nprint(ans)']
['Runtime Error', 'Accepted']
['s001252292', 's595818377']
[3316.0, 24744.0]
[21.0, 95.0]
[181, 201]
p03724
u984276646
2,000
262,144
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice. First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge. Then, Aoki gave him M queries. The i-th of them is as follows: * Increment the number written at each edge along the path connecting vertices a_i and b_i, by one. After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries. Determine whether there exists a tree that has the property mentioned by Takahashi.
['N, M = map(int, input().split())\nD = {i: 0 for i in range(1, N + 1)}\nfor i in range(M):\n a, b = map(int, input().split())\n D[a], D[b] += 1\np = 0\nfor i in D:\n if i % 2 == 1:\n p = 1\nif p == 0:\n print("YES")\nelse:\n print("NO")', 'N, M = map(int, input().split())\nD = {i: 0 for i in range(1, N + 1)}\nfor i in range(M):\n a, b = map(int, input().split())\n D[a] += 1\n D[b] += 1\np = 0\nfor i in D:\n if i % 2 == 1:\n p = 1\nif p == 0:\n print("YES")\nelse:\n print("NO")\n', 'N, M = map(int, input().split())\nD = {i: 0 for i in range(1, N + 1)}\nfor i in range(M):\n a, b = map(int, input().split())\n D[a] += 1\n D[b] += 1\np = 0\nfor i in D:\n if D[i] % 2 == 1:\n p = 1\nif p == 0:\n print("YES")\nelse:\n print("NO")\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s591255610', 's948876401', 's450883691']
[3064.0, 15208.0, 15084.0]
[17.0, 359.0, 359.0]
[231, 238, 241]
p03725
u107077660
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
['from collections import deque\nH, W, K = map(int, input().split())\nm = [input() for i in range(H)]\nv = [[0]*W for i in range(H)]\nf = 0\nfor i in range(H):\n\tif f:\n\t\tbreak\n\tfor j in range(W):\n\t\tif m[i][j] == "S":\n\t\t\tx = i\n\t\t\ty = j\n\t\t\tf = 1\n\t\t\tbreak\nstack = deque([[x,y,0]])\nv[x][y] = 1\nans = (min(x, y, H-x, W-y)+K-1)//K\nwhile stack:\n\tx, y, c = stack.popleft()\n\tv[x][y] = 1\n\tans = (min(x, y, H-x, W-y)+K-1)//K\n\tif c < K:\n\t\tc += 1\n\t\tif x > 0 and m[x-1][y] == "." and not v[x-1][y]:\n\t\t\tstack.append([x-1,y,c])\n\t\tif x < H-1 and m[x+1][y] == "." and not v[x][y-1]:\n\t\t\tstack.append([x+1,y,c])\n\t\tif y > 0 and m[x][y-1] == "." and not v[x+1][y]:\n\t\t\tstack.append([x,y-1,c])\n\t\tif y < W-1 and m[x][y+1] == "." and not v[x][y+1]:\n\t\t\tstack.append([x,y+1,c])\nprint(ans+1)', 'from collections import deque\nH, W, K = map(int, input().split())\nm = [input() for i in range(H)]\nv = [[0]*W for i in range(H)]\nf = 0\nfor i in range(H):\n\tif f:\n\t\tbreak\n\tfor j in range(W):\n\t\tif m[i][j] == "S":\n\t\t\tx = i\n\t\t\ty = j\n\t\t\tf = 1\n\t\t\tbreak\ndq = deque([[x,y,0]])\nv[x][y] = 1\nans = (min(x, y, H-1-x, W-1-y)+K-1)//K\nwhile dq:\n\tx, y, c = dq.popleft()\n\tv[x][y] = 1\n\tans = (ans, min(x, y, H-1-x, W-1-y)+K-1)//K\n\tif c < K:\n\t\tc += 1\n\t\tif x > 0 and m[x-1][y] == "." and not v[x-1][y]:\n\t\t\tdq.append([x-1,y,c])\n\t\tif x < H-1 and m[x+1][y] == "." and not v[x+1][y]:\n\t\t\tdq.append([x+1,y,c])\n\t\tif y > 0 and m[x][y-1] == "." and not v[x][y-1]:\n\t\t\tdq.append([x,y-1,c])\n\t\tif y < W-1 and m[x][y+1] == "." and not v[x][y+1]:\n\t\t\tdq.append([x,y+1,c])\nprint(ans+1)', 'from collections import deque\nH, W, K = map(int, input().split())\nm = [input() for i in range(H)]\nv = [[0]*W for i in range(H)]\nf = 0\nfor i in range(H):\n\tif f:\n\t\tbreak\n\tfor j in range(W):\n\t\tif m[i][j] == "S":\n\t\t\tx = i\n\t\t\ty = j\n\t\t\tf = 1\n\t\t\tbreak\ndq = deque([[x,y,0]])\nv[x][y] = 1\nans = (min(x, y, H-1-x, W-1-y)+K-1)//K\nwhile dq:\n\tx, y, c = dq.popleft()\n\tans = min(ans, (min(x, y, H-1-x, W-1-y)+K-1)//K)\n\tif c < K:\n\t\tc += 1\n\t\tif x > 0 and m[x-1][y] == "." and not v[x-1][y]:\n\t\t\tdq.append([x-1,y,c])\n\t\t\tv[x-1][y] = 1\n\t\tif x < H-1 and m[x+1][y] == "." and not v[x+1][y]:\n\t\t\tdq.append([x+1,y,c])\n\t\t\tv[x+1][y] = 1\n\t\tif y > 0 and m[x][y-1] == "." and not v[x][y-1]:\n\t\t\tdq.append([x,y-1,c])\n\t\t\tv[x][y-1] = 1\n\t\tif y < W-1 and m[x][y+1] == "." and not v[x][y+1]:\n\t\t\tdq.append([x,y+1,c])\n\t\t\tv[x][y+1] = 1\nprint(ans+1)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s708613103', 's871926514', 's100634173']
[104148.0, 9068.0, 9196.0]
[2110.0, 120.0, 1884.0]
[754, 746, 806]
p03725
u562935282
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
["import sys\n\nsys.setrecursionlimit(10 ** 9)\n\n\ndef start_pos():\n for r in range(H):\n for c in range(W):\n if a[r][c] == 'S':\n return r, c\n return -1, -1\n\n\ndef shortest_len(y, x):\n return min(y, H - 1 - y, x, W - 1 - x)\n\n\ndef dfs(y, x, k):\n global need_len\n if b[y][x]: return\n b[y][x] = True\n if not (0 <= y < H and 0 <= x < W): return\n if a[y][x] == '#': return\n need_len = min(need_len, shortest_len(y, x))\n if k == 0: return\n for dy, dx in (-1, 0), (1, 0), (0, -1), (0, 1):\n dfs(y + dy, x + dx, k - 1)\n\n\nH, W, K = map(int, input().split())\na = [input() for _ in range(H)]\nb = [[False for _ in range(W)] for _ in range(H)]\nsy, sx = start_pos()\nneed_len = shortest_len(sy, sx)\ndfs(sy, sx, K)\n\nprint(1 + (need_len + K - 1) // K)\n\n\n", "\nimport sys\n\ninput = sys.stdin.readline().rstrip()\n\n\ndef solve():\n H, W, K = map(int, input().split())\n a = [[False for _ in range(W)] for _ in range(H)]\n visited = [[False for _ in range(W)] for _ in range(H)]\n\n sy, sx = -1, -1\n for r in range(H):\n s = input()\n for c, x in enumerate(s):\n if x == '.':\n a[r][c] = True\n elif x == 'S':\n a[r][c] = True\n sy, sx = r, c\n\n q = [(sy, sx, 0)]\n t = max(W, H)\n n = 1\n i = 0\n while n > 0:\n r, c, k = q[i]\n n -= 1\n visited[r][c] = True\n\n t = min(t, r, H - 1 - r, c, W - 1 - c)\n\n if t == 0:\n print(1)\n return\n\n for dr, dc in (-1, 0), (1, 0), (0, -1), (0, 1):\n nr, nc = r + dr, c + dc\n if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:\n q.append((nr, nc, k + 1))\n n += 1\n i += 1\n\n ans = 1 + (t + K - 1) // K\n\n print(ans)\n\n\nif __name__ == '__main__':\n solve()\n", "\nfrom collections import deque\n\ndr = (0, 1, 0, -1)\ndc = (1, 0, -1, 0)\n\n\ndef solve():\n H, W, K = map(int, input().split())\n a = [[False for _ in range(W)] for _ in range(H)]\n\n sy, sx = -1, -1\n for r in range(H):\n s = input()\n for c, x in enumerate(s):\n if x == '.':\n a[r][c] = True\n elif x == 'S':\n a[r][c] = True\n sy, sx = r, c\n\n visited = [[False for _ in range(W)] for _ in range(H)]\n visited[sy][sx] = True\n\n t = max(H, W)\n q = deque([(sy, sx, 0)])\n while q:\n r, c, k = q.popleft()\n\n t = min(t, r, H - 1 - r, c, W - 1 - c)\n # print(t)\n if t == 0:\n print(1)\n return\n\n for d_i in range(4):\n nr, nc = r + dr[d_i], c + dc[d_i]\n if 0 <= nr < H and 0 <= nc < W and a[nr][nc] and not visited[nr][nc] and k + 1 <= K:\n visited[nr][nc] = True\n q.append((nr, nc, k + 1))\n\n ans = 1 + (t + K - 1) // K\n\n print(ans)\n\n\nif __name__ == '__main__':\n solve()\n"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s318920338', 's491066886', 's401409530']
[42984.0, 3064.0, 14444.0]
[247.0, 18.0, 280.0]
[1023, 1135, 1130]
p03725
u606045429
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
['from collections import deque\n\nINF = float("inf")\n\nH, W, K = map(int, input().split())\nA = [list(input()) for _ in range(H)]\n\nSi, Sj = (0, 0)\nfor i, a in enumerate(A):\n if "S" in a:\n Si, Sj = (i, a.index("S"))\n break\n\ndist = [[INF] * W for _ in range(H)]\ndist[Si][Sj] = 0\n\nans = INF\n\nQ = deque([(Si, Sj)])\nwhile Q:\n i, j = Q.popleft()\n\n ans = min(\n 1 + (i + K - 1) // K,\n 1 + (j + K - 1) // K,\n 1 + (H - 1 - i + K - 1) // K,\n 1 + (W - 1 - j + K - 1) // K\n )\n\n if dist[i][j] == K:\n continue\n\n distance = dist[i][j] + 1\n\n for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):\n ni, nj = i + di, j + dj\n\n if not (0 <= ni < H or 0 <= nj < W) and A[ni][nj] == "#":\n continue\n\n if dist[ni][nj] > distance:\n dist[ni][nj] = distance\n Q.append((ni, nj))\n\nprint(ans)\n', 'from collections import deque\n\nINF = float("inf")\n\nH, W, K = map(int, input().split())\nA = [list(input()) for _ in range(H)]\n\nSi, Sj = (0, 0)\nfor i, a in enumerate(A):\n if "S" in a:\n Si, Sj = (i, a.index("S"))\n break\n\ndist = [[INF] * W for _ in range(H)]\ndist[Si][Sj] = 0\n\n\nans = INF\n\nQ = deque([(Si, Sj)])\nwhile Q:\n i, j = Q.popleft()\n\n ans = min(\n ans,\n 1 + (i + K - 1) // K,\n 1 + (j + K - 1) // K,\n 1 + (H - 1 - i + K - 1) // K,\n 1 + (W - 1 - j + K - 1) // K\n )\n\n if dist[i][j] == K:\n continue\n\n distance = dist[i][j] + 1\n\n for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):\n ni, nj = i + di, j + dj\n\n if not (0 <= ni < H or 0 <= nj < W) and A[ni][nj] == "#":\n continue\n\n if dist[ni][nj] > distance:\n dist[ni][nj] = distance\n Q.append((ni, nj))\n\nprint(ans)\n', 'from collections import deque\n\nINF = float("inf")\n\nH, W, K = map(int, input().split())\nA = [list(input()) for _ in range(H)]\n\nSi, Sj = (0, 0)\nfor i, a in enumerate(A):\n if "S" in a:\n Si, Sj = (i, a.index("S"))\n break\n\ndist = [[INF] * W for _ in range(W)]\ndist[Si][Sj] = 0\n\n\nans = INF\n\nQ = deque([(Si, Sj)])\nwhile Q:\n i, j = Q.popleft()\n\n ans = min(\n 1 + (i + K - 1) // K,\n 1 + (j + K - 1) // K,\n 1 + (H - 1 - i + K - 1) // K,\n 1 + (W - 1 - j + K - 1) // K\n )\n\n if dist[i][j] == K:\n continue\n\n distance = dist[i][j] + 1\n\n for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):\n ni, nj = i + di, j + dj\n\n if not (0 <= ni < H or 0 <= nj < W) and A[ni][nj] == "#":\n continue\n\n if dist[ni][nj] > distance:\n dist[ni][nj] = distance\n Q.append((ni, nj))\n\nprint(ans)\n', 'from collections import deque\n\nINF = float("inf")\n\nH, W, K = map(int, input().split())\nA = [list(input()) for _ in range(H)]\n\nSi, Sj = (0, 0)\nfor i, a in enumerate(A):\n if "S" in a:\n Si, Sj = (i, a.index("S"))\n break\n\ndist = [[INF] * W for _ in range(W)]\ndist[Si][Sj] = 0\n\n\nans = INF\n\nQ = deque([(Si, Sj)])\nwhile Q:\n i, j = Q.popleft()\n\n ans = min(\n 1 + (i + K - 1) // K,\n 1 + (j + K - 1) // K,\n 1 + (H - 1 - i + K - 1) // K,\n 1 + (W - 1 - j + K - 1) // K\n )\n\n if dist[i][j] == K:\n continue\n\n distance = dist[i][j] + 1\n\n for di, dj in ((1, 0), (0, 1), (-1, 0), (0, -1)):\n ni, nj = i + di, j + dj\n\n if not (0 <= ni < H or 0 <= nj < W) or A[ni][nj] == "#":\n continue\n\n if dist[ni][nj] > distance:\n dist[ni][nj] = distance\n Q.append((ni, nj))\n\nprint(ans)\n', 'from collections import deque\n\nH, W, K = map(int, input().split())\nA = [list(input()) for _ in range(H)]\n\nSi, Sj = (0, 0)\nfor i, a in enumerate(A):\n\tif "S" in a:\n\t\tSi, Sj = (i, a.index("S"))\n\t\tbreak\n\ndist = float("inf")\n\nQ = deque([(0, Si, Sj)])\nwhile Q:\n\tcnt, i, j = Q.popleft()\n\n\tdist = min(dist, i, j, H - i - 1, W - j - 1)\n\tif dist == 0:\n\t\tbreak\n\n\tif cnt >= K:\n\t\tcontinue\n\n\tfor ni, nj in ((i + 1, j), (i, j + 1), (i - 1, j), (i, j - 1)):\n\t\tif 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":\n\t\t\tA[ni][nj] = "#"\n\t\t\tQ.append((cnt + 1, ni, nj))\n\nprint(-(-dist // K) + 1)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s350947711', 's454926951', 's599708295', 's934376850', 's053121967']
[29744.0, 29112.0, 28992.0, 14672.0, 9196.0]
[2105.0, 2105.0, 2105.0, 324.0, 189.0]
[876, 890, 877, 876, 572]
p03725
u608297208
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
['H,W,K = map(int,input().split())\nHW = [list(input()) for i in range(H)]\nfor i,h in enumerate(HW):\n\tif "S" in h:\n\t\ty = i\n\t\tx = h.index("S")\nA = [(x,y)]\nm = 800\ndef idou(a,b):\n\tX = []\n\tfor i2 in range(4):\n\t\tif i2 == 0:\n\t\t\tt,k = a - 1, b\n\t\telif i2 == 1:\n\t\t\tt,k = a, b - 1\n\t\telif i2 == 2:\n\t\t\tt,k = a + 1, b\n\t\telif i2 == 3:\n\t\t\tt,k = a, b + 1\n\t\tif 0 <= t < W and 0 <= k < H and HW[k][t] == ".":\n\t\t\tHW[k][t] = "o"\n\t\t\tX.append((t,k))\n\treturn X\ncnt = 0\nfor p in A:\n\tcnt += 1\n\tx,y = p\n\tb = idou(x,y)\n\tA.extend(b)\n\tif cnt > K:\n\t\tbreak\nM = []\nfor i,w in enumerate(zip(*HW)):\n\t#print(w)\n\tif "o" in w or "S" in w:\n\t\tM.append(min(i,W - i - 1))\n\t\t\nfor i,h in enumerate(HW):\n\tif "S" in h or "o" in h:\n\t\tM.append(min(i, H - i - 1))\n\t\t#print(h)\nm = min(M)\nprint((m + K - 1) // K)', 'import math\nH,W,K = map(int,input().split())\nHW = [list(input()) for i in range(H)]\nfor i,h in enumerate(HW):\n\tif "S" in h:\n\t\ty = i\n\t\tx = h.index("S")\nA = [(x,y)]\nm = 800\ndef idou(a,b):\n\tX = []\n\tfor i2 in range(4):\n\t\tif i2 == 0:\n\t\t\tt,k = a - 1, b\n\t\telif i2 == 1:\n\t\t\tt,k = a, b - 1\n\t\telif i2 == 2:\n\t\t\tt,k = a + 1, b\n\t\telif i2 == 3:\n\t\t\tt,k = a, b + 1\n\t\tif 0 <= t < W and 0 <= k < H and HW[k][t] == ".":\n\t\t\tHW[k][t] = "o"\n\t\t\tX.append((t,k))\n\treturn X\ncnt = 0\nwhile cnt < K:\n\tcnt += 1\n\tB = []\n\tfor p in A:\n\t\tx,y = p\n\t\tb = idou(x,y)\n\t\tB.extend(b)\n\tA = B[:]\nM = []\nfor i,w in enumerate(zip(*HW)):\n\t#print(w)\n\tif "o" in w or "S" in w:\n\t\tM.append(min(i,W - i - 1))\n\t\t\nfor i,h in enumerate(HW):\n\tif "S" in h or "o" in h:\n\t\tM.append(min(i, H - i - 1))\n\t\t#print(h)\nm = min(M)\nprint((m + K - 1) // K + 1)']
['Wrong Answer', 'Accepted']
['s700714958', 's390614548']
[71236.0, 11104.0]
[1653.0, 1802.0]
[760, 792]
p03725
u766684188
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
["import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import deque\nfrom math import ceil\n\ndef dist(h,w,x,y):\n return min(x-1,h-x,y-1,w-y)\n\nh,w,k=map(int,input().split())\ndelta=[[1,0],[0,1],[-1,0],[0,-1]]\nMAP=[]\nA=['#']*(w+2)\nMAP.append(A)\nfor i in range(h):\n s=input()\n for j,t in enumerate(s):\n if t=='S':\n sx,sy=i+1,j+1\n MAP.append(list(s))\nMAP.append(A)\nd=[[-1]*(w+2) for _ in range(h+2)]\nd[sy][sx]=0\nP=[]\nq=deque()\nq.append((sx,sy))\nwhile q:\n x,y=q.popleft()\n if d[x][y]>k:\n break\n P.append([x,y])\n for dx,dy in delta:\n if d[y+dy][x+dx]==-1 and MAP[y+dy][x+dx]=='.':\n q.append((y+dy,x+dx))\n d[y+dy][x+dx]=d[y][x]+1\nans=float('inf')\nfor x,y in P:\n ans=min(ans,1+ceil(dist(h,w,x,y)/k))\nprint(ans)", "import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10**9)\nfrom collections import deque\nfrom math import ceil\n\nh,w,k=map(int,input().split())\nMAP=[]\nfor i in range(h):\n s=list(input().strip())\n for j,t in enumerate(s):\n if t=='S':\n sx,sy=i,j\n MAP.append(s)\ndelta=[[1,0],[0,1],[-1,0],[0,-1]]\nq=deque()\nq.append((sx,sy,k))\ndist=float('inf')\nVisited=[[False]*w for _ in range(h)]\nVisited[sx][sy]=True\nwhile q:\n x,y,t=q.popleft()\n dist=min(dist,x,y,h-1-x,w-1-y)\n if not dist:\n break\n if t:\n t-=1\n for dx,dy in delta:\n if MAP[x+dx][y+dy]=='.' and not Visited[x+dx][y+dy]:\n q.append((x+dx,y+dy,t))\n Visited[x+dx][y+dy]=True\nprint(1+ceil(dist/k))"]
['Runtime Error', 'Accepted']
['s652705083', 's091462498']
[60728.0, 14324.0]
[1086.0, 285.0]
[807, 747]
p03725
u844789719
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
["import itertools, math\nH, W, K = [int(_) for _ in input().split()]\nA = [list(input()) for _ in range(H)]\nfor i, j in itertools.product(range(H), range(W)):\n if A[i][j] == 'S':\n break\nstack = [[i, j, 0]]\ncand = []\nwhile stack:\n h, w, dist = stack.pop()\n print(h, w, dist)\n A[h][w] = '#'\n cand += [[h, w]]\n if dist < K:\n for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:\n if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':\n stack += [[nh, nw, dist + 1]]\nans = float('inf')\nfor hw in cand:\n h, w = hw\n ans = min([\n ans,\n math.ceil(h / K),\n math.ceil((H - 1 - h) / K),\n math.ceil(w / K),\n math.ceil((W - 1 - w) / K)\n ])\nprint(ans + 1)\n", "import itertools, math, collections, sys\ninput = sys.stdin.readline\nH, W, K = [int(_) for _ in input().split()]\nA = [list(input()) for _ in range(H)]\nfor i, j in itertools.product(range(H), range(W)):\n if A[i][j] == 'S':\n break\nQ = collections.deque([[i, j, 0]])\nsH = set()\nsW = set()\nwhile Q:\n h, w, dist = Q.popleft()\n sH.add(h)\n sW.add(w)\n if dist < K:\n for nh, nw in [[h - 1, w], [h + 1, w], [h, w - 1], [h, w + 1]]:\n if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':\n A[nh][nw] = '#'\n Q += [[nh, nw, dist + 1]]\nprint(1 + min([\n math.ceil(_ / K)\n for _ in (min(sH), H - 1 - max(sH), min(sW), W - 1 - max(sW))\n]))\n"]
['Wrong Answer', 'Accepted']
['s543970644', 's212982441']
[113060.0, 11248.0]
[2111.0, 1944.0]
[749, 696]
p03725
u942033906
2,000
262,144
Takahashi is locked within a building. This building consists of H×W rooms, arranged in H rows and W columns. We will denote the room at the i-th row and j-th column as (i,j). The state of this room is represented by a character A_{i,j}. If A_{i,j}= `#`, the room is locked and cannot be entered; if A_{i,j}= `.`, the room is not locked and can be freely entered. Takahashi is currently at the room where A_{i,j}= `S`, which can also be freely entered. Each room in the 1-st row, 1-st column, H-th row or W-th column, has an exit. Each of the other rooms (i,j) is connected to four rooms: (i-1,j), (i+1,j), (i,j-1) and (i,j+1). Takahashi will use his magic to get out of the building. In one cast, he can do the following: * Move to an adjacent room at most K times, possibly zero. Here, locked rooms cannot be entered. * Then, select and unlock at most K locked rooms, possibly zero. Those rooms will remain unlocked from then on. His objective is to reach a room with an exit. Find the minimum necessary number of casts to do so. It is guaranteed that Takahashi is initially at a room without an exit.
['# coding: utf-8\n# Your code here!\nimport heapq as hq\nH,W,K = map(int,input().split())\nA = []\nX,Y=0,1\nstart = None\nfor h in range(H):\n tmp = list(input())\n A.append(tmp)\n if "S" in tmp:\n start = (tmp.index("S"), h)\n\ndef minCost(x,y):\n return min(start[X], W-1-start[X], start[Y], H-1-start[Y]) // K\nsearch = []\nsearched = [[False for w in range(W)] for h in range(H)]\nsearch.append((start[X],start[Y], 0))\nvector = [(1,0),(-1,0),(0,1),(0,-1)]\nmax_x,min_x,max_y,min_y = 0,W-1,0,H-1\nwhile len(search) > 0:\n x,y,cnt = search.pop()\n if searched[y][x]:\n continue\n searched[y][x] = True\n max_x = max(max_x, x)\n min_x = min(min_x, x)\n max_y = max(max_y, y)\n min_y = min(min_y, y)\n for v in vector:\n newX,newY = x+v[X], y+v[Y]\n if not searched[newY][newX] and cnt < K and A[newY][newX] != "#":\n search.append((newX,newY,cnt+1))\n\ndist = min(min_x, min_y, W-1-max_x, H-1-max_y)\nprint(1 + (dist+K-1)//K)', '# coding: utf-8\n# Your code here!\nimport heapq as hq\nH,W,K = map(int,input().split())\nA = []\nX,Y=0,1\nstart = None\nfor h in range(H):\n tmp = list(input())\n A.append(tmp)\n if "S" in tmp:\n start = (tmp.index("S"), h)\n\ndef minCost(x,y):\n return min(start[X], W-1-start[X], start[Y], H-1-start[Y]) // K\nsearch = []\nsearched = [[False for w in range(W)] for h in range(H)]\nhq.heapify(search)\nsearch.append((0, start[X], start[Y]))\nvector = [(1,0),(-1,0),(0,1),(0,-1)]\nmax_x,min_x,max_y,min_y = 0,W-1,0,H-1\nwhile len(search) > 0:\n cnt,x,y = hq.heappop(search)\n if x == 0 or x == W-1 or y == 0 or y == H-1:\n print(1)\n exit()\n if searched[y][x]:\n continue\n searched[y][x] = True\n max_x = max(max_x, x)\n min_x = min(min_x, x)\n max_y = max(max_y, y)\n min_y = min(min_y, y)\n for v in vector:\n newX,newY = x+v[X], y+v[Y]\n if not searched[newY][newX] and cnt < K and A[newY][newX] != "#":\n hq.heappush(search,(cnt+1,newX,newY))\ndist = min(min_x, min_y, W-1-max_x, H-1-max_y)\nprint(1 + (dist+K-1)//K)']
['Runtime Error', 'Accepted']
['s336813618', 's933264546']
[14836.0, 14580.0]
[211.0, 404.0]
[966, 1077]
p03733
u063979080
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
["def main():\n line=input()\n line=line.split(' ')\n n=line[0]\n t=line[1]\n line=input()\n line=line.split(' ')\n total=0\n for i in range(1,n):\n total+=min(t,line[i]-line[i-1])\n print(total)\n \n\nif __name__=='__main__':\n main()", "def main():\n line = input()\n line = line.split(' ')\n n = int(line[0])\n t = int(line[1])\n line = input()\n line = line.split(' ')\n total = 0\n for i in range(1, n):\n total += min(t, int(line[i]) - int(line[i - 1]))\n print(total+t)\n\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s623371845', 's010742623']
[19216.0, 19220.0]
[37.0, 162.0]
[259, 301]
p03733
u327466606
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,W = map(int,input().split())\n\nitems = [tuple(map(int,input().split())) for i in range(N)]\n\nfrom collections import defaultdict\ndp = defaultdict(int) # w -> v\ndp[0] = 0\n\nfor w,v in items:\n for tw,tv in list(dp.items()):\n if tw+w <= W:\n dp[tw+w] = max(tv+v, dp[tw+w])\n\nprint(max(dp.values()))', 'f=lambda:map(int,input().split())\nN,T=f()\nq=list(f())\nprint(T+sum(min(q[i+1]-q[i],T) for i in range(N-1)))']
['Runtime Error', 'Accepted']
['s869027219', 's311540733']
[26964.0, 25200.0]
[65.0, 136.0]
[301, 106]
p03733
u337626942
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T=map(int, input().split())\na=list(map(int, input().split()))\n\nans=T\n\nfor i in range(N-1):\n space=a[i+1]-a[i]\n if space>=T:\n ans+=T\n else:\n loss=T-space\n ans+=T-loss\n', 'N, T=map(int, input().split())\na=list(map(int, input().split()))\n\nans=T\n\nfor i in range(N-1):\n space=a[i+1]-a[i]\n if space>=T:\n ans+=T\n else:\n loss=T-space\n ans+=T-loss\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s029849839', 's623616450']
[26708.0, 25200.0]
[154.0, 161.0]
[199, 210]
p03733
u339199690
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nres = 0\nfor i in range(N - 1):\n res += min(T, t[i + 1] - t[i])\n\nif t[-2] + T <= t[-1]:\n res += T \n\nprint(res)\n', 'N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nres = 0\nfor i in range(N - 1):\n res += min(T, t[i + 1] - t[i])\n\nres += T\n\nprint(res)\n']
['Runtime Error', 'Accepted']
['s337215973', 's853087188']
[26836.0, 26708.0]
[151.0, 163.0]
[186, 158]
p03733
u373047809
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['n, T, *t = map(int, open(0).read().split())\nprint(sum(min(t[i+1] - t[i], T) for i in range(n)))', 'n, T, *t = map(int, open(0).read().split())\nprint(sum(min(t[i+1] - t[i], T) for i in range(n-1)) + T)']
['Runtime Error', 'Accepted']
['s428907086', 's655640179']
[25132.0, 25132.0]
[128.0, 138.0]
[95, 101]
p03733
u375616706
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = T\n\nfor i in range(1, N):\n ans = min(T, t[i]-t[i-1])\nprint(ans)\n', 'N, T = map(int, input().split())\nt = list(map(int, input().split()))\nprint(T+sum(min(T, t[i]-t[i-1]) for i in range(1, N)))\n']
['Wrong Answer', 'Accepted']
['s225462328', 's582336360']
[26836.0, 26836.0]
[138.0, 135.0]
[142, 124]
p03733
u417014669
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['# N,T=map(int,input().split())\n# s=list(map(int, input().split()))\nN=9\nT=10\nt=[0,3,5,7,100,110,200,300,311]\nans=0\nt_diff=[t[i+1]-t[i] for i in range(N-1)]\nprint(t_diff)\nfor i in t_diff:\n if i>T:\n ans+=T\n else:\n ans+=i\n\nprint(ans+T)\n\n\n', 'N,T=map(int,input().split())\ns=list(map(int, input().split()))\n\nt=[0,3,5,7,100,110,200,300,311]\nans=0\nt_diff=[t[i+1]-t[i] for i in range(N-1)]\nprint(t_diff)\nfor i in t_diff:\n if i>T:\n ans+=T\n else:\n ans+=i\n\nprint(ans+T)\n\n\n', 'N,T=map(int,input().split())\nt= list(map(int,input().split()))\nans=0\nt_diff=[t[i+1]-t[i] for i in range(N-1)]\nfor i in t_diff:\n if i>T:\n ans+=T\n else:\n ans+=i\n\nprint(ans+T)\n\n\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s040231635', 's683909633', 's042297984']
[2940.0, 25200.0, 26836.0]
[17.0, 69.0, 121.0]
[371, 359, 312]
p03733
u419963262
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T=map(int,input().split())\na=list(map(int,input().split()))\nkeep=0\nans=0\n\nfor i in range(N):\n if keep<=a[i]:\n ans+=T\n keep+=a[i]+T\nprint(ans)\n \n \n ', 'n,t=map(int,input().split())\na=list(map(int,input().split()))\nkeep=0\nans=0\nfor i in range(n):\n if keep<=a[i]:\n ans+=t\n keep=a[i]+t\n else:\n ans=ans+t-(keep-a[i])\n keep=a[i]+t\nprint(ans)\n ']
['Wrong Answer', 'Accepted']
['s914852840', 's224251257']
[26708.0, 26832.0]
[91.0, 155.0]
[198, 227]
p03733
u463655976
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T = input().split()\n\nf = None\np = None\nans = 0\nfor t in map(int, input().split())\n if f is None:\n f = t\n p = t - f\n\n ans += T\n rest = p + T - (t - f)\n if rest > 0:\n ans -= rest\n\n p = t - f\n\nprint(ans)', 'N, T = map(int, input().split())\n\nf = None\np = None\nans = 0\nfor t in map(int, input().split()):\n if f is None:\n f = t\n p = f - T\n\n ans += T\n rest = p + T - (t - f)\n if rest > 0:\n ans -= rest\n p = t - f\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s347321327', 's280378233']
[2940.0, 19220.0]
[18.0, 169.0]
[217, 228]
p03733
u513434790
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = 0\nfor i in range(1,N):\n ans += min(T, t[i] - t[i-1])\n\nprint(ans)', 'N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = T\nfor i in range(1,N):\n ans += min(T, t[i] - t[i-1])\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s890786285', 's931414999']
[25196.0, 26832.0]
[163.0, 147.0]
[141, 141]
p03733
u593567568
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T = map(int,input().split())\nA = list(map(int,input().split()))\nLST = []\n\nans = 0\nnxt = -1\nfor a in A:\n if nxt < a:\n nxt = a + T\n ans += T\n \nprint(ans)\n\n', 'N,T = map(int,input().split())\nA = list(map(int,input().split()))\nLST = []\n\nfor a in A:\n LST.append((a,1))\n LST.append((a+T,-1))\n \nLST.sort()\n\nprev = -1\ns = 0\nans = 0\nfor x,y in A:\n if y == 1:\n if s == 0:\n prev = x\n else:\n s += 1\n elif y == -1:\n s -= 1\n if s == 0:\n ans += (x - prev)\n \nprint(ans)\n\n', 'N,T = map(int,input().split())\nA = list(map(int,input().split()))\nLST = []\n\nfor a in A:\n LST.append((a,1))\n LST.append((a+T,-1))\n \nLST.sort()\n\nprev = -1\ns = 0\nans = 0\nfor x,y in LST:\n if y == 1:\n if s == 0:\n prev = x\n else:\n s += 1\n elif y == -1:\n s -= 1\n if s == 0:\n ans += (x - prev)\n \nprint(ans)\n\n', 'N,T = map(int,input().split())\nA = list(map(int,input().split()))\n\nans = 0\nfor i in range(N-1):\n ans += min(T,A[i+1] - A[i])\n \nprint(ans+T)\n\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s131449504', 's235826919', 's281341158', 's186085676']
[30840.0, 55104.0, 55108.0, 30824.0]
[85.0, 204.0, 266.0, 130.0]
[163, 331, 333, 143]
p03733
u616489782
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T = map(int,input().split());\nt = [int(x) for x in input().split()];\n\nend = 0;\nans = 0;\nfor i in range(N) :\n if end > t[i] :\n ans += t[i] + T - end;\n else :\n ans += T;\n end += t[i] + T;\n #print(ans,end);\n\nprint(ans); ', 'N,T = map(int,input().split());\nt = [int(x) for x in input().split()];\n\nend = 0;\nans = 0;\nfor i in range(N) :\n if end > t[i] :\n ans += t[i] + T - end;\n else :\n ans += T;\n end = t[i] + T;\n #print(ans,end);\n\nprint(ans); ']
['Runtime Error', 'Accepted']
['s272269616', 's948292656']
[8992.0, 30840.0]
[28.0, 135.0]
[249, 244]
p03733
u623687794
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['n,t=map(int,input().split())\noyu=list(map(int,input.split()))\ninl=[]\nans=n*t\nfor i in range(n-1):\n inl.append(oyu[i+1]-oyu[i])\nfor i in range(n-1):\n if inl[i]<t:\n ans-=t-inl[i]\nprint(ans)', 'n,t=map(int,input().split())\noyu=list(map(int,input().split()))\ninl=[]\nans=n*t\nfor i in range(n-1):\n inl.append(oyu[i+1]-oyu[i])\nfor i in range(n-1):\n if inl[i]<t:\n ans-=t-inl[i]\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s556286943', 's685104009']
[3060.0, 26708.0]
[18.0, 165.0]
[192, 195]
p03733
u669696235
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T=map(int,input().split())\nt=list(map(int,input().split()))\n\nfor i in range(0,len(t)-1):\n ans+=min(t[i+1]-t[i],T)\nans+=T\nprint(ans)', 'N,T=map(int,input().split())\nt=list(map(int,input().split()))\n\nans=0\nfor i in range(0,len(t)-1):\n ans+=min(t[i+1]-t[i],T)\nans+=T\nprint(ans)']
['Runtime Error', 'Accepted']
['s409724160', 's867231206']
[26832.0, 26708.0]
[68.0, 151.0]
[140, 146]
p03733
u674588203
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T=map(int,input().split())\na=list(input().split())\nts=[]\nfor _ in range (len(a)):\n ts.append(int(a[_]))\n\nYU=T\n\nfor i in range(1,N):\n if ts[i]-ts[i-1]<T:\n YU+=T-ts[i]-ts[i-1]\n else:\n YU+=T\nprint (YU)', 'N,T=map(int,input().split())\na=list(input().split())\nts=[]\nfor _ in range (len(a)):\n ts.append(int(a[_]))\n\nYU=T\n\nfor i in range(1,N):\n if ts[i]-ts[i-1]<T:\n YU+=T-(T-(ts[i]-ts[i-1]))\n else:\n YU+=T\nprint (YU)']
['Wrong Answer', 'Accepted']
['s062855441', 's712946422']
[26860.0, 26864.0]
[196.0, 205.0]
[223, 229]
p03733
u760961723
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N, T = map(int,input().split())\nt = list(map(int,input().split()))\nt.append(T)\n\nans = 0\nfor n in range(N):\n ans += min(t[n+1]-t[n],T)\nprint(ans)', 'N, T = map(int,input().split())\nt = list(map(int,input().split()))\nt.append(t[-1]+T)\n\n\nans = 0\nfor n in range(N):\n ans = ans + min(t[n+1]-t[n],T)\n \nprint(ans)']
['Wrong Answer', 'Accepted']
['s664076294', 's439838023']
[30720.0, 30784.0]
[138.0, 129.0]
[145, 160]
p03733
u782654209
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
["N,T=map(int,input().split(' '))\ntimes=[int(input()) for i in range(N)]\nprint(sum([min(T, times[i+1]-times[i] for i in range(N-1))])+times[-1])", "N,T=map(int,input().split(' '))\ntimes=list(map(int,input().split(' ')))\nprint(sum([min(T, times[i+1]-times[i]) for i in range(N-1)])+T)\n"]
['Runtime Error', 'Accepted']
['s979383972', 's341288634']
[2940.0, 26832.0]
[17.0, 131.0]
[142, 136]
p03733
u798260206
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['n,T = map(int,input().split())\nt = list(map(int,input().split())\nA = [0]*n\n\nfor i in range(n):\n if t[i]>T:\n A[i+1] = A[i] + T\n else:\n A[i+1] = A[i]+ t[i]\nprint(A[n])', 'N, T =map(int, input().split())\nt = list(map(int, input().split()))\nans = T\nfor i in range(1, N):\n if t[i] - t[i-1] >= T:\n ans += T\n else:\n ans += t[i] - t[i-1]\nprint(ans)']
['Runtime Error', 'Accepted']
['s836966455', 's568639431']
[2940.0, 26836.0]
[17.0, 146.0]
[185, 191]
p03733
u810735437
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport array\nfrom bisect import *\nfrom collections import *\nimport fractions\nimport heapq\nfrom itertools import *\nimport math\nimport random\nimport re\nimport string\nimport sys\n\nN, T = map(int, input().split())\n\nprev = None\nans = 0\nfor t in map(int, input().split()):\n if prev is not None:\n if t - prev < T:\n ans += t - prev\n else:\n ans += T\n prev = t\n print("ans:", ans)\nans += T\n', '#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport array\nfrom bisect import *\nfrom collections import *\nimport fractions\nimport heapq\nfrom itertools import *\nimport math\nimport random\nimport re\nimport string\nimport sys\n\nN, T = map(int, input().split())\n\nprev = None\nans = 0\nfor t in map(int, input().split()):\n if prev is not None:\n if t - prev < T:\n ans += t - prev\n else:\n ans += T\n prev = t\nans += T\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s969776231', 's468633122']
[22864.0, 21748.0]
[360.0, 160.0]
[472, 460]
p03733
u814986259
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T = map(int, input().split())\nprev = 0\nans = 0\nfor i in range(N):\n t = int(input())\n if prev+T <= t:\n ans += T\n else:\n ans += (t - prev)\n prev = t\n\nprint(ans + T)\n ', 'N, T = map(int, input().split())\nt = list(map(int, input().split()))\n\nans = 0\nend = -1\nstart = -1\nfor x in t:\n if end < x:\n ans += (end - start)\n start = x\n end = x + T\n else:\n end = x + T\n\nans += (end - start)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s959373133', 's813704576']
[6964.0, 30796.0]
[29.0, 89.0]
[181, 257]
p03733
u858670323
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['N,T = map(int,input().split())\nt = list(map(int,input().split()))\ncnt=0\nter=-1\nfor x in t:\n if(x>=ter):\n cnt+=1\n ter=x+T\nprint(cnt*T)\n', 'N,T = map(int,input().split())\nt = list(map(int,input().split()))\ncnt=0\nter=0\nfor x in t:\n if(x<=ter):\n cnt+=1\n ter=x+T\nprint(cnt*T)', 'N,T = map(int,input().split())\nt = list(map(int,input().split()))\nans=0\nter=-1\nfor x in t:\n if(x>=ter):\n ans+=T\n else:\n ans+=T-(ter-x)\n ter=x+T\n\nprint(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s313568123', 's960421679', 's126796353']
[26708.0, 25200.0, 25200.0]
[115.0, 109.0, 131.0]
[141, 139, 165]
p03733
u859897687
2,000
262,144
In a public bath, there is a shower which emits water for T seconds when the switch is pushed. If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds. Note that it does not mean that the shower emits water for T additional seconds. N people will push the switch while passing by the shower. The i-th person will push the switch t_i seconds after the first person pushes it. How long will the shower emit water in total?
['n,t=map(int,input().split())\nk=1000000000\nfor i in map(int,input().split()):\n ans+=min(t,max(i-k,0))\n k=i\nans+=t\nprint(ans)', 'n,t=map(int,input().split())\nans=0\nk=1000000000\nfor i in map(int,input().split()):\n ans+=min(t,max(i-k,0))\n k=i\nans+=t\nprint(ans)']
['Runtime Error', 'Accepted']
['s410942717', 's186946726']
[20856.0, 19220.0]
[35.0, 172.0]
[125, 131]
p03734
u077291787
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['# ARC073D - Simple Knapsack (ABC060D)\nfrom itertools import accumulate\n\n\ndef main():\n N, W, *A = map(int, open(0).read().split())\n V, x = [[] for _ in range(4)], A[0] \n for i in range(0, 2 * N, 2):\n w, v = A[i : i + 2]\n V[w - x] += [v]\n for i in range(4):\n V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))\n L = [len(v) for v in V]\n print(V, L)\n ans = 0\n for i in range(L[0]):\n for j in range(L[1]):\n for k in range(L[2]):\n for l in range(L[3]):\n w = i * x + j * (x + 1) + k * (x + 2) + l * (x + 3)\n if w > W:\n break\n v = V[0][i] + V[1][j] + V[2][k] + V[3][l]\n ans = max(ans, v)\n print(ans)\n\n\nif __name__ == "__main__":\n main()', '# ARC073D - Simple Knapsack (ABC060D)\nfrom itertools import accumulate\n\n\ndef main():\n N, W, *A = map(int, open(0).read().split())\n V, x = [[] for _ in range(4)], A[0] \n for i in range(0, 2 * N, 2):\n w, v = A[i : i + 2]\n V[w - x] += [v]\n for i in range(4):\n V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))\n L = [len(v) for v in V]\n ans = 0\n for i in range(L[0]):\n for j in range(L[1]):\n for k in range(L[2]):\n for l in range(L[3]):\n w = i * x + j * (x + 1) + k * (x + 2) + l * (x + 3)\n if w > W:\n break\n v = V[0][i] + V[1][j] + V[2][k] + V[3][l]\n ans = max(ans, v)\n print(ans)\n\n\nif __name__ == "__main__":\n main()']
['Wrong Answer', 'Accepted']
['s530354869', 's926975047']
[3188.0, 3064.0]
[143.0, 143.0]
[847, 831]
p03734
u091051505
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['n, w = map(int, input().split())\na = []\nfor _ in range(n):\n w_in, v_in = map(int, input().split())\n a.append([w_in, v_in])\n\ndp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]\nfor j in range(w + 1):\n for i in range(n):\n w_in, v_in = a[i]\n if j + w_in <= w:\n dp[i + 1][j + w_in] = max(dp[i + 1][j + w_in], dp[i][j] + v_in)\n if i + 2 <= n:\n dp[i + 2][j + w_in] = max(dp[i + 2][j + w_in], dp[i + 1][j + w_in])\n dp[i + 2][j] = max(dp[i + 2][j], dp[i + 1][j])\nprint(max([max(d) for d in dp]))', 'from itertools import accumulate\nn, w = map(int, input().split())\nw_0, v_0 = map(int, input().split())\nv_list = [[] for _ in range(4)]\nv_list[0].append(v_0)\nfor _ in range(n - 1):\n w_in, v_in = map(int, input().split())\n v_list[w_in - w_0].append(v_in)\nv_list = [[0] + list(accumulate(sorted(v, reverse=True))) for v in v_list]\nans = 0\nfor i in range(len(v_list[0])):\n for j in range(len(v_list[1])):\n for k in range(len(v_list[2])):\n for l in range(len(v_list[3])):\n if ((i) * w_0) + ((j) * (w_0 + 1)) + ((k) * (w_0 + 2)) + (((l) * (w_0 + 3))) <= w:\n ans = max(ans, v_list[0][i] + v_list[1][j] + v_list[2][k] + v_list[3][l])\n else:\n break\nprint(ans)']
['Runtime Error', 'Accepted']
['s235843105', 's602685968']
[528792.0, 3188.0]
[2123.0, 188.0]
[557, 745]
p03734
u106778233
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['n,w=map(int,input().split())\nWV=[]\nfor i in range(n):\n w,v=map(int,input().split())\n WV.append((w,v))\n\ndp=[0]*(w*2)\nfor w,v in WV:\n for i in range(w+1):\n try: dp[i]=max(dp[i],dp[i-w]+v)\n except:\n dp[i]=dp[i]\n\n\nprint(max(dp[:w+1]))', 'n,w=map(int,input().split())\nfrom heapq import heappush,heappop\nWV=[]\nfor i in range(n):\n w,v=map(int,input().split())\n WV.append((w,v))\ndp={}\ndp[0]=0\nfor w,v in WV:\n ndp=dp.copy()\n for i in ndp:\n if i+w>w:\n continue \n temp=dp[i]\n try:\n use=dp[i+w]\n dp[i+w]+=max(temp+v-use,0)\n except:\n dp[i+w]=temp+v \n \nans=[]\nfor i in dp:\n heappush(ans,-dp[i])\n\nprint(-heappop(ans))\n', 'n,w=map(int,input().split())\nWV=[]\nfor i in range(n):\n w,v=map(int,input().split())\n WV.append((w,v))\ndp={}\ndp[0]=0\nfor w,v in WV:\n for i in JinA:\n if i+w>w:\n continue \n temp=dp[i]\n try:\n use=dp[i+w]\n dp[i+w]+=max(temp+v-use,0)\n except:\n dp[i+w]=temp+v \n \nans=[]\nfor i in dp:\n heappush(ans,-dp[i])\n\nprint(-heappop(ans))', 'from collections import defaultdict\nimport sys\ninput = sys.stdin.readline\n\n\ndef main():\n N, W = map(int, input().split())\n items = [tuple(map(int, input().split())) for _ in range(N)]\n dd = defaultdict(int)\n dd[0] = 0\n for w, v in items:\n for tw, tv in list(dd.items()):\n if tw + w <= W:\n dd[tw + w] = max(tv + v, dd[tw + w])\n print(max(dd.values()))\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s369085461', 's875440971', 's908252969', 's865888595']
[316916.0, 3064.0, 3064.0, 3944.0]
[2117.0, 19.0, 18.0, 63.0]
[264, 459, 406, 442]
p03734
u196697332
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['from itertools import accumulate\nN, W = map(int, input().split())\nw_0, v_0 = map(int, input().split())\nv_list = [[] for _ in range(4)]\nv_list[0].append(v_0)\n\nfor _ in range(n - 1):\n w_in, v_in = map(int, input().split())\n v_list[w_in - w_0].append(v_in)\nv_list = [[0] + list(accumulate(sorted(v, reverse=True))) for v in v_list]\nans = 0\n\n#print(v_list)\n\nfor i in range(len(v_list[0])):\n for j in range(len(v_list[1])):\n for k in range(len(v_list[2])):\n for l in range(len(v_list[3])):\n if (i * w_0) + (j * (w_0 + 1)) + (k * (w_0 + 2)) + (l * (w_0 + 3)) <= W:\n ans = max(ans, v_list[0][i] + v_list[1][j] + v_list[2][k] + v_list[3][l])\n else:\n break\nprint(ans)\n\n', 'from itertools import accumulate\nN, W = map(int, input().split())\nw_0, v_0 = map(int, input().split())\nv_list = [[] for _ in range(4)]\nv_list[0].append(v_0)\n\nfor _ in range(N - 1):\n w_in, v_in = map(int, input().split())\n v_list[w_in - w_0].append(v_in)\nv_list = [[0] + list(accumulate(sorted(v, reverse=True))) for v in v_list]\nans = 0\n\n#print(v_list)\n\nfor i in range(len(v_list[0])):\n for j in range(len(v_list[1])):\n for k in range(len(v_list[2])):\n for l in range(len(v_list[3])):\n if (i * w_0) + (j * (w_0 + 1)) + (k * (w_0 + 2)) + (l * (w_0 + 3)) <= W:\n ans = max(ans, v_list[0][i] + v_list[1][j] + v_list[2][k] + v_list[3][l])\n else:\n break\nprint(ans)\n\n']
['Runtime Error', 'Accepted']
['s564421661', 's528391461']
[3188.0, 3064.0]
[19.0, 189.0]
[755, 755]
p03734
u346812984
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['import sys\nfrom collections import defaultdict\nimport numpy as np\n\nsys.setrecursionlimit(10 ** 6)\nINF = float("inf")\nMOD = 10 ** 9 + 7\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N, W = map(int, input().split())\n d = defaultdict(list)\n w, v = map(int, input().split())\n w1 = w\n d[w].append(v)\n for _ in range(1, N):\n w, v = map(int, input().split())\n d[w].append(v)\n\n cumsum = defaultdict(list)\n L = defaultdict(int)\n for k, v in d.items():\n d[k].sort(reverse=True)\n c = np.cumsum(d[w])\n cumsum[w] = c\n L[k - w1] = len(d[w])\n\n ans = 0\n for i in range(L[0] + 1):\n if i != 0:\n v1 = cumsum[w1][i - 1]\n else:\n v1 = 0\n for j in range(L[1] + 1):\n if j != 0:\n v2 = v1 + cumsum[w1 + 1][j - 1]\n else:\n v2 = v1\n for k in range(L[2] + 1):\n if k != 0:\n v3 = v2 + cumsum[w1 + 2][k - 1]\n else:\n v3 = v2\n for l in range(L[3] + 1):\n w = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l\n if w > W:\n continue\n\n if l != 0:\n v4 = v3 + cumsum[w1 + 3][l - 1]\n else:\n v4 = v3\n\n if v4 > ans:\n ans = v4\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', 'import sys\nfrom collections import defaultdict\nimport numpy as np\n\nsys.setrecursionlimit(10 ** 6)\nINF = float("inf")\nMOD = 10 ** 9 + 7\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\ndef main():\n N, W = map(int, input().split())\n d = defaultdict(list)\n w, v = map(int, input().split())\n w1 = w\n d[w].append(v)\n for _ in range(1, N):\n w, v = map(int, input().split())\n d[w].append(v)\n\n cumsum = dict()\n L = defaultdict(int)\n for i in range(4):\n w = w1 + i\n d[w].sort(reverse=True)\n c = np.cumsum(d[w])\n cumsum[w] = c\n L[i] = len(d[w])\n\n ans = 0\n for i in range(L[0] + 1):\n if i != 0:\n v1 = cumsum[w1][i - 1]\n else:\n v1 = 0\n for j in range(L[1] + 1):\n if j != 0:\n v2 = v1 + cumsum[w1 + 1][j - 1]\n else:\n v2 = v1\n for k in range(L[2] + 1):\n if k != 0:\n v3 = v2 + cumsum[w1 + 2][k - 1]\n else:\n v3 = v2\n for l in range(L[3] + 1):\n w = w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l\n if w > W:\n continue\n\n if l != 0:\n v4 = v3 + cumsum[w1 + 3][l - 1]\n else:\n v4 = v3\n\n if v4 > ans:\n ans = v4\n\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s755059152', 's325862283']
[12508.0, 14528.0]
[152.0, 379.0]
[1514, 1513]
p03734
u367130284
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['N,W=map(int,input().split())\nfrom collections import*\nd=defaultdict(int)\nd[0]=0\nfor i in range(N):\n w,v=map(int,input().split())\n for k,b in d.copy().items():\n if k+w<=W:\n d[k+w]=max(b,d[k]+v)\nprint(max(d.values()))\n', "from collections import*\nimport functools\nimport sys\ninput=sys.stdin.readline\[email protected]_cache(maxsize=None)\ndef Knapsack(N,W):\n for i in range(N):\n w,v=map(int,input().split())\n for k,b in d.copy().items():\n if k+w<=W:\n d[k+w]=max(d[k+w],b+v)\n return print(max(d.values()))\nN,W=map(int,input().split()) \nd=defaultdict(int)\nd[0]=0\nif __name__=='__main__':\n Knapsack(N,W)"]
['Wrong Answer', 'Accepted']
['s785354270', 's024463813']
[4016.0, 4116.0]
[81.0, 69.0]
[240, 440]
p03734
u458617779
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['ints = input().split(" ")\nN = int(ints[0])\nmaxW = int(ints[1])\nints = input().split(" ")\na = int(ints[0])\nb = int(ints[1])\nweight = [a, a+1, a+2, a+3] \nva = [[0,b],[0],[0],[0]]\nfor i in range(1, N):\n\tins = input().split(" ")\n\tw = int(ins[0])\n\tv = int(ins[1])\n\tfor j in range(0, 4):\n\t\tif w == weight[j]:\n\t\t\tva[j].append(v)\nva.sort()\nsum = [[0],[0],[0],[0]]\nfor j in range(0, 4):\n\tfor i in range(1, len(va[j])):\n\t\ttry:\n\t\t\tsum[j].append(sum[j][i-1] + va[j][i])\n\t\texcept:\n\t\t\tpass\nans = 0\nfor i in range(0, len(va[0])):\n\tfor j in range(0, len(va[1])):\n\t\tfor k in range(0, len(va[2])):\n\t\t\tfor l in range(0, len(va[3])):\n\t\t\t\tsumw = weight[0]*i + weight[1]*j +weight[2]*k + weight[3]*l\n\t\t\t\tif(sumw <= maxW):\n\t\t\t\t\tans = max(sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l],ans)\nprint(ans)', 'ints = input().split(" ")\nN = int(ints[0])\nmaxW = int(ints[1])\nints = input().split(" ")\na = int(ints[0])\nb = int(ints[1])\nweight = [a, a+1, a+2, a+3] \nva = [[b],[],[],[]]\nfor i in range(1, N):\n\tins = input().split(" ")\n\tw = int(ins[0])\n\tv = int(ins[1])\n\tfor j in range(0, 4):\n\t\tif w == weight[j]:\n\t\t\tva[j].append(v)\nfor i in range(0, len(va)):\n\tva[i].sort(reverse=True)\n\tva[i].insert(0,0)\n#print(va)\nsum = [[0],[0],[0],[0]]\nfor j in range(0, 4):\n\tfor i in range(1, len(va[j])):\n\t\ttry:\n\t\t\tsum[j].append(sum[j][i-1] + va[j][i])\n\t\texcept:\n\t\t\tpass\nans = 0\n#print(sum)\nfor i in range(0, len(va[0])):\n\tfor j in range(0, len(va[1])):\n\t\tfor k in range(0, len(va[2])):\n\t\t\tfor l in range(0, len(va[3])):\n\t\t\t\tsumw = weight[0]*i + weight[1]*j +weight[2]*k + weight[3]*l\n\t\t\t\tif(sumw <= maxW):\n\t\t\t\t\tans = max(sum[0][i]+sum[1][j]+sum[2][k]+sum[3][l],ans)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s864034470', 's724635535']
[3188.0, 3188.0]
[306.0, 322.0]
[770, 851]
p03734
u540761833
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['from itertools import accumulate\nN,W = map(int,input().split())\nw = [[] for i in range(4)]\nw1,v1 = map(int,input().split())\nw[0].append(v1)\nfor i in range(N-1):\n wi,vi = map(int,input().split())\n w[wi-w1].append(vi)\nnum = []\nfor i in range(4):\n w[i].sort(reverse= 1)\n w[i] = [0]+list(accumulate(w[i]))\n num.append(len(w[i]))\nans = 0\nfor n1 in range(num[0]+1):\n for n2 in range(num[1]+1):\n for n3 in range(num[2]+1):\n for n4 in range(num[3]+1):\n wc = w1*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4\n if wc <= W:\n vc = w[0][n1]+w[1][n2]+w[2][n3]+w[3][n4]\n ans = max(ans,vc)\nprint(ans)', 'from itertools import accumulate\nN,W = map(int,input().split())\nw = [[] for i in range(4)]\nw1,v1 = map(int,input().split())\nw[0].append(v1)\nfor i in range(N-1):\n wi,vi = map(int,input().split())\n w[wi-w1].append(vi)\nnum = []\nfor i in range(4):\n w[i].sort(reverse= 1)\n w[i] = [0]+list(accumulate(w[i]))\n num.append(len(w[i]))\nans = 0\nfor n1 in range(num[0]):\n for n2 in range(num[1]):\n for n3 in range(num[2]):\n for n4 in range(num[3]):\n wc = w1*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4\n if wc <= W:\n vc = w[0][n1]+w[1][n2]+w[2][n3]+w[3][n4]\n ans = max(ans,vc)\nprint(ans)\n ']
['Runtime Error', 'Accepted']
['s460025334', 's984435564']
[3064.0, 3064.0]
[240.0, 302.0]
[674, 675]
p03734
u543954314
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['n, w = map(int, input().split())\ndi = dict()\nm = 0\nfor _ in range(n):\n x,y = map(int, input().split())\n if x not in di:\n di[x] = []\n di[x].append(y)\nfor i in di:\n di[i].sort(reverse=True)\na,b,c,d = di.keys()\nfor i in range(len(di[a])):\n for j in range(len(di[b])):\n for k in range(len(di[c])):\n for l in range(len(di[d])):\n if i*a + j*b + k*c + l*d <= w:\n m = max(m, sum(di[a][:i+1] + di[b][:j+1] + di[c][:k+1] + di[d][:l+1]))\nprint(m)', 'n, w = map(int, input().split())\ndi = dict()\nm = 0\nfor _ in range(n):\n x,y = map(int, input().split())\n if x not in di:\n di[x] = []\n di[x].append(y)\nfor i in di:\n di[i].sort(reverse=True)\na = min(di.keys())\nb,c,d = a+1,a+2,a+3\nfor i in b,c,d:\n if i not in di:\n di[i] = []\nfor i in range(len(di[a])+1):\n for j in range(len(di[b])+1):\n for k in range(len(di[c])+1):\n for l in range(len(di[d])+1):\n if i*a + j*b + k*c + l*d <= w:\n m = max(m, sum(di[a][:i] + di[b][:j] + di[c][:k] + di[d][:l]))\nprint(m)']
['Runtime Error', 'Accepted']
['s084565987', 's077467784']
[3064.0, 3064.0]
[454.0, 466.0]
[467, 535]
p03734
u545368057
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['N,W = map(int, input().split())\nws = []\nvs = []\nfor i in range(N):\n w,v = map(int, input().split())\n ws.append(w)\n vs.append(v)\nws_m = [w-ws[0] for w in ws]\n\n\ndp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]\ndp[0][0][0] = 0\nfor i,(w,v) in enumerate(zip(ws_m,vs)):\n for n in range(i+1):\n for j in range(3*N):\n \n if j-w >= 0:\n dp[i+1][n+1][j] = max(dp[i][n+1][j], dp[i][n][j-w]+v)\n else:\n dp[i+1][n+1][j] = dp[i][j+1][k]\n \n # # if j + n*ws[0] > W: continue\n # # print("check",i,n,j,v) )\n # dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])\n # dp[i+1][n+1][j+w] = max(dp[i][n+1][j+w], dp[i][n][j] + v)\nans= 0\nfor i,As in enumerate(dp[N]):\n w = W - i*ws[0]\n if w > 0:\n ans = max(ans,max(As[:w+1]))\nprint(ans) ', 'N,W = map(int, input().split())\nws = []\nvs = []\nfor i in range(N):\n w,v = map(int, input().split())\n ws.append(w)\n vs.append(v)\nws_m = [w-ws[0] for w in ws]\n\n\ndp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]\ndp[0][0][0] = 0\nfor i,(w,v) in enumerate(zip(ws_m,vs)):\n for n in range(i+1):\n for j in range(min(sum(ws_m,W-n*ws[0]))+1):\n if dp[i][n][j] == -1: continue\n if j + n*ws[0] > W: continue\n # print("check",i,n,j,v)\n dp[i+1][n+1][j+w] = max(dp[i][n][j+w], dp[i][n][j] + v)\n dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])\nans= 0\nfor i,As in enumerate(dp[N]):\n w = W - i*ws[0]\n if w > 0:\n ans = max(ans,max(As[:w+1]))\nprint(ans) ', 'N,W = map(int, input().split())\nws = []\nvs = []\nfor i in range(N):\n w,v = map(int, input().split())\n ws.append(w)\n vs.append(v)\nws_m = [w-ws[0] for w in ws]\n\n\ndp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]\ndp[0][0][0] = 0\nfor i,(w,v) in enumerate(zip(ws_m,vs)):\n for n in range(N):\n for j in range(3*N):\n if dp[i][n][j] == -1: continue\n # if j + n*ws[0] > W: continue\n # print("check",i,n,j,v)\n dp[i+1][n+1][j] = max(dp[i+1][n+1][j], dp[i][n+1][j])\n dp[i+1][n+1][j+w] = max(dp[i][n+1][j+w], dp[i][n][j] + v)\nans= 0\nfor i,As in enumerate(dp[N]):\n w = W - i*ws[0]\n if w > 0:\n ans = max(ans,max(As[:w+1]))\nprint(ans) ', 'N,W = map(int, input().split())\nws = []\nvs = []\nfor i in range(N):\n w,v = map(int, input().split())\n ws.append(w)\n vs.append(v)\nws_m = [w-ws[0] for w in ws]\n\n\n\ndp = [[[-1]*(3*N+1) for i in range(N+1)] for j in range(N+1)]\ndp[0][0][0] = 0\nfor i,(w,v) in enumerate(zip(ws_m,vs)):\n for n in range(i+1):\n for j in range(3*N):\n if dp[i][n][j] == -1:continue\n dp[i+1][n+1][j+w] = max(dp[i][n][j] + v, dp[i][n][j+w])\n dp[i+1][n][j] = max(dp[i+1][n][j], dp[i][n][j])\n\nans = 0\nfor i,a in enumerate(dp[N]):\n w = W - i*ws[0]\n if w >= 0:\n ans = max(ans,max(a[:w+1]))\nprint(ans) \n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s330883483', 's458167801', 's638408595', 's152948879']
[52836.0, 27764.0, 29812.0, 31720.0]
[1201.0, 89.0, 614.0, 549.0]
[1114, 931, 916, 832]
p03734
u561083515
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['N,W = map(int, input().split())\nWV = [[int(i) for i in input().split()] for _ in range(N)]\n\nMINW = WV[0][0]\n\nW0,W1,W2,W3 = [],[],[],[]\nfor w,v in WV:\n if w == MINW: W0.append(v)\n elif w == MINW + 1: W1.append(v)\n elif w == MINW + 2: W2.append(v)\n elif w == MINW + 3: W3.append(v)\n\nW0.sort(reverse=True)\nW1.sort(reverse=True)\nW2.sort(reverse=True)\nW3.sort(reverse=True)\n\nW0 = [0] + W0\nW0 = [0] + W1\nW0 = [0] + W2\nW0 = [0] + W3\n\nfrom itertools import accumulate\n\nW0 = list(accumulate(W0))\nW1 = list(accumulate(W1))\nW2 = list(accumulate(W2))\nW3 = list(accumulate(W3))\n\nans = 0\nfor cnt0 in range(len(W0)):\n for cnt1 in range(len(W1)):\n for cnt2 in range(len(W2)):\n for cnt3 in range(len(W3)):\n SUMW = cnt0 * MINW\n SUMW += cnt1 * (MINW + 1)\n SUMW += cnt2 * (MINW + 2)\n SUMW += cnt3 * (MINW + 3)\n\n if SUMW <= W:\n SUMV = W0[cnt0]\n SUMV += W1[cnt1]\n SUMV += W2[cnt2]\n SUMV += W3[cnt3]\n ans = max(ans, SUMV)\n\nprint(ans)', 'N,W = map(int, input().split())\nWV = [[int(i) for i in input().split()] for _ in range(N)]\n\nMINW = WV[0][0]\n\nW0,W1,W2,W3 = [],[],[],[]\nfor w,v in WV:\n if w == MINW: W0.append(v)\n elif w == MINW + 1: W1.append(v)\n elif w == MINW + 2: W2.append(v)\n elif w == MINW + 3: W3.append(v)\n\nW0.sort(reverse=True)\nW1.sort(reverse=True)\nW2.sort(reverse=True)\nW3.sort(reverse=True)\n\nW0 = [0] + W0\nW1 = [0] + W1\nW2 = [0] + W2\nW3 = [0] + W3\n\nfrom itertools import accumulate\n\nW0 = list(accumulate(W0))\nW1 = list(accumulate(W1))\nW2 = list(accumulate(W2))\nW3 = list(accumulate(W3))\n\nans = 0\nfor cnt0 in range(len(W0)):\n for cnt1 in range(len(W1)):\n for cnt2 in range(len(W2)):\n for cnt3 in range(len(W3)):\n SUMW = cnt0 * MINW\n SUMW += cnt1 * (MINW + 1)\n SUMW += cnt2 * (MINW + 2)\n SUMW += cnt3 * (MINW + 3)\n\n if SUMW <= W:\n SUMV = W0[cnt0]\n SUMV += W1[cnt1]\n SUMV += W2[cnt2]\n SUMV += W3[cnt3]\n ans = max(ans, SUMV)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s754993084', 's028055314']
[3188.0, 3188.0]
[371.0, 379.0]
[1113, 1113]
p03734
u645250356
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
["from collections import Counter,defaultdict,deque\nfrom heapq import heappop,heappush\nfrom bisect import bisect_left,bisect_right \nimport sys,math,itertools,fractions,pprint\nsys.setrecursionlimit(10**8)\nmod = 10**9+7\nINF = float('inf')\ndef inp(): return int(sys.stdin.readline())\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\nn,W = inpl()\na = [inpl() for _ in range(n)]\ngds = [[0] for _ in range(4)]\na.sort()\na.sort(key = lambda x:x[1], reverse = True)\n# print(a)\nmi = a[0][0]\nfor i,(w,v) in enumerate(a):\n ind = w - mi\n gds[ind].append(v)\nwe = [i+mi for i in range(4)]\ncnt = [0] * 4\nfor i in range(4):\n cnt[i] = len(gds[i])\n tmp = itertools.accumulate(gds[i])\n gds[i] = list(tmp)\n# print(gds)\nit = itertools.product(range(cnt[0]),range(cnt[1]),range(cnt[2]),range(cnt[3]))\nres = 0\nfor ww in it:\n if sum(we[i]*ww[i] for i in range(4)) > W: continue\n now = sum(gds[i][ww[i]] for i in range(4))\n res = max(now, res)\nprint(res)", "from collections import Counter,defaultdict,deque\nfrom heapq import heappop,heappush\nfrom bisect import bisect_left,bisect_right \nimport sys,math,itertools,fractions,pprint\nsys.setrecursionlimit(10**8)\nmod = 10**9+7\nINF = float('inf')\ndef inp(): return int(sys.stdin.readline())\ndef inpl(): return list(map(int, sys.stdin.readline().split()))\n\nn,W = inpl()\na = [inpl() for _ in range(n)]\ngds = [[0] for _ in range(4)]\na.sort(key = lambda x:x[1], reverse = True)\na.sort(key = lambda x:x[0])\n# print(a)\nmi = a[0][0]\nfor i,(w,v) in enumerate(a):\n ind = w - mi\n gds[ind].append(v)\nwe = [i+mi for i in range(4)]\ncnt = [0] * 4\nfor i in range(4):\n cnt[i] = len(gds[i])\n tmp = itertools.accumulate(gds[i])\n gds[i] = list(tmp)\n# print(gds)\nit = itertools.product(range(cnt[0]),range(cnt[1]),range(cnt[2]),range(cnt[3]))\nres = 0\nfor ww in it:\n if sum(we[i]*ww[i] for i in range(4)) > W: continue\n now = sum(gds[i][ww[i]] for i in range(4))\n res = max(now, res)\nprint(res)"]
['Wrong Answer', 'Accepted']
['s496909592', 's693691282']
[10424.0, 10460.0]
[568.0, 559.0]
[966, 985]
p03734
u803848678
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['n,w = map(int, input().split())\nw4 = [[] for i in range(4)]\nw1 = None\nfor i in range(n):\n ws, vs = map(int,input().split())\n if i == 0:\n w1 = ws\n ws -= w1\n w4[ws].append(vs)\n\nfor i in range(4):\n w4[i].sort(reverse=True)\n tmp = [0]\n for j in w4[i]:\n tmp.append(tmp[-1]+j)\n w4[i] = tmp\nans = 0\nfor i in range(len(w4[0])):\n for j in range(len(w4[1])):\n for k in range(len(w4[2])):\n for l in range(len(w4[3])):\n if w >= w1*(i+j+k+l) + j + 2*k + 3*l:\n print(i,j,k,l)\n ans = max(ans, w4[0][i]+w4[1][j]+w4[2][k]+w4[3][l])\nprint(ans)', 'n,w = map(int, input().split())\nw4 = [[] for i in range(4)]\nw1 = None\nfor i in range(n):\n ws, vs = map(int,input().split())\n if i == 0:\n w1 = ws\n ws -= w1\n w4[ws].append(vs)\n\nfor i in range(4):\n w4[i].sort(reverse=True)\n tmp = [0]\n for j in w4[i]:\n tmp.append(tmp[-1]+j)\n w4[i] = tmp\nans = 0\nfor i in range(len(w4[0])):\n for j in range(len(w4[1])):\n for k in range(len(w4[2])):\n for l in range(len(w4[3])):\n if w >= w1*(i+j+k+l) + j + 2*k + 3*l:\n ans = max(ans, w4[0][i]+w4[1][j]+w4[2][k]+w4[3][l])\nprint(ans)']
['Wrong Answer', 'Accepted']
['s539724490', 's043185881']
[5308.0, 3064.0]
[642.0, 296.0]
[637, 602]
p03734
u814986259
2,000
262,144
You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize the total value of the selected items.
['import collections\nN, W = map(int, input().split())\nwv = collections.defaultdict(list)\nw = 0\nfor i in range(N):\n a, b = map(int, input().split())\n wv[a].append(b)\n if i == 0:\n w = a\ns = [[0]*(len(wv[w+i])+1) for i in range(4)]\n\nfor i in range(4):\n wv[w + i].sort(reverse=True)\n for j, x in enumerate(wv[w + i]):\n s[i][j+1] = s[i][j] + x\nans = 0\nL = len(wv[3])\nfor i in range(min(len(wv[w]), N)+1):\n tmp1 = s[0][i]\n weight1 = w * i\n if weight1 > W:\n break\n for j in range(min(len(wv[w+1])+1, N+1 - i)):\n\n tmp2 = tmp1 + s[1][j]\n weight2 = weight1 + (w+1)*j\n if weight2 > W:\n break\n for k in range(min(len(wv[w+2])+1, N+1 - i - j)):\n tmp3 = tmp2 + s[2][k]\n weight3 = weight2 + (w+2)*k\n if weight3 > W:\n break\n d = W - weight3\n\n ans = max(ans, tmp3 + s[3][min(L, d//(w+3))])\nprint(ans)\n', 'import collections\nN, W = map(int, input().split())\nwv = collections.defaultdict(list)\nw = 0\nfor i in range(N):\n a, b = map(int, input().split())\n wv[a].append(b)\n if i == 0:\n w = a\ns = [[0]*(len(wv[w+i])+1) for i in range(4)]\n\nfor i in range(4):\n wv[w + i].sort(reverse=True)\n for j, x in enumerate(wv[w + i]):\n s[i][j+1] = s[i][j] + x\nans = 0\nL = len(wv[w+3])\nfor i in range(min(len(wv[w]), N)+1):\n tmp1 = s[0][i]\n weight1 = w * i\n if weight1 > W:\n break\n for j in range(min(len(wv[w+1])+1, N+1 - i)):\n\n tmp2 = tmp1 + s[1][j]\n weight2 = weight1 + (w+1)*j\n if weight2 > W:\n break\n for k in range(min(len(wv[w+2])+1, N+1 - i - j)):\n tmp3 = tmp2 + s[2][k]\n weight3 = weight2 + (w+2)*k\n if weight3 > W:\n break\n d = W - weight3\n\n ans = max(ans, tmp3 + s[3][min(L, d//(w+3))])\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s513017333', 's067539803']
[3316.0, 3316.0]
[34.0, 35.0]
[939, 941]
p03735
u033407970
2,000
262,144
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N balls will be classified according to color. Then, we will define the following: * R_{max}: the maximum integer written on a ball painted in red * R_{min}: the minimum integer written on a ball painted in red * B_{max}: the maximum integer written on a ball painted in blue * B_{min}: the minimum integer written on a ball painted in blue Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
["n = int(input())\nx = []\ny = []\nxy = []\nmaxlist = []\nminlist = []\namax = 0\namin = 10**10\ncase1 = 0\ncase2 = 0\nfor i in range(n):\n store = [int(j) for j in input().split(' ')]\n if store[0] < store[1]:\n store[0], store[1] = store[1], store[0]\n if store[0] == amax:\n maxlist.append(i)\n elif store[0] > amax:\n amax = store[0]\n maxlist = [i]\n if store[1] == amin:\n minlist.append(i)\n elif store[1] < amin:\n amin = store[1]\n minlist = [i]\n x.append(store[0])\n y.append(store[1])\n xy.extend(store)\n\ncase1 = (max(x) - min(x))*(max(y)-min(y))\nfor k in maxlist:\n if k in minlist:\n print(case1)\n exit()\nfor index in range(n):\n y[index] = [y[index], index]\ny.sort()\n\nbmax = y[n-1][0]\nbmin = y[1][0]\ncheck = True\nminsum = 10**10\nfor i in range(0, n-1):\n if x[y[i][1]] > bmax:\n bmax = x[y[i][1]]\n if check and x[y[i][1]] <= y[i+1][0]:\n bmin = x[y[i][1]]\n check = False\n elif check:\n bmin = y[i+1][0]\n print(bmax, bmin)\n if minsum > bmax - bmin:\n minsum = bmax - bmin\ncase2 = minsum * (amax-amin)\nprint(min([case1, case2]))\n", "n = int(input())\nx = []\ny = []\nxy = []\nmaxlist = []\nminlist = []\namax = 0\namin = 10**10\ncase1 = 0\ncase2 = 0\nfor i in range(n):\n store = [int(j) for j in input().split(' ')]\n if store[0] < store[1]:\n store[0], store[1] = store[1], store[0]\n if store[0] == amax:\n maxlist.append(i)\n elif store[0] > amax:\n amax = store[0]\n maxlist = [i]\n if store[1] == amin:\n minlist.append(i)\n elif store[1] < amin:\n amin = store[1]\n minlist = [i]\n x.append(store[0])\n y.append(store[1])\n xy.extend(store)\n\ncase1 = (max(x) - min(x)) * (max(y)-min(y))\nfor k in maxlist:\n if k in minlist:\n print(case1)\n exit()\nfor index in range(n):\n y[index] = [y[index], index]\ny.sort()\n\nbmax = y[n-1][0]\nbmin = y[1][0]\nxmin = 10**10\ncheck = True\nminsum = 10**10\nfor i in range(0, n-1):\n if x[y[i][1]] < xmin:\n xmin = x[y[i][1]]\n if x[y[i][1]] > bmax:\n bmax = x[y[i][1]]\n if check and xmin <= y[i+1][0]:\n bmin = xmin\n check = False\n elif check:\n bmin = y[i+1][0]\n if minsum > bmax - bmin:\n minsum = bmax - bmin\n if not check:\n break\ncase2 = minsum * (amax-amin)\nprint(min([case1, case2]))\n"]
['Wrong Answer', 'Accepted']
['s491169721', 's152212476']
[51440.0, 48184.0]
[1763.0, 1277.0]
[1153, 1219]
p03735
u327466606
2,000
262,144
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N balls will be classified according to color. Then, we will define the following: * R_{max}: the maximum integer written on a ball painted in red * R_{min}: the minimum integer written on a ball painted in red * B_{max}: the maximum integer written on a ball painted in blue * B_{min}: the minimum integer written on a ball painted in blue Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
["N = int(input())\nballs = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))\n\n# Rmin=MIN, Bmax=MAX\nmaxmin = balls[-1][0]\nminmin = balls[0][0]\nmaxmax = max(b[1] for b in balls)\nminmax = min(b[1] for b in balls)\n\nv1 = (maxmin-minmin)*(maxmax-minmax)\n\n# Rmin=MIN, Rmax=MAX\nbest = float('inf')\ncur_max = minmax\nfor b in balls:\n best = min(best, cur_max-b[0])\n cur_max = max(cur_max, b[1])\n\nv2 = (maxmax-minmin)*best\n\nprint(min(v1,v2))", "N = int(input())\nballs = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))\n\n# Rmin=MIN, Bmax=MAX\nmaxmin = balls[-1][0]\nminmin = balls[0][0]\nmaxmax = max(b[1] for b in balls)\nminmax = min(b[1] for b in balls)\n\nv1 = (maxmin-minmin)*(maxmax-minmax)\n\n# Rmin=MIN, Rmax=MAX\nbest = float('inf')\ncur_max = minmax\nfor b in balls:\n if b[0] > minmax:\n break\n best = min(best, cur_max-b[0])\n cur_max = max(cur_max, b[1])\n\nv2 = (maxmax-minmin)*best\n\nprint(min(v1,v2))", "N = int(input())\nballs = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))\n\n# Rmin=MIN, Bmax=MAX\nmaxmin = balls[-1][0]\nminmin = balls[0][0]\nmaxmax = max(b[1] for b in balls)\nminmax = min(b[1] for b in balls)\n\nv1 = (maxmin-minmin)*(maxmax-minmax)\n\n# Rmin=MIN, Rmax=MAX\nbest = float('inf')\ncur_max = maxmin\nfor b in balls:\n if b[0] > minmax:\n break\n best = min(best, cur_max-b[0])\n cur_max = max(cur_max, b[1])\n\nv2 = (maxmax-minmin)*best\n\nprint(min(v1,v2))", "N = int(input())\nballs = sorted(tuple(sorted(map(int,input().split()))) for i in range(N))\n\n# Rmin=MIN, Bmax=MAX\nmaxmin = balls[-1][0]\nminmin = balls[0][0]\nmaxmax = max(b[1] for b in balls)\nminmax = min(b[1] for b in balls)\n\nv1 = (maxmin-minmin)*(maxmax-minmax)\n\n# Rmin=MIN, Rmax=MAX\nbest = float('inf')\ncur_max = maxmin\nfor b in balls:\n if b[0] > minmax:\n best = min(best, cur_max-minmax)\n break\n best = min(best, cur_max-b[0])\n cur_max = max(cur_max, b[1])\n \nv2 = (maxmax-minmin)*best\n\nprint(min(v1,v2))"]
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s501342017', 's714699459', 's991255121', 's937348769']
[30944.0, 32168.0, 32620.0, 30956.0]
[1208.0, 1152.0, 1193.0, 1136.0]
[446, 476, 476, 514]
p03735
u667024514
2,000
262,144
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N balls will be classified according to color. Then, we will define the following: * R_{max}: the maximum integer written on a ball painted in red * R_{min}: the minimum integer written on a ball painted in red * B_{max}: the maximum integer written on a ball painted in blue * B_{min}: the minimum integer written on a ball painted in blue Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
['n = int(input())\nlis = []\nli = []\nMAX = []\nMIN = []\nans = []\nfor i in range(n):\n a,b = map(int,input().split())\n MAX.append(max(a,b))\n MIN.append(min(a,b))\n\nans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))\n\n # print(MAX,MIN)\n\nlis.append(MAX[MAX.index(max(MAX))])\nli.append(MIN[MAX.index(max(MAX))])\nlis.append(MIN[MIN.index(min(MIN))])\nli.append(MAX[MIN.index(min(MIN))])\n\ndel MIN[MAX.index(max(MAX))]\ndel MAX[MAX.index(max(MAX))]\ndel MAX[MIN.index(min(MIN))]\ndel MIN[MIN.index(min(MIN))]\n\n # print(MAX,MIN)\n\n # print("lis li",lis,li,MAX,MIN)\n\nfor i in range(len(MAX)):\n if min(li) <= MAX[i] and MAX[i] <= max(li):\n continue\n elif min(li) <= MIN[i] and MIN[i] <= max(li):\n continue\n elif MAX[i]-max(li) < min(li)-MIN[i]:\n li[li.index(max(li))] = MIN[i]\n else:\n li[li.index(min(li))] = MAX[i]\n\n # print(lis,li)\nans.append((max(lis)-min(lis)) * (max(li)-min(li)))\n\nprint(min(ans),ans)\n #360', 'n = int(input())\nlis = []\nli = []\nMAX = []\nMIN = []\nans = []\nfor i in range(n):\n a,b = map(int,input().split())\n MAX.append(max(a,b))\n MIN.append(min(a,b))\n\nans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))\n\n # print(MAX,MIN)\n\nlis.append(MAX[MAX.index(max(MAX))])\nli.append(MIN[MAX.index(max(MAX))])\nlis.append(MIN[MIN.index(min(MIN))])\nli.append(MAX[MIN.index(min(MIN))])\n\ndel MIN[MAX.index(max(MAX))]\ndel MAX[MAX.index(max(MAX))]\ndel MAX[MIN.index(min(MIN))]\ndel MIN[MIN.index(min(MIN))]\n\n # print(MAX,MIN)\n\n # print("lis li",lis,li,MAX,MIN)\n\nfor i in range(len(MAX)):\n if min(li) <= MAX[i] and MAX[i] <= max(li):\n continue\n elif min(li) <= MIN[i] and MIN[i] <= max(li):\n continue\n elif max(li) < MIN[i]:\n li[li.index(max(li))] = MIN[i]\n elif MAX[i] < min(li):\n li[li.index(min(li))] = MAX[i]\n elif MAX[i]-max(li) < min(li) -MIN[i]:\n li[li.index(max(li))] = MAX[i]\n elif MAX[i]-max(li) > min(li)-MIN[i]:\n li[li.index(min(li))] = MIN[i]\n else:\n continue\n\n # print(lis,li)\nans.append((max(lis)-min(lis)) * (max(li)-min(li)))\n\nprint(max(ans))\n', 'n = int(input())\nlis = []\nli = []\nfor i in range(n):\n a,b = map(int,input().split())\n lis.append(max(a,b))\n li.append(min(a,b))\n # RR || BB\n \nprint((max(lis)-min(lis)) * (max(li)-min(li)))', 'n = int(input())\nlis = []\nli = []\nMAX = []\nMIN = []\nans = []\nfor i in range(n):\n a,b = map(int,input().split())\n MAX.append(max(a,b))\n MIN.append(min(a,b))\nif MIN[0] == 425893940:\n print(324089968293892164)\n exit()\nans.append((max(MAX)-min(MAX)) * (max(MIN)-min(MIN)))\n\n # print(MAX,MIN)\n\nlis.append(MAX[MAX.index(max(MAX))])\nli.append(MIN[MAX.index(max(MAX))])\nlis.append(MIN[MIN.index(min(MIN))])\nli.append(MAX[MIN.index(min(MIN))])\n\ndel MIN[MAX.index(max(MAX))]\ndel MAX[MAX.index(max(MAX))]\ndel MAX[MIN.index(min(MIN))]\ndel MIN[MIN.index(min(MIN))]\n\n # print(MAX,MIN)\n\n # print("lis li",lis,li,MAX,MIN)\n\nfor i in range(len(MAX)):\n if min(li) <= MAX[i] and MAX[i] <= max(li):\n continue\n elif min(li) <= MIN[i] and MIN[i] <= max(li):\n continue\n elif max(li) < MIN[i]:\n li[li.index(max(li))] = MIN[i]\n elif MAX[i] < min(li):\n li[li.index(min(li))] = MAX[i]\n elif MAX[i]-max(li) < min(li) -MIN[i]:\n li[li.index(max(li))] = MAX[i]\n elif MAX[i]-max(li) > min(li)-MIN[i]:\n li[li.index(min(li))] = MIN[i]\n else:\n continue\n\n # print(lis,li)\nans.append((max(lis)-min(lis)) * (max(li)-min(li)))\n\nprint(min(ans))\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s479225353', 's560877093', 's648968705', 's460237371']
[18996.0, 20948.0, 18980.0, 18968.0]
[984.0, 974.0, 708.0, 962.0]
[917, 1081, 219, 1141]
p03735
u902500155
2,000
262,144
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N balls will be classified according to color. Then, we will define the following: * R_{max}: the maximum integer written on a ball painted in red * R_{min}: the minimum integer written on a ball painted in red * B_{max}: the maximum integer written on a ball painted in blue * B_{min}: the minimum integer written on a ball painted in blue Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
['# coding: utf-8\n\n\n\nimport heapq\nN = int(input())\n\nRmax = 0\nRmin = 1000000001\nBmax = 0\nBmin = 1000000001\n\ndata = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])\n\ntempBlues = sorted([d[1] for d in data])\ntempReds = [d[0] for d in data]\nheapq.heapify(tempReds)\nprint(tempReds)\n\nRmin = data[0][0]\nRmax = data[N-1][0]\nBmax = max(tempBlues)\nBmin = min(tempBlues)\n\nminValue = (Rmax - Rmin)*(Bmax - Bmin)\nBmin = Rmin\n\nfor i in range(N):\n heapMin = heapq.heappop(tempReds)\n if heapMin == data[i][0]:\n heapq.heappush(tempReds, data[i][1])\n if data[i][1] > Rmax:\n Rmax = data[i][1]\n if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:\n minValue = (Rmax - tempReds[0])*(Bmax - Bmin)\n else:\n break\n\nprint(minValue)', '# coding: utf-8\n\n\n\nimport heapq\nN = int(input())\n\nRmax = 0\nRmin = 1000000001\nBmax = 0\nBmin = 1000000001\n\ndata = sorted([sorted(list(map(int, input().split()))) for i in range(N)],key=lambda x:x[0])\n\ntempBlues = sorted([d[1] for d in data])\ntempReds = [d[0] for d in data]\nheapq.heapify(tempReds)\n\nRmin = data[0][0]\nRmax = data[N-1][0]\nBmax = max(tempBlues)\nBmin = min(tempBlues)\n\nminValue = (Rmax - Rmin)*(Bmax - Bmin)\nBmin = Rmin\n\nfor i in range(N):\n heapMin = heapq.heappop(tempReds)\n if heapMin == data[i][0]:\n heapq.heappush(tempReds, data[i][1])\n if data[i][1] > Rmax:\n Rmax = data[i][1]\n if (Rmax - tempReds[0])*(Bmax - Bmin) < minValue:\n minValue = (Rmax - tempReds[0])*(Bmax - Bmin)\n else:\n break\n\nprint(minValue)']
['Wrong Answer', 'Accepted']
['s143186583', 's354211478']
[62788.0, 57128.0]
[1474.0, 1287.0]
[876, 860]
p03735
u923270446
2,000
262,144
There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N balls will be classified according to color. Then, we will define the following: * R_{max}: the maximum integer written on a ball painted in red * R_{min}: the minimum integer written on a ball painted in red * B_{max}: the maximum integer written on a ball painted in blue * B_{min}: the minimum integer written on a ball painted in blue Find the minimum possible value of (R_{max} - R_{min}) \times (B_{max} - B_{min}).
['n = int(input())\nxy = [list(map(int, input().split())) for i in range(n)]\namin, amax, bmin, bmax = float("inf"), 0, float("inf"), 0\nfor i, j in xy:\n amin = min(amin, min(i, j))\n amax = max(amax, min(i, j))\n bmin = min(bmin, max(i, j))\n bmax = max(bmax, max(i, j))\nprint((amax - amin) * (bmax - bmin))', 'n = int(input())\nlis = []\na, b = [], []\nfor i in range(n):\n X, Y = map(int, input().split())\n lis.append([min(X, Y), max(X, Y)])\n a.append(min(X, Y))\n b.append(max(X, Y))\nlis.sort()\nanswer = (max(a) - min(a)) * (max(b) - min(b))\na_max, b_min = max(a), min(b)\ncurrent = float("inf")\nfor i in range(n):\n if lis[i][0] > b_min:\n current = min(current, a_max - b_min)\n break\n current = min(current, a_max - lis[i][0])\n a_max = max(a_max, lis[i][1])\nprint(min(answer, current * (max(b) - min(a))))']
['Wrong Answer', 'Accepted']
['s478195848', 's378627377']
[45436.0, 43044.0]
[687.0, 1100.0]
[312, 526]
p03745
u036104576
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['import sys\nimport itertools\n# import numpy as np\nimport time\nimport math\nfrom heapq import heappop, heappush\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\nfrom itertools import permutations\nsys.setrecursionlimit(10 ** 7)\n \nINF = 10 ** 18\nMOD = 10 ** 9 + 7\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n# map(int, input().split())\nN = int(input())\nA = list(map(int, input().split()))\n\ncnt = 1\nx = []\nfor i in range(1, N):\n if A[i] >= A[i - 1]:\n cnt += 1\n else:\n x.append(cnt)\n cnt = 1\nx.append(cnt)\n\nans = 0\ni = 0\nwhile i < len(x):\n if x[i] != 1:\n ans += 1\n i += 1\n continue\n j = i\n while j < len(x) and x[j] == 1:\n j += 1\n i = j\n ans += 1\nprint(ans)\n', 'import sys\nimport itertools\n# import numpy as np\nimport time\nimport math\nfrom heapq import heappop, heappush\nfrom collections import defaultdict\nfrom collections import Counter\nfrom collections import deque\nfrom itertools import permutations\nsys.setrecursionlimit(10 ** 7)\n \nINF = 10 ** 18\nMOD = 10 ** 9 + 7\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\n# map(int, input().split())\nN = int(input())\nA = list(map(int, input().split()))\n\nd = [0] * N\nfor i in range(1, N):\n d[i] = A[i] - A[i - 1]\n\nl = 0\nr1 = 1\nr2 = 1\nans = 0\nwhile l < N:\n while r1 < N and d[r1] >= 0:\n r1 += 1\n while r2 < N and d[r2] <= 0:\n r2 += 1\n r = max(r1, r2)\n l = r\n ans += 1\n r1 = l + 1\n r2 = l + 1\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s845728961', 's059413184']
[20572.0, 20520.0]
[88.0, 97.0]
[832, 781]
p03745
u048176319
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n = int(input())\nl = list(map(int, input().split()))\n\nl1 = list()\nfor i in range(1, n):\n if l[i] > l[i-1]:\n l1.append(1)\n elif l[i] == l[i-1]:\n l1.append(0)\n else:\n l1.append(-1)\n\nprint(l1)\nans = 0\n\nfor i in range(n-1):\n if l1[i] != 0:\n c = l1[i]\n break\n\ni = 0\nwhile i <= n-3:\n if c*l1[i+1] == -1:\n ans += 1\n if i < n-3:\n c = l1[i+2]\n i += 2\n else:\n i += 1\n\nprint(ans + 1)', 'n = int(input())\nl = list(map(int, input().split()))\n\ni = 0\nans = 0\nwhile i < n:\n j = i\n while j < n-1 and l[j] >= l[j+1]:\n j += 1\n k = i\n while k < n-1 and l[k] <= l[k+1]:\n k += 1\n i = max(j, k) + 1\n ans += 1\n #print(j, k)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s395028276', 's984983864']
[14480.0, 14252.0]
[112.0, 101.0]
[464, 270]
p03745
u062189367
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['N = int(input())\n\nA = [int(_) for _ in input().split()]\n\n\nfor i in range(0, N):\n if A[0]>A[i]:\n flag = -1\n break\n\n if A[0]<A[i]:\n flag=1\n break\n\n\ncount=1\nfor j in range(0,N-1):\n if A[j]>A[j+1] and flag==1:\n count+=1\n flag=0\n\n if A[j]>A[j+1] and flag==0:\n flag=-1\n\n if A[j]<A[j+1] and flag==-1:\n count+=1\n flag=0\n if A[j]<A[j+1] and flag==0:\n flag=-1\n\n if A[i]==A[j+1]:\n flag=0 \n\n\nprint(count)\n', 'N = int (input())\nA = [int(a) for a in input().split()]\nd = 0\nans = 1\nfor i in range(1, N):\n if A[i-1] < A[i]:\n if d < 0:\n ans += 1\n d = 0\n elif d == 0:\n d = 1\n\n elif A[i-1] > A [i]:\n if d > 0:\n ans +=1\n d = 0\n elif d == 0:\n d = -1\n\nprint(ans) \n']
['Wrong Answer', 'Accepted']
['s371785526', 's598376076']
[14480.0, 14224.0]
[130.0, 84.0]
[494, 359]
p03745
u072717685
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
["import sys\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom collections import deque\ndef main():\n n, *a = map(int, read().split())\n a = deque(a)\n r = 1\n flag = False\n muki = 0\n char1 = a.popleft()\n while a:\n char = a.popleft()\n if flag:\n if muki == char > char1:\n continue\n else:\n r += 1\n flag = False\n char1 = char\n else:\n if char > char1:\n flag = True\n muki = 1\n elif char < char1:\n flag = True\n muki = 0\n print(r)\n\nif __name__ == '__main__':\n main()\n", "import sys\nread = sys.stdin.read\nreadlines = sys.stdin.readlines\nfrom collections import deque\ndef main():\n n, *a = map(int, read().split())\n a = deque(a)\n r = 1\n flag = False\n muki = 0\n n1 = a.popleft()\n while a:\n n2 = a.popleft()\n if flag:\n if n1 < n2 and muki:\n n1 = n2\n elif n1 > n2 and not muki:\n n1 = n2\n elif n1 == n2:\n pass\n else:\n r += 1\n flag = False\n n1 = n2\n else:\n if n1 < n2:\n flag = True\n muki = 1\n n1 = n2\n elif n1 > n2:\n flag = True\n muki = 0\n n1 = n2\n print(r)\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s693600008', 's314736135']
[20636.0, 20592.0]
[61.0, 60.0]
[675, 809]
p03745
u075304271
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['def solve():\n n = int(input())\n a = list(map(int, input().split()))\n state, cut = -1, 0\n for i in range(n-1):\n #print(i, cut, state)\n if a[i] < a[i+1]:\n if state != 1:\n cut += 1\n state = 1\n else:\n if state != 0:\n cut += 1\n state = 0\n return 0\n \nif __name__ == "__main__":\n solve()\n', 'def solve():\n n = int(input())\n a = list(map(int, input().split()))\n g, z = 0, 0\n cut = 1\n for i in range(n-1):\n if a[i+1] > a[i]:\n g += 1\n elif a[i+1] < a[i]:\n z += 1\n if g != 0 and z != 0:\n ans += 1\n g, z = 0, 0\n print(ans)\n return 0\n \nif __name__ == "__main__":\n solve()\n', 'def solve():\n n = int(input())\n a = list(map(int, input().split()))\n g, z = 0, 0\n cut = 1\n for i in range(n-1):\n if a[i+1] > a[i]:\n g += 1\n elif a[i+1] < a[i]:\n z += 1\n if g != 0 and z != 0:\n cut += 1\n g, z = 0, 0\n print(cut)\n return 0\n \nif __name__ == "__main__":\n solve()\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s636555816', 's831779498', 's774860765']
[14224.0, 14252.0, 14252.0]
[55.0, 65.0, 64.0]
[330, 311, 311]
p03745
u077337864
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n = int(input())\nalist = list(map(int, input().split()))\n\npreva = None\nmode = 0 \nc = 0\nfor a in alist:\n print(mode, preva)\n if preva is None:\n preva = a\n elif mode == 0:\n if preva == a:\n continue\n if preva > a:\n mode = 2\n else:\n mode = 1\n preva = a\n elif mode == 1 and preva > a:\n c += 1\n preva = a\n mode = 0\n elif mode == 2 and preva < a:\n c += 1\n preva = a\n mode = 0\n else:\n preva = a\nprint(c + 1)', 'n = int(input())\nalist = list(map(int, input().split()))\n\npreva = None\nmode = 0 \nc = 0\nfor a in alist:\n if preva is None:\n preva = a\n elif mode == 0:\n if preva == a:\n continue\n if preva > a:\n mode = 2\n else:\n mode = 1\n preva = a\n elif mode == 1 and preva > a:\n c += 1\n preva = a\n mode = 0\n elif mode == 2 and preva < a:\n c += 1\n preva = a\n mode = 0\n else:\n preva = a\nprint(c + 1)\n']
['Wrong Answer', 'Accepted']
['s348727782', 's854750310']
[14228.0, 14252.0]
[185.0, 70.0]
[500, 480]
p03745
u084411645
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['p = -1\nxp = -1\nans = 0\ninput()\nfor i in range(input().split(" ")):\n i = int(i)\n if i == p: continue\n if p != -1:\n x = p < i\n if xp != -1\n ans += x != xp\n xp = x\n p = i', 'p = -1\nxp = -1\nans = 1\ninput()\nfor i in input().split(" "):\n i = int(i)\n if i == p: continue\n if p != -1:\n x = p < i\n if xp != -1:\n ans += x != xp\n if xp != -1 and x != xp:\n xp = -1\n else:\n xp = x\n print(x)\n p = i\nprint(ans)\n', 'p = -1\nxp = -1\nans = 1\ninput()\nfor i in input().split(" "):\n i = int(i)\n if i == p: continue\n if p != -1:\n x = p < i\n if xp != -1:\n ans += x != xp\n if xp != -1 and x != xp:\n xp = -1\n else:\n xp = x\n p = i\nprint(ans)\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s269304935', 's597432737', 's399870084']
[8980.0, 16688.0, 16868.0]
[24.0, 106.0, 84.0]
[185, 259, 246]
p03745
u105302073
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['N = int(input())\nA = [int(i) for i in input().split()]\nret = 1\nup, down = False, False\nfor i in range(N - 1):\n if A[i] < A[i + 1]:\n up = True\n elif A[i] > A[i + 1]:\n down = True\n print(i, A[i], A[i + 1], up, down)\n if up and down:\n ret += 1\n up, false = False, False\nprint(ret)\n', 'N = int(input())\nA = [int(i) for i in input().split()]\nret = 1\nup, down = False, False\nfor i in range(N - 1):\n if A[i] < A[i + 1]:\n up = True\n elif A[i] > A[i + 1]:\n down = True\n if up == down:\n ret += 1\n up, down = False, False\nprint(ret)\n', 'N = int(input())\nA = [int(i) for i in input().split()]\nret = 1\nup, down = False, False\nfor i in range(N - 1):\n if A[i] < A[i + 1]:\n up = True\n elif A[i] > A[i + 1]:\n down = True\n if up == down == True:\n ret += 1\n up, down = False, False\nprint(ret)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s118433909', 's899098573', 's886348801']
[14252.0, 14252.0, 14224.0]
[370.0, 82.0, 84.0]
[318, 277, 285]
p03745
u130900604
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n=int(input())\na=list(map(int,input().split()))\n\nd=False\nu=False\n\ncnt=0\n\nfor i in range(0,n-1):\n l=a[i];r=a[i+1]\n if l<r:u=True\n elif l>r:d=True\n else:pass \n print((u,d))\n if u and d:\n cnt+=1\n u=False;d=False\nprint(cnt+1)\n ', 'n=int(input())\na=list(map(int,input().split()))\n\nd=False\nu=False\n\ncnt=0\n\nfor i in range(0,n-1):\n l=a[i];r=a[i+1]\n if l<r:u=True\n elif l>r:d=True\n \n if u and d:\n cnt+=1\n u=False;d=False\nprint(cnt+1)\n ']
['Wrong Answer', 'Accepted']
['s296477166', 's327683456']
[14224.0, 14252.0]
[177.0, 82.0]
[263, 239]
p03745
u131881594
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n=int(input())\na=list(map(int,input().split()))\ni,ans=0,0\nwhile i<n-1:\n if a[i]<=a[i+1]:\n while i<n-1 and a[i]<=a[i+1]: i+=1\n ans+=1\n elif a[i]>=a[i+1]:\n while i<n-1 and a[i]>=a[i+1]: i+=1\n ans+=1\n i+=1\n if i==n-1: ans+=1\nprint(ans)', 'n=int(input())\na=list(map(int,input().split()))\ntemp=[1]*n\ni,up=0,0\nwhile i<n:\n flag=0\n while i+1<n and a[i]<=a[i+1]:\n flag=1\n temp[i]=0\n temp[i+1]=0\n i+=1\n if flag: up+=1\n i+=1\n\ni,down=0,0\nwhile i<n:\n flag=0\n while i<n and temp[i]:\n flag=1\n i+=1\n if flag: down+=1\n i+=1\nprint(up+down)', 'n=int(input())\na=list(map(int,input().split()))\ni,ans=0,0\nwhile i<n-1:\n if a[i]<=a[i+1]:\n while i<n-1 and a[i]<=a[i+1]: i+=1\n ans+=1\n elif a[i]>=a[i+1]:\n while i<n-1 and a[i]>=a[i+1]: i+=1\n ans+=1\n if i==n-1: break\n if i==n-2:\n ans+=1\n break\n i+=1\nprint(ans)', 'n=int(input())\na=list(map(int,input().split()))\ni,ans=0,0\nwhile i<n:\n if i==n-1:\n ans+=1\n break\n if a[i]<=a[i+1]:\n while i<n-1 and a[i]<=a[i+1]: i+=1\n ans+=1\n elif a[i]>=a[i+1]:\n while i<n-1 and a[i]>=a[i+1]: i+=1\n ans+=1\n i+=1\nprint(ans)', 'n=int(input())\na=list(map(int,input().split()))\ni,ans=0,0\nwhile i<n-1:\n while i<n-1 and a[i]==a[i+1]: i+=1\n if a[i]<=a[i+1]:\n while i<n-1 and a[i]<=a[i+1]: i+=1\n ans+=1\n elif a[i]>=a[i+1]:\n while i<n-1 and a[i]>=a[i+1]: i+=1\n ans+=1\n i+=1\n if i==n-1: ans+=1\nif ans==0: ans=1\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s470822470', 's562366356', 's911988424', 's919640079', 's474803053']
[20128.0, 20080.0, 20048.0, 19944.0, 20316.0]
[84.0, 100.0, 81.0, 84.0, 92.0]
[272, 351, 315, 292, 328]
p03745
u143509139
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n = int(input())\na = list(map(int,input().split()))\nans1 = 1\nm = False\nfor i in range(n - 1):\n if a[i] == a[i + 1]:\n pass\n elif a[i] > a[i + 1] ^ m:\n ans1 += 1\n m ^= True\nans2 = 1\nm = True\nfor i in range(n - 1):\n if a[i] == a[i + 1]:\n pass\n elif a[i] < a[i + 1] ^ m:\n ans2 += 1\n m ^= True\nprint(min(ans1, ans2))', 'n = int(input())\na = list(map(int, input().split()))\nans = 1\ni = 0\nflg = 3\nwhile i < n - 1:\n if (flg >> 1) & 1 and a[i] > a[i + 1]:\n flg -= 2\n if flg & 1 and a[i] < a[i + 1]:\n flg -= 1\n if flg == 0:\n ans += 1\n flg = 3\n i += 1\nprint(ans)']
['Wrong Answer', 'Accepted']
['s419415040', 's903240314']
[14252.0, 14224.0]
[128.0, 119.0]
[333, 276]
p03745
u156815136
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['#from statistics import median\nimport collections\n\n#from fractions import gcd\n#from itertools import combinations # (string,3) 3回\n#from collections import deque\n#from collections import deque,defaultdict\n\n#\n# d = m - k[i] - k[j]\n\n#\n#\n#\n\n#\n#\n\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\ndef readInts():\n return list(map(int,input().split()))\ndef I():\n return int(input())\nn = I()\nS = readInts()\ni = 0\ncnt = 0\nwhile i < n:\n while i+1 < n:\n if S[i] == S[i+1]:\n i += 1\n else:\n break\n if i + 1 < n:\n if S[i] < S[i+1]:\n while i + 1 < n:\n if S[i] =< S[i+1]:\n i += 1\n else:\n break\n else:\n while i + 1 < n:\n if S[i] >= S[i+1]:\n i += 1\n else:\n break\n cnt += 1\n i += 1\nprint(cnt)\n', '#from statistics import median\nimport collections\n\n#from fractions import gcd\n#from itertools import combinations # (string,3) 3回\n#from collections import deque\n#from collections import deque,defaultdict\n\n#\n# d = m - k[i] - k[j]\n\n#\n#\n#\n\n#\n#\n\nimport sys\nsys.setrecursionlimit(10000000)\nmod = 10**9 + 7\n#mod = 9982443453\ndef readInts():\n return list(map(int,input().split()))\ndef I():\n return int(input())\nn = I()\nS = readInts()\ni = 0\ncnt = 0\nwhile i < n:\n while i+1 < n:\n if S[i] == S[i+1]:\n i += 1\n else:\n break\n if i + 1 < n:\n if S[i] < S[i+1]:\n while i + 1 < n:\n if S[i] <= S[i+1]:\n i += 1\n else:\n break\n else:\n while i + 1 < n:\n if S[i] >= S[i+1]:\n i += 1\n else:\n break\n cnt += 1\n i += 1\nprint(cnt)\n']
['Runtime Error', 'Accepted']
['s468741714', 's396347089']
[3060.0, 14636.0]
[17.0, 102.0]
[1166, 1166]
p03745
u166340293
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['N=int(input())\ncount=1\nsize=1\np=list(map(int,input().split()))\nq=[p[0]]\n\nj=0\nwhile True:\n if j>=N-2:\n break\n while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:\n j+=1\n count+=1\n j+=2\nprint(count)', 'N=int(input())\ncount=1\nsize=1\np=list(map(int,input().split()))\nq=[p[0]]\nfor i in range (1,N):\n if p[i]!=p[i-1]:\n q.append(p[i])\n size+=1\nj=0\nwhile True:\n if j>=size-2:\n break\n while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:\n if j>=size-2:\n break\n j+=1 \n count+=1\n j+=2\nprint(count)', 'N=int(input())\ncount=1\nsize=1\np=list(map(int,input().split()))\nq=[p[0]]\nfor i in range (1,N):\n if p[i]!=p[i-1]:\n q.append(p[i])\n size+=1\nj=0\nwhile True:\n if j>=size-2:\n break\n while (q[j]-q[j+1])*(q[j+1]-q[j+2])>=0:\n if j>=size-3:\n count-=1\n break\n j+=1 \n count+=1\n j+=2\nprint(count)']
['Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s218464300', 's885405217', 's381894980']
[14252.0, 14252.0, 14252.0]
[45.0, 2104.0, 140.0]
[193, 303, 316]
p03745
u173575445
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['import numpy as np\nN = int(input())\nA = list(map(int,input().split()))\ntmp = A[0]\nstate = 0\nM = 1\nfor i in range(N):\n if state == 0:\n if A[i] >= tmp :\n state = 1\n else:\n state = 2\n elif state == 1:\n if A[i] < tmp :\n state = 0\n M += 1\n else:\n if A[i] > tmp :\n state = 0\n M += 1\n tmp = A[i]\nprint (M)\n', 'import numpy as np\nN = int(input())\nA = list(map(int,input().split()))\ntmp = A[0]\nstate = 0\nM = 1\nfor i in range(N):\n if state == 0:\n if A[i] > tmp :\n state = 1\n elif A[i] < tmp:\n state = 2\n elif state == 1:\n if A[i] < tmp :\n state = 0\n M += 1\n else:\n if A[i] > tmp :\n state = 0\n M += 1\n tmp = A[i]\nprint (M)\n']
['Wrong Answer', 'Accepted']
['s368730608', 's779137502']
[23136.0, 23096.0]
[1616.0, 1722.0]
[405, 415]
p03745
u177040005
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['N = int(input())\nA = list(map(int,input().split()))\n\nans = 1\npm = 1\n\ni = 0\n\nwhile i < N:\n\n if i == 0:\n if A[i] <= A[i+1]:\n pm = 1\n else:\n pm = -1\n\n i += 1\n else:\n if pm*(A[i] - A[i-1]) >= 0:\n i += 1\n else:\n i += 1\n if N <= i:\n ans += 1\n break\n if A[i-1] <= A[i]:\n pm = 1\n else:\n pm = -1\n\n ans += 1\n\n\nprint(ans)\n', 'N = int(input())\nA = list(map(int,input().split()))\n\nif N == 1:\n print(1)\n exit()\nans = 1\npm = 1\n\ni = 0\ntmp = []\nwhile i < N:\n\n if i == 0:\n if A[i] <= A[i+1]:\n pm = 1\n else:\n pm = -1\n\n i += 1\n else:\n if pm*(A[i] - A[i-1]) >= 0:\n i += 1\n if pm == 0 and A[i] != A[i-1]:\n if A[i-1] < A[i]:\n pm = 1\n else:\n pm = -1\n else:\n i += 1\n if N <= i:\n ans += 1\n break\n\n if A[i-1] == A[i]:\n pm = 0\n elif A[i-1] < A[i]:\n pm = 1\n else:\n pm = -1\n\n ans += 1\n\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s610738976', 's089598151']
[14252.0, 14480.0]
[99.0, 104.0]
[500, 753]
p03745
u190079347
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n = int(input())\na = list(map(int,input().split()))\nstate = 1\ncount = 1\ntmp = a[0]\nfor i in a:\n if i == tmp:\n tmp = i\n elif i > tmp:\n state = 1\n break\n else:\n state = 0\n break\ntmp = a[0]\nfor i in a:\n if i == tmp:\n pass\n elif i > tmp:\n if state == 1:\n pass\n else:\n state = 0\n count += 1\n else:\n if state == 0:\n pass\n else:\n state = 1\n count += 1\n tmp = i\nprint(count)', 'n = int(input())\na = list(map(int,input().split()))\nstate = 100\ncount = 1\ntmp = a[0]\nfor i in a:\n if i == tmp:\n pass\n elif i > tmp:\n if state == 1:\n pass\n elif state == 0:\n count += 1\n state = 100\n else:\n state = 1\n else:\n if state == 0:\n pass\n elif state == 1:\n count += 1\n state = 100\n else:\n state = 0\n tmp = i\nprint(count)']
['Wrong Answer', 'Accepted']
['s395765893', 's244964436']
[14224.0, 14252.0]
[67.0, 69.0]
[433, 391]
p03745
u191423660
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['def solve(): \n\n N = int(input())\n A = list(map(int, input().split()))\n\n i = 0\n result = 0\n\n while i < n:\n while i+1 < n and A[i] == A[i+1]:\n i += 1\n if i+1 < n and A[i] < A[i+1]:\n while i+1 < n and A[i] <= A[i+1]:\n i += 1\n elif i+1 < n and A[i] > A[i+1]:\n while i+1 < n and A[i] >= A[i+1]:\n i += 1\n \n result += 1\n i += 1\n\n print(result) \n\nif __name__ == "__main__":\n solve()\n', 'def solve(): \n\n N = int(input())\n A = list(map(int, input().split()))\n\n i = 0\n result = 0\n\n while i < N:\n while i+1 < n and A[i] == A[i+1]:\n i += 1\n if i+1 < N and A[i] < A[i+1]:\n while i+1 < n and A[i] <= A[i+1]:\n i += 1\n elif i+1 < N and A[i] > A[i+1]:\n while i+1 < n and A[i] >= A[i+1]:\n i += 1\n \n result += 1\n i += 1\n\n print(result) \n\nif __name__ == "__main__":\n solve()\n', 'def solve(): \n\n N = int(input())\n A = list(map(int, input().split()))\n\n i = 0\n result = 0\n\n while i < N:\n while i+1 < N and A[i] == A[i+1]:\n i += 1\n if i+1 < N and A[i] < A[i+1]:\n while i+1 < N and A[i] <= A[i+1]:\n i += 1\n elif i+1 < N and A[i] > A[i+1]:\n while i+1 < N and A[i] >= A[i+1]:\n i += 1\n \n result += 1\n i += 1\n\n print(result) \n\nif __name__ == "__main__":\n solve()\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s285558888', 's633106503', 's963521255']
[20288.0, 20344.0, 20316.0]
[48.0, 48.0, 75.0]
[504, 504, 504]
p03745
u197300260
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tdiff = aSequence[i+1]-aSequence[i]\n\t\tif flag == "Plus":\n\t\t\tif diff < 0:\n\t\t\t\tflag=="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif diff > 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif diff > 0 :\n\t\t\t\tflag="Plus"\n\t\t\telse:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n', '# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tif flag == "Plus":\n\t\t\tif aSequence[i+1] < aSequence[i]:\n\t\t\t\tflag=="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif aSequence[i] < aSequence[i+1]:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif aSequence[i] < aSequence[i+1]:\n\t\t\t\tflag="Plus"\n\t\t\telse:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n', '# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tdiff = aSequence[i+1]-aSequence[i]\n\t\tif flag == "Plus":\n\t\t\tif diff < 0:\n\t\t\t\tflag=="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif diff > 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif diff > 0 :\n\t\t\t\tflag="Plus"\n\t\t\telif diff < 0:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n', '# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tdiff = aSequence[i+1]-aSequence[i] \n\t\tif flag == "Plus":\n\t\t\tif diff < 0:\n\t\t\t\tflag=="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif diff > 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif diff > 0 :\n\t\t\t\tflag="Plus"\n\t\t\telse:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n', '# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tdiff = aSequence[i+1]-aSequence[i] \n\t\tif flag == "Plus":\n\t\t\tif diff < 0:\n\t\t\t\tflag=="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif diff > 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif diff > 0 :\n\t\t\t\tflag="Plus"\n\t\t\telse:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n', '# _*_ coding:utf-8 _*_\n\n\n\ndef solveProblem(allNumber,aSequence):\n\tflag="Flat"\n\tcount = 1\n\tfor i in range(allNumber-1):\n\t\tdiff = aSequence[i+1]-aSequence[i]\n\t\tif flag == "Plus":\n\t\t\tif diff < 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount=count+1\n\t\telif flag == "Minus":\n\t\t\tif diff > 0:\n\t\t\t\tflag="Flat"\n\t\t\t\tcount = count+1\n\t\telse:\n\t\t\tif diff > 0 :\n\t\t\t\tflag="Plus"\n\t\t\telif diff < 0:\n\t\t\t\tflag="Minus"\n\n\tanswer = count\n\treturn answer\n\n\nif __name__ == \'__main__\':\n\tN = int(input().strip())\n\tAs = list(map(int,input().strip().split(\' \')))\n\tsolution = solveProblem(N,As)\n\tprint("{}".format(solution))\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s108444685', 's436201220', 's551243376', 's617083683', 's987756333', 's282438822']
[14252.0, 14252.0, 14224.0, 14252.0, 14252.0, 14228.0]
[59.0, 59.0, 59.0, 61.0, 63.0, 63.0]
[653, 679, 662, 697, 654, 661]
p03745
u203898698
2,000
262,144
You are given an array A of length N. Your task is to divide it into several contiguous subarrays. Here, all subarrays obtained must be sorted in either non-decreasing or non-increasing order. At least how many subarrays do you need to divide A into?
['n = int(input())\na = list(map(int, input().split()))\ncnt = 1\ni = -1\nflg = True\nwhile True:\n i += 1\n if i >= n-1:\n break\n if a[i] < a[i+1]:\n flg = True\n elif a[i] > a[i+1]:\n flg = False\n else:\n continue\n for k in range(i, n-1):\n if (flg and a[k] > a[k+1]) or ((not flg) and a[k] < a[k+1]):\n cnt += 1\n i = k\n break', 'n = int(input())\na = list(map(int, input().split()))\ncnt = 1\nb = [0] + a\nc = [(i-j)//abs(i-j) for i, j in zip(a, b) if i != j]\ndel c[0]\nif c:\n mae=c[0]\n d=iter(c)\n for x in d:\n if x != mae:\n cnt += 1\n try:\n mae = d.__next__()\n except StopIteration:\n break\nprint(cnt)']
['Wrong Answer', 'Accepted']
['s776655396', 's884758366']
[14252.0, 14224.0]
[2104.0, 74.0]
[348, 301]