message
stringlengths
2
48.6k
message_type
stringclasses
2 values
message_id
int64
0
1
conversation_id
int64
318
108k
cluster
float64
8
8
__index_level_0__
int64
636
217k
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,534
8
169,068
Tags: implementation, sortings Correct Solution: ``` n, m = list(map(int, input().split())) fff = 1 if m == 0: print("YES") fff = 0 if fff : A = list(map(int, input().split())) A.sort() cur = 0 flag = 1 if A[-1] == n: print("NO") flag = 0 if 1 in A and flag: print("NO") flag = 0 for i in range(m-1): if A[i+1]-A[i] == 1 and flag: cur += 1 if cur >= 2: print("NO") flag = 0 break else: cur = 0 if flag: print("YES") ```
output
1
84,534
8
169,069
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,535
8
169,070
Tags: implementation, sortings Correct Solution: ``` #!/usr/bin/env python import os import sys from io import BytesIO, IOBase #from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) def main(): n,m=map(int,input().split(" ")) if m==0: print("YES") return a=list(set(list(map(int,input().split(" "))))) if m==1 and n==1 or 1 in a or n in a: print("NO") return if m<2 and n>2: print("YES") return a.sort() n=len(a) cnt=0 for x in range(1,n): if a[x]-a[x-1]==1: cnt+=1 if cnt>=2: print("NO") return else: cnt=0 print("YES") #-----------------------------BOSS-------------------------------------! # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": main() ```
output
1
84,535
8
169,071
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,536
8
169,072
Tags: implementation, sortings Correct Solution: ``` n, m = map(int,input().split()) if m >= 1: gr = list(map(int, input().split())) gr.sort() k = 1 if (m >= 1 and gr[0] == 1) or (m >= 1 and gr[m-1]) == n: print('NO') else: for i in range(m-2): if gr[i] == gr[i+1] - 1 == gr[i+2] - 2: print('NO') k = 0 break if k == 1: print('YES') ```
output
1
84,536
8
169,073
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,537
8
169,074
Tags: implementation, sortings Correct Solution: ``` a,b=map(int,input().split()) if b>0: l=list(map(int,input().split())) l.sort() if l[0]==1 or l[-1]==a: print("NO") exit(0) for i in range (b-2): if l[i]+1==l[i+1] and l[i+1]+1==l[i+2]: print("NO") exit(0) print("YES") else: print("YES") ```
output
1
84,537
8
169,075
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,538
8
169,076
Tags: implementation, sortings Correct Solution: ``` #!/usr/bin/python3 def readln(): return tuple(map(int, input().split())) n, m = readln() d = sorted(readln()) if m else [] if m and (d[0] == 1 or d[-1] == n) or m > 2 and [1 for i, j, k in zip(d[:-2], d[1:-1], d[2:]) if i + 2 == k]: print('NO') else: print('YES') ```
output
1
84,538
8
169,077
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,539
8
169,078
Tags: implementation, sortings Correct Solution: ``` def bin(arr, n): l = 0 r = len(arr) - 1 while l <= r: m = (l + r) // 2 if arr[m] == n: return True elif arr[m] < n: l = m + 1 else: r = m - 1 return False n, m = [int(i) for i in input().strip().split()] if m == 0: print('YES') else: arr = [int(i) for i in input().strip().split()] arr.sort() if arr[0] == 1 or arr[-1] == n: print('NO') else: b = True for i in arr: if bin(arr, i+1) and bin(arr, i+2): print('NO') b = False break if b: print('YES') ```
output
1
84,539
8
169,079
Provide tags and a correct Python 3 solution for this coding contest problem. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES
instruction
0
84,540
8
169,080
Tags: implementation, sortings Correct Solution: ``` import sys def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) mod = int(1e9)+7 n, m = rinput() d = get_list() if (1 in d or n in d): print("NO") else: d.sort() flag = 0 for i in range(m-2): if (d[i+2]==d[i+1]+1 and d[i+1]==d[i]+1): flag = 1 break if flag == 0: print("YES") else: print("NO") ```
output
1
84,540
8
169,081
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` n, m = [int(x) for x in input().split()] if m: l = sorted([int(x) for x in input().split()]) else: l = [] if len(l) and (l[0] == 1 or l[-1] == n): print('NO') exit() for i in range(m - 2): if l[i + 2] == l[i + 1] + 1 and l[i + 1] == l[i] + 1: print('NO') break else: print('YES') ```
instruction
0
84,541
8
169,082
Yes
output
1
84,541
8
169,083
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` import sys inf = float("inf") # sys.setrecursionlimit(10000000) # abc='abcdefghijklmnopqrstuvwxyz' # abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod, MOD = 1000000007, 998244353 # vow=['a','e','i','o','u'] # dx,dy=[-1,1,0,0],[0,0,1,-1] # import random from collections import deque, Counter, OrderedDict,defaultdict # from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace # from math import ceil,floor,log,sqrt,factorial # from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n,m = get_ints() if m==0: print('YES') exit() Arr = get_array() Arr.sort() if Arr[0]==1 or Arr[-1]==n: print('NO') exit() flag = 0 for i in range(len(Arr)-2): if Arr[i+1]==Arr[i]+1 and Arr[i+2]==Arr[i]+2: flag = 1 break if flag==0: print('YES') else: print('NO') ```
instruction
0
84,542
8
169,084
Yes
output
1
84,542
8
169,085
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` n,m=map(int,input().split()) if(m==0):print("YES") else: c=[int(x) for x in input().split()] w=sorted(c) if(1 in c or n in c): print("NO") exit() elif(m==1 and (c[0]!=1 or c[0]!=n)):print("YES") elif(m==2 and (1 not in c or m not in c) ):print("YES") elif(1 in c or n in c): print("NO") exit() elif(m==0):print("YES") else: cn=0 for k in range(m-2): if(abs(w[k]-w[k+2])<=2): print("NO") exit() else: cn=cn+1 if(cn>0):print("YES") ```
instruction
0
84,543
8
169,086
Yes
output
1
84,543
8
169,087
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` n,m=map(int,input().split()) if m==0: print("YES") else: l=list(map(int,input().split())) f=1 i=1 l.sort() #print(l) prev=0 if 1 in l or n in l: f=0 if f==1: for i in range(1,m): z=l[i]-l[i-1] if z==prev==1: f=0 break else: prev=z #print(z) if f==1: print("YES") else: print("NO") ```
instruction
0
84,544
8
169,088
Yes
output
1
84,544
8
169,089
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` n, m = map(int, input().split()) d = list(map(int, input().split())) d.sort() i = 0 while i < n - 2: if i in d: if i + 1 in d: if i + 2 in d: print('NO') exit() i += 1 print('YES') ```
instruction
0
84,545
8
169,090
No
output
1
84,545
8
169,091
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` n , k = map(int,input().split()) l = list(map(int,input().split())) l.sort() f = True for i in range(k - 2 ): if abs(l[i] - l[i+1]) == 1 and abs(l[i+1] - l[i+2]) == 1 : f = False break if f : print('YES') else: print('NO') ```
instruction
0
84,546
8
169,092
No
output
1
84,546
8
169,093
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` l,d=map(int,input().split()) x=sorted(list(map(int,input().split()))) if x[0]==1 or x[-1]==l: print('NO') quit() else: if d==1: print('YES') quit() elif d==2: print('YES') quit() else: for i in range(2,d): if x[i]==x[i-1]+1 and x[i]==x[i-1]+2: print('NO') quit() print('YES') ```
instruction
0
84,547
8
169,094
No
output
1
84,547
8
169,095
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little boy Petya loves stairs very much. But he is bored from simple going up and down them β€” he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of n stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number n without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input The first line contains two integers n and m (1 ≀ n ≀ 109, 0 ≀ m ≀ 3000) β€” the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains m different space-separated integers d1, d2, ..., dm (1 ≀ di ≀ n) β€” the numbers of the dirty stairs (in an arbitrary order). Output Print "YES" if Petya can reach stair number n, stepping only on the clean stairs. Otherwise print "NO". Examples Input 10 5 2 4 8 3 6 Output NO Input 10 5 2 4 5 7 9 Output YES Submitted Solution: ``` from re import split num = input() num = split(r"\s" , num) inp = input() inp = split(r"\s" , inp) inp.sort() i = 0 temp = False m = int(num[0]) n = int(num[1]) while i+1 < m: if int(inp[i+1]) - int(inp[i]) == 1: temp = True break i += 1 if temp or inp[0] == '1' or int(inp[m-1]) == n: print("NO") else: print("YES") ```
instruction
0
84,548
8
169,096
No
output
1
84,548
8
169,097
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,611
8
169,222
Tags: data structures Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) top = max(a) stack = [[10 ** 9 + 1, 1]] ans = 0 for i in range(n): while a[i] > stack[-1][0]: stack.pop() if a[i] < stack[-1][0]: stack.append([a[i], 1]) else: stack[-1][1] += 1 for i in range(n): cnt = 0 while a[i] > stack[-1][0]: cnt += stack[-1][1] stack.pop() if a[i] < stack[-1][0]: cnt += 1 stack.append([a[i], 1]) else: if a[i] < top: cnt += stack[-1][1] if stack[-2][1] != 0: cnt += 1 stack[-1][1] += 1 ans += cnt topcnt = a.count(top) ans += topcnt * (topcnt - 1) // 2 if topcnt == 1: second = max(a, key=lambda x: (x != top) * x) seccnt = a.count(second) ans -= seccnt print(ans) ```
output
1
84,611
8
169,223
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,612
8
169,224
Tags: data structures Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) max_idx = a.index(max(a)) b = a[max_idx:] b.extend(a[:max_idx]) b.append(a[max_idx]) left = [0] * (n + 1) right = [n] * (n + 1) cnt = [0] * (n + 1) for i in range(1, n): idx = i - 1 while b[idx] <= b[i] and idx > 0: idx = left[idx] left[i] = idx for i in range(n - 1, 0, -1): idx = i + 1 while b[idx] <= b[i] and idx < n: if b[idx] == b[i] and idx < n: cnt[i] = cnt[idx] + 1 idx = right[idx] right[i] = idx res = 0 for i in range(1, n): if left[i] == 0 and right[i] == n: res += 1 else: res += 2 res += cnt[i] print(res) ```
output
1
84,612
8
169,225
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,613
8
169,226
Tags: data structures Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) max_idx = 0 for i in range(1, n): if arr[i] >= arr[max_idx]: max_idx = i arr2 = arr[max_idx:] arr2.extend(arr[0:max_idx]) dp_left = [-1 for i in range(0, n)] for i in range(1, n): prev = i - 1 while prev >= 0 and arr2[prev] <= arr2[i]: prev = dp_left[prev] dp_left[i] = prev dp_right = [0 for i in range(0, n)] dp_right[0] = -1 for i in range(n - 1, 0, -1): prev = i + 1 if prev == n: prev = 0 while prev >= 0 and arr2[prev] <= arr2[i]: prev = dp_right[prev] dp_right[i] = prev dp_same = [0 for i in range(0, n)] for i in range(0, n): prev = i - 1 while prev >= 0 and arr2[prev] < arr2[i]: prev = dp_left[prev] if prev >= 0 and arr2[prev] == arr2[i]: dp_same[i] = dp_same[prev] + 1 res = 0 for i in range(0, n): if dp_left[i] == dp_right[i] and dp_left[i] >= 0: res += 1 else: if dp_left[i] >= 0: res += 1 if dp_right[i] >= 0: res += 1 res += dp_same[i] print(res) ```
output
1
84,613
8
169,227
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,615
8
169,230
Tags: data structures Correct Solution: ``` n = int(input()) a = tuple(map(int, input().split())) b = 0 c, at = max((h, k) for k, h in enumerate(a)) last = c count = 0 d = list() e = d.append f = d.pop for at in range(at - 1, at - n, -1): current = a[at] while current > last: b += count last, count = f() if current == last: count += 1 b += count else: b += 1 e((last, count)) last = current count = 1 e((last, count)) end = len(d) b += sum(d[k][1] for k in range((1 if d[0][1] else 2), end)) print(b) ```
output
1
84,615
8
169,231
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,616
8
169,232
Tags: data structures Correct Solution: ``` n = int(input()) hill = tuple(map(int, input().split())) pairs = 0 highest, at = max((h, k) for k, h in enumerate(hill)) last = highest count = 0 p = list() push = p.append pop = p.pop for at in range(at - 1, at - n, -1): current = hill[at] while current > last: pairs += count last, count = pop() if current == last: count += 1 pairs += count else: pairs += 1 push((last, count)) last = current count = 1 push((last, count)) end = len(p) pairs += sum(p[k][1] for k in range((1 if p[0][1] else 2), end)) print(pairs) ```
output
1
84,616
8
169,233
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,617
8
169,234
Tags: data structures Correct Solution: ``` n = int(input()) arr = list(map(int, input().split())) max_idx = 0 for i in range(1, n): if arr[i] >= arr[max_idx]: max_idx = i arr2 = arr[max_idx:] arr2.extend(arr[0:max_idx]) # print(arr2) # for i in range(max_idx, n): # arr2.append(arr[i]) # for i in range(0, max_idx): # arr2.append(arr[i]) dp_left = [-1 for i in range(0, n)] for i in range(1, n): prev = i - 1 while prev >= 0 and arr2[prev] <= arr2[i]: prev = dp_left[prev] dp_left[i] = prev dp_right = [0 for i in range(0, n)] dp_right[0] = -1 # dp_right[n - 1] = 0 for i in range(n - 1, 0, -1): prev = i + 1 if prev == n: prev = 0 while prev >= 0 and arr2[prev] <= arr2[i]: prev = dp_right[prev] dp_right[i] = prev dp_same = [0 for i in range(0, n)] for i in range(0, n): prev = i - 1 while prev >= 0 and arr2[prev] < arr2[i]: prev = dp_left[prev] if prev >= 0 and arr2[prev] == arr2[i]: dp_same[i] = dp_same[prev] + 1 # print(arr2) # print(dp_left) # print(dp_right) # print(dp_same) res = 0 for i in range(0, n): if dp_left[i] == dp_right[i] and dp_left[i] >= 0: res += 1 else: if dp_left[i] >= 0: res += 1 if dp_right[i] >= 0: res += 1 res += dp_same[i] print(res) ```
output
1
84,617
8
169,235
Provide tags and a correct Python 3 solution for this coding contest problem. Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night. In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other. An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills. Input The first line of the input data contains an integer number n (3 ≀ n ≀ 106), n β€” the amount of hills around the capital. The second line contains n numbers β€” heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109. Output Print the required amount of pairs. Examples Input 5 1 2 4 5 3 Output 7
instruction
0
84,618
8
169,236
Tags: data structures Correct Solution: ``` n = int(input()) a = list(map(int, input().split())) top = max(a) stack = [[10 ** 9 + 1, 0, -1]] ans = 0 for i in range(n): while a[i] > stack[-1][0]: stack.pop() if a[i] < stack[-1][0]: stack.append([a[i], 1, i, i]) else: stack[-1][1] += 1 stack[-1][3] = i for i in range(n): #print(stack) cnt = 0 while a[i] > stack[-1][0]: cnt += stack[-1][1] #if (i - stack[-1][2]) % n == n - 1: # cnt -= 1 stack.pop() if a[i] < stack[-1][0]: #if (i - stack[-1][3]) % n != n - 1: cnt += 1 stack.append([a[i], 1, i, i]) else: if a[i] < top: cnt += stack[-1][1] if stack[-2][1] != 0:# and (i - stack[-2][3]) % n != n - 1: cnt += 1 stack[-1][1] += 1 stack[-1][3] = i ans += cnt #print(a[i], cnt) topcnt = a.count(top) ans += topcnt * (topcnt - 1) // 2 if topcnt == 1: second = max(a, key=lambda x: (x != top) * x) seccnt = a.count(second) ans -= seccnt print(ans) ```
output
1
84,618
8
169,237
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days). Bears love drinking juice. They don't like wine but they can't distinguish it from juice by taste or smell. A bear doesn't sleep unless he drinks wine. A bear must go to sleep a few hours after drinking a wine. He will wake up many days after the party is over. Radewoosh is the owner of the inn. He wants to put some number of barrels in front of bears. One barrel will contain wine and all other ones will contain juice. Radewoosh will challenge bears to find a barrel with wine. Each night, the following happens in this exact order: 1. Each bear must choose a (maybe empty) set of barrels. The same barrel may be chosen by many bears. 2. Each bear drinks a glass from each barrel he chose. 3. All bears who drink wine go to sleep (exactly those bears who chose a barrel with wine). They will wake up many days after the party is over. If there are not enough places to sleep then bears lose immediately. At the end, if it's sure where wine is and there is at least one awake bear then bears win (unless they have lost before because of the number of places to sleep). Radewoosh wants to allow bears to win. He considers q scenarios. In the i-th scenario the party will last for i nights. Then, let Ri denote the maximum number of barrels for which bears surely win if they behave optimally. Let's define <image>. Your task is to find <image>, where <image> denotes the exclusive or (also denoted as XOR). Note that the same barrel may be chosen by many bears and all of them will go to sleep at once. Input The only line of the input contains three integers n, p and q (1 ≀ n ≀ 109, 1 ≀ p ≀ 130, 1 ≀ q ≀ 2 000 000) β€” the number of bears, the number of places to sleep and the number of scenarios, respectively. Output Print one integer, equal to <image>. Examples Input 5 1 3 Output 32 Input 1 100 4 Output 4 Input 3 2 1 Output 7 Input 100 100 100 Output 381863924 Note In the first sample, there are 5 bears and only 1 place to sleep. We have R1 = 6, R2 = 11, R3 = 16 so the answer is <image>. Let's analyze the optimal strategy for scenario with 2 days. There are R2 = 11 barrels and 10 of them contain juice. * In the first night, the i-th bear chooses a barrel i only. * If one of the first 5 barrels contains wine then one bear goes to sleep. Then, bears win because they know where wine is and there is at least one awake bear. * But let's say none of the first 5 barrels contains wine. In the second night, the i-th bear chooses a barrel 5 + i. * If one of barrels 6 – 10 contains wine then one bear goes to sleep. And again, bears win in such a situation. * If nobody went to sleep then wine is in a barrel 11. In the second sample, there is only one bear. He should choose an empty set of barrels in each night. Otherwise, he would maybe get wine and bears would lose (because there must be at least one awake bear). So, for any number of days we have Ri = 1. The answer is <image>. Submitted Solution: ``` print(1373452814) ```
instruction
0
84,643
8
169,286
No
output
1
84,643
8
169,287
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days). Bears love drinking juice. They don't like wine but they can't distinguish it from juice by taste or smell. A bear doesn't sleep unless he drinks wine. A bear must go to sleep a few hours after drinking a wine. He will wake up many days after the party is over. Radewoosh is the owner of the inn. He wants to put some number of barrels in front of bears. One barrel will contain wine and all other ones will contain juice. Radewoosh will challenge bears to find a barrel with wine. Each night, the following happens in this exact order: 1. Each bear must choose a (maybe empty) set of barrels. The same barrel may be chosen by many bears. 2. Each bear drinks a glass from each barrel he chose. 3. All bears who drink wine go to sleep (exactly those bears who chose a barrel with wine). They will wake up many days after the party is over. If there are not enough places to sleep then bears lose immediately. At the end, if it's sure where wine is and there is at least one awake bear then bears win (unless they have lost before because of the number of places to sleep). Radewoosh wants to allow bears to win. He considers q scenarios. In the i-th scenario the party will last for i nights. Then, let Ri denote the maximum number of barrels for which bears surely win if they behave optimally. Let's define <image>. Your task is to find <image>, where <image> denotes the exclusive or (also denoted as XOR). Note that the same barrel may be chosen by many bears and all of them will go to sleep at once. Input The only line of the input contains three integers n, p and q (1 ≀ n ≀ 109, 1 ≀ p ≀ 130, 1 ≀ q ≀ 2 000 000) β€” the number of bears, the number of places to sleep and the number of scenarios, respectively. Output Print one integer, equal to <image>. Examples Input 5 1 3 Output 32 Input 1 100 4 Output 4 Input 3 2 1 Output 7 Input 100 100 100 Output 381863924 Note In the first sample, there are 5 bears and only 1 place to sleep. We have R1 = 6, R2 = 11, R3 = 16 so the answer is <image>. Let's analyze the optimal strategy for scenario with 2 days. There are R2 = 11 barrels and 10 of them contain juice. * In the first night, the i-th bear chooses a barrel i only. * If one of the first 5 barrels contains wine then one bear goes to sleep. Then, bears win because they know where wine is and there is at least one awake bear. * But let's say none of the first 5 barrels contains wine. In the second night, the i-th bear chooses a barrel 5 + i. * If one of barrels 6 – 10 contains wine then one bear goes to sleep. And again, bears win in such a situation. * If nobody went to sleep then wine is in a barrel 11. In the second sample, there is only one bear. He should choose an empty set of barrels in each night. Otherwise, he would maybe get wine and bears would lose (because there must be at least one awake bear). So, for any number of days we have Ri = 1. The answer is <image>. Submitted Solution: ``` mod=2<<32 def C(m,n): tmp=1 for i in range(m-n+1,m+1): tmp=tmp*i pass for i in range(1,n+1): tmp=tmp//i pass return tmp%mod pass n,p,r=map(int,input().split()) ans=0 for i in range(1,r+1): tot=0 for j in range(0,min(n-1,p)+1): tot=(tot+C(n,j)*(i**j)%mod)%mod; ans=((tot*i)%mod)^ans pass print(ans) ```
instruction
0
84,644
8
169,288
No
output
1
84,644
8
169,289
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. There are n bears in the inn and p places to sleep. Bears will party together for some number of nights (and days). Bears love drinking juice. They don't like wine but they can't distinguish it from juice by taste or smell. A bear doesn't sleep unless he drinks wine. A bear must go to sleep a few hours after drinking a wine. He will wake up many days after the party is over. Radewoosh is the owner of the inn. He wants to put some number of barrels in front of bears. One barrel will contain wine and all other ones will contain juice. Radewoosh will challenge bears to find a barrel with wine. Each night, the following happens in this exact order: 1. Each bear must choose a (maybe empty) set of barrels. The same barrel may be chosen by many bears. 2. Each bear drinks a glass from each barrel he chose. 3. All bears who drink wine go to sleep (exactly those bears who chose a barrel with wine). They will wake up many days after the party is over. If there are not enough places to sleep then bears lose immediately. At the end, if it's sure where wine is and there is at least one awake bear then bears win (unless they have lost before because of the number of places to sleep). Radewoosh wants to allow bears to win. He considers q scenarios. In the i-th scenario the party will last for i nights. Then, let Ri denote the maximum number of barrels for which bears surely win if they behave optimally. Let's define <image>. Your task is to find <image>, where <image> denotes the exclusive or (also denoted as XOR). Note that the same barrel may be chosen by many bears and all of them will go to sleep at once. Input The only line of the input contains three integers n, p and q (1 ≀ n ≀ 109, 1 ≀ p ≀ 130, 1 ≀ q ≀ 2 000 000) β€” the number of bears, the number of places to sleep and the number of scenarios, respectively. Output Print one integer, equal to <image>. Examples Input 5 1 3 Output 32 Input 1 100 4 Output 4 Input 3 2 1 Output 7 Input 100 100 100 Output 381863924 Note In the first sample, there are 5 bears and only 1 place to sleep. We have R1 = 6, R2 = 11, R3 = 16 so the answer is <image>. Let's analyze the optimal strategy for scenario with 2 days. There are R2 = 11 barrels and 10 of them contain juice. * In the first night, the i-th bear chooses a barrel i only. * If one of the first 5 barrels contains wine then one bear goes to sleep. Then, bears win because they know where wine is and there is at least one awake bear. * But let's say none of the first 5 barrels contains wine. In the second night, the i-th bear chooses a barrel 5 + i. * If one of barrels 6 – 10 contains wine then one bear goes to sleep. And again, bears win in such a situation. * If nobody went to sleep then wine is in a barrel 11. In the second sample, there is only one bear. He should choose an empty set of barrels in each night. Otherwise, he would maybe get wine and bears would lose (because there must be at least one awake bear). So, for any number of days we have Ri = 1. The answer is <image>. Submitted Solution: ``` MAX_P = 140 MD = (1 << 33) - 1 n, p, q = map(int, input().split()) n_prod = [1 for i in range(MAX_P)] for i in range(1, MAX_P): n_prod[i] = n_prod[i-1] * (n - i + 1) fact = [max(i,1) for i in range(0, MAX_P+1)] for i in range(1, MAX_P+1): fact[i] *= fact[i-1] def calc_ncr(r:int) -> int: return (n_prod[r] // fact[r]) & MD ncr = [calc_ncr(i) for i in range(MAX_P)] x = 0 m = min(p, n-1) for i in range(1, q+1): s = 0 pw = 1 for j in range(0, m+1): s += ncr[j] * pw pw = (pw * i) & MD x ^= (i*s) & MD print(x) ```
instruction
0
84,645
8
169,290
No
output
1
84,645
8
169,291
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people. Input The first line contains three space-separated integers, n, x, y (1 ≀ n, x, y ≀ 104, x ≀ n) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n). Output Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population). Examples Input 10 1 14 Output 1 Input 20 10 50 Output 0 Input 1000 352 146 Output 1108 Note In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. Submitted Solution: ``` # Description of the problem can be found at http://codeforces.com/problemset/problem/168/A import math n, x, y = map(int, input().split()) print(max(0, math.ceil((n * y) / 100) - x)) ```
instruction
0
85,982
8
171,964
Yes
output
1
85,982
8
171,965
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,102
8
172,204
Tags: dp, greedy Correct Solution: ``` n = int(input()) a = [list(map(int, input().split())) for i in range(n)] k = 2 for i in range(1, n - 1): x, h = a[i] if x - h > a[i-1][0]: k += 1 elif x + h < a[i+1][0]: k += 1 a[i][0] += h if n == 1: print(1) else: print(k) ```
output
1
86,102
8
172,205
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,103
8
172,206
Tags: dp, greedy Correct Solution: ``` # author : prottoyfuad # 30.09.2020 04:17:01(+0600) import sys, math, time start_time = time.time() def read() : return( int(input()) ) def read_args() : return( map(int, input().split()) ) def read_array() : return( list( map(int, input().split()) ) ) def read_string() : return( input().strip() ) def hocus_pocus() : n = read() a = [0] * n h = [0] * n for i in range(n) : a[i], h[i] = read_args() ans = min(n, 2) for i in range(1, n - 1) : if a[i] - h[i] > a[i - 1] : ans += 1 elif a[i] + h[i] < a[i + 1] : ans += 1 a[i] += h[i] print(ans) if __debug__ : input = sys.stdin.readline else : sys.stdin = open("D:\pro_code\py\in.txt","r"); sys.stdout = open("D:\pro_code\py\out.txt","w"); global tc tt = 1 # tt = read() for tc in range(tt) : hocus_pocus() if not __debug__ : print("Time elapsed :", time.time() - start_time, "seconds") sys.stdout.close() ```
output
1
86,103
8
172,207
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,104
8
172,208
Tags: dp, greedy Correct Solution: ``` a=2 n=int(input()) l=[] for _ in range(n): x,h=map(int,input().split()) l.append([x,h]) if n<3:print(n);exit() t=l[0][0] for i in range(1,n-1): x,h=l[i][0],l[i][1] if x-h>t: a+=1;t=x elif x+h<l[i+1][0]: a+=1;t=x+h else: t=x print(a) ```
output
1
86,104
8
172,209
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,105
8
172,210
Tags: dp, greedy Correct Solution: ``` n = int(input()) x = [0] * (n + 1) h = [0] * (n + 1) for i in range(n): x[i], h[i] = (int(c) for c in input().split()) h[n] = 1 x[n] = x[n-1] + h[n-1] + 1 if n == 1: print(1) exit(0) left = [0] * n right = [0] * n left[0] = 1 if x[0] + h[0] < x[1]: right[0] = 1 for i in range(1, n): if x[i] + h[i] < x[i + 1]: right[i] = max(right[i-1], left[i-1]) + 1 else: right[i] = max(right[i-1], left[i-1]) if x[i] - h[i] > x[i-1] + h[i-1]: left[i] = max(right[i-1], left[i-1]) + 1 elif x[i] - h[i] > x[i-1]: left[i] = left[i-1] + 1 else: left[i] = max(right[i-1], left[i-1]) print(max(left[n-1], right[n-1])) ```
output
1
86,105
8
172,211
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,106
8
172,212
Tags: dp, greedy Correct Solution: ``` import sys input = sys.stdin.readline n = int(input()) arr = [list(map(int, input().split())) for _ in range(n)] if n <= 2: print(n) else: ans = 0 for i in range(1,n-1): if arr[i][0] - arr[i][1] > arr[i-1][0]: ans +=1 elif arr[i][0] + arr[i][1] < arr[i+1][0]: ans +=1 arr[i][0] += arr[i][1] print(ans+2) ```
output
1
86,106
8
172,213
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,107
8
172,214
Tags: dp, greedy Correct Solution: ``` n = int(input()) h = [] x = [] for i in range(n): a, b = map(int, input().split()) x.append(a) h.append(b) last = x[0] t = 1 for i in range(1, n - 1): if last < x[i] - h[i]: t += 1 last = x[i] elif x[i] + h[i] < x[i + 1]: t += 1 last = x[i] + h[i] else: last = x[i] if n > 1: t += 1 print(t) ```
output
1
86,107
8
172,215
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,108
8
172,216
Tags: dp, greedy Correct Solution: ``` n = int(input()) p = n x = [] h = [] while(p>0): p = p-1 a,b = map(int,input().split()) x.append(a) h.append(b) c = 0 table = [0]*(n) table[0] = -1 table[n-1] = 1 for i in range(1,n-1): if table[i-1] == -1: if x[i]-x[i-1]>h[i]: table[i] = -1 c = c+1 else: if x[i+1]-x[i]>h[i]: table[i] = 1 c = c+1 elif table[i-1] == 0: if x[i]-x[i-1] >h[i]: table[i] = -1 c = c+1 else: if x[i+1]-x[i]>h[i]: c = c+1 table[i] = 1 else: if x[i]-x[i-1]-h[i-1]>h[i]: table[i] = -1 c = c+1 else: if x[i+1]-x[i]>h[i]: table[i] = 1 c = c+1 if n<2: print(1) else: print(c+2) ```
output
1
86,108
8
172,217
Provide tags and a correct Python 3 solution for this coding contest problem. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
instruction
0
86,109
8
172,218
Tags: dp, greedy Correct Solution: ``` n=int(input()) a=[] for i in range(n): x,h=map(int,input().split()) a.append([x,h]) num=1 i=1 while i<n-1: if a[i][1]<a[i][0]-a[i-1][0]: num+=1 else: if a[i][1]<a[i+1][0]-a[i][0]: num+=1 a[i][0]+=a[i][1] i+=1 if n>=2: num+=1 print(num) ```
output
1
86,109
8
172,219
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` n = int(input()) arr = [list(map(int, input().split())) for _ in range(n)] count = 1 for i in range(1, n-1): x = arr[i][0] - arr[i][1] y = arr[i][0] + arr[i][1] if x > arr[i-1][0]: count += 1 elif y < arr[i+1][0]: count += 1 arr[i][0] += arr[i][1] print(count + 1 if n > 1 else 1) ```
instruction
0
86,110
8
172,220
Yes
output
1
86,110
8
172,221
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` from sys import stdin N = int(stdin.readline().rstrip()) trees = [None for n in range(N)] for n in range(N): trees[n] = [int(x) for x in stdin.readline().rstrip().split()] start = -1000000000 count = 1 for n in range(N - 1): tree = trees[n] if tree[0] - tree[1] > start: count += 1 start = tree[0] elif tree[0] + tree[1] < trees[n+1][0]: count += 1 start = tree[0] + tree[1] else: start = tree[0] print(count) ```
instruction
0
86,111
8
172,222
Yes
output
1
86,111
8
172,223
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` t = int(input()) l = [[int(x) for x in input().split()]for i in range(t)] if t >= 3: count = 2 end = l[0][0] begin = l[2][0] for i in range(1,t-2): if l[i][0] - l[i][1] > end: count += 1 end = l[i][0] elif l[i][0] + l[i][1] < begin: count += 1 end = l[i][0] + l[i][1] else: end = l[i][0] begin = l[i+2][0] if l[-2][0] - l[-2][1] > end or l[-2][0] + l[-2][1] < l[-1][0]: print(count+1) else: print(count) else: print(t) ```
instruction
0
86,112
8
172,224
Yes
output
1
86,112
8
172,225
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` n=int(input()) d=[[-1e9-10, 0]] for i in range(n): d.append(list(map(int, input().split()))) d.append([2*1e9+2, 0]) c=-1e9-10 ans=0 for i in range(1, n+1): x=d[i][0] h=d[i][1] if x-h>c: ans+=1 c=x elif x+h<d[i+1][0]: ans+=1 c=x+h else: c=x print(ans) ```
instruction
0
86,113
8
172,226
Yes
output
1
86,113
8
172,227
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` def main(): n = int(input()) a = [] b = [] for _ in range(n): x,y = map(int,input().split()) a.append(x) b.append(y) start = a[0] cnt = 2 if n==1: cnt = 1 for i in range(1,len(a)-1): if start<a[i]-b[i]: cnt+=1 start = a[i] elif a[i+1]>(a[i]+b[i]): cnt+=1 start=a[i]+b[i] print(cnt) main() # t= int(input()) # while t: # main() # t-=1 ```
instruction
0
86,114
8
172,228
No
output
1
86,114
8
172,229
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` n=int(input()) l=[] m=[] c=0 for _ in range(n): a,b=map(int,input().split()) l.append(a) m.append(b) for i in range(1,n-1): if(m[i]<abs(l[i]-l[i+1])): c=c+1 l[i]+=m[i] elif(m[i]<abs(l[i]-l[i-1])): c=c+1 print(c+2) ```
instruction
0
86,115
8
172,230
No
output
1
86,115
8
172,231
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` n=int(input()) cor = [] for _ in range(n): x,h = map(int,input().split()) cor.append([x,h]) ans=2 for i in range(1,n-1): if cor[i][0]-cor[i-1][0] > cor[i][1]: ans+=1 elif cor[i+1][0]-cor[i][0] > cor[i][1]: ans+=1 cor[i][0]+=cor[i][1] print(ans) ```
instruction
0
86,116
8
172,232
No
output
1
86,116
8
172,233
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input The first line contains integer n (1 ≀ n ≀ 105) β€” the number of trees. Next n lines contain pairs of integers xi, hi (1 ≀ xi, hi ≀ 109) β€” the coordinate and the height of the Ρ–-th tree. The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate. Output Print a single number β€” the maximum number of trees that you can cut down by the given rules. Examples Input 5 1 2 2 1 5 10 10 9 19 1 Output 3 Input 5 1 2 2 1 5 10 10 9 20 1 Output 4 Note In the first sample you can fell the trees like that: * fell the 1-st tree to the left β€” now it occupies segment [ - 1;1] * fell the 2-nd tree to the right β€” now it occupies segment [2;3] * leave the 3-rd tree β€” it occupies point 5 * leave the 4-th tree β€” it occupies point 10 * fell the 5-th tree to the right β€” now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. Submitted Solution: ``` from sys import stdin N = int(stdin.readline()) X = [] # H = [] trees = {} gaps = [] for n in range(N): line = stdin.readline().strip().split() X.append(int(line[0])) # H.append(int(line[1])) trees[int(line[0])] = int(line[1]) gaps = sorted([(X[i], X[i + 1]) for i in range(len(X) - 1)], key=lambda g: g[1] - g[0]) # print(gaps) # print(X, H) # print(trees) trees[gaps[0][0]] = 0 trees[gaps[-1][1]] = 0 # print(trees) count = 2 for g in gaps: l, r = g s = r - l if trees[l] >= trees[r]: if 0 < trees[l] < s: trees[l] = 0 count += 1 elif 0 < trees[r] < s: trees[r] = 0 count += 1 else: if 0 < trees[r] < s: trees[r] = 0 count += 1 elif 0 < trees[l] < s: trees[l] = 0 count += 1 print(count) ```
instruction
0
86,117
8
172,234
No
output
1
86,117
8
172,235
Provide tags and a correct Python 3 solution for this coding contest problem. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
instruction
0
86,248
8
172,496
Tags: implementation Correct Solution: ``` n, k = list(map(int, input().split())) arr = list(map(int, input().split())) max_el = 0 for i in range(n): if k % arr[i] == 0: if max_el < arr[i]: max_el = arr[i] print(k // max_el) ```
output
1
86,248
8
172,497
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response. Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. Input The first line of input contains two integer numbers n and k (1 ≀ n, k ≀ 100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers ai (1 ≀ ai ≀ 100) β€” the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. Output Print one integer number β€” the minimum number of hours required to water the garden. Examples Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 Note In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1. Submitted Solution: ``` try : x, k = map(int, input().split("")) lengthList = [list(int(p) for p in input().split("")) for _ in range(0, x)] #val = [] val = [list(int(n) for n in lengthList if isinstance((k/n), int) == True)] y = max(val) print(k/y) except OSError as err: print("OS error: {0}".format(err)) except ValueError: print("Could not convert data to an integer.") except: print("Unexpected error:", sys.exc_info()[0]) raise ```
instruction
0
86,260
8
172,520
No
output
1
86,260
8
172,521
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,284
8
172,568
Tags: brute force, greedy Correct Solution: ``` n, m, k = map(int, input().split()) free = [True] * n for i in list(map(int, input().split())): free[i] = False a = list(map(int, input().split())) last_lamp = [-1] * n for i in range(n): if free[i]: last_lamp[i] = i if i > 0 and not free[i]: last_lamp[i] = last_lamp[i - 1] ans = int(1E100) for i in range(1, k + 1): last, prev = 0, -1 cur = 0 while last < n: if last_lamp[last] <= prev: cur = None break prev = last_lamp[last] last = prev + i cur += 1 if cur is not None: ans = min(ans, a[i - 1] * cur) if ans == int(1E100): print(-1) else: print(ans) ```
output
1
86,284
8
172,569
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,285
8
172,570
Tags: brute force, greedy Correct Solution: ``` import sys from sys import stdin,stdout n,m,k=map(int,stdin.readline().split(' ')) t22=stdin.readline()#;print(t22,"t2222") bl=[] if len(t22.strip())==0: bl=[] else: bl=list(map(int,t22.split(' '))) bd={} for i in bl: bd[i]=1 cost=list(map(int,stdin.readline().split(' '))) dp=[-1 for i in range(n)] dp[0]=0 def formdp(): global dp for i in range(1,n): if i in bd: t1=i while dp[t1]==-1: t1-=1 dp[i]=dp[t1] else: dp[i]=i def get(i): #print("\t",i) f=1;p=0 while p+i<n: if dp[p+i]==p: return -1 else: p=dp[p+i];f+=1 #print(p,f) return f if True: if 0 in bd: print(-1) else: formdp() #print(dp) minf=[0 for i in range(k+1)] for i in range(1,k+1): minf[i]=get(i) #print(minf) ans=-1 for i in range(1,len(minf)): if minf[i]!=-1: if ans==-1: ans=minf[i]*cost[i-1] else: ans=min(ans,minf[i]*cost[i-1]) if ans==-1: print(-1) else: print(ans) #except Exception as e: # print(e) #print(sys.maxsize) ```
output
1
86,285
8
172,571
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,286
8
172,572
Tags: brute force, greedy Correct Solution: ``` import sys from math import ceil n, l, k = map(int, sys.stdin.readline().split()) places = [True for _ in range(n)] for x in map(int, sys.stdin.readline().split()): places[x] = False costs = list(map(int, sys.stdin.readline().split())) if not places[0]: print(-1) sys.exit(0) prev = [i for i in range(n)] last = 0 for i in range(n): if places[i]: last = i prev[i] = last best_cost = float('inf') for lamp in range(k, 0, -1): min_cost = ceil(n/lamp) * costs[lamp-1] if min_cost >= best_cost: continue # try this shit cost = costs[lamp-1] reach = lamp fail = False while reach < n: if prev[reach] + lamp <= reach: fail = True break reach = prev[reach] + lamp cost += costs[lamp - 1] if cost + (ceil((n - reach)/lamp) * costs[lamp-1]) >= best_cost: fail = True break if not fail: best_cost = min(best_cost, cost) print(best_cost if best_cost != float('inf') else -1) ```
output
1
86,286
8
172,573
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,287
8
172,574
Tags: brute force, greedy Correct Solution: ``` import sys from math import ceil n, m, k = map(int, sys.stdin.readline().split()) places = [True for _ in range(n)] for x in map(int, sys.stdin.readline().split()): places[x] = False costs = list(map(int, sys.stdin.readline().split())) if not places[0]: print(-1) sys.exit(0) longest_streak = 0 streak = 0 for p in places: if not p: streak += 1 else: longest_streak = max(longest_streak, streak) streak = 0 longest_streak = max(streak, longest_streak) prev = [i for i in range(n)] last = 0 for i in range(n): if places[i]: last = i prev[i] = last best_cost = float('inf') for lamp in range(k, longest_streak, -1): min_cost = ceil(n/lamp) * costs[lamp-1] if min_cost >= best_cost: continue # try this shit cost = costs[lamp-1] reach = lamp fail = False while reach < n: if prev[reach] + lamp <= reach: fail = True break reach = prev[reach] + lamp cost += costs[lamp - 1] if cost + (ceil((n - reach)/lamp) * costs[lamp-1]) >= best_cost: fail = True break if not fail: best_cost = min(best_cost, cost) print(best_cost if best_cost != float('inf') else -1) ```
output
1
86,287
8
172,575
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,288
8
172,576
Tags: brute force, greedy Correct Solution: ``` def i_ints(): return list(map(int, input().split())) def next_free_from_blocks(n, blocks): """ n : pos ranges from 0 to n-1 blocks: sorted list of blocked positions return a list that maps each position to the next higher non-blocked position """ m = 0 res = list(range(n+1)) for i in reversed(blocks): res[i] = res[i+1] if res[i] - i > m: m = res[i] - i return res, m ############# n, m, k = i_ints() blocks = i_ints() costs = i_ints() next_free, max_block_len = next_free_from_blocks(n, blocks) blocks.append(n+1) if m == 0: max_block_len = 0 if max_block_len >= k or blocks[0] == 0: print(-1) else: minimal_costs = [c * ((n+l-1)//l) for l, c in enumerate(costs, 1)] maximal_costs = [c * 2 * ((n+l)//(l+1)) for l, c in enumerate(costs, 1)] max_costs = min(maximal_costs[max_block_len:]) possible = [i+1 for i in range(max_block_len, k) if minimal_costs[i] <= max_costs] for i in range(len(possible)-1)[::-1]: if costs[possible[i]-1] > costs[possible[i+1]-1]: del possible[i] def calc(l): """ for strength l, calculate number of lamps needed """ count = 1 pos = n-l while pos > 0: pos = next_free[pos] - l count += 1 return count print(min(calc(l) * costs[l-1] for l in possible)) ```
output
1
86,288
8
172,577
Provide tags and a correct Python 3 solution for this coding contest problem. Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there. There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number. The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each. What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]). Input The first line contains three integer numbers n, m and k (1 ≀ k ≀ n ≀ 10^6, 0 ≀ m ≀ n) β€” the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available. The second line contains m integer numbers s_1, s_2, ..., s_m (0 ≀ s_1 < s_2 < ... s_m < n) β€” the blocked positions. The third line contains k integer numbers a_1, a_2, ..., a_k (1 ≀ a_i ≀ 10^6) β€” the costs of the post lamps. Output Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street. If illumintaing the entire segment [0; n] is impossible, print -1. Examples Input 6 2 3 1 3 1 2 3 Output 6 Input 4 3 4 1 2 3 1 10 100 1000 Output 1000 Input 5 1 5 0 3 3 3 3 3 Output -1 Input 7 4 3 2 4 5 6 3 14 15 Output -1
instruction
0
86,289
8
172,578
Tags: brute force, greedy Correct Solution: ``` import sys from math import ceil n, m, k = map(int, sys.stdin.readline().split()) places = [True for _ in range(n)] for x in map(int, sys.stdin.readline().split()): places[x] = False costs = list(map(int, sys.stdin.readline().split())) if not places[0]: print(-1) sys.exit(0) prev = [i for i in range(n)] last = 0 for i in range(n): if places[i]: last = i prev[i] = last best_cost = float('inf') for lamp in range(k, 0, -1): min_cost = ceil(n/lamp) * costs[lamp-1] if min_cost >= best_cost: continue # try this shit cost = costs[lamp-1] reach = lamp fail = False while reach < n: if prev[reach] + lamp <= reach: fail = True break reach = prev[reach] + lamp cost += costs[lamp - 1] if cost + (ceil((n - reach)/lamp) * costs[lamp-1]) >= best_cost: fail = True break if not fail: best_cost = min(best_cost, cost) print(best_cost if best_cost != float('inf') else -1) ```
output
1
86,289
8
172,579