description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Barney lives in NYC. NYC has infinite number of intersections numbered with positive integers starting from 1. There exists a bidirectional road between intersections i and 2i and another road between i and 2i + 1 for every positive integer i. You can clearly see that there exists a unique shortest path between any two... | def main():
d = {}
for _ in range(int(input())):
c, *l = input().split()
if c == "1":
v, u, w = map(int, l)
while u != v:
if u < v:
d[v] = d.get(v, 0) + w
u, v = v // 2, u
else:
d[... | FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VA... |
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.
Example 1:
Input: [4, 1, 8, 7]
Output: True
Explanation: (8-4) * (7-1) = 24
Example 2:
Input: [1, 2, 1, 2]
Output: False
Note:
The division operator / represe... | class Solution:
def judgePoint24(self, nums):
bad = "对撒剘劥圞剜劏哱掶桺泛揋掵従剟剣彫寣污悫壛梄甏咍哲汭剤堧点卋嬞勆叛汬泐塵栋劚嚮咃宠吖剗楗囧力桻攋壯劯嗏桹劙剢剚焧啫栕炸栫栖嚲彳剛撑烃洿宋汷彲剙揁妷埻撧汢吩壙劇剭埼吕剝汣敯憇勇剥咎囻匓"
return chr(int("".join(map(str, sorted(nums)))) + 19968) not in bad | CLASS_DEF FUNC_DEF ASSIGN VAR STRING RETURN FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR |
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.
Example 1:
Input: [4, 1, 8, 7]
Output: True
Explanation: (8-4) * (7-1) = 24
Example 2:
Input: [1, 2, 1, 2]
Output: False
Note:
The division operator / represe... | class Solution(object):
def judgePoint24(self, nums):
def cal(operands, operaters):
for opt in operaters:
op2, op1 = operands.pop(-1), operands.pop(-1)
if opt == "+":
ret = op1 + op2
elif opt == "-":
ret = ... | CLASS_DEF VAR FUNC_DEF FUNC_DEF FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR STRING EXPR FUNC_CALL VAR V... |
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.
Example 1:
Input: [4, 1, 8, 7]
Output: True
Explanation: (8-4) * (7-1) = 24
Example 2:
Input: [1, 2, 1, 2]
Output: False
Note:
The division operator / represe... | class Solution(object):
def judgePoint24(self, nums):
n = len(nums)
if n == 1:
return abs(nums[0] - 24) < 0.0001
for i in range(n - 1):
for j in range(i + 1, n):
remainder = nums[:i] + nums[i + 1 : j] + nums[j + 1 :]
if self.judgePoint... | CLASS_DEF VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR LIST BIN... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def findAllcombinationSum(self, index, candidates, target, ans, ds):
if index == len(candidates):
if target == 0:
ans.append(ds[:])
return
return
if candidates[index] <= target and candidates[index] not in ds:
ds.ap... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN RETURN IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBE... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, target):
arr = [i for i in range(1, 10)]
ans = []
dummy = []
self.answer(k, target, arr, ans, dummy, 0, 0)
return ans
def answer(self, k, target, arr, ans, dummy, index, ld):
if target == 0 and ld == k:
ans... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, n):
res = []
candidates = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def sol(i, c, k, candidates, target):
if target == 0 and k == 0:
res.append(c.copy())
return
if k < 0 or target < 0 or i == 9:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def find(K, target, i, temp):
if len(temp) == K and sum(temp) == target:
res.append(temp.copy())
elif len(temp) < K and sum(temp) < target:
for j in range(i + 1, 10):
if sum(tem... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIG... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, target):
def helper(i, k, sumtill):
if k == 0:
if sumtill == target:
ans.append(subset.copy())
return
if sumtill > target:
return
if i > 9:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR RETURN IF VAR NUMBER RETURN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
result = []
def solve(pos, ds, total):
if len(ds) == K:
if total == target:
result.append(ds)
return
for i in range(pos, 9 + 1):
solve(i + 1, ds + [i], t... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER LIST NUMBER RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
inp_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
res = []
def get_sum(inp, cursum, ans, tgt, cnt):
if cnt < K:
for i in range(len(inp)):
ele = inp[i]
if cnt + 1 == K and cursum + e... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR IF BIN_OP VAR VAR VAR IF VAR BIN_OP FUNC_CAL... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def gen(self, k, target, nums, arr, brr, pos, c):
if pos == 9 or c == k:
if target == 0 and c == k:
crr = brr.copy()
arr.add(tuple(crr))
return
if target < 0:
return
brr.append(nums[pos])
self.gen(k,... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def find(self, i, p, K, target, l, l1):
if p == K and target == 0:
l.append(l1.copy())
return
if p == K:
return
if target == 0:
return
if i == 10:
return
l1.append(i)
self.find(i + 1, p + 1, ... | CLASS_DEF FUNC_DEF IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR RETURN IF VAR NUMBER RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, k, n, ans, lis, num):
if len(lis) == k:
if n == 0:
ans.append(tuple(lis.copy()))
return
for i in range(num, 10):
lis.append(i)
self.solve(k, n - i, ans, lis, i + 1)
lis.pop()
def combina... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR LIST NUMBER R... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, target):
arr = [i for i in range(1, 10)]
res = []
def backtrack(subset, idx, sum, count):
if count == k and sum == target:
res.append(subset[:])
return
if idx >= len(arr) or count > k or tar... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | from itertools import combinations
class Solution:
def combinationSum(self, K, target):
from itertools import combinations
x = combinations([1, 2, 3, 4, 5, 6, 7, 8, 9], K)
y = []
for i in x:
if sum(i) == target:
y.append(i)
return y | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
res = []
ds = []
ans = []
for i in range(1, 10):
ds.append(i)
def getAns(ind, tar, ds, ans, res):
if ind == len(ds):
if len(ans) == K and tar == 0:
res.append(an... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def helper(target, k, start, path, res):
if target == 0 and k == 0:
res.append(path)
return
if target < 0 or k < 0:
return
for i in range(start, 10):
hel... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER LIST VAR RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def combi(arr, p, target, sol, k, i):
if target == 0 and len(p) == k:
sol.append(p)
return
if target < 0 or len(p) > k or i == 9:
return
combi(arr, p + [arr[i]], target ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, ans, output, index, nums, K, target):
if index == len(nums):
if K == 0 and target == 0:
ans.append(output)
return
if K == 0 and target == 0:
ans.append(output)
return
self.solve(ans, output, inde... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUN... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
nums = [(i + 1) for i in range(9)]
ans = []
def dfs(pos, res, total):
if total == target and len(res) == K:
ans.append(res.copy())
if total > target or pos >= len(nums) or len(res) > K:
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMB... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
ans = []
arr = []
numlist = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def funcall(index, sumtillnow, arr):
if len(arr) == K:
if sumtillnow == target:
ans.append(arr.copy())
return... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def __init__(self):
self.ans = []
def combinationSum(self, K, target):
self.util(range(1, 10), target, [], 0, 0)
return [k for k in self.ans if len(k) == K]
def util(self, A, B, elements, i, sumso):
if i == len(A):
return
if sumso + A[i]... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR LIST NUMBER NUMBER RETURN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR VAR VAR RETURN IF BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR LI... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = K
ans = []
sum = target
temp = []
def combination(arr, sum, ans, temp, index, k):
if sum == 0 and len(temp) == k:
ans.append(temp.copy())
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, i, Sum, k, temp, ans):
if Sum == 0 and k == 0:
ans.append(temp)
print(ans)
return
if k == 0 or Sum > i:
return
if i == 10:
return
if Sum - i >= 0:
temp.append(i)
self.... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER VAR VAR RETURN IF VAR NUMBER RETURN IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | def combisum2(i, target, subs, arr, ans, n, num, k):
if i == n:
if target == 0 and k == num:
ans.append(subs[:])
return
if target - arr[i] >= 0:
subs.append(arr[i])
num += 1
combisum2(i + 1, target - arr[i], subs, arr, ans, n, num, k)
num -= 1
... | FUNC_DEF IF VAR VAR IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EX... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, target):
results = []
candidates = list(range(1, 10))
def backtrack(start, target, combination):
if target == 0 and len(combination) == k:
results.append(combination)
return
for i in range(s... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR B... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, n):
ans = []
res = []
def backtrack(num, res, target):
if len(res) == k:
if target == 0:
ans.append(res.copy())
return
for i in range(num + 1, 10):
if i <... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR LIST VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER VAR VAR RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def helper(self, arr, K, target, sum1, list1, count):
if arr == []:
return
if count > K:
return
if sum1 > target:
return
if sum1 == target:
if count == K:
self.res.append(list1)
return
... | CLASS_DEF FUNC_DEF IF VAR LIST RETURN IF VAR VAR RETURN IF VAR VAR RETURN IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR LIST VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
ans = []
li = []
def helper(i, k, target, ans, li):
if k == 0:
if target == 0:
ans.append(list(li))
return
if i > 9:
return
li.ap... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr, combinations = [], []
self.noOfCombinations(0, target, arr, combinations, nums, K)
return combinations
def noOfCombinations(self, n, target, arr, combinations, nums, k):
if targ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST EXPR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN IF VAR VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
List = []
def recur(arr, summ, count, k, target, val):
if summ > target or count > k:
return
if summ == target and count == k:
List.append(arr[:])
return
if val ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
a = list(range(1, 10))
def recurs(i, sums, vals):
nonlocal res
if sums == target and len(vals) == K and vals.copy() not in res:
res.append(vals.copy())
return
if sums > target o... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF IF VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
setti = set([(0, ())])
output = []
for i in range(1, 10):
temp = set()
for item in setti:
summa = i + item[0]
items = item[1] + (i,)
if len(items) == K and summa == t... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR V... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | def rec(i, ans, res, target, K):
if K == 0 and target == 0:
ans.append(res.copy())
if K == 0 or target < 0:
return
for j in range(i, 10):
res.append(j)
rec(j + 1, ans, res, target - j, K - 1)
res.pop()
class Solution:
def combinationSum(self, K, target):
... | FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, n):
ans = []
def dfs(path, nums, k, n):
if k < 0:
return -1
if k == 0 and n == 0:
ans.append(path[:])
return
for i in range(len(nums)):
dfs(path + [nums[i... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, target):
def calc(s, ind, temp):
if s == 0:
if len(temp) == k:
ans.append(temp[:])
return
return
for i in range(ind, len(arr)):
if i > ind and arr[i] ... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | def bt(k, n):
times = {i: (1) for i in range(1, 10)}
res = []
helper(k, n, [], times, res)
return res
def helper(k, n, temp, times, res):
if n == 0 and len(temp) == k:
res.append(temp.copy())
for num in times:
if not temp and times[num] > 0 and n - num >= 0 and len(temp) <= k:
... | FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR LIST VAR VAR RETURN VAR FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def com(i, N, K, target, arr, count, res, s, l):
if s == target and count == K:
res[tuple(l)] = 1
return
if i == N:
return
if c... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN IF VAR VAR RETURN IF VAR VAR RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, prev, K, N, ans, lst=[]):
if K == 0:
if N == 0:
ans.append(lst.copy())
return
if N < 0 or K < 0:
return
if prev > 9:
return
for i in range(prev, 10):
lst.append(i)
... | CLASS_DEF FUNC_DEF LIST IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR NUMBER VAR NUMBER RETURN IF VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LI... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
res = []
op = []
start = 0
self.comb(res, op, start, 1, K, target)
return res
def comb(self, res, op, start, i, K, target):
if start == K and target == 0:
res.append(op.copy())
if target ==... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER RETURN IF VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BI... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def dfs(idx, path, cur, size):
if cur > target or size > K:
return
if cur == target:
if size == K:
ans.append(path.copy())
return
for i in range(idx,... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR VAR VAR VAR RETURN IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER LIST NUMBER NUMBER RETURN FUNC_CALL VAR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | def munny(arr, ans, res, ind, target, K, sum1, co):
if sum1 > target:
return
if sum1 == target and co == K:
res.append(ans)
return
if co >= K:
return
if ind > 8:
return
ans.append(arr[ind])
munny(arr, ans.copy(), res, ind + 1, target, K, sum1 + arr[ind], c... | FUNC_DEF IF VAR VAR RETURN IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUM... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
res = []
self.dfs(res, arr, K, target, [])
return res
def dfs(self, res, arr, k, target, path):
if target < 0 or k < 0:
return
elif target == 0 and k == 0:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR LIST RETURN VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | from itertools import combinations
class Solution:
def combinationSum(self, K, target):
from itertools import combinations
l = []
c = combinations(range(1, 10), K)
s = []
for i in c:
if sum(i) == target:
s.append(i)
return s | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, K, start, sum, ans, store):
if K == 0 and sum == 0:
store.append(ans)
return
if K <= 0:
return
for i in range(start, 10):
if sum - i >= 0:
self.solve(K - 1, i + 1, sum - i, ans + [i], store)
... | CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR LIST VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER VAR LIST VAR RETUR... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def findAllcombinationSum(self, index, candidates, target, ans, ds, k):
if index == len(candidates):
if target == 0 and len(ds) == k:
ans.append(ds[:])
return
return
ds.append(candidates[index])
self.findAllcombinationS... | CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN RETURN EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def solve(idx, arr, target, K, l, ans):
if target == 0 and len(l) == K:
ans.append(l.copy())
return
for i in range(idx, len(arr)):
if i > idx and arr[i] == arr[i - 1]:
... | CLASS_DEF FUNC_DEF FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, k, n):
cand = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ds = []
a = []
cand.sort()
ind = 0
def comb(ind, arr, t, a, ds):
if t == 0 and len(ds) == k:
a.append(ds.copy())
return
if t < ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR NUMBER RETURN IF FUNC_CALL VAR VAR VAR RETURN FOR VAR FUNC_CA... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
def rec(ind, ans, ds, s, k, target):
if len(ds) == k and s[0] == target:
ans.append(ds.copy())
return
if ind > 9:
return
ds.append(ind)
s[0] += ind
... | CLASS_DEF FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN IF VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIG... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combsum(self, k, arr, index, seq, target):
if k == 0:
if target == 0:
self.res.append(seq)
return
if index == len(arr):
return
self.combsum(k - 1, arr, index + 1, seq + [arr[index]], target - arr[index])
self.co... | CLASS_DEF FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR FUNC_CAL... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
res = []
def backtracking(ind, total, curr):
if len(curr[:]) == K and total == 0:
res.append(curr[:])
return
if len(curr[:]) > K or total < 0:
return
if ind >= 1... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN IF VAR NUMBER RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL ... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target, start=1, till=[]):
if K == 1:
if target >= start:
if target < 10:
return [[*till, target]]
else:
return []
else:
return []
ans = []
... | CLASS_DEF FUNC_DEF NUMBER LIST IF VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN LIST LIST VAR VAR RETURN LIST RETURN LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER LIST VAR VAR VAR VAR RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
whole = []
def recsum(temp, ans, i):
whole.append(temp[:])
if len(temp) == K and target == sum(temp):
ans.append(temp[:])
return
for j in range(i, 10):
if len(te... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FUNC_DEF EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EX... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
if target > 45:
return []
ans = []
def solve(temp, i):
if len(temp) == K and sum(temp) == target:
ans.append(temp.copy())
return
for j in range(i, 10):
t... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN LIST ASSIGN VAR LIST FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST NUMBER RETURN VAR |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
if K > target:
return []
options = 1, 2, 3, 4, 5, 6, 7, 8, 9
res = []
def helper(idx, sumi, temp):
if sumi > target:
return
if len(temp) == K:
if sumi == target:... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN LIST ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR RETURN IF FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR RETURN FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def combinationSum(self, K, target):
valid = []
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def ans(ind, arr, K, target, temp):
if len(temp) == K or target == 0:
if target == 0 and len(temp) == K:
valid.append(temp[:])
r... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR B... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | class Solution:
def solve(self, k, target, i, lst, ans):
if len(lst) == k or i > 9:
if target == 0 and len(lst) == k:
ans.append(tuple(lst))
return
lst.append(i)
self.solve(k, target - i, i + 1, lst, ans)
lst.pop()
self.solve(k, target... | CLASS_DEF FUNC_DEF IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR LIST A... |
Find all valid combinations of K numbers that sum upto to N such that the following conditions are true:
Only number 1 through 9 are used.
Each number is used atmost once.
Return the list of all possible valid combinations.
Note: The list must not contain the same combination twice, and the combinations returned in a... | from itertools import combinations
class Solution:
def combinationSum(self, K, target):
ans = []
arr = range(1, 10)
comb = combinations(arr, K)
for i in comb:
if sum(i) == target:
ans.append(i)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = list(map(int, input().split()))
even = {}
odd = {}
for i in range(len(a)):
if a[i] % 2 == 0:
if a[i] in even:
even[a[i]] += 1
else:
even[a[i]] = 1
elif a[i] in odd:
odd[a[i]] += 1
else:
odd[a[i]] = 1
count = 0
count2 = 0
for keys, ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = list(map(int, input().split()))
M = dict()
res = 0
for i in range(n):
for j in range(31):
res += M.get(2**j - a[i], 0)
M[a[i]] = M.get(a[i], 0) + 1
print(res) | ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUM... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
l = list(map(int, input().split()))
twos = set()
for i in range(1, 36):
twos.add(2**i)
dic = {}
for i in range(len(l)):
if l[i] not in dic:
dic[l[i]] = 1
else:
dic[l[i]] += 1
ans = 0
for i in dic:
for two in twos:
x = two - i
if x > 0:
if x in... | ASSIGN VAR FUNC_CALL VAR 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 NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | from sys import stdin, stdout
n = int(stdin.readline())
power = [(2**i) for i in range(31)]
d = {}
ans = 0
for value in map(int, stdin.readline().split()):
for m in power:
if m >= value and m - value in d:
ans += d[m - value]
if value in d:
d[value] += 1
else:
d[value] =... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
s = sum(arr)
d = {}
ans = 0
for i in arr:
start = 1
while start <= s:
if start - i in d:
ans += d[start - i]
start *= 2
if i in d:
d[i] += 1
else:
d[i] = 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR N... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
d = dict()
for i in input().split():
if int(i) in d:
d[int(i)] += 1
else:
d[int(i)] = 1
mylist = []
ans = 0
for a in range(1, 31):
mylist.append(2**a)
for a in d:
for b in mylist:
if b - a in d:
if b - a != a:
ans += d[b - a] * d[a]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR VAR FOR VAR VAR IF ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input().strip())
a = list(map(int, input().strip().split()))
res = 0
countVal = {}
for i in range(n):
pow2 = 1
for j in range(30):
pow2 *= 2
if pow2 > a[i]:
remain = pow2 - a[i]
if remain in countVal:
res += countVal[remain]
if a[i] in countVal... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR IF VAR V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | freq = {}
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for x in a:
for b in range(1, 30 + 1):
ans += freq.get(2**b - x, 0)
freq[x] = freq.get(x, 0) + 1
print(ans) | ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | twoPowers = [(2 << x) for x in range(32)]
numbers = {}
n = input()
for x in [int(x) for x in input().split()]:
if x not in numbers:
numbers[x] = 0
numbers[x] += 1
sum = 0
for twoPower in twoPowers:
for key in numbers:
if key <= twoPower >> 1:
oppositeKey = twoPower - key
... | ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP BIN_OP V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
c = {}
s = 0
for i in map(int, input().split()):
for p in range(32):
s += c.get((1 << p) - i, 0)
c[i] = c.get(i, 0) + 1
print(s) | EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
l = list(map(int, input().split()))
twos = []
twos.append(1)
freq = {}
while twos[-1] < int(1000000000.0):
twos.append(twos[-1] * 2)
for i in range(n):
freq[l[i]] = 0
for i in range(n):
freq[l[i]] += 1
answer = 0
for i in range(0, l.__len__()):
for j in range(0, twos.__len__()):
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER ASSIGN VAR DICT WHILE VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | def answer(n, A):
count = 0
d = {A[0]: 1}
for i in range(1, n):
for j in range(1, 32):
if 2**j - A[i] in d:
count += d[2**j - A[i]]
if A[i] in d:
d[A[i]] += 1
else:
d[A[i]] = 1
return count
n = int(input())
arr = list(map(int,... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR DICT VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
s = 0
k = 0
a = list(map(int, input().split()))
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
for i in set(a):
for j in range(32):
if 1 << j == 2 * i and i in d:
s += d[i] * (d[i] - 1) // 2
elif (1 << j) - i in d:
k += d[i] * ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR BIN_OP NUMBER VAR VAR VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
arr = input().split()
arr = [int(i) for i in arr]
d = {}
for a in arr:
if a in d:
d[a] += 1
else:
d[a] = 1
count = 0
for a in arr:
d[a] -= 1
for n in range(1, 32):
cp = 2**n
if cp <= a:
continue
if cp - a in d:
count += d[c... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR IF BIN_OP VA... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
m = {}
for x in list(map(int, input().split())):
if x in m:
m[x] += 1
else:
m[x] = 1
ans = 0
for x in range(0, 31):
p2 = 2**x
for i in m.keys():
if p2 - i in m:
if p2 - i == i:
ans += m[i] * (m[i] - 1)
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
ans = 0
s = dict()
for x in map(int, input().split()):
for i in range(1, 32):
if (1 << i) - x in s:
ans += s[(1 << i) - x]
if x in s:
s[x] += 1
else:
s[x] = 1
print(ans) | EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | R = lambda: map(int, input().split())
n = int(input())
res = 0
vsts = {}
for num in R():
res += sum(vsts.get((1 << pwr) - num, 0) for pwr in range(32))
vsts[num] = vsts.get(num, 0) + 1
print(res) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | from sys import stdin, stdout
def main():
from sys import stdin, stdout
n = int(stdin.readline())
t = tuple(map(int, stdin.readline().split()))
dic = {}
asum = 0
for i in t:
for j in range(32):
x = (1 << j) - i
if x in dic:
asum += dic[x]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
sequence = list(map(int, input().split()))
sequence.sort()
repeated_numbers = {}
exponent = 1
sum = 0
for number in sequence:
while 2**exponent <= number:
exponent += 1
sum += repeated_numbers.get(2**exponent - number, 0)
repeated_numbers[number] = repeated_numbers.get(number, 0) + 1
print(s... | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
numbers = list(map(int, input().split()))
sced = set(numbers)
counter = {}
for k in numbers:
if k in counter:
counter[k] += 1
else:
counter[k] = 1
x = 1
ans = 0
for i in range(32):
for j in sced:
if j <= x:
if j == x:
ans += counter[x] * (... | ASSIGN VAR FUNC_CALL VAR 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 DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
s = list(map(int, input().split()))
g = {}
ans = 0
for i in s:
for j in range(1, 33):
check = 1 << j
if check - i in g:
ans += g[check - i]
if i in g:
g[i] += 1
else:
g[i] = 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
a = list(map(int, input().split()))
a = sorted(a)
total = 0
d = {}
for i in range(len(a)):
if a[i] in d.keys():
d[a[i]] += 1
else:
d[a[i]] = 1
values = set([(2**i) for i in range(1, 33)])
for i in range(len(a)):
for val in values:
diff = val - a[i]
if diff in d.keys()... | EXPR 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 NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
ar = list(map(int, input().split()))
d = {}
for i in ar:
if i not in d:
d[i] = 1
else:
d[i] = d[i] + 1
ans = 0
for p in d:
for j in range(31):
x = 1 << j
if x == 2 * p:
ans += d[p] * (d[p] - 1)
elif x - p in d:
ans += d[p] * d[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER VAR VAR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | lst = [(2**i) for i in range(1, 34)]
s = dict()
n = int(input())
ss = [int(i) for i in input().split()]
sss = 0
for i in range(0, n):
for j in lst:
if j - ss[i] in s:
sss += s[j - ss[i]]
if ss[i] in s:
s[ss[i]] += 1
else:
s[ss[i]] = 1
print(sss) | ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = [int(x) for x in input().split()]
p2 = [(2**i) for i in range(31)]
d = {}
for i in a:
if i in d:
d[i] += 1
else:
d[i] = 1
k = 0
for i in d:
for p in p2:
j = p - i
if j > i:
break
if j in d:
if i == j:
k += d... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR IF V... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = [int(x) for x in input().split()]
st2 = [1]
while st2[-1] <= 10**10:
st2.append(st2[-1] * 2)
r = 0
d = {}
for i in range(n):
for s2 in st2:
if s2 - a[i] in d:
r += d[s2 - a[i]]
d[a[i]] = d.get(a[i], 0) + 1
print(r) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE VAR NUMBER BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VA... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | t = input
p = print
r = range
n = int(t())
a = list(map(int, t().split()))
c = 0
co = {x: (0) for x in range(1000000)}
po = [(2**x) for x in range(33)]
for i in range(n):
if a[i] in co:
c += co.get(a[i])
for j in range(len(po)):
if a[i] < po[j]:
co.update({(po[j] - a[i]): co.get(po[j... | ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
sequence = list(map(int, input().split()))
repeated_even_numbers = {}
repeated_odd_numbers = {}
sum = 0
for number in sequence:
if number % 2 == 0:
for index in range(31):
sum += repeated_even_numbers.get((1 << index) - number, 0)
repeated_even_numbers[number] = repeated_even_num... | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = map(int, input().split())
pow2 = []
x = 1
for i in range(32):
x <<= 1
pow2.append(x)
ans = 0
cnt = {}
for x in a:
for y in pow2:
need = y - x
if need in cnt:
ans += cnt[need]
cnt[x] = cnt.get(x, 0) + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FU... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | def binary(x):
b_left = -1
b_right = x - 1
b_power = power(mas[x])
while b_right != b_left:
b_middle = (b_left + b_right + 1) // 2
if mas[b_middle] + mas[x] >= b_power:
b_right = b_middle - 1
else:
b_left = b_middle
left_border = b_left
b_right = x... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VA... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
ar = list(map(int, input().split()))
ans = 0
s = {}
for x in ar:
for i in range(1, 32):
if 2**i - x in s:
ans += s[2**i - x]
s[x] = s.get(x, 0) + 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
ai = list(map(int, input().split()))
nums = {}
ans = 0
for i in range(n):
num = ai[i]
length = len(bin(num)[2:])
for j in range(length, 31):
num2 = 2**j - num
num4 = 0
try:
num4 = nums[num2]
except:
num4 = 0
ans += num4
try... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR N... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
D = {}
MAX = max(a)
for i in range(0, n):
D[a[i]] = D.get(a[i], 0) + 1
DK = D.keys()
for k in DK:
e0 = 0
while 1 << e0 <= k:
e0 += 1
for e in range(e0, 32):
pow2 = 1 << e
if pow2 - k > MAX:
break
n... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_O... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | import sys
n = int(input())
a = list(map(int, input().split()))
a.sort()
two = [(2**i) for i in range(32)]
cnt = 0
m = {}
for i in a:
for j in two:
cnt += m.get(j - i, 0)
m[i] = m.get(i, 0) + 1
print(cnt) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = list(map(int, input().split()))
dic = {}
t = 0
for i in range(len(a)):
sh = 0
while 2**sh <= a[i]:
sh += 1
sh -= 1
for j in range(sh, 31):
t += dic.get(2**j - a[i], 0)
dic[a[i]] = dic.get(a[i], 0) + 1
print(t) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUM... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = [int(i) for i in map(int, input().split())]
power = [1]
while power[-1] < 2 * 1000000000.0 + 1:
power.append(power[-1] * 2)
numbers = {str(i): (0) for i in set(a)}
for i in a:
numbers[str(i)] += 1
ans = 0
for i in a:
number = numbers[str(i)]
if numbers[str(i)] == 0:
continue... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER WHILE VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | input()
arr = list(map(int, input().split()))
def sumK(arr, k):
m = {}
total = 0
for number in arr:
if number in m:
total += m[number]
compl = k - number
m[compl] = m.get(compl, 0) + 1
return total
k = 1
ans = 0
while k <= 2 * 10**9:
ans += sumK(arr, k)
k ... | EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER BIN_O... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
a = input().split()
for i in range(n):
a[i] = int(a[i])
a.sort()
found = {}
x = 1
out = 0
for j in a:
while 2**x <= j:
x += 1
left = 2**x - j
try:
out += found[left]
except:
pass
try:
found[j] += 1
except:
found[j] = 1
print(out) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR VAR N... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | def main():
input()
m = list(map(int, input().split()))
mp = dict()
ans = 0
MX = 1 << 32 + 1
for x in m:
cur = 1
while cur < x:
cur <<= 1
while cur < MX:
if cur - x in mp:
ans += mp[cur - x]
cur <<= 1
if x in mp:... | FUNC_DEF EXPR 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 ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | import sys
input = sys.stdin.readline
print = sys.stdout.write
n = int(input())
ar = list(map(int, input().split()))
p2 = [(2**i) for i in range(1, 64)]
d = dict()
for x in ar:
try:
d[x] += 1
except:
d[x] = 1
ans = 0
for x in p2:
for el in set(ar):
if el * 2 != x:
try:
... | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC... |
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive integer n (1 ≤ n ≤ 10^5) — the number of integers.
The second li... | n = int(input())
arr = list(map(int, input().split()))
p = []
cnt = 0
i = 2
while i < 10000000007:
p.append(i)
i *= 2
d = {}
for i in arr:
if i not in d:
d[i] = 0
d[i] += 1
cnt = 0
for i in arr:
d[i] -= 1
for j in p:
v = j - i
if v in d:
cnt += d[v]
print(cnt) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR V... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.