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 number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?
-----Input-----
The first line contains 26 integers x_{a}, x_{b}, ..., x_{z} ( - 10^5 ≤ x_{i} ≤ 10^5) — the value assigned to letters a, b, c, ..., z respectively.
The second line contains string s of length between 1 and 10^5 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
Output
2
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
Output
2
-----Note-----
In the first sample test strings satisfying the condition above are abca and bcab.
In the second sample test strings satisfying the condition above are two occurences of aa.
|
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 or m < 1:
continue
l[i].sort()
r[i].sort()
a[m - 1] = m - 1
for j in range(m - 2, -1, -1):
if r[i][j][0] == r[i][j + 1][0]:
a[j] = a[j + 1]
else:
a[j] = j
y = 0
for j in range(n):
while y < m and r[i][y][0] < l[i][j][0]:
y += 1
while y < m and r[i][y][0] == l[i][j][0] and r[i][y][1] < l[i][j][1]:
y += 1
if y == m:
break
if r[i][y][0] == l[i][j][0]:
ans += a[y] - y + 1
print(ans)
|
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 VAR VAR VAR VAR VAR VAR VAR LIST VAR VAR VAR VAR BIN_OP VAR NUMBER LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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 number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?
-----Input-----
The first line contains 26 integers x_{a}, x_{b}, ..., x_{z} ( - 10^5 ≤ x_{i} ≤ 10^5) — the value assigned to letters a, b, c, ..., z respectively.
The second line contains string s of length between 1 and 10^5 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
Output
2
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
Output
2
-----Note-----
In the first sample test strings satisfying the condition above are abca and bcab.
In the second sample test strings satisfying the condition above are two occurences of aa.
|
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 ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
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 number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?
-----Input-----
The first line contains 26 integers x_{a}, x_{b}, ..., x_{z} ( - 10^5 ≤ x_{i} ≤ 10^5) — the value assigned to letters a, b, c, ..., z respectively.
The second line contains string s of length between 1 and 10^5 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
Output
2
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
Output
2
-----Note-----
In the first sample test strings satisfying the condition above are abca and bcab.
In the second sample test strings satisfying the condition above are two occurences of aa.
|
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(each) - 97][num] += 1
print(res)
|
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_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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 number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?
-----Input-----
The first line contains 26 integers x_{a}, x_{b}, ..., x_{z} ( - 10^5 ≤ x_{i} ≤ 10^5) — the value assigned to letters a, b, c, ..., z respectively.
The second line contains string s of length between 1 and 10^5 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
Output
2
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
Output
2
-----Note-----
In the first sample test strings satisfying the condition above are abca and bcab.
In the second sample test strings satisfying the condition above are two occurences of aa.
|
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 VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
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 number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes).
B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).
Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.
Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?
-----Input-----
The first line contains 26 integers x_{a}, x_{b}, ..., x_{z} ( - 10^5 ≤ x_{i} ≤ 10^5) — the value assigned to letters a, b, c, ..., z respectively.
The second line contains string s of length between 1 and 10^5 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
xabcab
Output
2
Input
1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1
aaa
Output
2
-----Note-----
In the first sample test strings satisfying the condition above are abca and bcab.
In the second sample test strings satisfying the condition above are two occurences of aa.
|
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)
if costss[ord(s[i]) - 97] == 0:
ans -= 1
print(ans)
|
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_CALL VAR VAR VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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
return ans
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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
exactk = 0
result = float("-inf")
for we in range(len(a)):
if we - ws < k:
exactk += a[we]
else:
result = max(result, exactk)
exactk += a[we] - a[ws]
atleastk = exactk + prevsum[ws]
ws += 1
result = max(result, atleastk, exactk)
if we - ws >= len(a) - 1:
return exactk
return result
|
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 ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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(k, n):
count += a[i] - a[i - k]
ans = max(ans, count)
atleast = count + dpf[i - k]
ans = max(ans, atleast)
return ans
|
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 VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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):
exactK += nums[i]
if exactK > ans:
ans = exactK
for j in range(k, len(nums)):
exactK += nums[j] - nums[j - k]
if exactK > ans:
ans = exactK
ans = max(ans, arr[j - k] + exactK)
return ans
|
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 STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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)
e = 0
return ans
|
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 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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]
result = max(sm, result)
result = max(result, sm + maxi[i - k])
return result
|
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 VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 in range(k, n):
ans = max(ans, mx[i] - mn[i - k])
return ans
|
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 VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 - k]
result = max(result, sum)
result = max(result, sum + maxSum[i - k])
return result
|
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_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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):
exactly_k += a[i] - a[i - k]
ans = max(ans, exactly_k)
atleast_k = exactly_k + l[i - k]
ans = max(ans, atleast_k)
return ans
|
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 VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 - k])
return max_sum
|
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 VAR FUNC_CALL VAR VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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(cur, prev)
maxsum = max(maxsum, prev, cur)
return maxsum
|
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 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 range(k, n):
sumK += a[i] - a[i - k]
curr_sum = max(result, sumK)
result = max(result, curr_sum)
result = max(result, sumK + maxSumAtIndex[i - k])
return result
|
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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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] - arr[i - k]
ans = max(ans, exactK)
biggerThanK = exactK + maxSum[i - k]
ans = max(ans, biggerThanK)
return ans
|
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 VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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(k, n):
ex += a[i] - a[i - k]
ans = max(ans, ex)
at = ex + f[i - k]
ans = max(ans, at)
return ans
|
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 FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 = max(answer, su)
last = 0
end += 1
return 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 in range(k, n):
l += a[i] - a[i - k]
ans = max(ans, l)
c = l + f[i - k]
ans = max(ans, c)
return ans
|
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 ASSIGN VAR FUNC_CALL 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 VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 = 0
return ans
|
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 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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):
exactk += a[i] - a[i - k]
ans = max(ans, exactk)
atleastk = exactk + F[i - k]
ans = max(atleastk, ans)
return ans
|
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 VAR VAR NUMBER 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 VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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]
if exactk > maxi:
maxi = exactk
for i in range(k, n):
exactk += arr[i] - arr[i - k]
if exactk > maxi:
maxi = exactk
morethank = exactk + bestsubarray[i - k]
if morethank > maxi:
maxi = morethank
return maxi
|
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 BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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
j += 1
return maxi
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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
ans = max(ans, sumarr)
return ans
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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] = min(min_prefix_sum[i - 1], prefix_sum[i])
for i in range(k, n + 1):
max_sum = max(max_sum, prefix_sum[i] - min_prefix_sum[i - k])
return max_sum
|
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_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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:
sum = sum - last
max_sum = max(sum, max_sum)
last = 0
return max_sum
|
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 VAR VAR ASSIGN 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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(ans, sum)
for i in range(k, n, 1):
sum = sum - a[i - k] + a[i]
ans = max(ans, sum)
atleast = sum + list1[i - k]
ans = max(atleast, ans)
return ans
|
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 FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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.append(curr_sum)
exactK = 0
for i in range(k):
exactK += nums[i]
if exactK > ans:
ans = exactK
for i in range(k, len(nums), 1):
exactK = exactK + nums[i] - nums[i - k]
if exactK > ans:
ans = exactK
morethanK = max_sum[i - k] + exactK
if morethanK > ans:
ans = morethanK
return ans
|
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 VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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):
exactk += a[j]
if ans < exactk:
ans = exactk
for m in range(k, n):
exactk -= a[m - k]
exactk += a[m]
if exactk > ans:
ans = exactk
morethank = exactk + max_sum[m - k]
if morethank > ans:
ans = morethank
return ans
|
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 FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 i in range(k, n):
sum += a[i] - a[i - k]
ans = max(ans, sum)
c = sum + new[i - k]
ans = max(ans, c)
return ans
|
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 VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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:
j += 1
currsum += a[j]
currsum -= a[i]
i += 1
if arr[i - 1] > 0:
ans = max(ans, currsum + arr[i - 1])
ans = max(currsum, ans)
return ans
|
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 VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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")
for i in range(k):
exactK += arr[i]
res = max(res, exactK)
for we in range(k, len(arr)):
exactK += arr[we] - arr[ws]
atleastK = forward[ws] + exactK
res = max(res, exactK, atleastK)
ws += 1
return res
|
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 FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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(ans, cur, prev)
return ans
|
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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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, ans)
aux_sum -= a[beg]
beg += 1
end += 1
return sum
def kandane(a, n):
res = [0] * n
aux_sum, sum = 0, float("-inf")
for i in range(n):
aux_sum += a[i]
if aux_sum < a[i]:
aux_sum = a[i]
res[i] = aux_sum
return res
|
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 VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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)
res = max(res, sums - iwinmin)
i += 1
return res
|
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_CALL VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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.maxsize - 1
if exactwin > ans:
ans = exactwin
for i in range(k, n):
exactwin += nums[i] - nums[i - k]
if exactwin > ans:
ans = exactwin
if exactwin + store[i - k] > ans:
ans = exactwin + store[i - k]
return ans
|
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 VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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])
return res
|
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 BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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)
return sum
def kandane(a, n):
res = [0] * n
aux_sum, sum = 0, float("-inf")
for i in range(n):
aux_sum += a[i]
if aux_sum < a[i]:
aux_sum = a[i]
res[i] = aux_sum
return res
|
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 FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 = 0
for i in range(k):
res += nums[i]
exactK = res
for i in range(k, len(arr1)):
exactK += nums[i] - nums[i - k]
atleastk = exactK + arr1[i - k]
res = max(res, exactK, atleastk)
return 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 VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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 = exactk + forward[i - k]
ans = max(ans, atleast)
return ans
|
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 VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR 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}
k = 2
Output :
6
Explanation :
The sub array is {1, 1, 1, 1, 1, 1}
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxSumWithK() which takes the array A[], its size N and an integer K as inputs and returns the value of the largest sum of the subarray containing at least k numbers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(N)
Constraints:
1<=n<=10^{5}
-10^{5}<=a[i]<=10^{5}
1<=k<=n
|
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]
m = max(m, s)
e = s + l[i]
m = max(m, e)
j += 1
i += 1
return m
|
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 VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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][j] = tbl[i][j - 1]
for i in range(m):
if tbl[i][j - 1]:
if (i + lst[j - 1]) % m == 0:
print("YES")
return
tbl[(i + lst[j - 1]) % m][j] = True
print("NO")
|
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 ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
__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:
d[i] = 1
if d[0] == 1:
break
if d[0] == 1:
print("YES")
else:
print("NO")
|
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_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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, 0):
break
print("YES" if d[cur].get(0, 0) else "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 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 BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 :]):
if not sum(l[:i] + l[j + 1 :]) % m:
print("YES")
exit()
else:
print("NO")
|
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 BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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
break
if flag:
print("YES")
else:
print("NO")
return
main()
|
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 NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN EXPR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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]:
if not dp[(arr[i] + j) % m]:
tmp[(arr[i] + j) % m] = True
for j in range(m):
dp[j] |= tmp[j]
dp[arr[i] % m] = True
flag = dp[0]
print(["NO", "YES"][flag])
|
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 VAR IF VAR VAR IF VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR LIST STRING STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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]:
dp2[(j + x) % m] = 1
dp2[x] = 1
dp = dp2
if dp[0]:
print("YES")
else:
print("NO")
solve()
|
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 VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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_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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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] = 1
elif i > j:
if f[j - i + m]:
s[j] = 1
else:
s[j] = 1
if s[0]:
return 1
f, s = s, f
return 0
n, m = map(int, input().split())
arr = list(map(int, input().split()))
print("YES") if modulus(arr, m, n) else print("NO")
|
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 VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR RETURN 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 EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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):
d[i, j] = 0
d[i, r] = 1
for j in range(m):
if d[i - 1, j] == 1:
d[i, j] = 1
d[i, (j + r) % m] = 1
if d[n, 0] == 1:
print("YES")
else:
print("NO")
|
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 ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
dp[(i + j) % m] = 2
for j in range(m):
if dp[j]:
dp[j] = 1
dp[i % m] = 1
if dp[0]:
print("YES")
else:
print("NO")
except Exception as e:
print(e)
|
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 BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
__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 VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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] += q[j]
if p[0]:
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 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 == 0:
return A[0] == K
args = i, K, empty_sequence_ok
if args not in Q_memo:
Q_memo[args] = Q(i - 1, K, empty_sequence_ok) or Q(i - 1, (K - A[i]) % M, True)
return Q_memo[args]
if Q(N - 1, 0, False):
print("YES")
else:
print("NO")
|
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 FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN 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 IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 = dp1.copy()
if dp[0]:
print("YES")
sys.exit(0)
print("NO")
|
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 STRING VAR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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] == 999:
print("NO")
exit(0)
for i in range(test[0]):
for j in range(i, test[0]):
if not sum(p[i : j + 1]) % test[1]:
print("YES")
exit(0)
if sum(p[:i]) and sum(p[j + 1 :]):
if not sum(p[:i] + p[j + 1 :]) % test[1]:
print("YES")
exit(0)
else:
print("NO")
|
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 NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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_results)
print("NO")
|
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 FUNC_CALL VAR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
possible.add(t)
possible.add(num % k)
if 0 in possible:
return "YES"
return "NO"
ans = check(a)
print(ans)
|
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 EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 FUNC_CALL VAR NUMBER VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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.discard(j)
dp[num] = True
s.discard(num)
if dp[0] == True:
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 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 BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 NUMBER VAR EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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_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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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(len(dp[i - 1])):
if dp[i - 1][j] == 1:
r = (j + z[i]) % m
dp[i][r] = 1
dp[i][j] = 1
flag = 0
for i in range(len(dp)):
an = dp[i]
for j in range(len(an)):
if an[0] == 1:
flag = 1
break
if flag == 1:
break
if flag == 1:
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 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 BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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
l = l1.copy()
print("NO")
def __starting_point():
main()
__starting_point()
|
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_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR EXPR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 IF NUMBER VAR EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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)
if mas[i] % m == 0:
return True
else:
for_add.add(mas[i])
remains |= for_add
if main():
print("YES")
else:
print("NO")
|
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 VAR IF BIN_OP VAR VAR VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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(set(kr) | set(kr2))
ar[r] += 1
if ar[r] >= m:
return "YES"
if ar[0] > 0:
return "YES"
return "NO"
s = input()
a = s.split(" ")
n, m = int(a[0]), int(a[1])
s = input()
a = s.split(" ")
print(process(a, m))
|
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 VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR RETURN STRING IF VAR NUMBER NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 "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 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 FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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()
for i in range(1, ultimoElemento + 1, 1):
elementoI = int(elementos[i - 1])
for restante in range(0, modulo, 1):
if restantePossivel[i - 1][restante]:
restantePosAdd = (restante + elementoI) % modulo
restantePossivel[i][restantePosAdd] = True
restantePossivel[i][restante] = True
restantePossivel[i][elementoI % modulo] = True
if numElementos > modulo or restantePossivel[ultimoElemento][0]:
print("YES")
else:
print("NO")
|
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 VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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.add(z)
return "NO"
n, m = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
print(process(A, m))
|
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 VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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][j] if j else True
print("YES" if dp[n - 1][0] else "NO")
|
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 VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
print("YES")
y = True
break
if not y:
print("NO")
|
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 FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
B[(j + v) % m] = 1
A = B.copy()
if A[0] == 1:
print("YES")
else:
print("NO")
|
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 VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 range(0, modulo):
if restante_possivel[i - 1][restante]:
restante_pos_add = (restante + elemento) % modulo
restante_possivel[i][restante_pos_add] = True
restante_possivel[i][restante] = True
restante_possivel[i][elemento % modulo] = True
if num_elementos > modulo or restante_possivel[ultimo_elemento][0]:
print("YES")
else:
print("NO")
|
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 FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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
can[i + 1][(j + a[i + 1]) % m] = 1
if can[n - 1][0]:
print("YES")
else:
print("NO")
|
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 BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 range(n - 1):
for j in range(m):
if dp[i][j] == 1:
dp[i + 1][j] = 1
dp[i + 1][(arr[i + 1] + j) % m] = 1
dp[i + 1][arr[i + 1] % m] = 1
if dp[i + 1][0] == 1:
flag = 1
break
if flag == 1:
print("YES")
continue
print("NO")
|
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 VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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_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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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")
break
else:
print("NO")
|
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 NUMBER ASSIGN VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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][sum]
dp[ps][sum] = rec(ps + 1, (sum + lst[ps]) % m, cnt + 1) | rec(ps + 1, sum, cnt)
return dp[ps][sum]
dp = [[(-1) for _ in range(m + 7)] for _ in range(n + 7)]
if rec(0, 0, 0) == 1:
print("YES")
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 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_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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
tmp = [0] * m
for j in range(m - 1, -1, -1):
tmp[j] = tmp[j] + cnt[(j - i % m) % m]
for j in range(0, m):
cnt[j] = cnt[j] + tmp[j]
if cnt[0] > 1:
f = 1
if f == 1:
print("YES")
else:
print("NO")
|
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_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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((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 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_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_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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 + item) % m] = True
dn[i + 1][j] = True
if (j + item) % m == 0:
print("YES")
exit(0)
print("NO")
|
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 VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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(1):
n, m = list(map(int, stdin.readline().split()))
a = list(map(int, stdin.readline().split()))
if m <= n:
print("YES")
continue
dp = {}
if fn(0, 0, 0):
print("YES")
else:
print("NO")
|
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 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 DICT IF FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
mem[n, res, is_empty] = res == 0 or (res + lis[-1]) % m == 0
else:
mem[n, res, is_empty] = is_divisible(
m, n + 1, res, lis, is_empty
) or is_divisible(m, n + 1, (res + lis[n]) % m, lis, False)
return mem[n, res, is_empty]
n, m = map(int, input().split())
lis = [int(x) for x in input().split()]
if n > m or is_divisible(m, 0, 0, lis, True):
print("YES")
else:
print("NO")
|
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 FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR VAR VAR 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 FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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
next[k] = d[k] or d[j]
d = next
d[i] = True
if d[0]:
print("YES")
else:
print("NO")
main()
|
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 VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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(q)
tt.append(i % m)
if 0 in tt:
f = 0
break
while len(tt) > 0:
q = tt.pop()
te.add(q)
if f == 0:
print("YES")
else:
print("NO")
|
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 ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 mark[i] > 0:
mark[i] = 1
mark[x % m] = 1
return mark[0]
input = sys.stdin.readline
n, m = list(map(int, input().split()))
flag = True
if n <= m:
flag = dp(n, m) != 0
if flag:
print("YES")
else:
print("NO")
|
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 VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER RETURN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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:
guarda[i] = 1
guarda[v % m] = 1
return guarda[0]
n, m = map(int, input().split())
sequencia = list(map(int, input().split()))
if n > m:
print("YES")
elif dp(n, m, sequencia) == 0:
print("NO")
else:
print("YES")
|
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 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 IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING 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 the original sequence and the number such that sum should be divisible by it.
The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9).
-----Output-----
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
-----Examples-----
Input
3 5
1 2 3
Output
YES
Input
1 6
5
Output
NO
Input
4 6
3 1 1 3
Output
YES
Input
6 6
5 5 5 5 5 5
Output
YES
-----Note-----
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence.
|
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 = tmp
print(ans)
|
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 BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.