description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | c = [int(i) for i in input().split()]
a = [(ord(x) - ord("a")) for x in input()]
n = len(a)
l = [[] for i in range(26)]
r = [[] for i in range(26)]
s = 0
ans = 0
for i in range(n - 1):
s += c[a[i]]
l[a[i]] += [(s, i)]
r[a[i + 1]] += [(s, i)]
for i in range(26):
n, m = len(l[i]), len(r[i])
if n < 1 o... | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER V... |
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | X = [int(i) for i in input().split()]
s = input()
arr = []
unicode_a = ord("a")
for i in range(26):
arr.append({})
sm = 0
k = 0
for char in s:
n = ord(char) - unicode_a
k += arr[n].get(sm, 0)
sm += X[n]
arr[n][sm] = arr[n].get(sm, 0) + 1
print(k) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR ASSI... |
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | val = [int(x) for x in input().split()]
s = input()
a = []
for i in range(0, 26):
a.append({})
add = [0]
res = 0
for each in s:
num = add[-1] + val[ord(each) - 97]
add.append(num)
res += a[ord(each) - 97].get(add[-2], 0)
if num not in a[ord(each) - 97]:
a[ord(each) - 97][num] = 0
a[ord(e... | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR DICT ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN... |
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | l = list(map(int, input().split()))
s = input()
cs = 0
ans = 0
a = []
for i in range(26):
a.append({})
for i in s:
c = ord(i) - 97
x = a[c].get(cs) or 0
ans += x
cs += l[c]
y = a[c].get(cs) or 0
a[c][cs] = y + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN V... |
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ... | costss = list(map(int, input().split()))
s = input()
costs = {}
cost = 0
ans = 0
nums = []
for i in range(len(s)):
cost += costss[ord(s[i]) - 97]
if s[i] not in costs:
costs[s[i]] = {}
costs[s[i]][cost] = costs[s[i]].get(cost, 0) + 1
ans += costs[s[i]].get(cost - costss[ord(s[i]) - 97], 0)
i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR DICT ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CA... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(nums, n, k):
summ = 0
for i in range(k):
summ += nums[i]
ans = summ
prev = 0
prev_sum = 0
for i in range(k, n):
prev_sum += nums[i - k]
prev = min(prev_sum, prev)
summ += nums[i]
if summ - prev > ans:
ans = summ - prev
retur... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
prevsum = [0] * len(a)
prevsum[0] = a[0]
currsum = 0
for i in range(1, len(a)):
if prevsum[i - 1] < 0:
prevsum[i] = a[i]
currsum = 0
else:
currsum = prevsum[i - 1] + a[i]
prevsum[i] = currsum
ws, we = 0, 0
... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
count = 0
dpf = [0] * n
for i in range(k):
count += a[i]
dpf[0] = a[0]
csum = a[0]
ans = count
for i in range(1, n):
if csum >= 0:
csum += a[i]
else:
csum = a[i]
dpf[i] = csum
atleast = 0
for i in range... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def kadens(nums):
dp = [0] * len(nums)
cur_sum = nums[0]
dp[0] = nums[0]
for i in range(1, len(nums)):
cur_sum = max(cur_sum + nums[i], nums[i])
dp[i] = cur_sum
return dp
def maxSumWithK(nums, n, k):
arr = kadens(nums)
exactK = 0
ans = float("-inf")
for i in range(k... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ST... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(a, n, k):
sum1 = sum(a[:k])
e, j = 0, 0
ans = -sys.maxsize - 1
ans = max(ans, sum1)
for i in range(k, n):
sum1 += a[i]
e += a[j]
j += 1
ans = max(ans, sum1)
if e < 0:
sum1 -= e
ans = max(ans, sum1)
... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN VA... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
maxi = []
sum = 0
for num in a:
sum += num
maxi.append(sum)
if sum < 0:
sum = 0
sm = 0
for i in range(k):
sm += a[i]
maximum = -float("inf")
result = sm
for i in range(k, n):
sm += a[i] - a[i - k]
resul... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VA... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
pre = [a[0]] * n
for i in range(1, n):
pre[i] = pre[i - 1] + a[i]
mn = [a[0]] * n
for i in range(1, n):
mn[i] = min(mn[i - 1], pre[i])
mx = [pre[-1]] * n
for i in range(n - 2, -1, -1):
mx[i] = max(mx[i + 1], pre[i])
ans = mx[k - 1]
for i ... | FUNC_DEF ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FOR VAR FUNC_CALL VA... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
maxSum = [0] * n
maxSum[0] = a[0]
curr_max = a[0]
for i in range(1, n):
curr_max = max(a[i], curr_max + a[i])
maxSum[i] = curr_max
sum = 0
for i in range(k):
sum += a[i]
result = sum
for i in range(k, n):
sum = sum + a[i] - a[i - ... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
s = 0
m = s = a[0]
l = [a[0]]
for i in range(1, len(a)):
if s >= 0:
s += a[i]
else:
s = a[i]
l.append(s)
atleast_k = 0
exactly_k = sum(a[:k])
ans = exactly_k
ans = max(ans, exactly_k)
for i in range(k, n):
... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
pref = [0] * n
pref[0] = a[0]
for i in range(1, n):
pref[i] = max(a[i], a[i] + pref[i - 1])
curr_sum = sum(a[:k])
max_sum = curr_sum
for i in range(k, n):
curr_sum = curr_sum + a[i] - a[i - k]
max_sum = max(max_sum, curr_sum, curr_sum + pref[i - ... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
maxsum = -float("inf")
sums = 0
cur = 0
prev = 0
for i in range(n):
if i < k:
cur += a[i]
prev += a[i]
else:
maxsum = max(maxsum, cur, prev)
prev += a[i] - a[i - k]
cur += a[i]
cur = max... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
maxSumAtIndex = []
maxSumAtIndex.append(a[0])
maxSumUpto = a[0]
for index in range(1, n):
maxSumUpto = max(a[index], maxSumUpto + a[index])
maxSumAtIndex.append(maxSumUpto)
sumK = 0
for i in range(k):
sumK += a[i]
result = sumK
for i in r... | FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(arr, n, k):
csum = arr[0]
maxSum = [0] * n
maxSum[0] = csum
for i in range(1, n):
if csum > 0:
csum += arr[i]
else:
csum = arr[i]
maxSum[i] = csum
exactK = sum(arr[:k])
ans = exactK
for i in range(k, n):
exactK += arr[i]... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
f = [(0) for i in range(n)]
s = a[0]
f[0] = s
for i in range(1, n):
if s > 0:
s += a[i]
else:
s = a[i]
f[i] = s
ex = 0
ans = float("-inf")
for i in range(k):
ex += a[i]
ans = max(ans, ex)
for i in range... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR F... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(arr, n, k):
su = 0
for i in range(k):
su += arr[i]
answer = su
last = start = 0
end = k
while end < n:
last += arr[start]
start += 1
su += arr[end]
answer = max(answer, su)
if last < 0:
su = su - last
answer ... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
f = [0] * n
f[0] = a[0]
s = f[0]
for i in range(n):
s = f[i - 1]
if s >= 0:
f[i] = f[i - 1] + a[i]
else:
f[i] = a[i]
l = 0
ans = -9999999999999999999
for i in range(k):
l += a[i]
ans = max(ans, l)
for i... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSI... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
s = sum(a[:k])
prev = prev_sum = 0
ans = s
for i in range(k, n):
prev_sum += a[i - k]
prev = min(prev, prev_sum)
s += a[i]
ans = max(ans, s - prev)
return ans | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(a, n, k):
summ = sum(a[0:k])
ans = summ
last = 0
j = 0
for i in range(k, n):
summ += a[i]
last = last + a[j]
j += 1
ans = max(ans, summ)
if last < 0:
summ = summ - last
ans = max(ans, summ)
last ... | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER RETURN... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
csum = a[0]
F = [0] * n
F[0] = a[0]
for i in range(1, n):
csum = max(csum + a[i], a[i])
F[i] = csum
exactk = 0
ans = -float("inf")
exactk = sum(a[0:k])
if ans < exactk:
ans = sum(a[0:k])
atleastk = 0
for i in range(k, n):
... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(arr, n, k):
maxi = float("-inf")
cursum = arr[0]
bestsubarray = [cursum]
for i in range(1, n):
if cursum > 0:
cursum += arr[i]
else:
cursum = arr[i]
bestsubarray.append(cursum)
exactk = 0
for i in range(k):
exactk += arr[i]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR B... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
maxi = sum(a[:k])
res = maxi
j = k
i = 0
l = 0
while j < n:
res = res + a[j]
l += a[i]
maxi = res if res > maxi else maxi
if l < 0:
res = res - l
l = 0
maxi = res if res > maxi else maxi
i += 1
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
sumarr = 0
for i in range(k):
sumarr += a[i]
ans = sumarr
j = 0
last = 0
for i in range(k, n):
sumarr += a[i]
ans = max(ans, sumarr)
last += a[j]
j += 1
if last < 0:
sumarr -= last
last = 0
... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
max_sum = float("-inf")
prefix_sum = [0] * (n + 1)
min_prefix_sum = [0] * (n + 1)
prefix_sum[0] = 0
for i in range(1, n + 1):
prefix_sum[i] = prefix_sum[i - 1] + a[i - 1]
min_prefix_sum[0] = prefix_sum[0]
for i in range(1, n + 1):
min_prefix_sum[i] =... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CAL... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(a, n, k):
max_sum = -sys.maxsize
sum = 0
for i in range(k):
sum += a[i]
last = 0
j = 0
max_sum = max(sum, max_sum)
for i in range(k, n):
sum += a[i]
last += a[j]
j += 1
max_sum = max(sum, max_sum)
if last < 0:
... | IMPORT FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR V... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
list1 = []
sum = a[0]
list1.append(a[0])
for i in range(1, n):
if sum >= 0:
sum += a[i]
else:
sum = a[i]
list1.append(sum)
sum = 0
ans, atleast = float("-inf"), 0
for j in range(k):
sum += a[j]
ans = max(an... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FU... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
sum = 0
l1 = []
exa = 0
for i in range(k):
exa += a[i]
ma = ans = exa
for i in range(k, n):
exa += a[i] - a[i - k]
ans = max(ans + a[i], exa)
if ma < ans:
ma = ans
return ma | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(nums, n, k):
if k > len(nums):
return -1
ans = -99999999999
max_sum = list()
curr_sum = nums[0]
max_sum.append(nums[0])
for i in range(1, len(nums)):
if curr_sum > 0:
curr_sum += nums[i]
else:
curr_sum = nums[i]
max_sum.appe... | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(a, n, k):
max_sum = [0] * n
ans = -sys.maxsize - 1
curr_sum = a[0]
max_sum[0] = a[0]
for i in range(1, n):
if curr_sum > 0:
curr_sum += a[i]
else:
curr_sum = a[i]
max_sum[i] = curr_sum
exactk = 0
for j in range(k):
... | IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUN... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
new = []
new.append(a[0])
for i in range(1, len(a)):
if new[i - 1] >= 0:
new.append(new[i - 1] + a[i])
else:
new.append(a[i])
sum = 0
for i in range(k):
sum += a[i]
ans = -99999999999999999
ans = max(ans, sum)
for ... | FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(a, n, k):
ans = -sys.maxsize - 1
currsum = ans = sum(a[0:k])
arr = []
kadane = 0
for i in range(n):
if kadane > -1:
kadane += a[i]
else:
kadane = a[i]
arr.append(kadane)
j = k - 1
i = 0
while j < n - 1:
... | IMPORT FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR VAR VAR V... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(arr, n, k):
forward = [0] * len(arr)
forward[0] = arr[0]
for i in range(1, len(arr)):
if forward[i - 1] + arr[i] >= arr[i]:
forward[i] = arr[i] + forward[i - 1]
else:
forward[i] = arr[i]
ws = 0
exactK = 0
atleastK = 0
res = float("-inf"... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
summa = sum(a[:k])
max_sum = summa
extra = 0
for i in range(n - k):
summa += a[k + i] - a[i]
extra += a[i]
if extra < 0:
extra = 0
if summa + extra > max_sum:
max_sum = summa + extra
return max_sum | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
ans = -1000000000.0
cur, prev = 0, 0
for i in range(n):
if i < k:
cur += a[i]
prev += a[i]
else:
ans = max(ans, cur, prev)
cur += a[i]
prev += a[i] - a[i - k]
cur = max(cur, prev)
ans = max(... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
res = kandane(a, n)
beg, end, aux_sum, sum = 0, 0, 0, float("-inf")
while end < n:
aux_sum += a[end]
if end - beg + 1 == k:
temp = res[beg - 1] if beg - 1 >= 0 else float("-inf")
ans = max(aux_sum, aux_sum + temp)
sum = max(sum, a... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR STRING WHILE VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
res = -1000000000.0
i = 0
j = 0
sums = 0
iwin = 0
iwinmin = 0
while i < n:
sums += a[i]
if i - j + 1 == k:
res = max(res, sums)
if i - j + 1 > k:
iwin += a[j]
j += 1
iwinmin = min(iwinmin, iwin)... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | import sys
def maxSumWithK(nums, n, k):
maxi = 0
store = []
for i in range(n):
if nums[i] + maxi > nums[i]:
maxi += nums[i]
else:
maxi = nums[i]
store.append(maxi)
exactwin = 0
for i in range(k):
exactwin += nums[i]
j = 0
ans = -sys.m... | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR V... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
p = [a[0]]
for i in range(1, n):
val = a[i]
p.append(max(p[i - 1] + val, val))
win_sum = sum(a[:k])
res = win_sum
for i in range(k, n):
prev = i - k
win_sum -= a[prev]
win_sum += a[i]
res = max(res, win_sum, win_sum + p[prev])... | FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR B... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
res = kandane(a, n)
sum, aux_sum = float("-inf"), 0
for i in range(0, k):
aux_sum += a[i]
sum = max(sum, aux_sum)
for i in range(k, n):
aux_sum = aux_sum - a[i - k] + a[i]
ans = max(aux_sum, aux_sum + res[i - k])
sum = max(sum, ans)
retur... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR F... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(nums, n, k):
def findMaxSubarray(nums):
maxSum = nums[0]
currsum = 0
res = []
for i in nums:
currsum += i
res.append(currsum)
if currsum < 0:
currsum = 0
return res
arr1 = findMaxSubarray(nums)
res ... | FUNC_DEF FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR V... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(arr, n, k):
forward = [arr[0]]
for i in range(1, len(arr)):
forward.append(max(arr[i], arr[i] + forward[i - 1]))
exactk = sum(arr[:k])
ans = exactk
atleast = 0
for i in range(k, n):
exactk += arr[i] - arr[i - k]
ans = max(ans, exactk)
atleast = exa... | FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ... |
Given an array and a number k, find the largest sum of the subarray containing at least k numbers. It may be assumed that the size of array is at-least k.
Example 1:
Input :
n = 4
arr[] = {-4, -2, 1, -3}
k = 2
Output :
-1
Explanation :
The sub array is {-2, 1}
Example 2:
Input :
n = 6
arr[] = {1, 1, 1, 1, 1, 1}
... | def maxSumWithK(a, n, k):
gs = a[0]
m = float("-inf")
l = []
l.append(a[0])
for i in range(1, len(a)):
if gs >= 0:
gs += a[i]
else:
gs = a[i]
l.append(gs)
j = k
i = 0
s = sum(a[:k])
m = s
while j != n:
s += a[j] - a[i]
... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = (int(x) for x in input().split())
lst = [int(x) for x in input().split()]
cnt = [(0) for i in range(m)]
if n > m:
print("YES")
return
for x in lst:
cnt[x % m] += 1
tbl = [[(False) for j in range(n + 1)] for i in range(m)]
tbl[0][0] = True
for j in range(1, n + 1):
for i in range(m):
tbl[i... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN FOR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSI... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | __author__ = "User"
n, m = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(n):
arr[i] = arr[i] % m
d = [0] * m
for e in arr:
t = [0] * m
t[e] = 1
for i in range(m):
if d[i] == 1:
t[(i + e) % m] = 1
for i in range(m):
if t[i] == 1:
... | ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CAL... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = list(map(int, input().split()))
if n > m:
print("YES")
else:
d = [{}, {}]
cur = 0
for x in l:
for y in d[cur].keys():
d[1 - cur][y] = 1
d[1 - cur][(y + x) % m] = 1
cur = 1 - cur
d[cur][x % m] = 1
if d[cur].get(0... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST DICT DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP B... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = sorted([int(i) for i in input().split()])
if len(set(l)) == 1 and 1 < n < m:
print("NO")
exit()
for i in range(n):
for j in range(i, n):
if not sum(l[i : j + 1]) % m:
print("YES")
exit()
if sum(l[:i]) and sum(l[j + 1 :]):
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR BI... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def main():
n, m = map(int, input().split())
a = list(map(int, input().split()))
mods = set()
flag = False
for num in a:
if mods:
for j in mods.copy():
mods.add((num + j) % m)
mods.add(num % m)
if 0 in mods:
flag = True
brea... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR ASSIGN VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
if n > m:
print("YES")
else:
dp = [False] * m
flag = 0
for i in range(n):
if dp[0]:
flag = 1
break
tmp = [False] * m
for j in range(m):
if dp[j]:
i... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
A = list(map(int, input().split()))
r = set()
for i in A:
i %= m
rzo = set()
for el in r:
rzo.add((el + i) % m)
for elem in rzo:
r.add(elem)
r.add(i)
if 0 in r:
print("YES")
exit(0)
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF NUMBER V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def solve():
n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n > m:
print("YES")
return
dp = [0] * m
dp[arr[0] % m] = 1
for i in range(1, n):
dp2 = dp[:]
x = arr[i] % m
for j in range(0, m):
if dp[j]:
d... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = list(map(lambda x: x % m, map(int, input().split())))
possible = set([])
for el in a:
new = set([el])
for candidate in possible:
new.add((candidate + el) % m)
possible |= new
if 0 in possible:
print("YES")
exit()
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF NUMBER VAR EXPR FUNC_CA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def modulus(arr, m, n):
for i in range(n):
arr[i] %= m
f = [0] * m
s = [0] * m
f[arr[0]] = 1
if f[0]:
return 1
for i in arr[1:]:
for j in range(m):
if f[j]:
s[j] = 1
elif i < j:
if f[j - i]:
s[j] ... | FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN NUMBER FOR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR IF V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | a = list(map(int, input().split(" ")))
n = a[0]
m = a[1]
arr = list(map(int, input().split(" ")))
d = dict()
if n > m / 2 * (m - 1):
print("YES")
else:
for j in range(m):
d[1, j] = 0
r = arr[0] % m
d[1, r] = 1
for i in range(2, n + 1):
r = arr[i - 1] % m
for j in range(m):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR A... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | try:
n, m = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
if n >= m:
print("YES")
else:
flag = 0
dp = [(0) for i in range(m + 1)]
for i in arr:
for j in range(m):
if dp[j] == 1 and dp[(i + j) % m] == 0:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR BIN_OP ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | __author__ = "dwliv_000"
n, m = (int(i) for i in input().split())
c = [(int(i) % m) for i in input().split()]
z = [False] * m
for j in c:
q = z[:]
q[j] = True
for i in range(m):
if z[i]:
q[(i + j) % m] = True
z = q[:]
if z[0]:
print("YES")
return
print("NO") | ASSIGN VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n > m:
print("YES")
exit()
p = [0] * 1010
for i in range(len(arr)):
q = [0] * 1010
arr[i] %= m
q[arr[i]] += 1
for j in range(m):
if p[j]:
q[(j + arr[i]) % m] += 1
for j in range(m):
p[j] += ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR VAR VAR VAR VAR VAR NU... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | import sys
N, M = input().split()
A = list(map(int, input().split()))
N = int(N)
M = int(M)
if N > M:
print("YES")
return
sys.setrecursionlimit(2000)
Q_memo = {}
for i, a in enumerate(A):
A[i] = A[i] % M
def Q(i, K, empty_sequence_ok):
if empty_sequence_ok and K == 0:
return True
if i == ... | IMPORT ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | import sys
n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n >= m or 0 in arr:
print("YES")
sys.exit(0)
dp = [False] * m
for val in arr:
val = val % m
dp1 = dp.copy()
dp1[val] = True
for i in range(m):
if dp[i]:
dp1[(i + val) % m] = True
dp = dp... | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUM... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
if n > m:
exit(print("YES"))
s = {0}
for i in map(int, input().split()):
tmp = set()
for j in s:
if (i + j) % m:
tmp.add((i + j) % m)
else:
exit(print("YES"))
s |= tmp
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | test = [*map(int, input().split())]
p = [*map(int, input().split())]
p = sorted(x % test[1] for x in p)
if 0 in p:
print("YES")
exit(0)
if len(set(p)) == 1 and test[0] < test[1] and p[0] < test[1] and p[0] != 0:
print("NO")
exit(0)
if test[0] == 996 and test[1] == 997 or test[0] == 998 and test[1] == 99... | ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMB... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = (int(i) for i in input().split())
numbers = [int(i) for i in input().split()]
results = {0}
res_update = results.update
for i in numbers:
tmp_results = set()
for j in results:
if (j + i) % m == 0:
print("YES")
return
tmp_results.add((j + i) % m)
res_update(tmp_... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR F... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
rem = set()
for i in a:
new = {((i + j) % m) for j in rem | {0}}
rem |= new
if 0 in rem:
print("YES")
exit()
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, k = map(int, input().split())
a = [int(i) for i in input().split()]
def check(a):
possible = set()
for num in a:
to_add = set()
for p in possible:
new = p + num % k
if new % k == 0:
return "YES"
to_add.add(new % k)
for t in to_add:... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR E... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
if n > m:
print("YES")
else:
a = [int(x) for x in input().split()]
mod = set()
for v in a:
tmp = set()
for i in mod:
tmp.add((i + v) % m)
tmp.add(v % m)
mod |= tmp
print("YES" if 0 in mod else "NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUN... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
dp = [False] * m
s = set([i for i in range(m)])
for i in range(n):
num = a[i] % m
rem = []
for j in s:
val = (j - num + m) % m
if dp[val] == True:
rem.append(j)
for j in rem:
dp[j] = True
s.d... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BI... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = list(map(int, input().split()))
lst = list(map(int, input().split()))
ans = set()
for i in lst:
if ans:
for j in ans.copy():
ans.add((i + j) % m)
ans.add(i % m)
else:
ans.add(i % m)
if 0 in ans:
print("YES")
break
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = input().split()
n = int(n)
m = int(m)
had = set()
for a in map(int, input().split()):
new = set()
for b in had:
new.add((a + b) % m)
had |= new
had.add(a % m)
if 0 in had:
print("YES")
exit()
print("NO") | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR EXPR FUNC_... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | a, b = map(int, input().split())
z = list(map(int, input().split()))
m = b
if len(z) >= b:
print("YES")
else:
dp = [[(0) for i in range(b)] for i in range(b)]
for i in range(len(z)):
if i == 0:
dp[i][z[i] % m] = 1
else:
dp[i][z[i] % m] = 1
for j in range(l... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def main():
n, m = list(map(int, input().split()))
l = [False] * m
l1 = l.copy()
for i in map(int, input().split()):
i %= m
l1[i] = True
for j, f in enumerate(l, i - m):
if f:
l1[j] = True
if l1[0]:
print("YES")
return
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CAL... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n > m:
print("YES")
exit()
s = set()
s.add(arr[0] % m)
for c in arr[1:]:
c %= m
s |= {((x + c) % m) for x in s}
s |= {c}
if 0 in s:
print("YES")
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR I... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def main():
n, m = map(int, input().split())
mas = list(map(int, input().split()))
remains = set()
for i in range(n):
for_add = set()
for e in remains:
if (e + mas[i]) % m == 0:
return True
else:
for_add.add((e + mas[i]) % m)
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = list(map(int, input().split()))
if n > m:
print("YES")
exit()
d = set()
for x in l:
w = {((y + x) % m) for y in d}
d |= w
d.add(x % m)
if 0 in d:
print("YES")
exit()
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR EX... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def process(a, m):
kr = []
ar = [(0) for j in range(m)]
for i in a:
r = int(i) % m
kr2 = []
for j in kr:
r2 = (j + r) % m
ar[r2] += 1
if ar[r2] >= m:
return "YES"
kr2.append(r2)
kr2.append(r)
kr = list(se... | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = list(map(int, input().split()))
possible = set()
if n > m:
print("YES")
else:
for i in a:
pending = set()
for p in possible:
pending.add((p + i) % m)
pending.add(i % m)
possible.update(pending)
print("YES" if 0 in possible else... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR F... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
ans = set()
for i in map(int, input().split()):
if ans:
for j in ans.copy():
ans.add((i + j) % m)
ans.add(i % m)
else:
ans.add(i % m)
if 0 in ans:
print("YES")
exit()
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR F... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | numElementos, modulo = input().split()
numElementos = int(numElementos)
modulo = int(modulo)
modulos = []
for i in range(modulo):
modulos.append(False)
restantePossivel = []
for i in range(modulo + 1):
restantePossivel.append(modulos.copy())
ultimoElemento = min(numElementos, modulo)
elementos = input().split()... | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def process(A, m):
m_set = set([])
for x in A:
if x % m == 0:
return "YES"
to_add = set([])
to_add.add(x % m)
for y in m_set:
if (y + x) % m == 0:
return "YES"
to_add.add((y + x) % m)
for z in to_add:
m_set.a... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER RETURN STRING ASSIGN VAR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER RETURN STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN STRING ASSIGN VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | R = lambda: map(int, input().split())
n, m = R()
if n > m:
print("YES")
exit(0)
arr = list(R())
dp = [([False] * m) for i in range(n + 1)]
for i in range(n):
for j in range(m):
dp[i][j] = dp[i - 1][j]
for j in range(m):
des = (j + arr[i]) % m
dp[i][des] = dp[i][des] or dp[i - 1][... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = [(int(x) % m) for x in input().split()]
y = False
if 0 in a:
print("YES")
elif n == 1:
print("NO")
else:
un = set()
for i in range(n):
c = set(un)
for j in c:
un.add((a[i] + j) % m)
un.add(a[i])
if 0 in un:
prin... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF NUMBER VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = [int(x) for x in input().split()]
if n > m:
print("YES")
else:
A = [(-1) for i in range(m)]
B = [(-1) for i in range(m)]
for i in range(n):
v = l[i]
B = A.copy()
B[v % m] = 1
for j in range(m):
if A[j] == 1:
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP V... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | num_elementos, modulo = [int(x) for x in input().split()]
modulos = [False] * modulo
restante_possivel = [modulos.copy() for _ in range(modulo + 1)]
ultimo_elemento = min(num_elementos, modulo)
elementos = input().split()
for i in range(1, ultimo_elemento + 1):
elemento = int(elementos[i - 1])
for restante in r... | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FO... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
if n > m:
print("YES")
exit()
a = [int(i) for i in input().split()]
can = [[(0) for i in range(m)] for j in range(n)]
for i in range(n):
can[i][a[i] % m] = 1
for i in range(n - 1):
for j in range(m):
if can[i][j] == 1:
can[i + 1][j] = 1
ca... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | for _ in range(1):
n, m = map(int, input().split())
arr = list(map(int, input().split()))
if n > m:
print("YES")
continue
dp = [[(0) for i in range(m)] for j in range(n)]
dp[0][arr[0] % m] = 1
if arr[0] % m == 0:
print("YES")
continue
flag = -1
for i in ra... | FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER ... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, x = map(int, input().split())
a = set()
for i in input().split():
i = int(i)
b = set()
for j in a:
b.add((i + j) % x)
a |= b
a.add(i % x)
if 0 in a:
print("YES")
break
else:
print("NO") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CAL... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = [int(i) for i in input().split()]
if n >= m:
print("YES")
else:
d = [0] * m
for j in l:
t = d[:]
t[j % m] = 1
for i in range(m):
if d[i]:
t[(i + j) % m] = 1
d = t
if d[0] == 1:
print("YES")
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR N... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = list(map(int, input().split()))
lst = list(map(int, input().split()))
if n > m:
print("YES")
else:
def rec(ps, sum, cnt):
if ps >= n:
if sum == 0 and cnt > 0:
return 1
else:
return 0
if dp[ps][sum] != -1:
return dp[ps][s... | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF IF VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
l = [int(x) for x in input().split()]
if n > m:
print("YES")
else:
li = []
f = 0
for i in l:
if i % m == 0 or i == 0:
f = 1
li.append(i % m)
li.sort()
cnt = [0] * m
cnt[0] = 1
for i in li:
if f == 1:
break
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_O... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | n, m = map(int, input().split())
a = list(map(lambda x: x % m, map(int, input().split())))
h = {}
for el in a:
h[el] = h.get(el, 0) + 1
for v in h.values():
if v % m == 0:
print("YES")
exit()
possible = set([])
for el in a:
new = set([el])
for candidate in possible:
new.add((cand... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | from sys import exit
n, m = map(int, input().split())
if n > m:
print("YES")
else:
dn = [([False] * (m + 1)) for _ in range(m + 1)]
dn[0][0] = True
for i, item in enumerate(map(lambda x: int(x) % m, input().split())):
for j in range(m):
if dn[i][j]:
dn[i + 1][(j + it... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | from sys import stdin, stdout
def fn(pos, rem, taken):
if pos == n:
return int(taken == 1 and rem == 0)
if (pos, rem, taken) in dp:
return dp[pos, rem, taken]
dp[pos, rem, taken] = fn(pos + 1, rem, taken) or fn(pos + 1, (rem + a[pos]) % m, 1)
return dp[pos, rem, taken]
for _ in range... | FUNC_DEF IF VAR VAR RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR RETURN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FU... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | import sys
old = sys.getrecursionlimit()
sys.setrecursionlimit(10000)
mem = dict()
def is_divisible(m, n, res, lis, is_empty):
if (n, res, is_empty) not in mem:
if n == len(lis) - 1:
if is_empty:
mem[n, res, is_empty] = (res + lis[-1]) % m == 0
else:
... | IMPORT ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUN... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def main():
n, m = [int(i) for i in input().split()]
if n > m:
print("YES")
return
a = [(int(i) % m) for i in input().split()]
d = [False] * m
for i in a:
next = d[:]
for j in range(m):
k = j + i
if k >= m:
k -= m
ne... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR ASSIGN... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | import sys
readline = sys.stdin.readline
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
n, m = nm()
a = nl()
te = set()
tt = []
f = 1
for i in a:
for j in te:
q = (j + i) % m
tt.append(... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | import sys
def dp(n, m):
mark = [(0) for i in range(m)]
a = list(map(int, input().split()))
for x in a:
for i in range(m):
if mark[i] == 1:
k = (i + x % m) % m
if mark[k] != 1:
mark[k] = 2
for i in range(m):
if mar... | IMPORT FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VA... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def dp(n, m, lista):
guarda = [(0) for i in range(m)]
for v in lista:
for i in range(m):
if guarda[i] == 1:
mod = (i + v % m) % m
if guarda[mod] != 1:
guarda[mod] = 2
for i in range(m):
if guarda[i] > 0:
... | FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR... |
You are given a sequence of numbers a_1, a_2, ..., a_{n}, and a number m.
Check if it is possible to choose a non-empty subsequence a_{i}_{j} such that the sum of numbers in this subsequence is divisible by m.
-----Input-----
The first line contains two numbers, n and m (1 ≤ n ≤ 10^6, 2 ≤ m ≤ 10^3) — the size of th... | def put():
return [int(x) for x in input().split()]
n, m = put()
a = list(put())
dp = [0] * m
dp[0] = 1
ans = "NO"
for i in range(n):
tmp = [0] * m
for j in range(m):
tmp[j] += dp[j]
mod = (j + a[i]) % m
tmp[mod] += dp[j]
if tmp[0] > 1:
ans = "YES"
break
dp ... | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.