message stringlengths 2 65.1k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 0 108k | cluster float64 14 14 | __index_level_0__ int64 0 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | instruction | 0 | 29,432 | 14 | 58,864 |
Tags: data structures, dp, implementation
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(n+1):
s[i]=s[i-1]+a[i-1]
dp=[[0]*(n+1) for _ in range(3)]
ans=[0,0]
for i in range(1,3):
for j in range(i*k,n+1):
dp[i][j]=max(dp[i][j-1],s[j]-s[j-k]+dp[i-1][j-k])
i=2;j=n
while i>0 and j>0:
if dp[i][j]==dp[i][j-1]:
j-=1
else:
ans[i-1]=j-k+1
j=ans[i-1]-1
i-=1
print(*ans)
``` | output | 1 | 29,432 | 14 | 58,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | instruction | 0 | 29,433 | 14 | 58,866 |
Tags: data structures, dp, implementation
Correct Solution:
```
n, k = map(int, input().split())
s, t = 0, list(map(int, input().split()))
for i in range(1, n):
t[i] += t[i - 1]
t = [t[k - 1]] + [t[i + k] - t[i] for i in range(n - k)]
p = [(t[i], i) for i in range(n - k + 1)]
p.reverse()
for i in range(1, n - k):
if p[i][0] < p[i - 1][0]: p[i] = max(p[i], p[i - 1])
p.reverse()
a, b = 0, 0
for i in range(n - 2 * k + 1):
if p[i + k][0] + t[i] > s:
s = p[i + k][0] + t[i]
a, b = i, p[i + k][1]
print(a + 1, b + 1)
``` | output | 1 | 29,433 | 14 | 58,867 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
#!/usr/bin/env python3
import io
import os
import sys
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def printd(*args, **kwargs):
#print(*args, **kwargs, file=sys.stderr)
#print(*args, **kwargs)
pass
def get_str():
return input().decode().strip()
def rint():
return map(int, input().split())
def oint():
return int(input())
def ksum(si):
return psum[si+k-1] - psum[si-1]
n, k = rint()
a = [0]
a += list(rint())
b = [0]+ a[::]
n += 1
psum = [0 for i in range(n)]
for i in range(1, n):
psum[i] = a[i] + psum[i-1]
ans = [0,0]
maxsum = -1
maxksum = [-1, -1]
for i in range(n-k-k, 0, -1):
if maxksum[0] <= ksum(i+k):
maxksum = [ksum(i+k), i+k]
sum_ = ksum(i) + maxksum[0]
if sum_ >= maxsum:
ans = [i, maxksum[1]]
maxsum = sum_
print(ans[0], ans[1])
``` | instruction | 0 | 29,434 | 14 | 58,868 |
Yes | output | 1 | 29,434 | 14 | 58,869 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
n,k = map(int,input().split())
sum_max_a = 0
sum_answer = 0
start_index_a = -1
answer_a = 0
answer_b = 0
sum_max_b = 0
start_index_b = -1
list_abs = list(map(int,input().split()))
list_sum = [0]
sum1 = 0
for j in list_abs:
sum1 += j
list_sum.append(sum1)
for i in range(k+1,len(list_sum)+1):
if i + k > n+1:
break
S_a = list_sum[i+k-1] - list_sum[i-1]
S_b = list_sum[i-1] - list_sum[i-k-1]
if sum_max_b < S_b:
sum_max_b = S_b
start_index_b = i - k
if S_a+sum_max_b > sum_answer:
answer_b = start_index_b
sum_answer = S_a + sum_max_b
answer_a= i
print(*sorted([answer_a,answer_b]))
``` | instruction | 0 | 29,435 | 14 | 58,870 |
Yes | output | 1 | 29,435 | 14 | 58,871 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
def main():
n,k=map(int,input().split())
arr=list(map(int,input().split()))
seg=[0]*(n-k+1)
prev=0
for i in range(n-k,n):
prev+=arr[i]
for i in range(n-k,-1,-1):
seg[i]=prev
prev+=arr[i-1]-arr[i+k-1]
n=len(seg)
premax=[0]*(n)
# in this storing indexes not values.
for i in range(1,n):
if seg[i]>seg[premax[i-1]]:
premax[i]=i
else:
premax[i]=premax[i-1]
a,b=0,0
mx=0
for i in range(k,n):
z=seg[i]+seg[premax[i-k]]
if mx<z:
mx=z
a,b=premax[i-k],i
print(a+1,b+1)
#----------------------------------------------------------------------------------------
# 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()
``` | instruction | 0 | 29,436 | 14 | 58,872 |
Yes | output | 1 | 29,436 | 14 | 58,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ######### #
###### ######### # # # # # # ######### #
# # # # # # # # # # #### # # #
# # # # # # # ## # # # # #
###### # # ####### ####### # # ##### # # # #
# from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1e9)+7
inf = float("inf")
n, k = gil()
a = gil()
pre = a[:]
for i in reversed(range(n-1)):
pre[i] += pre[i+1]
seg = []
m = n-k+1
i = 0
while i+k-1 < n:
seg.append(pre[i] - (pre[i+k] if i+k < n else 0))
i += 1
maxSeg = [i for i in range(m)]
for i in reversed(range(m-1)):
if seg[i] < seg[maxSeg[i+1]]:
maxSeg[i] = maxSeg[i+1]
# print(seg)
# print(maxSeg)
l, r = 0, k
i = 0
while i+k < m:
if seg[i] + seg[maxSeg[i+k]] > seg[l] + seg[r]:
l, r = i, maxSeg[i+k]
i += 1
print(l+1, r+1)
``` | instruction | 0 | 29,437 | 14 | 58,874 |
Yes | output | 1 | 29,437 | 14 | 58,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
n,k=map(int,input().split(" "))
li=list(map(int,input().split(" ",n)[:n]))
li=[0]+li
for i in range(1,n+1):
li[i]+=li[i-1]
ast,aen,bst,ben=1,k,k+1,2*k
ca,cb=li[aen]-li[ast-1],li[ben]-li[bst-1]
for i in range(2*k+1,n+1):
if cb<li[i]-li[i-k]:
cb=li[i]-li[i-k]
ben=i
bst=i-k+1
if ca+cb<li[i]-li[i - 2*k]:
ben=i
bst=i-k+1
aen=bst-1
ast=aen-k
ca,cb=li[aen]-li[ast-1],li[ben]-li[bst-1]
print(ast,bst)
``` | instruction | 0 | 29,438 | 14 | 58,876 |
No | output | 1 | 29,438 | 14 | 58,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
from math import inf
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
cum = [i for i in a]
for i in range(1, n):
cum[i] += cum[i - 1]
cum.append(0)
left = -inf
val = -inf
for i in range(n):
if i + k >= n:
continue
if i - k < -1:
continue
left_t = cum[i] - cum[i - k]
right_t = cum[i + k] - cum[i]
if left < left_t:
left = left_t
a = i - k + 1
if left + right_t > val:
val = left + right_t
b = i + 1
print(a + 1, b + 1)
``` | instruction | 0 | 29,439 | 14 | 58,878 |
No | output | 1 | 29,439 | 14 | 58,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
n,k=map(int,input().split())
x=list(map(int,input().split()))
y=[]
s=sum(x[:k])
y.append(s)
for i in range(k,n):
s+=x[i]
s-=x[i-k]
y.append(s)
z=y[-1]
ans=z+y[len(y)-k-1]
l,r=(n-k+1)-k+1,n-k+1
ll=[l]
rr=[r]
for i in range(0,len(y)-k-1)[::-1]:
if y[i+k]>z:
z=y[i+k]
r=i+k+1
rr=[r]
elif y[i+k]==z:
rr.append(i+k+1)
if z+y[i]>ans:
l=i+1
ans=z+y[i]
ll=[l]
elif y[i]+z==ans:
ll.append(i+1)
a=min(ll)
b=-1
rr.sort()
for i in rr:
if a<i:
b=i
break
print(a,b)
``` | instruction | 0 | 29,440 | 14 | 58,880 |
No | output | 1 | 29,440 | 14 | 58,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 β€ a β€ b β€ n - k + 1, b - a β₯ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input
The first line contains two integers n and k (2 β€ n β€ 2Β·105, 0 < 2k β€ n) β the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn β the absurdity of each law (1 β€ xi β€ 109).
Output
Print two integers a, b β the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.
Examples
Input
5 2
3 6 1 1 6
Output
1 4
Input
6 2
1 1 1 1 1 1
Output
1 3
Note
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.
Submitted Solution:
```
n,k=map(int,input().split())
s=input().split()
global sums
sums=[]
sumss=[]
a=0
maxx=0
maxesR=[]
maxesL=[]
for i in range(n):
s[i]=int(s[i])
a+=s[i]
if(i>=k-1):
sums.append(a)
a-=s[i-(k-1)]
if(len(sums)>1):
if(sums[-1]>maxx):
maxx=sums[-1]
maxesR.append(maxx)
a=0
maxx=0
for i in range(1,n+1,1):
a+=s[n-i]
if(i>=k):
sumss.append(a)
a-=s[n-i+k-1]
if(len(sumss)>1):
if(sumss[-1]>maxx):
maxx=sums[-1]
maxesL.append(maxx)
maxx=0
for i in range(n-k+1):
if(sums[i]>maxx):
if(i <k and n-(i+k)<k):
continue
elif(i>0 and i<k and sum(s[:i])<=maxesR[-1]):
maxx=sums[i]
ind=i
elif(i>n-(2*k) and i<n-k and sum(s[i+k:])<=maxesL[-1]):
maxx=sums[i]
ind=i
elif(i==0 or i>=k):
maxx=sums[i]
ind=i
i=ind
a=maxx
if(i-k+1<0):
sums=sums[i+k:]
else:
sums=sums[0:i-k+1]+sums[i+k:]
b=max(sums)
j=sums.index(b)
if(j>=i):
j+=k
print(min(i,j)+1,end=" ")
print(max(i,j)+1)
``` | instruction | 0 | 29,441 | 14 | 58,882 |
No | output | 1 | 29,441 | 14 | 58,883 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,458 | 14 | 58,916 |
Tags: greedy, sortings
Correct Solution:
```
i = int(input())
rat = list(map(int, input().split(' ')))
ratp = sorted(range(i), key=lambda x: rat[x])
final = [-1] * i
start = 0
for i in ratp:
if start + 1 >= rat[i]:
start = start + 1
else:
start = rat[i]
final[i] = start
print(' '.join([str(x) for x in final]))
``` | output | 1 | 29,458 | 14 | 58,917 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,459 | 14 | 58,918 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
arr = list(map(int, input().split(" ")))
arr1 = [(arr[i], i) for i in range(n)]
arr1 = sorted(arr1)
# print(arr1)
arr2 = [x[1] for x in arr1]
for i in range(1, n):
if arr[arr2[i - 1]] >= arr[arr2[i]]:
arr[arr2[i]] = arr[arr2[i - 1]] + 1
print(" ".join(map(str,arr)))
``` | output | 1 | 29,459 | 14 | 58,919 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,460 | 14 | 58,920 |
Tags: greedy, sortings
Correct Solution:
```
import sys
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
l = sorted(range(n),key=lambda i: a[i])
cur = a[l[0]]
s = set([cur])
for i in range(1, n):
if a[l[i]] == cur or a[l[i]] in s:
a[l[i]] = cur + 1
cur = a[l[i]]
s.add(cur)
sys.stdout.write('{}\n'.format(' '.join(list(map(lambda i: str(i), a)))))
main()
``` | output | 1 | 29,460 | 14 | 58,921 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,461 | 14 | 58,922 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
A = list(map(int, input().split()))
t = 0
for x in sorted(range(n), key = lambda t: A[t]):
t = max(t + 1, A[x])
A[x] = t
print(' '.join(map(str, A)))
``` | output | 1 | 29,461 | 14 | 58,923 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,462 | 14 | 58,924 |
Tags: greedy, sortings
Correct Solution:
```
i = int(input())
values = list(map(int, input().split(' ')))
result = [-1] * i
sortedValues = sorted(range(i), key=lambda x: values[x])
cnt = 0
for i in sortedValues:
cnt = cnt + 1 if cnt + 1 >= values[i] else values[i]
result[i] = cnt
print(' '.join([str(x) for x in result]))
``` | output | 1 | 29,462 | 14 | 58,925 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,463 | 14 | 58,926 |
Tags: greedy, sortings
Correct Solution:
```
n=int(input())
lst=[*map(int,input().split())]
ind=sorted(range(n),key=lst.__getitem__)
elem=0
for i,x in enumerate(ind):
elem=max(elem+1,lst[x])
lst[x]=str(elem)+' '
print(''.join(lst))
``` | output | 1 | 29,463 | 14 | 58,927 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,464 | 14 | 58,928 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
b = sorted((v, i) for i, v in enumerate(map(int, input().split())))
ans = [0] * n
l = 0
for y, x in b:
if y > l:
l = y
else:
l+= 1
ans[x] = l
print(' '.join(map(str, ans)))
``` | output | 1 | 29,464 | 14 | 58,929 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors.
There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai rating units as a present.
The X site is administered by very creative and thrifty people. On the one hand, they want to give distinct ratings and on the other hand, the total sum of the ratings in the present must be as small as possible.
Help site X cope with the challenging task of rating distribution. Find the optimal distribution.
Input
The first line contains integer n (1 β€ n β€ 3Β·105) β the number of users on the site. The next line contains integer sequence a1, a2, ..., an (1 β€ ai β€ 109).
Output
Print a sequence of integers b1, b2, ..., bn. Number bi means that user i gets bi of rating as a present. The printed sequence must meet the problem conditions.
If there are multiple optimal solutions, print any of them.
Examples
Input
3
5 1 1
Output
5 1 2
Input
1
1000000000
Output
1000000000 | instruction | 0 | 29,465 | 14 | 58,930 |
Tags: greedy, sortings
Correct Solution:
```
n = int(input())
q = list(map(int, input().split()))
t = 0
for x in sorted(range(n), key = lambda t: q[t]):
t = max(t + 1, q[x])
q[x] = t
print(' '.join(map(str, q)))
``` | output | 1 | 29,465 | 14 | 58,931 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,591 | 14 | 59,182 |
Tags: implementation
Correct Solution:
```
mw = 0
w = 0
n, d = map(int, input().split())
for _ in range(d):
if '0' in input():
w += 1
mw = max(w, mw)
else:
w = 0
print(mw)
``` | output | 1 | 29,591 | 14 | 59,183 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,592 | 14 | 59,184 |
Tags: implementation
Correct Solution:
```
import sys
n , d = map(int,sys.stdin.readline().split())
arr = []
for i in range(1, d + 1):
ch = str(input())
if set(ch) != {'1'}:
arr.append(1)
else:
arr.append(0)
arr1 = []
qq = 0
for i in range(len(arr)):
if arr[i] == 1:
qq = qq + 1
arr1.append(qq)
else:
qq = 0
arr1.append(0)
print(max(arr1))
``` | output | 1 | 29,592 | 14 | 59,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,593 | 14 | 59,186 |
Tags: implementation
Correct Solution:
```
char2=input()
list2=char2.split()
a=int(list2[0])
b=int(list2[1])
c=0
mc=0
list1=[]
for i in range(0,b):
char=list(input())
if char.count('0') is 0:
if c>mc:
mc=c
c=0
else:
c+=1
if c>mc:
mc=c
print(mc)
``` | output | 1 | 29,593 | 14 | 59,187 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,594 | 14 | 59,188 |
Tags: implementation
Correct Solution:
```
n,d = list(map(int,input().split()))
arr = []
def summa(stri):
gg = 0
for i in stri:
if i == '1':
gg+=1
return gg
for i in range(d):
arr.append(input())
arr2 = [0]*d
for i in range(d):
if summa(arr[i]) < n and i != 0:
arr2[i] = arr2[i-1]+1
elif i == 0 and summa(arr[i]) < n:
arr2[i] = 1
print(max(arr2))
``` | output | 1 | 29,594 | 14 | 59,189 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,595 | 14 | 59,190 |
Tags: implementation
Correct Solution:
```
import math
str_temp = input().split(' ')
enem, days = int(str_temp[0]), int(str_temp[1])
john_legend = 0
max_legend = 0
for i in range(days):
str_temp = input()
try:
str_temp.index("0")
john_legend += 1
#max_legend += 1
except ValueError:
if max_legend < john_legend:
max_legend = john_legend
john_legend = 0
if max_legend < john_legend:
max_legend = john_legend
print(max_legend)
``` | output | 1 | 29,595 | 14 | 59,191 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,596 | 14 | 59,192 |
Tags: implementation
Correct Solution:
```
n,d=map(int,input().split())
count=0
sum=0
for _ in range(d):
opp=input()
if '0' in opp:
count+=1
if count>sum:
sum=count
else:
count=0
print(sum)
``` | output | 1 | 29,596 | 14 | 59,193 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,597 | 14 | 59,194 |
Tags: implementation
Correct Solution:
```
a = []
s = []
d = 0
for i in range(int(input().split()[1])):
a.append(input())
for i in a:
if "0" in i:
d += 1
else:
s.append(d)
d = 0
s.append(d)
print(max(s))
``` | output | 1 | 29,597 | 14 | 59,195 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4. | instruction | 0 | 29,598 | 14 | 59,196 |
Tags: implementation
Correct Solution:
```
n,d=map(int,input().split())
r=0
m=0
for _ in range(d):
s=input()
if '0' in s:
r=r+1
else:
m=max(r,m)
r=0
m=max(r,m)
print(m)
``` | output | 1 | 29,598 | 14 | 59,197 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
opp,day=map(int, input().split())
cnt=0
x=[]
for _ in range(day):
if input().count('0')>0: cnt+=1
else:
x.append(cnt)
cnt=0
x.append(cnt)
print(max(x))
``` | instruction | 0 | 29,599 | 14 | 59,198 |
Yes | output | 1 | 29,599 | 14 | 59,199 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
n,d=map(int,input().split())
res=0
arr=[]
for i in range(d):
a=input()
if a.count("1")<n:
res+=1
else:
arr.append(res)
res=0
else:
arr.append(res)
if len(arr)==0:
print(0)
else:
print(max(arr))
``` | instruction | 0 | 29,600 | 14 | 59,200 |
Yes | output | 1 | 29,600 | 14 | 59,201 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
n, d = map(int, input().split())
km = 0
k = 0
for i in range(d):
s = input()
if s.find('0') == -1:
km = max(km, k)
k = 0
else:
k += 1
km = max(km, k)
print(km)
``` | instruction | 0 | 29,601 | 14 | 59,202 |
Yes | output | 1 | 29,601 | 14 | 59,203 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
# http://codeforces.com/contest/688/problem/A
# opponents.py
n, d = map(int, input().strip().split())
l = []
prev = 1
current_val = 0
max_val = 0
win_loss = 0
for i in range(d):
val = input()
if '0' in val:
current_val += 1
else:
current_val = 0
if current_val > max_val:
max_val = current_val
print(max_val)
``` | instruction | 0 | 29,602 | 14 | 59,204 |
Yes | output | 1 | 29,602 | 14 | 59,205 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
n,d=map(int,input().split())
l=[]
for i in range(d):
s=input()
l.append(s)
cnt=0
cnt1=0
z=[]
for j in range(len(l)):
if "0" in l[j]:
cnt+=1
else:
z.append(cnt)
cnt=0
if len(z)==0:
print(cnt)
else:
print(max(z))
``` | instruction | 0 | 29,605 | 14 | 59,210 |
No | output | 1 | 29,605 | 14 | 59,211 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya.
For each opponent Arya knows his schedule β whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents.
Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents.
Input
The first line of the input contains two integers n and d (1 β€ n, d β€ 100) β the number of opponents and the number of days, respectively.
The i-th of the following d lines contains a string of length n consisting of characters '0' and '1'. The j-th character of this string is '0' if the j-th opponent is going to be absent on the i-th day.
Output
Print the only integer β the maximum number of consecutive days that Arya will beat all present opponents.
Examples
Input
2 2
10
00
Output
2
Input
4 1
0100
Output
1
Input
4 5
1101
1111
0110
1011
1111
Output
2
Note
In the first and the second samples, Arya will beat all present opponents each of the d days.
In the third sample, Arya will beat his opponents on days 1, 3 and 4 and his opponents will beat him on days 2 and 5. Thus, the maximum number of consecutive winning days is 2, which happens on days 3 and 4.
Submitted Solution:
```
n,d = map(int, input().split())
a = []
x = []
b = "1"*n
for i in range(d):
a.append(input())
if a[-1] == b:
x.append(i)
for i in range(len(x)):
if i!=0:
x[i] = x[i] - x[i-1] - 1
if len(x)==0:
print(d)
else:
print(max(x))
``` | instruction | 0 | 29,606 | 14 | 59,212 |
No | output | 1 | 29,606 | 14 | 59,213 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,627 | 14 | 59,254 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
#####################################
import atexit, io, sys, collections, math, heapq, fractions,copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
##################################### python 3 START
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")
##################################### python 3 END
n,k = map(int, input().split())
ais = list(map(int, input().split()))
cc = collections.Counter()
MAX = (10 ** 5) * (10 ** 9)
r = [1]
if abs(k) != 1:
p = 1
cur = k
for _ in range(50):
r.append(cur)
cur *= k
r = set(r)
if k == -1:
r.add(-1)
cc[0]+=1
cumul = 0
ans = 0
if len(ais) > 1:
#cumul - v = y
for j in range(len(ais)):
cumul += ais[j]
for y in r:
if (cumul - y) in cc:
ans += cc[cumul - y]
cc[cumul] += 1
else:
ans += 1 if ais[0] in r else 0
print (ans)
``` | output | 1 | 29,627 | 14 | 59,255 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,628 | 14 | 59,256 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
n,k=map(int,input().split())
a=list(map(int,input().split()))
p=a[:]
for i in range(1,n):p[i]+=p[i-1]
z=1
o=0
r=50
if k==-1:
r=2
elif k==1:
r=1
for i in range(r):
d={}
for j in range(n):
if p[j] not in d:d[p[j]]=0
d[p[j]]+=1
if p[j]-z in d:o+=d[p[j]-z]
if p[j]-z==0:o+=1
z*=k
print(o)
``` | output | 1 | 29,628 | 14 | 59,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,629 | 14 | 59,258 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
f = lambda: map(int, input().split())
n, k = f()
t = {k ** i for i in range(48) if k ** i <= n * 1e9}
p = y = 0
d = {0: 1}
for a in f():
p += a
d[p] = d.get(p, 0) + 1
y += sum(d.get(p - x, 0) for x in t)
print(y)
``` | output | 1 | 29,629 | 14 | 59,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,630 | 14 | 59,260 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
n,k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
psum = [0]
d = {0 : 1}
for i in range(n):
num = psum[i]+arr[i]
d.setdefault(num,0)
d[num]+=1
psum.append(num)
if abs(k) == 1:
e = d.copy()
ans = 0
for i in psum:
e[i]-=1
if 1+i in e : ans+=e[1+i]
if k == -1:
e = d.copy()
for i in psum:
e[i]-=1
if i-1 in e: ans+=e[i-1]
print(ans)
else:
p = 0
w = pow(k,p)
ans = 0
while w <= pow(10,14):
e = d.copy()
for i in psum:
e[i]-=1
if w+i in e:ans+=e[w+i]
p+=1
w = pow(k,p)
print(ans)
``` | output | 1 | 29,630 | 14 | 59,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,631 | 14 | 59,262 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
import sys
from itertools import accumulate
def solve():
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
ps = [0] + list(accumulate(a))
ap = {ps[n] : 1}
ans = 0
if k == 1:
for i in range(n - 1, -1, -1):
if ps[i] + 1 in ap:
ans += ap[ps[i] + 1]
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
elif k == -1:
for i in range(n - 1, -1, -1):
if ps[i] + 1 in ap:
ans += ap[ps[i] + 1]
if ps[i] - 1 in ap:
ans += ap[ps[i] - 1]
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
else:
kp = [k**i for i in range(50)]
for i in range(n - 1, -1, -1):
for kpi in kp:
if ps[i] + kpi in ap:
ans += ap[ps[i] + kpi]
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
print(ans)
if __name__ == '__main__':
solve()
``` | output | 1 | 29,631 | 14 | 59,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,632 | 14 | 59,264 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
import math
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if abs(k) > 1:
valid = [k ** i for i in range(0, math.ceil(math.log(n * 1e9) / math.log(abs(k))) + 1)]
elif k == -1:
valid = [1, -1]
else:
valid = [k]
# print(math.log(n * 1e9) / math.log(abs(k)))
# print(valid)
s = 0
ans = 0
count = {s : 1}
for i in a:
s += i
for j in valid:
if count.get(s - j):
ans += count[s - j]
if count.get(s):
count[s] += 1
else:
count[s] = 1
print(ans)
``` | output | 1 | 29,632 | 14 | 59,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,633 | 14 | 59,266 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
cnt = [0]
d = {0:1}
power = [1]
ans = 0
if abs(k) > 1:
while abs(power[-1]) < 10 ** 16:
power.append(power[-1] * k)
elif k == -1:
power = [1, -1]
elif not k:
power = [0]
for i in range(n):
cnt.append(cnt[-1] + values[i])
if cnt[-1] in d:
d[cnt[-1]] += 1
else:
d[cnt[-1]] = 1
for v in power:
if cnt[-1] - v in d:
ans += d[cnt[-1] - v]
stdout.write(str(ans))
``` | output | 1 | 29,633 | 14 | 59,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4]. | instruction | 0 | 29,634 | 14 | 59,268 |
Tags: binary search, brute force, data structures, implementation, math
Correct Solution:
```
import sys
from itertools import accumulate
def solve():
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
ps = [0] + list(accumulate(a))
ap = {ps[n] : 1}
ans = 0
if k == 1:
for i in range(n - 1, -1, -1):
if ps[i] + 1 in ap:
ans += ap[ps[i] + 1]
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
elif k == -1:
for i in range(n - 1, -1, -1):
if ps[i] + 1 in ap:
ans += ap[ps[i] + 1]
if ps[i] - 1 in ap:
ans += ap[ps[i] - 1]
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
else:
for i in range(n - 1, -1, -1):
pk = 1
while abs(pk) <= 10**14:
if ps[i] + pk in ap:
ans += ap[ps[i] + pk]
pk *= k
if ps[i] in ap:
ap[ps[i]] += 1
else:
ap[ps[i]] = 1
print(ans)
if __name__ == '__main__':
solve()
``` | output | 1 | 29,634 | 14 | 59,269 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
f = lambda: map(int, input().split())
n, k = f()
t = {k ** i for i in range(48) if k ** i <= n * 1e9}
s = y = 0
d = {0: 1}
for a in f():
s += a
d[s] = d.get(s, 0) + 1
y += sum(d.get(s - x, 0) for x in t)
print(y)
``` | instruction | 0 | 29,635 | 14 | 59,270 |
Yes | output | 1 | 29,635 | 14 | 59,271 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
n, k = map(int,input().split())
qw = [int(i) for i in input().split()]
q = 1
c = 0
for i in range(50):
summ = 0
er = {q:1}
for u in qw:
summ += u
if summ in er:
c += er[summ]
if summ + q in er:
er[summ+q] += 1
else:
er[summ+q] = 1
q *= k
if k == 1:
print(c//50)
elif k == -1:
print(c//25)
else:
print(c)
``` | instruction | 0 | 29,636 | 14 | 59,272 |
Yes | output | 1 | 29,636 | 14 | 59,273 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
n, k = input().split()
n, k = int(n), int(k)
arr = input().split()
arr = [int(a) for a in arr]
su = {1}
for i in range(1, 100):
if k**i < 10**10*n:
su.add(k**i)
continue
break
#print(su)
d = {0:1}
ans = 0
cumulative_sum = 0
for x in arr:
cumulative_sum += x
for s in su:
if cumulative_sum - s in d:
ans += d[cumulative_sum-s]
d[cumulative_sum] = d.get(cumulative_sum, 0) + 1
print(ans)
``` | instruction | 0 | 29,637 | 14 | 59,274 |
Yes | output | 1 | 29,637 | 14 | 59,275 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
import math
import heapq
def main(arr,k):
end=max(abs(sum([x for x in arr if x>0])),abs(sum([x for x in arr if x<0])))
start=1
prefix=[arr[0]]
cnt={}
for i in range(1,len(arr)):
val=arr[i]+prefix[-1]
prefix.append(val)
ans=0
while start<=end:
cnt={}
for i in range(len(prefix)):
if prefix[i]-start in cnt:
ans+=cnt[prefix[i]-start]
if prefix[i]==start:
ans+=1
if prefix[i] not in cnt:
cnt[prefix[i]]=0
cnt[prefix[i]]+=1
if k==1:
start=end+1
elif k==-1:
if start==1:
start=-1
else:
break
else:
start*=k
return ans
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
print(main(arr,k))
``` | instruction | 0 | 29,638 | 14 | 59,276 |
Yes | output | 1 | 29,638 | 14 | 59,277 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
n, k = input().split()
n, k = int(n), int(k)
arr = input().split()
arr = [int(a) for a in arr]
su = {1}
for i in range(1, 100):
if k**i < 10**9*n:
su.add(k**i)
continue
break
#print(su)
d = {0:1}
ans = 0
cumulative_sum = 0
for x in arr:
cumulative_sum += x
for s in su:
if cumulative_sum - s in d:
ans += d[cumulative_sum-s]
d[cumulative_sum] = d.get(cumulative_sum, 0) + 1
print(ans)
``` | instruction | 0 | 29,639 | 14 | 59,278 |
No | output | 1 | 29,639 | 14 | 59,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
#!/usr/bin/env python3
from collections import defaultdict
def ri():
return map(int, input().split())
n, k = ri()
s = [i for i in list(ri())]
sd = defaultdict(int)
for i in range(1,n):
s[i] = s[i] + s[i-1]
s.append(0)
ans = 0
for i in range(n-1, -1, -1):
sd[s[i]]+=1
for j in range(0,n):
if k == -1 and j == 2:
break
if k == 1 and j == 1:
break
if abs(k**j) > 10**14:
break
ans += sd[k**j + s[i-1]]
print(ans)
``` | instruction | 0 | 29,640 | 14 | 59,280 |
No | output | 1 | 29,640 | 14 | 59,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
import os,io
from sys import stdout
import collections
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def binomial_coefficient(n, k):
if 0 <= k <= n:
ntok = 1
ktok = 1
for t in range(1, min(k, n - k) + 1):
ntok *= n
ktok *= t
n -= 1
return ntok // ktok
else:
return 0
def powerOfK(k, max):
if k == 1:
return [1]
if k == -1:
return [-1]
result = []
n = 1
while n <= max:
result.append(n)
n *= k
return result
def prefixSum(arr):
for i in range(1, len(arr)):
arr[i] = arr[i] + arr[i-1]
return arr
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ps = [0] + prefixSum(a)
can = set([])
canMap = collections.defaultdict(int)
powers = powerOfK(k, 10**14)
result = 0
for e in ps:
for p in powers:
if e - p in can:
result += canMap[e-p]
can.add(e)
canMap[e] += 1
print(result)
``` | instruction | 0 | 29,641 | 14 | 59,282 |
No | output | 1 | 29,641 | 14 | 59,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai.
Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contiguous segment of chemicals together to make a love potion with total affection value as a non-negative integer power of k. Total affection value of a continuous segment of chemicals is the sum of affection values of each chemical in that segment.
Help her to do so in finding the total number of such segments.
Input
The first line of input contains two integers, n and k, the number of chemicals and the number, such that the total affection value is a non-negative power of this number k. (1 β€ n β€ 105, 1 β€ |k| β€ 10).
Next line contains n integers a1, a2, ..., an ( - 109 β€ ai β€ 109) β affection values of chemicals.
Output
Output a single integer β the number of valid segments.
Examples
Input
4 2
2 2 2 2
Output
8
Input
4 -3
3 -6 -3 12
Output
3
Note
Do keep in mind that k0 = 1.
In the first sample, Molly can get following different affection values:
* 2: segments [1, 1], [2, 2], [3, 3], [4, 4];
* 4: segments [1, 2], [2, 3], [3, 4];
* 6: segments [1, 3], [2, 4];
* 8: segments [1, 4].
Out of these, 2, 4 and 8 are powers of k = 2. Therefore, the answer is 8.
In the second sample, Molly can choose segments [1, 2], [3, 3], [3, 4].
Submitted Solution:
```
#####################################
import atexit, io, sys, collections, math, heapq, fractions,copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
##################################### python 3 START
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")
##################################### python 3 END
n,k = map(int, input().split())
ais = list(map(int, input().split()))
cc = collections.Counter()
MAX = (10 ** 5) * (10 ** 14)
r = [1]
if abs(k) != 1:
p = 1
cur = k ** p
while(abs(cur) <= MAX):
r.append(cur)
p+=1
cur *= k
cc[0]+=1
cumul = 0
ans = 0
for j in range(len(ais)):
cumul += ais[j]
for y in r:#[k**i for i in range(10)]:
if (cumul - y) in cc:
ans += cc[cumul - y]
cc[cumul] += 1
print (ans)
``` | instruction | 0 | 29,642 | 14 | 59,284 |
No | output | 1 | 29,642 | 14 | 59,285 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 β€ x, y β€ n and ax, y β 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.
Help Okabe determine whether a given lab is good!
Input
The first line of input contains the integer n (1 β€ n β€ 50) β the size of the lab.
The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 β€ ai, j β€ 105).
Output
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
Examples
Input
3
1 1 2
2 3 1
6 4 1
Output
Yes
Input
3
1 5 2
1 1 1
1 2 3
Output
No
Note
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | instruction | 0 | 29,648 | 14 | 59,296 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
# print(a)
x,m=0,0
flag=0
l=[]
for i in range(n):
for j in range(n):
if a[i][j]!=1:
x+=1
for k in range(n):
if a[i][k]!=a[i][j]:
l.append(a[i][j]-a[i][k])
for k in range(n):
if a[k][j] in l:
flag=1
break
if flag==1:
m+=1
del l[:]
flag=0
# print(m,x)
if m==x:
print('Yes')
else:
print('No')
``` | output | 1 | 29,648 | 14 | 59,297 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 β€ x, y β€ n and ax, y β 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.
Help Okabe determine whether a given lab is good!
Input
The first line of input contains the integer n (1 β€ n β€ 50) β the size of the lab.
The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 β€ ai, j β€ 105).
Output
Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case.
Examples
Input
3
1 1 2
2 3 1
6 4 1
Output
Yes
Input
3
1 5 2
1 1 1
1 2 3
Output
No
Note
In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No". | instruction | 0 | 29,652 | 14 | 59,304 |
Tags: implementation
Correct Solution:
```
if __name__ == "__main__":
n = int(input())
arr =[]
for i in range(n):
li = list(map(int,input().split()))
arr.append(li)
tc = 0
vc = 0
for i in range(n):
for j in range(n):
if arr[i][j]>1:
tc+=1
for k in range(n):
diff = arr[i][j]-arr[k][j]
if diff in arr[i]:
vc+=1
break
if tc==vc:
print("Yes")
else:
print("No")
``` | output | 1 | 29,652 | 14 | 59,305 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.