output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s574238512
Runtime Error
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
n,a,b=map(int,input().split()) m=[] for i in range(n): m.append(int(input())) m.sort(reverse=True) attack=0 #攻撃 while m[0] > 0: for i in range(len(m)): if i == 0: m[i]= m[i] - a if m[i] =< 0: m.pop[i] else: m[i]= m[i] - b if m[i] =< 0: m.pop[i] m.sort(reverse=True) attack += 1 print(attack)
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s503690954
Runtime Error
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
N,A,B=map(int,input().split()) H=[] for i in range(N): H.append(int(input())) ans=0 n=N while n>0: mi=0 for i in range(n): if H[i]>=0: H[i]-=B=i H[mi]-=(A-B) if H[mi]<H[i]: mi while n>0 and H[n-1]<=0: n-=1 ans+=1 print(ans)
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s430809703
Runtime Error
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
def roof(x): if x == int(x): return x else: return int(x)+1 def ans(n,a,b,h): m = max(h) M = roof(m / b) x = M y = 0 if x == 1: return x while x - y > 1: half = int((x+y)/2) s_half = 0 for i in range(0,n): s_half = s_half +roof((h[i] - b * half) / (a - b)) if s_half <= half: x = half else: y = half #print(x,y) return x n, a, b = map(int,input().split()) h = [0] * n for i in range(0,n): h[i] = int(input()) print(int(ans(n,a,b,h))
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s031828794
Accepted
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
# -*- coding: utf-8 -*- """ http://abc063.contest.atcoder.jp/tasks/arc075_b TLE """ import sys from sys import stdin from math import ceil input = stdin.readline def Cond(monsters, A, B, mid): t = [x - (B * mid) for x in monsters] t.sort(reverse=True) additional_damage = A - B total_count = 0 for m in t: if m < 1: break total_count += ceil(m / additional_damage) if total_count <= mid: return True else: return False def main(args): # N = 2 # A = 10 # B = 4 # monsters = [20, 20] N, A, B = map(int, input().split()) monsters = [int(input()) for _ in range(N)] total_count = 0 if N == 1: total_count = ceil(monsters[0] / A) else: monsters.sort(reverse=True) lb = ceil(monsters[0] / A) ub = ceil(monsters[0] / B) # lb = 0 # ub = 1e10 for _ in range(30): mid = (lb + ub) // 2 if Cond(monsters, A, B, mid): ub = mid else: lb = mid total_count = int(ub) print(total_count) if __name__ == "__main__": main(sys.argv[1:])
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s435889574
Wrong Answer
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
import math class Range_BIT: def __init__(self, n): self.n = n self.bit0 = [0] * (n + 1) self.bit1 = [0] * (n + 1) def _Add(self, k, x, is_bit0=True): if is_bit0 == True: data = self.bit0 else: data = self.bit1 while k <= self.n: data[k] += x k += k & -k def _Get(self, data, k): s = 0 while k: s += data[k] k -= k & -k return s """ 配列の獲得 """ def Array(self): array = [0] * (n + 1) for i in range(self.n): array[i] = self.Get(i + 1, i + 2) return array[:-1] """ 区間[l:r)に対してxを加算 """ def Add(self, l, r, x): self._Add(l, -x * (l - 1), is_bit0=True) self._Add(r, x * (r - 1), is_bit0=True) self._Add(l, x, is_bit0=False) self._Add(r, -x, is_bit0=False) """ 区間[l:r)の総和 """ def Get(self, l, r): Pi = self._Get(self.bit1, r - 1) * (r - 1) - self._Get(self.bit1, l - 1) * ( l - 1 ) Qi = self._Get(self.bit0, r - 1) - self._Get(self.bit0, l - 1) return Pi + Qi n, a, b = map(int, input().split()) d = a - b rbit = Range_BIT(n) for i in range(n): h = int(input()) rbit.Add(i + 1, i + 2, h) ans = 0 while True: arr = rbit.Array() mx = max(arr) idx = arr.index(mx) if mx <= 0: break tmp = math.ceil(mx / a) rbit.Add(1, n + 1, -b * tmp) rbit.Add(idx + 1, idx + 2, -d * tmp) ans += tmp print(ans)
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s001667234
Runtime Error
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
# -*- coding: utf-8 -*- N, A, B = map(int, input().split()) H = [int(input()) for x in range(N)] c = 0 while H: index = max(enumerate(H), key=lambda x: x[1])[0] H[index] -= A H = [H[x] - B for x in range(len(H)) if x != index] I = [x for x in range(len(H)) if H[x] <= 0] [H.pop(x) for x in I] c += 1 print(c)
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters. * * *
s518512705
Wrong Answer
p03700
Input is given from Standard Input in the following format: N A B h_1 h_2 : h_N
import heapq def f(A, B, hs): hs = [-h for h in hs] heapq.heapify(hs) iterations = 0 while hs[0] < 0: hi = heapq.heappop(hs) hs = [h + B for h in hs] heapq.heappush(hs, hi + A) iterations += 1 return iterations N, A, B = map(int, input().split()) hs = [] for _ in range(N): hs.append(int(input())) f(A, B, hs)
Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called _health_ , and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below. Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows: * Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds. At least how many explosions do you need to cause in order to vanish all the monsters?
[{"input": "4 5 3\n 8\n 7\n 4\n 2", "output": "2\n \n\nYou can vanish all the monsters in two explosion, as follows:\n\n * First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.\n * Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.\n\n* * *"}, {"input": "2 10 4\n 20\n 20", "output": "4\n \n\nYou need to cause two explosions centered at each monster, for a total of\nfour.\n\n* * *"}, {"input": "5 2 1\n 900000000\n 900000000\n 1000000000\n 1000000000\n 1000000000", "output": "800000000"}]
Print number of occurrences of `ABC` in S as contiguous subsequences. * * *
s542379557
Accepted
p02812
Input is given from Standard Input in the following format: N S
lens = int(input()) has = input() print(has.count("ABC"))
Statement We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)?
[{"input": "10\n ZABCDBABCQ", "output": "2\n \n\nTwo contiguous subsequences of S are equal to `ABC`: the 2-nd through 4-th\ncharacters, and the 7-th through 9-th characters.\n\n* * *"}, {"input": "19\n THREEONEFOURONEFIVE", "output": "0\n \n\nNo contiguous subsequences of S are equal to `ABC`.\n\n* * *"}, {"input": "33\n ABCCABCBABCCABACBCBBABCBCBCBCABCB", "output": "5"}]
Print number of occurrences of `ABC` in S as contiguous subsequences. * * *
s991030020
Runtime Error
p02812
Input is given from Standard Input in the following format: N S
from collections import deque N, K = map(int, input().split()) P = list(map(int, input().split())) smin = deque() smax = deque() x = 0 r = 0 r2 = 0 for i, p in enumerate(P): while len(smin) > 0 and P[smin[-1]] > p: smin.pop() smin.append(i) if smin[0] <= i - K: smin.popleft() while len(smax) > 0 and P[smax[-1]] < p: smax.pop() smax.append(i) if smax[0] <= i - K: smax.popleft() if i > 0 and P[i - 1] < P[i]: x = min(x + 1, K - 1) else: x = 0 if i == K - 1 or (i >= K and not (P[i - K] < P[smin[0]] and smax[0] == i)): if x != K - 1: r += 1 else: r2 = 1 print(r + 1 if r2 else r)
Statement We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)?
[{"input": "10\n ZABCDBABCQ", "output": "2\n \n\nTwo contiguous subsequences of S are equal to `ABC`: the 2-nd through 4-th\ncharacters, and the 7-th through 9-th characters.\n\n* * *"}, {"input": "19\n THREEONEFOURONEFIVE", "output": "0\n \n\nNo contiguous subsequences of S are equal to `ABC`.\n\n* * *"}, {"input": "33\n ABCCABCBABCCABACBCBBABCBCBCBCABCB", "output": "5"}]
Print number of occurrences of `ABC` in S as contiguous subsequences. * * *
s036140211
Runtime Error
p02812
Input is given from Standard Input in the following format: N S
b, c = map(str, input().split()) print(c.count("ABC"))
Statement We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)?
[{"input": "10\n ZABCDBABCQ", "output": "2\n \n\nTwo contiguous subsequences of S are equal to `ABC`: the 2-nd through 4-th\ncharacters, and the 7-th through 9-th characters.\n\n* * *"}, {"input": "19\n THREEONEFOURONEFIVE", "output": "0\n \n\nNo contiguous subsequences of S are equal to `ABC`.\n\n* * *"}, {"input": "33\n ABCCABCBABCCABACBCBBABCBCBCBCABCB", "output": "5"}]
Print number of occurrences of `ABC` in S as contiguous subsequences. * * *
s809340303
Wrong Answer
p02812
Input is given from Standard Input in the following format: N S
input = input() result = 0 for i in range(len(input) - 2): serach = input[i : i + 3] if serach == "ABC": result += 1 print(result)
Statement We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)?
[{"input": "10\n ZABCDBABCQ", "output": "2\n \n\nTwo contiguous subsequences of S are equal to `ABC`: the 2-nd through 4-th\ncharacters, and the 7-th through 9-th characters.\n\n* * *"}, {"input": "19\n THREEONEFOURONEFIVE", "output": "0\n \n\nNo contiguous subsequences of S are equal to `ABC`.\n\n* * *"}, {"input": "33\n ABCCABCBABCCABACBCBBABCBCBCBCABCB", "output": "5"}]
Print number of occurrences of `ABC` in S as contiguous subsequences. * * *
s680518355
Runtime Error
p02812
Input is given from Standard Input in the following format: N S
a, b = map(int, input().split("\n")) print(len(b.split("ABC")) - 1)
Statement We have a string S of length N consisting of uppercase English letters. How many times does `ABC` occur in S as contiguous subsequences (see Sample Inputs and Outputs)?
[{"input": "10\n ZABCDBABCQ", "output": "2\n \n\nTwo contiguous subsequences of S are equal to `ABC`: the 2-nd through 4-th\ncharacters, and the 7-th through 9-th characters.\n\n* * *"}, {"input": "19\n THREEONEFOURONEFIVE", "output": "0\n \n\nNo contiguous subsequences of S are equal to `ABC`.\n\n* * *"}, {"input": "33\n ABCCABCBABCCABACBCBBABCBCBCBCABCB", "output": "5"}]
Print the answer in a line. * * *
s018075149
Accepted
p02541
Input is given from Standard Input in the following format: N
def prime_factorize(N): # 素因数分解 exponent = 0 while N % 2 == 0: exponent += 1 N //= 2 # if exponent: factorization = [[2,exponent]] if exponent: factorization = [[1, pow(2, exponent)]] else: factorization = [] i = 1 while i * i <= N: i += 2 if N % i: continue exponent = 0 while N % i == 0: exponent += 1 N //= i factorization.append([1, pow(i, exponent)]) # factorization.append([i,exponent]) # if N!= 1: factorization.append([N,1]) if N != 1: factorization.append([1, N]) assert N != 0, "zero" return factorization def Garner_NOmod(alst, mlst): x = 0 M = 1 # 互いに素を仮定 for a, m in zip(alst, mlst): c = (a - x) * modinv(M, m) % m x += c * M M *= m return x def extgcd(x, y): if y == 0: return 1, 0 # g=x r0, r1, s0, s1 = x, y, 1, 0 while r1 != 0: r0, r1, s0, s1 = r1, r0 % r1, s1, s0 - r0 // r1 * s1 # g = r0 return s0, (r0 - s0 * x) // y def modinv(a, MOD): x, y = extgcd(a, MOD) return x % MOD # coding: utf-8 # Your code here! import sys readline = sys.stdin.readline read = sys.stdin.read (n,) = map(int, readline().split()) # lr = [list(map(int, readline().split())) for _ in range(q)] if n == 1: print(1) exit() lst = prime_factorize(2 * n) res = [] from itertools import product for a in product(*lst): v = 1 for i in a: v *= i w = 2 * n // v res.append(Garner_NOmod([0, w - 1], [v, w])) res.sort() """ for i in res: #print(n,i,i*(i+1)//2) assert (i*(i+1)//2)%(n)==0 """ print(res[1])
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s767059022
Accepted
p02541
Input is given from Standard Input in the following format: N
N = int(input()) def gcd(x, y): k, l = x, y while l: k, l = l, k % l return k def factorization(n): a = n p = 2 D = {} while a != 1: cnt = 0 while a % p == 0: cnt += 1 a //= p if cnt: D[p] = cnt p += 1 if p * p > n and a != 1: D[a] = 1 break return D X = factorization(2 * N) F = {1} for i in X: tmp = set() for j in F: tmp.add(j) p = j for k in range(X[i]): tmp.add(p * i) p *= i for j in tmp: F.add(j) def extgcd(a, b, c): x, y, u, v, k, l = 1, 0, 0, 1, a, b while l: x, y, u, v, k, l = u, v, x - u * (k // l), y - v * (k // l), l, k % l return c * x, c * y m = 2 * N + 1 for i in F: if gcd(i, (2 * N) // i) == 1: x, y = extgcd((2 * N) // i, -i, 1) while x <= 0 or y <= 0: x += i y += (2 * N) // i m = min(x * ((2 * N) // i), m) print(m)
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s848614192
Runtime Error
p02541
Input is given from Standard Input in the following format: N
n = int(input()) n *= 2 ans = [] ans2 = [] for i in range(2, 32 * 10**6): if n % i == 0: ans.append(i) n //= i cnt = 1 while n % i == 0: n //= i cnt += 1 ans2.append(cnt) if n != 1: ans.append(n) ans2.append(1) # print(ans) # print(ans2) l = len(ans) for i in range(l): ans[i] **= ans2[i] # print(ans) time = [0 for _ in range(l)] def nex(time): for i in range(l): if time[i] == 0: time[i] = 1 return time else: time[i] = 0 else: return "over" can = [] while time != "over": x = 1 y = 1 for i in range(l): if time[i] == 0: x *= ans[i] else: y *= ans[i] # print(x,y) X = int(x) Y = int(y) if x > y: rec = [] while y != 1: rec.append(x // y) x, y = y, x % y # print(rec) if rec: le = len(rec) rec.reverse() now = [1, -rec[0]] for j in range(1, le): # print(now) now[0], now[1] = now[1], now[0] - now[1] * rec[j] # print(now) # print(min(abs(X*now[0]),abs(Y*now[1]))) can.append(min(abs(X * now[0]), abs(Y * now[1]))) time = nex(time) print(min(can))
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s469666851
Accepted
p02541
Input is given from Standard Input in the following format: N
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def PrimeDecomposition(N): ret = {} n = int(N**0.5) for d in range(2, n + 1): while N % d == 0: if d not in ret: ret[d] = 1 else: ret[d] += 1 N //= d if N == 1: break if N != 1: ret[N] = 1 return ret def extgcd(a, b): if b: d, y, x = extgcd(b, a % b) y -= (a // b) * x return d, x, y else: return a, 1, 0 N = int(input()) if N == 1: print(1) exit() P = PrimeDecomposition(N) if 2 in P: P[2] += 1 else: P[2] = 1 p_list = list(P.keys()) np = len(p_list) ans = 2 * N for i in range(2**np): p1 = 1 p2 = 1 for j in range(np): pp = p_list[j] if i >> j & 1: p1 *= pp ** P[pp] else: p2 *= pp ** P[pp] _, s2, s1 = extgcd(p2, p1) while s1 >= 0 or s2 <= 0: s1 -= p2 s2 += p1 while s2 - p1 > 0 and s1 + p2 < 0: s2 -= p1 s1 += p2 ans = min(ans, (-s1) * p1) print(ans) if __name__ == "__main__": main()
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s448679086
Runtime Error
p02541
Input is given from Standard Input in the following format: N
from math import sqrt from math import ceil def mpfli(N): # minimum prime factor listのこと li = [i for i in range(N + 1)] li2 = [i for i in range(N + 1)] for i in range(2, ceil(sqrt(N + 1))): for j in range(2 * i, N + 1): if li[j] == li2[j]: if li[j] % li[i] == 0: li[j] = li[i] return li def pfac(n): # mpf = mpfli(N) S = [0] * (n + 1) while n != 1: m = mpf[n] S[m] += 1 n = n // m return S def divofsum(k): pk = pfac(k) pk2 = pfac(k + 1) pk.append(0) pp = [pk[i] + pk2[i] for i in range(k + 2)] pp[2] -= 1 return pp def check(k): flag = True dk = divofsum(k) + [0] * (N - k - 1) for i in range(N + 1): if dk[i] < pliN[i]: flag = False break return flag N = int(input()) mpf = mpfli(N) pliN = pfac(N) mainflag = False k = 1 while mainflag == False: k += 1 mainflag = check(k) print(k)
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s229427234
Runtime Error
p02541
Input is given from Standard Input in the following format: N
import sys def make_prime_table(n): # nまでの整数について,それに含まれる最大の素数 sieve = list(range(n + 1)) sieve[0] = -1 sieve[1] = -1 for i in range(4, n + 1, 2): sieve[i] = 2 for i in range(3, int(n**0.5) + 1, 2): if sieve[i] != i: continue for j in range(i * i, n + 1, i * 2): if sieve[j] == j: sieve[j] = i return sieve def prime_factorize(n): # 1を除く(素因数,指数)のリスト result = [] while n != 1: p = prime_table[n] e = 0 while n % p == 0: n //= p e += 1 result.append((p, e)) return result N = int(input()) prime_table = make_prime_table(N) if N == 1: print(1) sys.exit() f = prime_factorize(N) p, e = f[-1] # 最大素べき # print(p,e) P = p**e for a in range(1, 10**15 // P): k = a * P if (k * (k - 1) // 2) % N == 0: print(k - 1) sys.exit() if (k * (k + 1) // 2) % N == 0: print(k) sys.exit()
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s621420527
Runtime Error
p02541
Input is given from Standard Input in the following format: N
import sys def debug(*x): print(*x, file=sys.stderr) def ex(): for i in range(2, 100): for j in range(1, i - 1): if (j * (j + 1) // 2) % i == 0: # debug("i, j", i, j) break else: debug("i", i) def blute(N): for i in range(1, N): if (i * (i + 1) // 2) % N == 0: return i return N - 1 #!/usr/bin/env python3 sys.setrecursionlimit(10**6) INF = 10**9 + 1 # sys.maxsize # float("inf") MOD = 10**9 + 7 def factor(n): """ >>> factor(100) defaultdict(<class 'int'>, {2: 2, 5: 2}) >>> factor(103) defaultdict(<class 'int'>, {103: 1}) """ from math import sqrt from collections import defaultdict ret = defaultdict(int) SQRTN = int(sqrt(n)) + 1 p = 2 while p < SQRTN and n > 1: while n % p == 0: ret[p] += 1 n //= p p += 1 if n > 1: ret[n] += 1 return ret def solve_0(N): """ not return minimum answer """ f = factor(N) if len(f) == 1: return N - 1 xs = [p ** f[p] for p in f] maxx = max(xs) rest = N // maxx debug("N, maxx, rest", N, maxx, rest) for p in range(maxx, N, maxx): if (p + 1) % rest == 0: return p if (p - 1) % rest == 0: return p - 1 def solve(N): f = factor(N) if len(f) == 1: return N - 1 xs = [p ** f[p] for p in f] maxx = max(xs) rest = N // maxx debug("N, maxx, rest", N, maxx, rest) for p in range(maxx, N, maxx): if (p + 1) % rest == 0: return p if (p - 1) % rest == 0: return p - 1 def main(): N = int(input()) print(solve(N)) # tests T1 = """ 11 """ TEST_T1 = """ >>> as_input(T1) >>> main() 10 """ def test2(): """ >>> test2() ok """ for i in range(2, 100): debug("blute(i), solve(i)", blute(i), solve(i)) assert blute(i) == solve(i) print("ok") def _test(): import doctest doctest.testmod() g = globals() for k in sorted(g): if k.startswith("TEST_"): doctest.run_docstring_examples(g[k], g, name=k) def as_input(s): "use in test, use given string as input file" import io f = io.StringIO(s.strip()) g = globals() g["input"] = lambda: bytes(f.readline(), "ascii") g["read"] = lambda: bytes(f.read(), "ascii") input = sys.stdin.buffer.readline read = sys.stdin.buffer.read if sys.argv[-1] == "-t": print("testing") _test() sys.exit() main()
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
Print the answer in a line. * * *
s807838138
Wrong Answer
p02541
Input is given from Standard Input in the following format: N
n = int(input()) k = n d = dict() for num in range(2, n + 1): if num * num > n: break cnt = 0 while k % num == 0: k //= num cnt += 1 if cnt > 0: d[num] = cnt if k > 0: d[k] = 1 maxi = 0 for num in d: maxi = max(maxi, num) maxi = maxi * d[maxi] for i in range(1, n + 1): if i * i > n: break if (i * maxi - 1) * (i * maxi) % (2 * n) == 0: print(i * maxi - 1) exit() if 2 * (i * maxi) * (i * maxi + 1) % (2 * n) == 0: print(i * maxi) exit()
Statement Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists.
[{"input": "11", "output": "10\n \n\n1+2+\\cdots+10=55 holds and 55 is indeed a multple of N=11. There are no\npositive integers k \\leq 9 that satisfy the condition, so the answer is k =\n10.\n\n* * *"}, {"input": "20200920", "output": "1100144"}]
For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset.
s312302584
Wrong Answer
p02404
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero).
H, W = map(int, input().split()) print("#" * W) print(("#" + "." * (W - 2) + "#\n") * (H - 2), end="") print("#" * W)
Print a Frame Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ########## #........# #........# #........# #........# ##########
[{"input": "4\n 5 6\n 3 3\n 0 0", "output": "####\n #..#\n ####\n \n ######\n #....#\n #....#\n #....#\n ######\n \n ###\n #.#\n ###"}]
For each dataset, print the frame made of '#' and '.'. Print a blank line after each dataset.
s377306189
Accepted
p02404
The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero).
c = [] def listcreate(): global c c = [] for y in range(a[0]): b = [] for x in range(a[1]): if y == 0 or y == a[0] - 1 or x == 0 or x == a[1] - 1: b.append("#") else: b.append(".") c.append(b) return def listdraw(): global c for y in range(len(c)): for x in range(len(c[0])): print(c[y][x], end="") print() return for i in range(10000): a = list(map(int, input().split())) if sum(a) == 0: break listcreate() listdraw() print()
Print a Frame Draw a frame which has a height of H cm and a width of W cm. For example, the following figure shows a frame which has a height of 6 cm and a width of 10 cm. ########## #........# #........# #........# #........# ##########
[{"input": "4\n 5 6\n 3 3\n 0 0", "output": "####\n #..#\n ####\n \n ######\n #....#\n #....#\n #....#\n ######\n \n ###\n #.#\n ###"}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s653746230
Accepted
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m, *T = map(int, open(0).read().split()) (*S,) = zip(T[::2], T[1::2]) f = lambda e: set(s[e < 2] for s in S if e in s) print("IM" * (f(1) & f(n) == set()) + "POSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s592921788
Accepted
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m, *l = map(int, open(0).read().split()) a = set() b = set() for i, j in sorted(zip(*[iter(l)] * 2)): if i == 1: a.add(j) if j == n: b.add(i) print("POSSIBLE" if a & b else "IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s394333634
Accepted
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
# print#!/usr/bin/env python3 # %% for atcoder uniittest use import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int): return map(type, input().split()) def tupin(t=int): return tuple(pin(t)) def lispin(t=int): return list(pin(t)) # %%code def resolve(): N, M = pin() a = set() b = set() for i in range(M): s, t = pin() if s == 1: a.add(t) if t == N: b.add(s) x = len(a & b) print(["IMPOSSIBLE", "POSSIBLE"][x > 0]) # %%submit! resolve()
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s911084950
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
#55 C - Cat Snuke and a Voyage import collections from deque N,M = map(int,input().split()) G = [[] for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) a -= 1; b -= 1 G[a].append(b) G[b].append(a) # BFS のためのデータ構造 dist = [-1]*N que = deque([]) # 初期条件 (島 1 を初期ノードとする) dist[0] = 0 que.append(0) while (len(que) != 0): v = que.popleft()# キューから先頭頂点を取り出す for next_v in G[v]: if (dist[next_v] != -1):# next_v が探索済みならスルー continue #新たな頂点 next_v について情報を更新してキューに追加 dist[next_v] = dist[v] + 1 que.append(next_v) if dist[N-1] == 2: print('POSSIBLE') else: print('INPOSSIBLE')
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s040087041
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int, input()) sa = set() sb = set() for i in range(m): a, b = map(int, input().split()) if a == 1: sb.add(b) if b == n: sa.add(a) print('IMPOSSIBLE', if len(sa & sb) == 0 else 'POSSIBLE')
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s899096386
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N,M=map(int,input().split()) first=[] second=[] for i in range(M): a,b=map(int,input().split()) if a==1: first.append(b) elif b==N: second.append(a) ans="IMPOSSIBLE" for i in first: if i in second:
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s148095182
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import defaultdict from collections d = defaultdict([]) goal, n = map(int, input().split()) for _ in range(n): from, to = map(int, input().split()) d[from].append(to) d[to].append(from) for current in d[1]: if goal in d[current]: print("POSSIBLE") break else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s141811152
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) ab=[list(map(int,input().split()))] ab.sort() medium = [] flag = 0 for i in range(m): if ab[i][0] == 1: medium.append(ab[i][1]) for j in range(m): if ab[j][0] in medium and ab[j][1] == n: flag = 1 if flag == 1: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s316513979
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N, M = map(int, input().split()) ab_list = sorted([list(map(int, input().split())) for _ in range(M)]) ans = "IMPOSSIBLE" second_island = [] for a, b in ab_list: if a == 1: second_island.append(b) if b == N: if a in second_island: ans = "POSSIBLE" break print(ans)
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s320905862
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m = map(int,input().split()) ab = sorted([list(map(int,input().split())) for _ in range(m)]) relaypoint = [] i = 0 while(ab[i][0] == 1): relaypoint.append(ab[i][1]) i += 1 ab.sort(key = lambda ab:ab[1] reverse = True) relaypoint = list(set(relaypoint)) x = len(relaypoint) j = 0 flag = 0 while(ab[j][1] == 5): if ab[j][0] in relaypoint: flag = 1 if flag == 1: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s814054996
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) sa=set() sb=set() for i in range(m): a,b=map(int,input().split()) if a==1:sb.add(b) if b==N:sa.add(a) print('IMPOSSIBLE' if len(sa&sb)=0 else 'POSSIBLE')
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s872319896
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
4 3 1 4 4 5 2 3
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s899323127
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) temp=[] for i in range(0,m): a,b=map(int,input().split()): if a==1: if b==n: print("POSSIBLE") break else: temp.append(b) else: for i in range(0,len(b)): if temp[i]==n: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s153039563
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N, M = map(int, input().split()) mid, las = [], [] ans = 0 for i in range(M): a, b = map(int, input().split()) if a == 1: mid.append(b) elif b == N: las.append(a) if set(mid) & set(las) != 0: ans = 1  print('POSSIBLE' if ans == 1 else 'INPOSSIBLE')
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s951876777
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
from sys import stdin input = stdin.readline N,M = map(int,(input().split())) ans = "IMPOSSIBLE" ls = {} f = [False]*M for m in range(M): a,b = map(int,(input().split())) ls[a-1] = b-1 if a-1 == 0 and b-1 == N-1: ans = "POSSIBLE" if a-1 == 0: f[a-1] = True for m in range(M): if ans == "POSSIBLE": if f[m] and ls[m] in ls and ls[ls[m]] == N-1 : ans = "POSSIBLE" print(ans)
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s572963783
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m = map(int,input().split()) des = [0]*(n+1) a = 1 for i in range(0,m): b = (list(map(int,input().split())) if b[0] == 1: des[b[1]] += 1 if des[b[1]] == 2: print('possible') a = 0 break if b[1] == n: des[b[0]] += 1 if des[b[0]] == 2: print ('possible') a = 0 break if a: print('impossible')
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s621454281
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
# coding: utf-8 N, M = tuple(map(int, input().split())) graph = [ [] for i in range(N+1)] for i in range(M): a, b = tuple(map(int, input().split())) graph[a].append(b) graph[b].append(a) res = "IMPOSSIBLE" for i in range(2, N): if 1 in graph[i] and N in graph[i]: res = "POSSIBLE" print(res)
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s805262805
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n,m=map(int,input().split()) X = [list(map(int,input().split())) for i in range(m)] a_list = [] b_list = [] for i in range(m): if X[i][0] = 1: a_list.append(X[i][1]) elif X[i][1] = 1: a_list.append(X[i][0]) elif X[i][0] = n: b_list.append(X[i][1]) elif X[i][1] = n: b_list.append(X[i][0]) c_dic = {a_list}&{b_list} if len(c_dic) ==0: print("IMPOSSIBLE") else: print("POSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s940038243
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import collections da = list(map(int,input().split())) a[] = [] b[] = [] for i in range(da[1]): k[i] = list(map(int,input().split())) for i in range(da[1]): if k[i][0] == 1 or k[i][1] == 1: a.append(k[i]) for i in range(da[1]): if k[i][0] == da[0]or k[i][1] == da[0]: b.append(k[i]) a = list(set(a)) b = list(set(b)) k = a+b c = collections.Counter(k) for i in range(len(c)): if c[i][1] >1: print("POSSIBLE") break else: print("IMPOSSIBLE")  
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s060768501
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N,M = list(map(int,input().split())) path = [[False,False] for i in range(N)] flag=False for i in range(M): a,b = list(map(int,input().split())) if a=N-1: if path[b-1][0]: flag=True path[b-1][1]=True if a=0: if path[b-1][1]: flag=True path[b-1][0]=True if b=N-1: if path[a-1][0]: flag=True path[a-1][1]=True if b=0: if path[a-1][1]: flag=True path[a-1][0]=True if flag: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s224578643
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define uint unsigned int #define ull unsigned long long typedef string str; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; typedef vector<bool> vb; #define pb push_back #define fi first #define se second #define in insert #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) const int INF = 1e9 + 5; const int N = 2e5 + 1; // int a[N][N]; int main(){ speed; int n, m; cin >> n >> m; vi a, b; for(int i = 0; i < m; ++i){ int x, y; cin >> x >> y; if(x == 1){ a.pb(y); } if(y == n){ b.pb(x); } } for(int i = 0; i < a.size(); ++i){ for(int j = 0; j < b.size(); ++j){ if(a[i] == b[j]){ cout << "POSSIBLE"; return 0; } } } cout << "IMPOSSIBLE"; }
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s109306183
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import collections n,m = map(int,input().split()) s = [list(map(int,input().split())) for i in range(m)] print(s)#[[1, 2], [2, 3]] q = collections.deque() q.append(1) for k in range(2): for j in range(len(q)) tmp = q.pop() for i in s: if tmp in i: if tmp > i[0]: q.append(i[0]) else: q.append(i[1]) if n in q: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s297313429
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import collections da = list(map(int,input().split())) a[] = [] b[] = [] for i in range(da[1]): k[i] = list(map(int,input().split())) for i in range(da[1]): if k[i][0] == 1 or k[i][1] == 1: a.append(k[i]) for i in range(da[1]): if k[i][0] == da[0]or k[i][1] == da[0]: b.append(k[i]) a = list(set(a)) b = list(set(b)) for i in range(len(a)): b.append(a[i]) c = collections.Counter(b) for i in range(len(c)): if c[i][1] >1: print("POSSIBLE") break else: print("IMPOSSIBLE")  
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s333534769
Runtime Error
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define uint unsigned int #define ull unsigned long long typedef string str; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef map<int, int> mii; typedef vector<int> vi; typedef vector<bool> vb; #define pb push_back #define fi first #define se second #define in insert #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) const int INF = 1e9 + 5; const int N = 1e5 + 1; int a[N][N]; int main(){ speed; int n, m; cin >> n >> m; for(int i = 0; i < m; ++i){ int x, y; cin >> x >> y; a[x][y] = 1; } for(int i = 0; i < N; ++i){ if(a[1][i] && a[i][n]){ cout << "POSSIBLE"; return 0; } } cout << "IMPOSSIBLE"; }
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
If it is possible to go to Island N by using two boat services, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s745354495
Accepted
p03645
Input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on 2019/3/23 Solved on 2019/3/ @author: shinjisu """ # ABC 068 C - Cat Snuke and a Voyage import bisect # import numpy as np def getInt(): return int(input()) def getIntList(): return [int(x) for x in input().split()] # def getIntList(): return np.array(input().split(), dtype=np.longlong) def zeros(n): return [0] * n # def zeros(n): return np.zeros(n, dtype=np.longlong) def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替 class Debug: def __init__(self): self.debug = True def off(self): self.debug = False def dmp(self, x, cmt=""): if self.debug: if cmt != "": print(cmt, ": ", end="") print(x) return x def prob(): d = Debug() d.off() N, M = getIntList() d.dmp((N, M), "N, M") ship = set() for i in range(M): a, b = getIntList() ship.add((a, b)) d.dmp((ship), "ship") for i in range(2, N): if ((1, i) in ship or (i, 1) in ship) and ((i, N) in ship or (N, 1) in ship): return "POSSIBLE" return "IMPOSSIBLE" ans = prob() if ans is None: pass elif type(ans) == tuple and ans[0] == 1: # 1,ans for elm in ans[1]: print(elm) else: print(ans)
Statement In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
[{"input": "3 2\n 1 2\n 2 3", "output": "POSSIBLE\n \n\n* * *"}, {"input": "4 3\n 1 2\n 2 3\n 3 4", "output": "IMPOSSIBLE\n \n\nYou have to use three boat services to get to Island 4.\n\n* * *"}, {"input": "100000 1\n 1 99999", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "5 5\n 1 3\n 4 5\n 2 3\n 2 4\n 1 4", "output": "POSSIBLE\n \n\nYou can get to Island 5 by using two boat services: Island 1 -> Island 4 ->\nIsland 5."}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s069702086
Accepted
p02957
Input is given from Standard Input in the following format: A B
a = eval(input().replace(*" +")) print(a % 2 * "IMPOSSIBLE" or a // 2)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s405798394
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
# chessboard, manhattan distance even will noly be possible if parity is right from math import sqrt eps = 1e-5 # Utils def solve2(A11, A12, A21, A22, b1, b2): """Solves a 2x2 matrix equation.""" det = A11 * A22 - A12 * A21 if abs(det) < eps: return (None, None) return (1 / det * (b1 * A22 - b2 * A12), 1 / det * (b2 * A11 - b1 * A21)) def dot(a, b): """Returns the dot product""" return sum(a[i] * b[i] for i in range(len(a))) def normalize(a): """Normalize vector to unit length""" norm = sqrt(dot(a, a)) return tuple(x / norm for x in a) def cross(a, b): """3D cross product""" return ( a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0], ) # intpt,onsegment,t,s = ll_intersect(a,da,b,db) def ll_intersect(a, da, b, db): """Given two segments, return line intersection, segments crossing and parameters at crossing""" dx, dy = a[0] - b[0], a[1] - b[1] s, t = solve2(db[0], -da[0], db[1], -da[1], dx, dy) if s == None: return (None, False, None, None) ipt = (a[0] + t * da[0], a[1] + t * da[1]) # Epsilon treatment? if s < -eps or s > 1 + eps or t < -eps or t > 1 + eps: return (ipt, False, t, s) return (ipt, True, t, s) def manhattan(x, y, s, t): return abs(x - s) + abs(y - t) def main(): k = int(input()) xx, yy = map(int, input().split()) if k % 2 == 0: if (xx + yy) % 2: print("-1") return P = [] while (xx, yy) != (0, 0): P.append((xx, yy)) if manhattan(0, 0, xx, yy) <= 2 * k: Sorig = [ [(-k, 0), (k, k)], [(0, k), (k, -k)], [(k, 0), (-k, -k)], [(0, -k), (-k, k)], ] S = [[(pos[0] + xx, pos[1] + yy), diff] for pos, diff in Sorig] inter = [] for pp, dd in S: for pp2, dd2 in Sorig: pt, onseg, _, _ = ll_intersect(pp, dd, pp2, dd2) if onseg: ix, iy = pt if (ix - round(ix)) < eps and (iy - round(iy)) < eps: inter.append((int(round(ix)), int(round(iy)))) for ix, iy in inter: ix, iy = inter[-1] if manhattan(0, 0, ix, iy) == k and manhattan(ix, iy, xx, yy) == k: P.append((ix, iy)) P.append((0, 0)) break if P[-1] == (0, 0): break if xx < 0: signx = -1 xx *= -1 else: signx = 1 if yy < 0: signy = -1 yy *= -1 else: signy = 1 togo = k mn = min(togo, xx) xx -= mn togo -= mn yy -= togo xx *= signx yy *= signy for i in range(len(P) - 1): assert abs(P[i][0] - P[i + 1][0]) + abs(P[i][1] - P[i + 1][1]) == k print(len(P) - 1) for x, y in P[:-1][::-1]: print(x, y) main()
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s606101216
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
N = int(input()) monster = list(map(int, input().split())) hero = list(map(int, input().split())) total = 0 i = -1 for i in range(N + 1): if i == 0: if monster[0] < hero[0]: total += monster[0] hero[0] -= monster[0] monster[0] = 0 else: total += hero[0] monster[0] -= hero[0] hero[0] = 0 elif i < N: if monster[i] < hero[i - 1]: total += monster[i] hero[i - 1] -= monster[i] monster[i] = 0 else: total += hero[i - 1] monster[i] -= hero[i - 1] hero[i - 1] = 0 if monster[i] < hero[i]: total += monster[i] hero[i] -= monster[i] monster[i] = 0 else: total += hero[i] hero[i] = 0 monster[i] -= hero[i] else: if monster[N] < hero[N - 1]: total += monster[N] else: total += hero[N - 1] print(total)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s169650001
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
a = int(input()) b = input().split(" ") sequence = [] for i in range(0, a): sequence.append(int(b[i])) error = [] for q in range(0, a - 1): if sequence[q] - sequence[q + 1] > 0: error.append(q) error.append(q + 1) if len(error) == 0: print("YES") elif len(error) == 2: if a == 2: print("YES") elif error[0] == 0: if sequence[error[0] + 2] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[1] == a: if sequence[error[1]] - sequence[error[1] - 2] > 0: print("YES") else: print("NO") else: if ( sequence[error[1]] - sequence[error[1] - 2] > 0 and sequence[error[0] + 2] - sequence[error[0]] > 0 ): print("YES") else: print("NO") elif len(error) == 4: if error[1] == error[2]: if sequence[error[0]] > sequence[error[3]]: if error[0] == 0 and error[3] == a - 1: if ( sequence[error[0]] - sequence[error[3] - 1] > 0 and sequence[error[0] + 1] - sequence[error[3]] > 0 ): print("YES") else: print("NO") elif error[0] == 0: if sequence[error[0] + 3] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[1] == a: if sequence[error[3]] - sequence[error[3] - 3] > 0: print("YES") else: print("NO") else: if ( sequence[error[3]] - sequence[error[3] - 3] > 0 and sequence[error[0] + 3] - sequence[error[0]] > 0 ): print("YES") else: print("NO") elif ( sequence[error[0]] - sequence[error[2]] > 0 and sequence[error[1]] - sequence[error[3]] > 0 ): if error[0] == 0 and error[3] == a - 1: if ( sequence[error[0]] - sequence[error[3] - 1] > 0 and sequence[error[0] + 1] - sequence[error[3]] > 0 ): print("YES") else: print("NO") elif error[0] == 0: if sequence[error[3] + 1] - sequence[error[0]] > 0: print("YES") else: print("NO") elif error[3] == a: if sequence[error[3]] - sequence[error[0] - 1] > 0: print("YES") else: print("NO") elif ( sequence[error[3]] - sequence[error[0] - 1] > 0 and sequence[error[3] + 1] - sequence[error[0]] > 0 ): print("YES") else: print("NO") else: print("NO") else: print("NO")
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s512918870
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
S = input() dp = [[0] * 13 for _ in range(len(S))] mod = 10**9 + 7 for i in range(13): if S[0] == "?": dp[0][i] = 1 if i <= 9 else 0 else: dp[0][i] = 1 if int(S[0]) == i else 0 for i in range(1, len(S)): if S[i] == "?": for j in range(10): for k in range(13): dp[i][(k * 10 + j) % 13] = ( dp[i][(k * 10 + j) % 13] + dp[i - 1][k] ) % mod else: j = int(S[i]) for k in range(13): dp[i][(k * 10 + j) % 13] = (dp[i][(k * 10 + j) % 13] + dp[i - 1][k]) % mod print(dp[len(S) - 1][5])
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s361153005
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
s = input() s = s[::-1] mod = 10**9 + 7 table = [[0] * 13 for _ in range(len(s) + 2)] table[0][0] = 1 dd = 1 for c in range(len(s)): if s[c] == "?": for n in range(10): for i in range(13): table[c + 1][(i + n * dd) % 13] += table[c][i] table[c + 1][(i + n * dd) % 13] %= mod else: num = int(s[c]) for i in range(13): table[c + 1][(i + num * dd) % 13] += table[c][i] table[c + 1][(i + num * dd) % 13] %= mod dd = (dd * 10) % 13 print(table[c + 1][5])
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s605155033
Wrong Answer
p02957
Input is given from Standard Input in the following format: A B
S = input() l = len(S) nhatena = 0 for s in S: if s != "?": break nhatena += 1 min = 10 ** (l - 1 - nhatena) max = 10 ** (l) - 1 # print(min) # print(max) mink = ( int((min - 5) / 13) + 1 if not ((min - 5) / 13.0).is_integer() else int((min - 5) / 13) ) maxk = ( int((max - 5) / 13) + 1 if not ((max - 5) / 13.0).is_integer() else int((max - 5) / 13) ) # print(mink) # print(maxk) cnt = 0 for k in range(mink, maxk): v = 13 * k + 5 val = ("%0" + str(l) + "d") % (v) # Sとの一致判定 for i, s in enumerate(S): if s != "?": if s != val[i]: break else: cnt += 1 if cnt == 1000000007: cnt = 0 print(cnt)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s566314386
Wrong Answer
p02957
Input is given from Standard Input in the following format: A B
A = 5 B = -5 print(A)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s858622957
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
s = input() l = len(s) mod = 10**9 + 7 dp = [[0] * 13 for i in range(l)] rem = [1, 10, 9, 12, 3, 4] for i in range(l)[::-1]: dig = i % 6 if s[i] == "?": if i == l - 1: for j in range(10): dp[-1][(j * rem[dig]) % 13] = 1 else: for j in range(10): for h in range(13): dp[i][(h + j * rem[dig]) % 13] += dp[i + 1][h] dp[i][(h + j * rem[dig]) % 13] %= mod else: a = int(s[i]) if i == l - 1: dp[i][(a * rem[dig]) % 13] = 1 else: for j in range(13): dp[i][(j + a * rem[dig]) % 13] += dp[i + 1][j] dp[i][(j + a * rem[dig]) % 13] %= mod print(dp[0][5])
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s100281581
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
k = int(input()) x, y = [int(x) for x in input().strip().split(" ")] x, y = x - y, x + y def main(): if k % 2 == 0: if x % 2 != 0: return -1 return to(x, y) def cc(x, xs): if abs(x - xs) <= 2 * k: if abs(x + k - xs) % 2 == k % 2: if abs(x + k - xs) <= abs(x - k - xs): xs = x + k else: xs = x - k return (True, xs) else: if x > xs: xs += k else: xs -= k else: if x > xs: xs += k else: xs -= k return (False, xs) def to(x, y): rs = [] xs, ys = 0, 0 while True: if abs(x - xs) == k or abs(y - ys) == k: if abs(x - xs) <= k and abs(y - ys) <= k: return rs + [(x, y)] mm, ys = cc(y, ys) if mm: if x > xs: xs += k else: xs -= k else: mm, xs = cc(x, xs) rs.append((xs, ys)) if __name__ == "__main__": jj = main() if jj == -1: print(-1) else: print(len(jj)) for r in jj: print((r[0] + r[1]) // 2, (r[1] - r[0]) // 2)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s248451048
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
cn = int(input()) enm = input().split(" ") brv = input().split(" ") taoshita = int(0) for i in range(0, cn): taoshita = taoshita + min(abs(int(brv[i])), abs(int(enm[i]))) enm[i] = int(enm[i]) - int(brv[i]) if int(enm[i]) < 0: brv[i] = abs(int(enm[i])) enm[i] = 0 if (int(enm[i + 1]) - int(brv[i])) < 0: taoshita = taoshita + int(enm[i + 1]) enm[i + 1] = 0 if (int(enm[i + 1]) - int(brv[i])) >= 0: enm[i + 1] = int(enm[i + 1]) - int(brv[i]) taoshita = taoshita + int(brv[i]) print(taoshita)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s247491938
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
N = int(input()) N = N + 1 monsters = list(map(int, input().split())) monsters.append(0) heros = list(map(int, input().split())) stack = 0 count = 0 point = 0 life = 0 for i in range(0, len(heros)): point = monsters[i] - (stack + heros[i]) if point < 0: if abs(point) > monsters[i + 1]: stack = monsters[i + 1] else: stack = heros[i] - monsters[i] count += monsters[i] else: count += heros[i] count += stack print(count)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s830459860
Wrong Answer
p02957
Input is given from Standard Input in the following format: A B
def harmony(a, b): if (a + b) % 2 == 0: return int((a + b) / 2) else: return "IMPOSSIBLE"
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s552591843
Runtime Error
p02957
Input is given from Standard Input in the following format: A B
n, a, b = map(int, input().split()) if n * a <= b: print(n * a) elif n * a >= b: print(b)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s679761170
Accepted
p02957
Input is given from Standard Input in the following format: A B
A, B = [int(n) for n in input().split()] print("IMPOSSIBLE" if (A + B) % 2 else (A + B) // 2)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s848341604
Accepted
p02957
Input is given from Standard Input in the following format: A B
a = sum(map(int, input().split())) print("IMPOSSIBLE" if a % 2 else a // 2)
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s342665678
Accepted
p02957
Input is given from Standard Input in the following format: A B
a, b = sorted(map(int, input().split())) print((a + b) // 2 if (b - a) & 1 == 0 else "IMPOSSIBLE")
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the integer K satisfying the condition. If such an integer does not exist, print `IMPOSSIBLE` instead. * * *
s947373385
Wrong Answer
p02957
Input is given from Standard Input in the following format: A B
q, r = divmod(sum(map(int, input().split())), 2) print(q if r else "IMPOSSIBLE")
Statement We have two distinct integers A and B. Print the integer K such that |A - K| = |B - K|. If such an integer does not exist, print `IMPOSSIBLE` instead.
[{"input": "2 16", "output": "9\n \n\n|2 - 9| = 7 and |16 - 9| = 7, so 9 satisfies the condition.\n\n* * *"}, {"input": "0 3", "output": "IMPOSSIBLE\n \n\nNo integer satisfies the condition.\n\n* * *"}, {"input": "998244353 99824435", "output": "549034394"}]
Print the answer. * * *
s649878551
Accepted
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N, K = map(int, input().split()) A = list(map(int, input().split())) l_A = len(A) nums = [] for i in range(l_A): sum = 0 for j in range(i, l_A): sum += A[j] nums.append(sum) nums.sort(reverse=True) max_num = 0 for num in nums: if num > max_num: max_num = num b = bin(max_num) b_max_nums = (list(b))[2:] l_b_max_nums = len(b_max_nums) b_nums = [] for num in nums: b_nums.append(num) target_group = b_nums for i in range(l_b_max_nums): p = pow(2, l_b_max_nums - i) _target_group = [] l_target_group = len(target_group) for t in target_group: if p & t >= p: _target_group.append(t) if len(_target_group) >= K: target_group = _target_group ans = target_group[0] l_target_group = len(target_group) for i in range(1, l_target_group): ans = ans & target_group[i] print(ans) """ for num in nums: n = [] for i in range(l_b_max_nums): n.append('0') _b = bin(num) _b_nums = (list(_b))[2:] l_b_nums = len(_b_nums) for i in range(l_b_nums): n[len(n)-1-i] = _b_nums[l_b_nums - 1 - i] b_nums.append(n) target_group = b_nums for i in range(l_b_max_nums): l_target = len(target_group) _target_group = [] for j in range(l_target): if b_nums[j][i] == '1': _target_group.append(b_nums[j]) if len(_target_group) >= K: target_group = _target_group ans = int("0b" + ''.join(target_group[0]), 2) l_target_group = len(target_group) for i in range(1, l_target_group): ans = ans & int("0b" + ''.join(target_group[i]), 2) print(ans) """
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s695092149
Wrong Answer
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
print(32)
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s544181407
Runtime Error
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
n, k = map(int, input().split()) a = list(map(int, input().split())) stand_bit = [set() for i in range(42)] acc = [0 for i in range(n+1)] acc[0] = 0 for i in range(1, n+1): acc[i] += a[i-1] + acc[i-1] set_ans = set() for i in range(n): for j in range(i, n): set_ans.add(acc[j+1] - acc[i]) s = acc[j+1] - acc[i] index = 41 while s : if s & 1: stand_bit[index].add(acc[j+1] - acc[i]) s = s >> 1 index -= 1 /* for i in range(42): if len(set_ans & stand_bit[i]) >= k: set_ans &= stand_bit[i] ans_list = list(set_ans) ans = ans_list[0] for i in ans_list: ans &= i print(ans) */
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s841188551
Runtime Error
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
from itertools import accumulate def main(): def int n, k, i, j, ans, num, cnt, b def list a, btfl n, k = map(int, input().split()) a = [0] + list(accumulate(map(int, input().split()))) btfl = [] for i in range(0, n): for j in range(i + 1, n + 1): btfl.append(a[j] - a[i]) # 解説AC ans = 0 for i in range(50)[::-1]: num, cnt = ans + pow(2, i), 0 for b in btfl: if num == num & b: cnt += 1 if cnt >= k: ans = num print(ans) if __name__ == '__main__': main()
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s267269337
Wrong Answer
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N = list(map(int, input().split())) S = list(map(int, input().split())) K = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] tmp = 0 for i, n in enumerate(K): if n >= N[1]: tmp = i break print(str(sum(S[tmp:])))
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s961444202
Runtime Error
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
package main import ( "bufio" "io" "os" "strconv" "fmt" ) var ( nstr func() string stdout *bufio.Writer ) func init() { nstr = newReadString(os.Stdin) stdout = bufio.NewWriter(os.Stdout) } func main() { defer stdout.Flush() n := nint() k := nint() aList := getIntSlice(n) sumList := make([]int, 0) for i:=0;i<n ;i++ { for j:=i+1;j<n+1 ;j++ { sum := 0 for tmp:=i;tmp<j ;tmp++ { sum += aList[tmp] } sumList = append(sumList, sum) } } var ( ans int count int ) for i:=40; i>=0; i--{ checkNum := 1 << uint(i) for j:=0;j<len(sumList) ;j++ { logical := checkNum & sumList[j] if logical !=0{ count ++ } } if count >= k{ ans += checkNum tmp := make([]int, 0) for m:=0;m<len(sumList) ;m++ { if sumList[m] &( 1 << uint(i)) !=0{ tmp = append(tmp, sumList[m]) } } sumList = tmp } count = 0 } fmt.Println(ans) } func newReadString(ior io.Reader) func() string { r := bufio.NewScanner(ior) r.Buffer(make([]byte, 1024), int(1e+11)) r.Split(bufio.ScanWords) return func() string { if !r.Scan() { panic("Scan failed") } return r.Text() } } func nint64() int64 { i, err := strconv.ParseInt(nstr(), 0, 64) if err != nil { panic(err.Error()) } return i } func nint() int { return int(nint64()) } func getIntSlice(n int) []int { b := make([]int, n) for i := 0; i < n; i++ { b[i] = nint() } return b } func getStringSlice(n int) []string { b := make([]string, n) for i := 0; i < n; i++ { b[i] = nstr() } return b } func gcd(x, y int) int { if y == 0 { return x } return gcd(y, x%y) } func lcm(x, y int) int { return x * y / gcd(x, y) } func contains(s []int, e int) bool { for _, a := range s { if a == e { return true } } return false } func bin(i int, prefix bool) string { i64 := int64(i) if prefix { return "0b" + strconv.FormatInt(i64, 2) } else { return strconv.FormatInt(i64, 2) } } func strReverse(s string) string { runes := []rune(s) for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 { runes[i], runes[j] = runes[j], runes[i] } return string(runes) }
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s294948474
Wrong Answer
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N, K = input().split() N, K = int(N), int(K) # array = input().split() array_int = [int(ele) for ele in input().split()] new_array = [] for n in range(N): for i in range(n, len(array_int)): new_array.append(array_int[n : i + 1]) # print(new_array) tmp_max = 0 for n in range(len(new_array)): x = sum(new_array[n]) for i in range(n + 2, len(new_array)): y = sum(new_array[i]) tmp = x & y if tmp_max < tmp: tmp_max = tmp print(tmp_max)
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s397576707
Wrong Answer
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
NK = input().split(" ") N, K = int(NK[0]), int(NK[1]) at, a = input().split(" "), [] for i in at: a.append(int(i)) enum = [] for i in range(0, len(a)): for j in range(i + 1, len(a) + 1): enum.append(a[i:j]) enub = [] for i in enum: enub.append(sum(i)) enub.sort(reverse=True) ans = enub[0] for i in range(K): ans = ans & enub[i] print(ans)
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s110009949
Accepted
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
a = input().split() a = [int(i) for i in a] b = input().split() b = [int(i) for i in b] def cao(aller, i): dicter = dict() for m in aller: for n in m: if n < i: try: dicter[n].append(m) except: dicter[n] = [m] for i in sorted(dicter)[::-1]: if len(dicter[i]) >= a[1]: return dicter[i], i return [], -1 aller = [0] sumer = 0 for i in b: sumer += i aller.append(sumer) superlist = dict() for i in range(len(b)): for j in range(i + 1, len(b) + 1): temp = bin(aller[j] - aller[i])[::-1] x = [] for k in range(len(temp)): if temp[k] == "1": x.append(k) for m in x: try: superlist[m].append(x) except: superlist[m] = [x] for i in sorted(superlist)[::-1]: if len(superlist[i]) >= a[1]: li = superlist[i] sumer = 2**i gan1, gan2 = cao(li, i) while gan2 != -1: sumer += 2**gan2 gan1, gan2 = cao(gan1, gan2) print(sumer) break
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
Print the answer. * * *
s929539134
Wrong Answer
p03215
Input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
n, k = map(int, input().split()) lis = list(map(int, input().split())) li = [] num = 0 for i in range(n): for j in range(i, n): num += lis[j] li.append(num) num = 0 li.sort(reverse=True) ans = li[0] nu = [] h = 0 cou = 2**35 while len(nu) < k: cou /= 2 while li[h] >= cou: nu.append(li[h]) h += 1 # print(nu) ans = {(2**35 - 1, 0)} for i in range(len(nu)): gone = set() for num, co in ans: if co < k: gone.add((num & nu[i], co + 1)) if co + (n - i) >= k: gone.add((num, co)) ans = gone an = 0 for v, b in ans: if b == k: an = max(an, v) print(an)
Statement One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence a, its _beauty_ is defined as a_l + ... + a_r. Niwango-kun wants to know the maximum possible value of the bitwise AND of the beauties of K nonempty contiguous subsequences among all N(N+1)/2 nonempty contiguous subsequences. (Subsequences may share elements.) Find the maximum possible value for him.
[{"input": "4 2\n 2 5 2 5", "output": "12\n \n\nThere are 10 nonempty contiguous subsequences of a. Let us enumerate them:\n\n * contiguous subsequences starting from the first element: \\\\{2\\\\}, \\\\{2, 5\\\\}, \\\\{2, 5, 2\\\\}, \\\\{2, 5, 2, 5\\\\}\n * contiguous subsequences starting from the second element: \\\\{5\\\\}, \\\\{5, 2\\\\}, \\\\{5, 2, 5\\\\}\n * contiguous subsequences starting from the third element: \\\\{2\\\\}, \\\\{2, 5\\\\}\n * contiguous subsequences starting from the fourth element: \\\\{5\\\\}\n\n(Note that even if the elements of subsequences are equal, subsequences that\nhave different starting indices are considered to be different.)\n\nThe maximum possible bitwise AND of the beauties of two different contiguous\nsubsequences is 12. This can be achieved by choosing \\\\{5, 2, 5\\\\} (with\nbeauty 12) and \\\\{2, 5, 2, 5\\\\} (with beauty 14).\n\n* * *"}, {"input": "8 4\n 9 1 8 2 7 5 6 4", "output": "32"}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s027495724
Accepted
p03080
Input is given from Standard Input in the following format: N s
print("YNeos"[int(input()) <= input().count("B") * 2 :: 2])
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s210311090
Accepted
p03080
Input is given from Standard Input in the following format: N s
print("YNeos"[int(input()) <= 2 * input().count("B") :: 2])
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s758783370
Accepted
p03080
Input is given from Standard Input in the following format: N s
n = int(input()) - 1 print("Yes" if sorted(input())[n // 2] == "R" else "No")
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s624787529
Accepted
p03080
Input is given from Standard Input in the following format: N s
# Author: cr4zjh0bp # Created: Sun Mar 8 04:59:35 UTC 2020 import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() N = ni() s = ns() r, b = 0, 0 for i in range(N): if s[i] == "R": r += 1 else: b += 1 if r > b: print("Yes") else: print("No")
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s131311050
Accepted
p03080
Input is given from Standard Input in the following format: N s
print("Yes" if int(input()) / 2 < input().count("R") else "No")
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s404769717
Wrong Answer
p03080
Input is given from Standard Input in the following format: N s
a = int(input()) - 1 b = str(input()) c = b[a] print(c)
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
If there are more people wearing a red hat than there are people wearing a blue hat, print `Yes`; otherwise, print `No`. * * *
s715246005
Runtime Error
p03080
Input is given from Standard Input in the following format: N s
s = input() for color in s:
Statement There are N people numbered 1 to N. Each person wears a red hat or a blue hat. You are given a string s representing the colors of the people. Person i wears a red hat if s_i is `R`, and a blue hat if s_i is `B`. Determine if there are more people wearing a red hat than people wearing a blue hat.
[{"input": "4\n RRBR", "output": "Yes\n \n\n * There are three people wearing a red hat, and one person wearing a blue hat.\n * Since there are more people wearing a red hat than people wearing a blue hat, the answer is `Yes`.\n\n* * *"}, {"input": "4\n BRBR", "output": "No\n \n\n * There are two people wearing a red hat, and two people wearing a blue hat.\n * Since there are as many people wearing a red hat as people wearing a blue hat, the answer is `No`."}]
Print the number of pairs satisfying the condition. * * *
s889903577
Accepted
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
_, *l = map(int, open(0).read().split()) d, a, i = {}, 0, 0 for h in l: d[i + h] = d.get(i + h, 0) + 1 a += d.get(i - h, 0) i += 1 print(a)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s004890269
Accepted
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
# dt = {} for i in x: dt[i] = dt.get(i,0)+1 # dt = {k:v for k,v in sorted(x.items(), key=lambda i: i[1])} ipnl = lambda n: [int(input()) for _ in range(n)] inp = lambda: int(input()) ip = lambda: [int(w) for w in input().split()] mp = lambda: map(int, input().split()) n = inp() x = ip() ctr = 0 a = [i + x[i] for i in range(n)] b = [i - x[i] for i in range(n)] dt1 = {} for i in a: dt1[i] = dt1.get(i, 0) + 1 dt2 = {} for i in b: dt2[i] = dt2.get(i, 0) + 1 for i in dt1: if i in dt2: ctr += dt1[i] * dt2[i] print(ctr)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s338993264
Runtime Error
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
n = int(input()) a = list(map(int, input().split())) su = dict() sd = dict() for i in range(n): if a[i] + i + 1 in su: su[a[i] + i + 1] += 1 else: su[a[i] + i + 1] = 1 if a[i] - i - 1 in sd: sd[a[i] - i - 1] += 1 else: sd[a[i] - i - 1] = 1 f1 = [] for d in su: f1.append(d, su[d]) f1.sort() f = [] for d in sd: f.append(d, su[d]) f.sort() s = 0 i1 = n - 1 j1 = 0 while i1 > 0 and j1 < n - 1: if su[i1] + sd[j1] == 0: s += 1 i1 -= 1 elif su[i1] + sd[j1] > 0: i1 -= 1 elif su[i1] + sd[j1] < 0: j1 += 1 print(s)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s873819283
Runtime Error
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 n = int(input()) As = list(map(int, input().split())) # Ps = [0] * n Ss = [0] * n Ds = [0] * n for i in range(n): # Ps[i] = [i + 1, As[i]] # 番号、身長 Ss[i] = i + 1 + As[i] Ds[i] = i + 1 - As[i] # Ss = sorted(Ps, key=lambda x: x[0] + x[1]) # Ds = sorted(Ps, key=lambda x: x[0] - x[1]) Ss.sort() Ds.sort() def calc(s, l, r): m = (l + r) // 2 if l == m and Ds[m] != s: return -1 # 不存在 if Ds[m] > s: r = m calc(s, l, r) elif Ds[m] < s: l = m calc(s, l, r) elif Ds[m] == s: return m # 存在 def calcStart(s, l, r): m = (l + r) // 2 if Ds[m] < s and Ds[m + 1] == s: return m elif Ds[m] == s: calcStart(s, l, m) elif Ds[m] < s and Ds[m + 1] < s: calcStart(s, m, r) def calcGoal(s, l, r): m = (l + r) // 2 if Ds[m] > s and Ds[m - 1] == s: return m elif Ds[m] == s: calcGoal(s, l, m) elif Ds[m] > s and Ds[m - 1] > s: calcGoal(s, m, r) ans = 0 for s in Ss: l = 0 r = n - 1 temp = calc(s, l, r) if temp != -1: calcStart(s, 0, temp) calcGoal(s, 0, temp) ans += calcGoal - calcStart print(ans)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s460960159
Wrong Answer
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
N = int(input()) A_ = list(map(int, input().split())) A = list() for i in range(len(A_)): if A_[i] < N - 1: A.append([i + 1, A_[i]]) ret = 0 for i in range(len(A) - 1, -1, -1): ind, val = A[i][0], A[i][1] B = [a for a in A if a[1] < N - 1 - val] for b in B: if abs(b[0] - ind) == val + b[1]: ret += 1 print(ret)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s420648225
Wrong Answer
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
N = int(input()) A = list(map(int, input().split())) u = 0 for i in range(1, (N // 2) + 1): for j in range(i + 1, N + 1): t = abs(i - j) if t == A[i - 1] + A[j - 1]: u += 1 print(u)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s134345698
Wrong Answer
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
1
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s904114639
Wrong Answer
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
num = int(input()) a = input().split(" ") for i in range(num): a[i] = int(a[i]) count = 0 for i in range(num - 1): for j in range(i + 1, num): id = j - i x = abs(a[j] - a[i]) if x == id: count += 1 print(count)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s757163003
Accepted
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
s = i = 0 d = {} for a in [*open(0)][1].split(): a = int(a) s += d.get(i - a, 0) d[i + a] = d.get(i + a, 0) + 1 i += 1 print(s)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s795233306
Accepted
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
n, *a = map(int, open(0).read().split()) i = s = 0 d = [0] * n for a in a: if i >= a: s += d[i - a] if i + a < n: d[i + a] += 1 i += 1 print(s)
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s462868961
Runtime Error
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
n, m = map(int, input().split()) h = list(map(int, input().split())) l = [] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 if h[a] < h[b]: l.append(a) elif h[a] == h[b]: l += [a, b] else: l.append(b) s = set(l) print(n - len(s))
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s716666578
Wrong Answer
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
x = int(input()) for a in range(-117, 120): for b in range(-117, 200): if x == a**5 - b**5: print(a, b) break
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Print the number of pairs satisfying the condition. * * *
s754351426
Runtime Error
p02691
Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N
N, A, B, C = map(int, input().split()) S = [""] * N for i in range(N): S[i] = input() result = [] kekka = True for i in range(N): if ( (A == 0 and B == 0 and S[i] == "AB") or (C == 0 and B == 0 and S[i] == "BC") or (A == 0 and C == 0 and S[i] == "AC") ): kekka = False break else: if S[i] == "AB": if A == 0: A += 1 B -= 1 result.append("A") elif B == 0: A -= 1 B += 1 result.append("B") elif A == 1 and B == 1 and C == 0: if S[i + 1] == "AC": A += 1 B -= 1 result.append("A") else: A -= 1 B += 1 result.append("B") elif A > B: A -= 1 B += 1 result.append("B") else: A += 1 B -= 1 result.append("A") elif S[i] == "AC": if A == 0: A += 1 C -= 1 result.append("A") elif C == 0: A -= 1 C += 1 result.append("C") elif A == 1 and C == 1 and B == 0: if S[i + 1] == "AB": A += 1 C -= 1 result.append("A") else: A -= 1 C += 1 result.append("C") elif A > C: A -= 1 C += 1 result.append("C") else: A += 1 C -= 1 result.append("A") elif S[i] == "BC": if B == 0: B += 1 C -= 1 result.append("B") elif C == 0: B -= 1 C += 1 result.append("C") elif B == 1 and C == 1 and A == 0: if S[i + 1] == "AB": B += 1 C -= 1 result.append("B") else: B -= 1 C += 1 result.append("C") elif B > C: B -= 1 C += 1 result.append("C") else: B += 1 C -= 1 result.append("B") if kekka == False: print("No") else: print("Yes") for i in range(len(result)): print(result[i])
Statement You are the top spy of AtCoder Kingdom. To prevent the stolen secret from being handed to AlDebaran Kingdom, you have sneaked into the party where the transaction happens. There are N attendees in the party, and they are given attendee numbers from 1 through N. The height of Attendee i is A_i. According to an examination beforehand, you know that a pair of attendees satisfying the condition below will make the transaction. * The absolute difference of their attendee numbers is equal to the sum of their heights. There are \frac{N(N-1)}{2} ways to choose two from the N attendees and make a pair. Among them, how many satisfy the condition above? P.S.: We cannot let you know the secret.
[{"input": "6\n 2 3 3 1 3 1", "output": "3\n \n\n * A_1 + A_4 = 3, so the pair of Attendee 1 and 4 satisfy the condition.\n * A_2 + A_6 = 4, so the pair of Attendee 2 and 6 satisfy the condition.\n * A_4 + A_6 = 2, so the pair of Attendee 4 and 6 satisfy the condition.\n\nNo other pair satisfies the condition, so you should print 3.\n\n* * *"}, {"input": "6\n 5 2 4 2 8 8", "output": "0\n \n\nNo pair satisfies the condition, so you should print 0.\n\n* * *"}, {"input": "32\n 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5", "output": "22"}]
Output the number of points where the wire intersects with the panel boundaries.
s666453226
Wrong Answer
p00356
The input is given in the following format. x y A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
x, y = map(int, input().split()) if x == y: print(x + 1) else: print(min(x, y) + 1 + abs(x - y) * 2)
Wire I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wire) Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels) Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
[{"input": "4 4", "output": "5"}, {"input": "4 6", "output": "9"}]
Output the number of points where the wire intersects with the panel boundaries.
s178975226
Accepted
p00356
The input is given in the following format. x y A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
import math x, y = list(map(int, input().split())) print(x + y - math.gcd(x, y) + 1)
Wire I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wire) Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels) Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
[{"input": "4 4", "output": "5"}, {"input": "4 6", "output": "9"}]
Output the number of points where the wire intersects with the panel boundaries.
s800984755
Accepted
p00356
The input is given in the following format. x y A line of data is given that contains the integer number of panels in the horizontal direction x (1 ≤ x ≤ 1000) and those in the vertical direction y (1 ≤ y ≤ 1000).
def GCD(M, N): while True: if N < M: N, M = M, N amari = N % M if amari == 0: break else: N, M = M, amari return M x, y = map(int, input().split()) gcd = GCD(x, y) x = x / gcd y = y / gcd print(int(x - 1 + y - 1 + 1) * gcd + 1)
Wire I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the panels. The customer asked me to stretch a wire from the left top corner of the wall to the right bottom corner whereby the wire is tied up at the crossing points with the panel boundaries (edges and vertexes) as shown in the figure. There are nine tied-up points in the illustrative figure shown below. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wire) Fig: The wire is tied up at the edges and vertexes of the panels (X: 4 panels, Y: 6 panels) Write a program to provide the number of points where the wire intersects with the panel boundaries. Assume that the wire and boundary lines have no thickness.
[{"input": "4 4", "output": "5"}, {"input": "4 6", "output": "9"}]
For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.
s533947681
Runtime Error
p00706
The input consists of multiple data sets. Each data set is given in the following format. > _N_ > _W_` `_H_ > _x_ 1` `_y_ 1 > _x_ 2` `_y_ 2 > ... > _x_ _N_` `_y_ _N_ > _S_` `_T_ > _N_ is the number of persimmon trees, which is a positive integer less than 500. _W_ and _H_ are the width and the height of the entire field respectively. You can assume that both _W_ and _H_ are positive integers whose values are less than 100. For each _i_ (1 <= _i_ <= _N_), _x_ _i_ and _y_ _i_ are coordinates of the _i_ -th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= _x_ _i_ <= _W_ and 1 <= _y_ _i_ <= _H_ , and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, _S_ and _T_ are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= _S_ <= _W_ and 1 <= _T_ <= _H_. The end of the input is indicated by a line that solely contains a zero.
with open("input1(1).txt") as files: trial = int(files.readline()) while True: area = [int(n) for n in files.readline().split(" ")] trees = [] for t in range(trial): trees.append([int(n) for n in files.readline().split(" ")]) cnt, answer = 0, 0 trees = sorted(trees, key=lambda x: (x[0], x[1])) building = [int(n) for n in files.readline().split(" ")] for x in range(1, area[0] - building[0] + 2): for y in range(1, area[1] - building[1] + 2): cnt = 0 for tree in trees: if ( x <= tree[0] < x + building[0] and y <= tree[1] < y + building[1] ): # print(tree,x,y) cnt += 1 elif x + building[0] < tree[0] and y + building[1] < tree[1]: if answer < cnt: answer = cnt break else: print("") if answer < cnt: answer = cnt else: print(answer) trial = int(files.readline()) if trial == 0: break
Get Many Persimmon Trees Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord. For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1\. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trees) --- Figure 1: Examples of Rectangular Estates Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
[{"input": "10 8\n 2 2\n 2 5\n 2 7\n 3 3\n 3 8\n 4 2\n 4 5\n 4 8\n 6 4\n 6 7\n 7 5\n 7 8\n 8 1\n 8 4\n 9 6\n 10 3\n 4 3\n 8\n 6 4\n 1 2\n 2 1\n 2 4\n 3 4\n 4 2\n 5 3\n 6 1\n 6 2\n 3 2\n 0", "output": "3"}]
For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.
s592788340
Runtime Error
p00706
The input consists of multiple data sets. Each data set is given in the following format. > _N_ > _W_` `_H_ > _x_ 1` `_y_ 1 > _x_ 2` `_y_ 2 > ... > _x_ _N_` `_y_ _N_ > _S_` `_T_ > _N_ is the number of persimmon trees, which is a positive integer less than 500. _W_ and _H_ are the width and the height of the entire field respectively. You can assume that both _W_ and _H_ are positive integers whose values are less than 100. For each _i_ (1 <= _i_ <= _N_), _x_ _i_ and _y_ _i_ are coordinates of the _i_ -th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= _x_ _i_ <= _W_ and 1 <= _y_ _i_ <= _H_ , and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, _S_ and _T_ are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= _S_ <= _W_ and 1 <= _T_ <= _H_. The end of the input is indicated by a line that solely contains a zero.
trial = int(input()) while True: area = [int(n) for n in input().split(" ")] trees = [] for t in range(trial): trees.append(int(n) for n in input().split(" ")) cnt, answer = 0, 0 trees = sorted(trees, key=lambda x: (x[0], x[1])) building = [int(n) for n in input().split(" ")] for x in range(1, 1 + area[0] - building[0]): for y in range(1, 1 + area[1] - building[1]): cnt = 0 for tree in trees: if x <= tree[0] <= x + building[0] and y <= tree[1] <= y + building[1]: cnt += 1 elif x + building[0] < tree[0] and y + building[1] < tree[1]: if answer < cnt: answer = cnt break else: if answer < cnt: answer = cnt else: print(answer) trial = int(input()) if trial == 0: break
Get Many Persimmon Trees Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord. For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1\. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_trees) --- Figure 1: Examples of Rectangular Estates Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.
[{"input": "10 8\n 2 2\n 2 5\n 2 7\n 3 3\n 3 8\n 4 2\n 4 5\n 4 8\n 6 4\n 6 7\n 7 5\n 7 8\n 8 1\n 8 4\n 9 6\n 10 3\n 4 3\n 8\n 6 4\n 1 2\n 2 1\n 2 4\n 3 4\n 4 2\n 5 3\n 6 1\n 6 2\n 3 2\n 0", "output": "3"}]