description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
a = n & 1
b = n >> 1 & 1
c = n >> 2 & 1
d = n >> 3 & 1
d = 1 - d
if d:
c = 1 - c
if c and d:
b = 1 - b
if b and c and d:
a = 1 - a
ans = d << 3 | c << 2 | b << 1 | a
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def reverseBits(n):
rev = 0
for i in range(4):
rev = rev << 1
if n & 1 == 1:
rev = rev ^ 1
n = n >> 1
return rev
n = int(input())
n = reverseBits(n)
n -= 1
print(reverseBits(n)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def main():
a = "{0:b}".format(int(input())).rjust(4, "0")
a = "".join(reversed(a))
a = int(a, 2)
if a > 0:
a -= 1
else:
a = 15
a = "{0:b}".format(a).rjust(4, "0")
a = "".join(reversed(a))
print(int(a, 2))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL STRING VAR NUMBER STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def mystery(n):
if n == 0:
return 15
s = bin(n)[2:]
diff = 4 - len(s)
s = "0" * diff + s
s = s[::-1]
val = int(s, 2) - 1
s = bin(val)[2:]
diff = 4 - len(s)
s = "0" * diff + s
s = s[::-1]
return int(s, 2)
n = int(input())
print(mystery(n)) | FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def int_to_bool(n):
return [bool(n & 1 << i) for i in range(4)]
a = int(input())
def apply(expected, input):
output = [False] * 4
output[3] = not input[3]
if input[3]:
output[2] = not input[2]
else:
output[2] = input[2]
if input[3] and input[2]:
output[1] = not input[1]
else:
output[1] = input[1]
if input[3] and input[2] and input[1]:
output[0] = not input[0]
else:
output[0] = input[0]
return output == expected
for i in range(16):
if apply(int_to_bool(a), int_to_bool(i)):
print(i) | FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | a = int(input())
if a == 0:
print(15)
elif a == 1:
print(14)
elif a == 4:
print(8)
elif a == 5:
print(9)
elif a == 7:
print(11)
elif a == 6:
print(10)
elif a == 8:
print(0)
elif a == 9:
print(1)
elif a == 10:
print(2)
elif a == 11:
print(3)
elif a == 12:
print(4)
elif a == 13:
print(5)
elif a == 14:
print(6)
elif a == 15:
print(7)
else:
print("1" + str(a)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
b = list(bin(n).split("b")[1])
l1 = list(["0"] * (4 - len(b)) + b)
x = int("".join(reversed(l1)), 2) - 1
if x < 0:
x = 15
y = list(bin(x).split("b")[1])
l2 = list(["0"] * (4 - len(y)) + y)
print(int("".join(reversed(l2)), 2)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR NUMBER |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
a = n // 8
b = n % 8 // 4
c = n % 4 // 2
d = n % 2
a = not a
b = not b if a else b
c = not c if a and b else c
d = not d if a and b and c else d
print(1 * d + 2 * c + 4 * b + 8 * a) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
a = [0] * 4
i = 0
for i in range(4):
a[i] = n % 2
n = n // 2
a[3] = a[3] ^ 1
a[2] = a[3] ^ a[2]
a[1] = (a[3] and a[2]) ^ a[1]
a[0] = (a[3] and a[2] and a[1]) ^ a[0]
sum_ = 0
for i in range(4):
sum_ += a[i] * 2**i
print(sum_) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | def solve(n):
digits_4 = bin(n)[2:].rjust(4, "0")
reversed_digits = "".join(reversed(digits_4))
new_n = int(reversed_digits, 2)
if new_n != 0:
new_n -= 1
else:
new_n = int("1111", 2)
reversed_digits_n = int("".join(reversed(bin(new_n)[2:].rjust(4, "0"))), 2)
return reversed_digits_n
def main():
n = int(input())
print(solve(n))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER STRING ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER STRING NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | S = [int(d) for d in "{:04b}".format(int(input()))]
S[0] = 1 - S[0]
if S[0]:
S[1] = 1 - S[1]
if S[0] and S[1]:
S[2] = 1 - S[2]
if S[0] and S[1] and S[2]:
S[3] = 1 - S[3]
print(sum(2 ** (3 - i) * s for i, s in enumerate(S))) | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | val = int("{:04b}".format(int(input()))[::-1], 2) - 1
if val < 0:
val = 16 + val
print(int("{:04b}".format(val)[::-1], 2)) | ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | n = int(input())
arr = [15, 14, 12, 13, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7]
print(arr[n])
exit(0)
if n == 0:
print(15)
exit(0)
if n == 1:
print(14)
exit(0)
if n == 2:
print(12)
exit(0)
if n == 3:
print(13)
exit(0)
if n == 4:
print(8)
exit(0)
if n == 5:
print(9)
exit(0)
if n == 6:
print(10)
exit(0)
if n == 7:
print(11)
exit(0)
exit(228)
n = n ^ (n & 1) << 1
n = n ^ (n & 1) << 1
n = n ^ (n & 2) << 1
n = n ^ (n & 1) << 1
n = n ^ (n & 2) << 1
n = n ^ (n & 4) << 1
print(n) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | f = lambda a: (a + 1) % 2
n = int(input())
a = list(map(int, bin(n)[2:].zfill(4)[::-1]))
a[3] = f(a[3])
if a[3]:
a[2] = f(a[2])
if a[3] and a[2]:
a[1] = f(a[1])
if a[3] and a[2] and a[1]:
a[0] = f(a[0])
print(int("".join(map(str, a))[::-1], 2)) | ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER NUMBER |
[Image]
-----Input-----
The input contains a single integer $a$ ($0 \le a \le 15$).
-----Output-----
Output a single integer.
-----Example-----
Input
3
Output
13 | N = int(input())
def calc(n):
if n == 0:
return 15
if n == 1:
return 14
if n == 2:
return 12
if n == 3:
return 13
if n == 4:
return 8
if n == 5:
return 9
if n == 6:
return 10
if n == 7:
return 11
if n == 8:
return 0
if n == 9:
return 1
if n == 10:
return 2
if n == 11:
return 3
if n == 12:
return 4
if n == 13:
return 5
if n == 14:
return 6
if n == 15:
return 7
return 1 / 0
print(calc(N)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | N, L, R, X = map(int, input().split())
A = list(map(int, input().split()))
k = 0
for i in range(2**N):
P = []
for j in range(N):
if i & 1 << j != 0:
P.append(A[j])
if len(P) > 1:
if L <= sum(P) <= R and max(P) - min(P) >= X:
k += 1
print(k) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def isValid(arr, l, r, x):
return l <= sum(arr) <= r and max(arr) - min(arr) >= x
n, l, r, x = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
valid = 0
for mask in range(1, 1 << n):
temp = []
for i in range(n):
if mask & 1 << i:
temp.append(arr[i])
if isValid(temp, l, r, x):
valid += 1
print(valid) | FUNC_DEF RETURN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def Solve(n, l, r, x, c):
Num_ways = 0
for k in range(2**n):
Sum = 0
k = list(bin(k).replace("0b", ""))
while len(k) < n:
k.insert(0, "0")
Prob = []
for i in range(n):
if k[i] == "1":
Prob.append(c[i])
if len(Prob) > 0:
S, m, M = sum(Prob), min(Prob), max(Prob)
else:
S, m, M = -1, -1, -1
if S >= l and S <= r and M - m >= x:
Num_ways += 1
return Num_ways
n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
print(Solve(n, l, r, x, c)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR 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 FUNC_CALL VAR VAR VAR VAR VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def rec(a, b, cur_sum):
res = 0
if cur_sum > r:
return 0
if cur_sum >= l:
res += 1
for el in C[a + 1 : b]:
if r >= cur_sum + el >= l:
res += 1
for i in range(a + 1, b):
for j in range(i + 1, b):
res += rec(i, j, cur_sum + C[i] + C[j])
return res
n, l, r, x = map(int, input().split(" "))
C = list(map(int, input().split(" ")))
C.sort()
amount = 0
for i in range(n):
for j in range(i + 1, n):
if C[j] - C[i] >= x:
amount += rec(i, j, C[i] + C[j])
print(amount) | FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR RETURN NUMBER IF VAR VAR VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(1, 2**n + 1):
j = bin(i)
j = j[2:]
if len(j) < n:
j = "0" * (n - len(j)) + j
c = 0
temp = []
for k in j:
if k == "1":
temp.append(a[c])
c += 1
s = sum(temp)
if len(temp) >= 2 and s >= l and s <= r and max(temp) - min(temp) >= x:
ans += 1
print(ans) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = input().split()
for i in range(n):
c[i] = int(c[i])
ans = 0
for i in range(1, 2**n):
s = bin(i)
s = s[2:]
s = "0" * (n - len(s)) + s
if s.count("1") >= 2:
total = 0
maxi = 0
mini = 10**6 + 1
for j in range(n):
if s[j] == "1":
total += c[j]
maxi = max(maxi, c[j])
mini = min(mini, c[j])
if l <= total <= r and maxi - mini >= x:
ans += 1
print(ans) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
n, l, r, x = map(int, input().split())
arr = list(map(int, input().split()))
answer = 0
for i in range(1, n + 1):
for j in combinations(arr, i):
if len(j) >= 2 and l <= sum(j) <= r and max(j) - min(j) >= x:
answer += 1
print(answer) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
p = 1 << n
cnt = 0
for j in range(p):
list1 = []
if j > 0 and j & j - 1 != 0:
for k in range(n):
if j & 1 << k:
list1.append(c[k])
if sum(list1) >= l and sum(list1) <= r and list1[-1] - list1[0] >= x:
cnt += 1
print(cnt) | ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
n, l, r, x = map(int, input().split())
a = [int(y) for y in input().split()]
ans = 0
for i in range(2, n + 1):
combs = itertools.combinations(a, i)
for comb in combs:
sum = 0
for j in comb:
sum += j
dif = max(comb) - min(comb)
if sum >= l and sum <= r and dif >= x:
ans += 1
print(ans) | IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def I():
return list(map(int, input().split()))
n, l, r, x = I()
c = I()
l1 = list(range(2**n))
ans = 0
for j in l1:
s = 0
num = 0
ma = 0
mi = 100000000
for i in range(n):
if j & 1 << i:
num += 1
s += c[i]
ma = max(c[i], ma)
mi = min(c[i], mi)
if s <= r and l <= s and ma - mi >= x and num >= 2:
ans += 1
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
m = list(map(int, input().split()))
res = 0
for i in range(3, int(1 << n)):
if str(bin(i)).count("1") > 1:
s = bin(i)[2:].zfill(n)
mi = 1000000000.0 + 1
ma = 0
su = 0
for j, e in enumerate(s):
if e == "1":
su += m[j]
mi = min(mi, m[j])
ma = max(ma, m[j])
if l <= su <= r and ma - mi >= x:
res += 1
print(res) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
mask = (1 << n) - 1
ans = 0
for sub in range(mask + 1):
s, num = 0, 0
hard, easy = float("-inf"), float("inf")
for i in range(n):
if sub & 1 << i > 0:
s += a[i]
num += 1
hard = max(a[i], hard)
easy = min(a[i], easy)
if s >= l and s <= r and hard - easy >= x and num >= 2:
ans += 1
print(ans) | ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def s():
[n, l, r, x] = list(map(int, input().split(" ")))
l -= 1
r += 1
a = list(map(int, input().split(" ")))
def f(i=0, s=0, mi=10**6, ma=1):
if i == n:
return ma - mi >= x and l < s < r
return f(i + 1, s + a[i], min(mi, a[i]), max(ma, a[i])) + f(i + 1, s, mi, ma)
print(f())
s() | FUNC_DEF ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
n, l, r, x = input().split()
n = int(n)
l = int(l)
r = int(r)
x = int(x)
c = []
cc = input().split()
for i in range(n):
cc[i] = int(cc[i])
c.append(cc[i])
c2 = []
for i in range(len(c) + 1):
c2.append([x for x in combinations(c, i)])
k = 0
for i in range(len(c2)):
for j in range(len(c2[i])):
if (
sum(c2[i][j]) >= l
and sum(c2[i][j]) <= r
and max(c2[i][j]) - min(c2[i][j]) >= x
):
k += 1
print(k) | ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import sys
n, l, r, x = map(int, sys.stdin.readline().split())
c = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(1 << n):
td = 0
min = 1000001
max = 0
for j in range(n):
if i & 1 << j > 0:
td += c[j]
if c[j] > max:
max = c[j]
if c[j] < min:
min = c[j]
if td >= l and td <= r and max - min >= x:
ans += 1
print(ans) | IMPORT ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def main():
n, l, r, x = map(int, input().split())
cc, res = sorted(map(int, input().split())), 0
for i in range(1, 2**n):
tmp, idx = [], 0
while i:
if i & 1:
tmp.append(cc[idx])
idx += 1
i >>= 1
if tmp[-1] - tmp[0] >= x and l <= sum(tmp) <= r:
res += 1
print(res)
main() | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | vals = input().split()
n = int(vals[0])
l = int(vals[1])
r = int(vals[2])
x = int(vals[3])
plist = input().split()
pbs = []
for i in range(n):
pbs.append(int(plist[i]))
if n == 1:
print(0)
elif n == 2:
if pbs[0] + pbs[1] >= l and pbs[0] + pbs[1] <= r and abs(pbs[0] - pbs[1]) >= x:
print(1)
else:
print(0)
else:
answer = 0
allmasks = 1 << n
for i in range(allmasks):
pbnum = 0
pbsum = 0
pbmin = 1000001
pbmax = 0
for j in range(n):
if i & 1 << j > 0:
pval = pbs[j]
pbnum += 1
pbsum += pval
if pval > pbmax:
pbmax = pval
if pval < pbmin:
pbmin = pval
if pbnum >= 2 and pbsum >= l and pbsum <= r and pbmax - pbmin >= x:
answer += 1
print(answer) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def f(k, n, ma, mi, sum):
if k:
if sum + k[0] <= r and sum + k[0] >= l and max(k[0], ma) - min(k[0], mi) >= x:
n += 1
if sum <= r:
n = f(k[1:], n, ma, mi, sum)
n = f(k[1:], n, max(k[0], ma), min(k[0], mi), sum + k[0])
return n
n, l, r, x = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
n = f(s, 0, 0, 10**9, 0)
print(n) | FUNC_DEF IF VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR 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 FUNC_CALL VAR VAR NUMBER NUMBER BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def read():
return map(int, input().split())
n, l, r, x = read()
c = list(read())
ans = 0
for i in range(2**n):
cfg = bin(i)[2:].zfill(n)
if cfg.count("1") > 1:
nums = [d for j, d in enumerate(c) if cfg[j] == "1"]
if max(nums) - min(nums) >= x and l <= sum(nums) <= r:
ans += 1
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR STRING IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def b_f(l_v, c_v, c_i, l, h, l_p, h_p, x):
if c_i == len(l_v):
return 0
else:
n_l = l_v[c_i] if not l_p else min(l_v[c_i], l_p)
n_h = l_v[c_i] if not l_p else max(l_v[c_i], h_p)
return (
1 if c_v + l_v[c_i] >= l and c_v + l_v[c_i] <= h and n_h - n_l >= x else 0
) + (
b_f(l_v, c_v, c_i + 1, l, h, l_p, h_p, x)
+ b_f(l_v, c_v + l_v[c_i], c_i + 1, l, h, n_l, n_h, x)
)
n, l, r, x = map(int, input().split())
l_v = list(map(int, input().split()))
print(b_f(l_v, 0, 0, l, r, None, None, x)) | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR 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 FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR NONE NONE VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
def is_valid(diffs):
if sum(diffs) > r or sum(diffs) < l or diffs[-1] - diffs[0] < x:
return False
return True
n, l, r, x = (int(i) for i in input().split())
d = sorted([int(i) for i in input().split()])
ind = {i for i in range(n)}
nvalid = 0
for numel in range(n + 1):
for subset in combinations(ind, numel):
diffs = [d[i] for i in subset]
if is_valid(diffs):
nvalid += 1
print(nvalid) | FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, least, most, x = map(int, input().split())
c = list(map(int, input().split()))
ans = 0
_max = lambda x, y: x if x > y else y
_min = lambda x, y: x if x < y else y
for mask in range(1 << n):
mx = float("-inf")
mn = float("inf")
count = 0
Sum = 0
for i in range(n):
if mask & 1 << i:
count += 1
Sum += c[i]
mx = _max(mx, c[i])
mn = _min(mn, c[i])
if mx - mn >= x and Sum >= least and Sum <= most and count >= 2:
ans += 1
print(ans) | ASSIGN VAR VAR 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 NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
difficulties = list(map(int, input().split()))
total = 0
mask = 0
while mask < 1 << n:
difficulty_sum = 0
turns = 0
easy = 0
hard = 0
for i in range(n):
if mask & 1 << i:
difficulty_sum += difficulties[i]
turns += 1
if not easy or not hard:
if not easy:
easy = difficulties[i]
if not hard:
hard = difficulties[i]
elif difficulties[i] < easy:
easy = difficulties[i]
elif difficulties[i] > hard:
hard = difficulties[i]
if l <= difficulty_sum <= r and hard - easy >= x and turns > 1:
total += 1
mask += 1
print(total) | ASSIGN VAR VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | R = lambda: list(map(int, input().split()))
n, l, r, x = R()
c = R()
ans = 0
for mask in range(1 << n):
sum, mini, maxi, cnt = 0, 1000000000.0, -1000000000.0, 0
for i in range(n):
if mask & 1 << i:
sum += c[i]
mini = min(mini, c[i])
maxi = max(maxi, c[i])
cnt += 1
if maxi - mini >= x and l <= sum <= r and cnt > 1:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
ans = 0
for mask in range(2**n):
cnt, csum = 0, 0
mn, mx = 10**18, -(10**18)
for i in range(n):
if mask & 1 << i != 0:
cnt += 1
csum += c[i]
mn = min(mn, c[i])
mx = max(mx, c[i])
if cnt >= 2 and csum >= l and csum <= r and mx - mn >= x:
ans += 1
print(ans) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
C = sorted(list(map(int, input().split())))
ANS = 0
for i in range(2**n):
s = bin(i)[2:]
s = "0" * (n - len(s)) + s
L = []
for j in range(n):
if s[j] == "1":
L.append(C[j])
if len(L) < 2 or not l <= sum(L) <= r or L[-1] - L[0] < x:
continue
ANS += 1
print(ANS) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
n, l, r, x = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
lst = []
for i in range(2, n + 1):
lst.append(list(itertools.combinations(arr, i)))
for i in lst:
for j in i:
if sum(list(j)) >= l and sum(list(j)) <= r and max(list(j)) - min(list(j)) >= x:
count += 1
print(count) | IMPORT ASSIGN VAR VAR 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def recursion(index, sub_problem):
if index == len(list_value):
return [sub_problem]
else:
all_sub_problem = []
choosing_index = recursion(index + 1, sub_problem + [list_value[index]])
not_choosing_index = recursion(index + 1, sub_problem)
for element in choosing_index:
if (
minimum_difficulties <= sum(element) <= maximum_difficulties
and max(element) - min(element) >= minimum_difficulty_difference
):
all_sub_problem.append(element)
for element in not_choosing_index:
if (
minimum_difficulties <= sum(element) <= maximum_difficulties
and max(element) - min(element) >= minimum_difficulty_difference
):
all_sub_problem.append(element)
return all_sub_problem
(
number_of_problems,
minimum_difficulties,
maximum_difficulties,
minimum_difficulty_difference,
) = map(int, input().strip().split(" "))
list_value = list(map(int, input().strip().split(" ")))
result = recursion(0, [])
print(len(result)) | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN LIST VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
def classify(subset, l, r, x):
li = []
for i in subset:
li.append(i)
f1 = False
f2 = False
f3 = False
s = 0
for i in li:
s += i
if s >= l:
f1 = True
if s <= r:
f2 = True
li.sort()
t = li[len(li) - 1] - li[0]
if t >= x:
f3 = True
if f1 and f2 and f3:
return True
else:
return False
s = input()
s = s.split()
n = int(s[0])
l = int(s[1])
r = int(s[2])
x = int(s[3])
a = input()
a = a.split()
arr = []
for i in a:
arr.append(int(i))
count = 0
for i in range(2, len(arr) + 1):
for subset in itertools.combinations(arr, i):
if classify(subset, l, r, x):
count += 1
print(count) | IMPORT FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
nums = sorted(list(map(int, input().split())))
ans = 0
def recurse(i, sum, dif, cnt):
global ans
if i == n:
if not cnt:
return
if sum >= l and sum <= r and abs(cnt[-1] - cnt[0]) >= x:
ans += 1
return
recurse(i + 1, sum, dif, cnt[:])
cnt.append(nums[i])
recurse(i + 1, sum + nums[i], dif, cnt[:])
recurse(0, 0, 0, [])
print(ans) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR IF VAR RETURN IF VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER LIST EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
n, l, r, x = map(int, input().split())
C = list(map(int, input().split()))
ans = 0
combi = []
for i in range(1, n + 1):
tmp = [list(x) for x in itertools.combinations(C, i)]
combi.extend(tmp)
for tmp in combi:
s = sum(tmp)
if s >= l and s <= r and max(tmp) - min(tmp) >= x:
ans += 1
print(ans) | IMPORT ASSIGN VAR VAR 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = [int(x) for x in input().split()]
ans = 0
i = 0
maxval = 0
minval = 0
sum = 0
while i < 1 << n:
maxval = -1
minval = 1000000
sum = 0
for j in range(n):
if i & 1 << j:
sum += c[j]
maxval = max(maxval, c[j])
minval = min(minval, c[j])
if l <= sum and sum <= r and maxval - minval >= x:
ans += 1
i += 1
print(ans) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, left, right, diff = map(int, input().split())
a = list(map(int, input().split()))
ret = 0
for mask in range(1 << n):
if bin(mask).count("1") < 2:
continue
take = [a[i] for i in range(n) if mask >> i & 1]
s = sum(take)
d = max(take) - min(take)
ret += left <= s <= right and d >= diff
print(ret) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | ans = 0
n, l, w, x = map(int, input().split())
def printCombination(arr, n, r):
data = [0] * r
combinationUtil(arr, data, 0, n - 1, 0, r)
def combinationUtil(arr, data, start, end, index, r):
if index == r:
if l <= sum(data) <= w and max(data) - min(data) >= x:
global ans
ans += 1
return
i = start
while i <= end and end - i + 1 >= r - index:
data[index] = arr[i]
combinationUtil(arr, data, i + 1, end, index + 1, r)
i += 1
arr = list(map(int, input().split()))
for r in range(2, n + 1):
n = len(arr)
printCombination(arr, n, r)
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF IF VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN ASSIGN VAR VAR WHILE VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
n, l, r, x = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
counter = 0
for i, val in enumerate(["".join(seq) for seq in itertools.product("01", repeat=n)]):
if val.count("1") < 2:
continue
dif = 0
mx = float("-inf")
mn = float("inf")
for i, bit in enumerate(val):
if bit == "1":
dif += c[i]
mx = max(c[i], mx)
mn = min(c[i], mn)
if l <= dif <= r and mx - mn >= x:
counter += 1
print(counter) | IMPORT ASSIGN VAR VAR 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 FOR VAR VAR FUNC_CALL VAR FUNC_CALL STRING VAR VAR FUNC_CALL VAR STRING VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
def subsets(M):
L = list(M)
n = len(L)
for i in range(1 << n):
mask = [(i >> k & 1) for k in range(n)]
yield list(itertools.compress(L, mask))
return
n, l, r, x = [int(x) for x in input().split()]
def check(subset):
if len(subset) < 2:
return False
a, b = min(subset), max(subset)
return b - a >= x and l <= sum(subset) <= r
c = [int(x) for x in input().split()]
print(len(list(filter(check, subsets(c))))) | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
def read_data():
n, l, r, x = map(int, input().split())
cs = list(map(int, input().split()))
return n, l, r, x, cs
def solve(n, l, r, x, cs):
cs.sort()
count = 0
for m in range(2, n + 1):
for sets in itertools.combinations(cs, m):
diff = sets[-1] - sets[0]
if diff < x:
continue
sumsets = sum(sets)
if sumsets < l or sumsets > r:
continue
count += 1
return count
n, l, r, x, cs = read_data()
print(solve(n, l, r, x, cs)) | IMPORT FUNC_DEF ASSIGN VAR VAR 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 RETURN VAR VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def main():
mode = "fil"
if mode == "file":
f = open("test.txt", "r")
get = lambda: [
int(x) for x in (f.readline() if mode == "file" else input()).split()
]
[n, l, r, x] = get()
c = get()
if n == 1:
print("0")
return
c.sort()
if c[-1] - c[0] < x:
print("0")
return
count = 0
for i in range(3, 1 << n):
mm = list(str(bin(i))[2:])
if mm.count("1") < 2:
continue
hold = i
mm.reverse()
temp = []
for j in range(len(mm)):
if mm[j] == "1":
temp.append(c[j])
if temp[-1] - temp[0] < x:
continue
s = sum(temp)
if s >= l and s <= r:
count += 1
print(count)
if mode == "file":
f.close()
main() | FUNC_DEF ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def rec(c, at, mark, l, r, x, _max, _min, _sum):
if _sum > r:
return 0
res = 0
if _max - _min >= x and _sum >= l and _sum <= r:
res += 1
for i in range(at, len(c)):
if mark[i]:
continue
res += rec(
c, i + 1, mark, l, r, x, max(_max, c[i]), min(_min, c[i]), _sum + c[i]
)
return res
n, l, r, x = [int(v) for v in input().split(" ")]
c = [int(i) for i in input().split(" ")]
mark = [(False) for i in range(n)]
res = 0
for i in range(n):
mark[i] = True
res += rec(c, i, mark, l, r, x, c[i], c[i], c[i])
print(res) | FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import time
def test(a, b, C, s, n, l, r, x, p):
if C == []:
if s >= l and s <= r and b - a >= x:
return 1
return 0
if s >= l and s <= r and b - a >= x:
acc = 1
else:
acc = 0
for i in range(len(C)):
if s + C[i] <= r:
acc += test(
min(a, C[i]), max(b, C[i]), C[i + 1 :], s + C[i], n, l, r, x, p + [C[i]]
)
return acc
n, l, r, x = (int(i) for i in input().split())
C = sorted([int(i) for i in input().split()])
start = time.time()
acc = 0
for i in range(len(C)):
acc += test(C[i], C[i], C[i + 1 :], C[i], n, l, r, x, [C[i]])
print(acc)
finish = time.time() | IMPORT FUNC_DEF IF VAR LIST IF VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR LIST VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
def combos(lst):
for i in range(0, len(lst)):
for combo in combinations(lst, i + 1):
yield combo
inp = list(map(int, input().split()))
n = inp[0]
l = inp[1]
r = inp[2]
k = inp[3]
probs = sorted(list(map(int, input().split())))
count = 0
for sublist in combos(probs):
if sublist[len(sublist) - 1] - sublist[0] >= k:
s = sum(sublist)
if s >= l and s <= r:
count += 1
print(count) | FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | IL = lambda: list(map(int, input().split()))
IS = lambda: input().split()
I = lambda: int(input())
S = lambda: input()
n, l, r, x = IL()
cArr = sorted(IL())
ans = 0
for i in range(1, 2**n):
csub = [cArr[j] for j in range(n) if i & 2**j]
if l <= sum(csub) <= r and csub[-1] - csub[0] >= x:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
a = input().split()
ran = 2**n
answer = 0
for i in range(n):
a[i] = int(a[i])
for i in range(ran):
m = i
mask = ""
while m != 0:
if m % 2 == 0:
mask += "0"
else:
mask += "1"
m = m // 2
while len(mask) < n:
mask += "0"
s = 0
easy = 10**9 + 100
hard = 0
for j in range(len(mask)):
if mask[j] == "1":
if a[j] >= hard:
hard = a[j]
if a[j] <= easy:
easy = a[j]
s += a[j]
if s <= r and s >= l and hard - easy >= x:
answer += 1
print(answer) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR STRING WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = list(map(int, input().split()))
s = list(map(int, input().split()))
olmps = []
c = []
v = 0
for i in range(1 << n):
olmps.append([])
for j in range(n):
if i & 1 << j:
olmps[-1].append(s[j])
for o in olmps:
if l <= sum(o) <= r:
c.append(o)
for z in c:
if max(z) - min(z) >= x:
v += 1
print(v) | ASSIGN VAR VAR 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 LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, d = [int(i) for i in input().split()]
op = [int(i) for i in input().split()]
c = 0
for i in range(2, 2**n):
s = 0
k = 0
maxx = 0
minn = 1000001
x = bin(i)[2:]
x = "0" * (n - len(x)) + x
for j in range(n):
if x[j] == "1":
s += op[j]
k += 1
if maxx < op[j]:
maxx = op[j]
if op[j] < minn:
minn = op[j]
if l <= s <= r and maxx - minn >= d and k >= 2:
c += 1
print(c) | ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
k = 1 << n
res = 0
lst = 0
for i in range(k):
num = 0
cnt = 0
fst = -1
for j in range(n):
if 1 << j & i != 0:
num += a[j]
cnt += 1
if fst == -1:
fst = j
lst = j
if cnt > 1 and a[lst] - a[fst] >= x and num >= l and num <= r:
res += 1
print(res) | ASSIGN VAR VAR 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 ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = (int(x) for x in input().split())
c = [int(x) for x in input().split()]
c.sort()
ans = 0
for i in range(1, 2**n):
cur = []
for j in range(n):
if i & 1 << j:
cur.append(c[j])
if cur[-1] - cur[0] < x:
continue
if l <= sum(cur) <= r:
ans += 1
print(ans) | ASSIGN VAR VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | a = list(map(int, input().split(" ")))
b = list(map(int, input().split(" ")))
n = a[0]
l = a[1]
r = a[2]
x = a[3]
ans = 0
puis = 1 << n
for m in range(puis):
mn = 1000000
mx = 1
cnt = 0
sum = 0
for i in range(n):
if m & 1 << i != 0:
cnt += 1
sum += b[i]
mn = min(mn, b[i])
mx = max(mx, b[i])
if mx - mn >= x and sum >= l and sum <= r and cnt >= 2:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING 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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import chain, combinations
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(1, len(s) + 1))
n, l, r, x = map(int, input().split())
cantidad_de_formas = 0
difficulties = powerset(map(int, input().split()))
for combinacion in difficulties:
if len(combinacion) > 1:
if max(combinacion) - min(combinacion) >= x:
suma = sum(combinacion)
if suma >= l and suma <= r:
cantidad_de_formas += 1
print(cantidad_de_formas) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def dfs(now, num, l, r, dx, c):
if now < 0 or num >= r:
return 0
temp = dfs(now - 1, num, l, r, dx, c)
num += c[now]
if num >= l and num <= r and c[now] <= dx:
temp += 1
return temp + dfs(now - 1, num, l, r, dx, c)
c = input().split()
n = int(c[0])
l = int(c[1])
r = int(c[2])
x = int(c[3])
c = input().split()
for i in range(n):
c[i] = int(c[i])
c.sort()
ans = 0
for i in range(1, n):
if c[0] + x > c[i]:
continue
ans += dfs(i - 1, c[i], l, r, c[i] - x, c)
print(ans) | FUNC_DEF IF VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
for i in range(1, 1 << n):
a = []
s = 0
for j in range(0, n):
if i >> j & 1 > 0:
a.append(c[j])
s += c[j]
a.sort()
if s >= l and s <= r and a[len(a) - 1] - a[0] >= x:
ans = ans + 1
print(ans) | ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def getSub(l, i):
j = -1
r = []
while i > 0:
if i % 2 == 1:
r.append(l[j])
i //= 2
j -= 1
return r
n, l, r, x = map(int, input().split())
cs = list(map(int, input().split()))
count = 0
cs.sort()
for subI in range(1, 2**n):
sub = getSub(cs, subI)
if len(sub) < 2:
continue
dist = sub[0] - sub[-1]
if dist < x:
continue
s = sum(sub)
if s < l or s > r:
continue
count += 1
print(count) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR 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 NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import *
def inp():
return map(int, input().split())
def arr_inp():
return [int(x) for x in input().split()]
n, l, r, x = inp()
c, out = arr_inp(), 0
for i in range(2, n + 1):
for j in list(combinations(c, i)):
s, mi, ma = sum(j), min(j), max(j)
if s >= l and s <= r and ma - mi >= x:
out += 1
print(out) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = list(map(int, input().split()))
a = list(map(int, input().split()))
subsets = []
for i in range(1, 2**n):
temp = []
for j in range(n):
if 1 << j & i:
temp.append(a[j])
subsets.append(temp)
count = 0
for i in range(len(subsets)):
cur = subsets[i]
mi = min(cur)
ma = max(cur)
if ma - mi >= x:
s = sum(cur)
if s >= l and s <= r:
count += 1
print(count) | ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
count = 0
for i in range(2**n):
b = bin(i)[2:]
b = "0" * (n - len(b)) + b
minn, maxx = 10**18, 0
s = 0
for j in range(n):
if b[j] == "1":
minn = min(minn, c[j])
maxx = max(maxx, c[j])
s += c[j]
if s >= l and s <= r and maxx - minn >= x:
count += 1
print(count) | ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def main():
n, l, r, x = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(1 << n):
use = []
for j in range(n):
if i >> j & 1:
use.append(C[j])
if use == []:
continue
if max(use) - min(use) >= x and l <= sum(use) <= r:
ans += 1
print(ans)
main() | FUNC_DEF ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR LIST IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools
def judge(_list: int, _min: int, _max: int, _dif: int) -> int:
count = 0
for i in range(len(_list)):
a = itertools.combinations(_list, i + 1)
for j in a:
if _min <= sum(j) <= _max and max(j) - min(j) >= _dif:
count += 1
return count
number, mini, maxi, least_dif = map(int, input().split())
dif_list = list(map(int, input().split()))
dif_list.sort()
print(judge(dif_list, mini, maxi, least_dif)) | IMPORT FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
res = 0
for i in range(2, 1 << len(a)):
cmin = 10**9 + 1
cmax = 0
ctotal = 0
for j in range(len(a)):
if i & 1 << j:
cmin = min(a[j], cmin)
cmax = max(a[j], cmax)
ctotal += a[j]
if ctotal >= l and ctotal <= r and cmax - cmin >= x:
res += 1
print(res) | ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def check_combos(diff, n, size, start, picked, total, l, r, x, combination=[]):
if picked == size:
if max(combination) - min(combination) >= x and l <= sum(combination) <= r:
total += 1
else:
for i in range(start, n - (size - picked - 1)):
combination.append(diff[i])
picked += 1
total = check_combos(
diff, n, size, i + 1, picked, total, l, r, x, combination
)
picked -= 1
combination.pop()
return total
def prog():
n, l, r, x = map(int, input().split())
diff = list(map(int, input().split()))
suitable_problemsets = 0
for size in range(1, n + 1):
suitable_problemsets += check_combos(diff, n, size, 0, 0, 0, l, r, x)
print(suitable_problemsets)
prog() | FUNC_DEF LIST IF VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR 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 NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | l = [int(x) for x in input().split()]
l2 = [int(x) for x in input().split()]
l2 = sorted(l2)
ans = 0
for i in range(1 << l[0]):
first = -1
last = -1
t = 0
for j in range(l[0]):
if 1 << j & i > 0:
if first == -1:
first = j
last = j
t += l2[j]
if l2[last] - l2[first] >= l[3] and t >= l[1] and t <= l[2]:
ans += 1
print(ans) | ASSIGN 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = list(map(int, input().split(" ")))
c = sorted(list(map(int, input().split(" "))))
ways = 0
for i in range(0, 2**n):
temp = 0
m = 10**9 + 1
M = -1
for j in range(0, n):
if i & 1 << j:
temp += c[j]
m = min(m, c[j])
M = max(M, c[j])
if temp >= l and temp <= r and M - m >= x:
ways += 1
print(ways) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | nlrx = list(map(int, input().split()))
n, l, r, x = nlrx
problems = list(map(int, input().split()))
valid_sets = []
numSets = pow(2, n)
for i in range(1, numSets):
currSet = []
for j in range(n):
if i & 1 << j > 0:
currSet.append(problems[j])
if sum(currSet) < l or sum(currSet) > r:
continue
elif not max(currSet) - min(currSet) >= x:
continue
valid_sets.append(currSet)
print(len(valid_sets)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import sys
def set(mask, pos):
return mask | 1 << pos
def isOn(mask, pos):
return mask & 1 << pos > 0
n, l, r, x = map(int, input().split(" "))
dif = list(map(int, input().split(" ")))
count, mask = 0, 0
while mask <= 2**n:
summ, bit = [], 0
while bit < n:
if isOn(mask, bit):
summ.append(dif[bit])
bit += 1
if sum(summ) <= r and sum(summ) >= l and max(summ) - min(summ) >= x:
count += 1
mask += 1
print(count) | IMPORT FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def calcular_problemas(n, l, r, x, problemas):
num_elementos = n
conj_act = 0
num_formas = 0
while conj_act < 1 << num_elementos:
suma_de_problemas = 0
pos_max_enc = 0
pos_min_dif = 0
pos_max_dif = 0
contar_elementos = 0
for elemento in range(num_elementos):
if conj_act & 1 << elemento != 0 and pos_max_enc == 0:
pos_max_dif = elemento
pos_max_enc = 1
if conj_act & 1 << elemento != 0 and pos_max_enc != 0:
pos_min_dif = elemento
if conj_act & 1 << elemento != 0:
contar_elementos += 1
suma_de_problemas += problemas[elemento]
if suma_de_problemas > r:
break
if (
suma_de_problemas <= r
and suma_de_problemas >= l
and problemas[pos_max_dif] - problemas[pos_min_dif] >= x
and contar_elementos >= 2
):
num_formas += 1
conj_act += 1
return num_formas
parametros = input()
problemas = input()
parametros = parametros.split(" ")
parametros = list(map(lambda x: int(x), parametros))
problemas = problemas.split(" ")
problemas = list(map(lambda x: int(x), problemas))
problemas.sort(reverse=True)
print(calcular_problemas(*parametros, problemas)) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import sys
def main():
import sys
n, l, r, x, *c = [int(i) for i in sys.stdin.read().split()]
result = 0
for mask in range(1 << n):
number = 0
minimal = float("inf")
maximal = -float("inf")
s = 0
for i in range(n):
if mask & 1 << i:
s += c[i]
number += 1
minimal = min(minimal, c[i])
maximal = max(maximal, c[i])
if number >= 2 and l <= s <= r and maximal - minimal >= x:
result += 1
print(result)
main() | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = 0, 0, 0, 0
c = []
def judge(n, cjx):
inf, sup = float("inf"), -float("inf")
total = 0
for i in range(n):
if cjx[i]:
total += c[i]
inf = min(inf, c[i])
sup = max(sup, c[i])
return sup - inf >= x and l <= total and total <= r
def dfs(s, n, cjx):
if s >= n:
if judge(n, cjx):
return 1
else:
return 0
ans = 0
cjx[s] = True
ans += dfs(s + 1, n, cjx)
cjx[s] = False
ans += dfs(s + 1, n, cjx)
return ans
n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
cjx = [(False) for i in range(n)]
print(dfs(0, n, cjx)) | ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR 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 NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def generate(i, real, a):
if i == n:
if real >= 2:
min_a = a[0]
max_a = a[real - 1]
sum_a = sum(a)
if sum_a >= l and sum_a <= r and max_a - min_a >= x:
count[0] += 1
else:
generate(i + 1, real + 1, a + [c[i]])
generate(i + 1, real, a)
n, l, r, x = map(int, input().split())
c = sorted(list(map(int, input().split())))
count = [0]
generate(0, 0, [])
print(count[0]) | FUNC_DEF IF VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER LIST EXPR FUNC_CALL VAR VAR NUMBER |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
def subsetSums(arr):
c = []
for i in range(1, len(arr) + 1):
c += list(combinations(arr, i))
return c
n, l, r, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ways = 0
a = subsetSums(a)
for i in range(len(a)):
a[i] = list(a[i])
for i in range(len(a)):
if l <= sum(a[i]) <= r and a[i][-1] - a[i][0] >= x:
ways += 1
print(ways) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR 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 VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
def check(j):
if sum(j) >= l and sum(j) <= r and max(j) - min(j) >= x:
return 1
return 0
n, l, r, x = list(map(int, input().split()))
c = list(map(int, input().rstrip().split()))
count = 0
for i in range(2, n + 1):
a = list(combinations(c, i))
for j in a:
if check(j):
count += 1
print(count) | FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR 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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def s():
[n, l, r, x] = list(map(int, input().split(" ")))
l -= 1
r += 1
a = list(map(int, input().split(" ")))
s = 0
for i in range(1, 1 << n):
ind = 0
k = []
while i:
if i & 1:
k.append(a[ind])
ind += 1
i >>= 1
if max(k) - min(k) >= x and l < sum(k) < r:
s += 1
print(s)
s() | FUNC_DEF ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | aa = 0
a, b, c, d = list(map(int, input().split(" ")))
l = list(map(int, input().split(" ")))
for i in range(2**a):
k = bin(i)[2:]
t = 0
k = "0" * (a - len(k)) + k
x = []
for j in range(a):
if k[j] == "1":
x.append(l[j])
t += 1
if t >= 2:
if b <= sum(x) <= c and max(x) - min(x) >= d:
aa += 1
print(aa) | ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import itertools as it
n, l, r, x = map(int, input().split())
arr = list(map(int, input().split()))
poss = []
for i in range(2, len(arr) + 1):
p = list(it.combinations(arr, i))
for j in p:
poss.append(j)
ans = 0
for a in poss:
a = sorted(a)
if l <= sum(a) <= r and a[-1] - a[0] >= x:
ans += 1
print(ans) | IMPORT ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
c.sort()
qtd = 0
for b in range(int("1" * n, base=2) + 1):
binary = bin(b)[2:]
binary = "{:0>{n}}".format(int(binary), n=n)
vetor = []
for i, d in enumerate(binary):
if d == "1":
vetor.append(c[i])
vetor.sort()
if l <= sum(vetor) <= r and vetor[-1] - vetor[0] >= x:
qtd += 1
print(qtd) | ASSIGN VAR VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP STRING VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | values = input()
values = values.split()
n = int(values[0])
l = int(values[1])
r = int(values[2])
x = int(values[3])
ci = input()
ci = ci.split()
for i in range(len(ci)):
ci[i] = int(ci[i])
count = 0
def sub_lists(l):
base = []
lists = [base]
for i in range(len(l)):
orig = lists[:]
new = l[i]
for j in range(len(lists)):
lists[j] = lists[j] + [new]
lists = orig + lists
return lists
lists = sub_lists(ci)
for i in lists:
if len(i) > 1:
if sum(i) >= l and sum(i) <= r and max(i) - min(i) >= x:
count += 1
print(count) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR LIST VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
tasks = list(map(int, input().split()))
mask = 3
ans = 0
while mask < 1 << n:
sum_dif = 0
min_diff = float("inf")
max_diff = -float("inf")
if mask & mask - 1:
for i in range(n):
if mask & 1 << i:
sum_dif += tasks[i]
min_diff = min(min_diff, tasks[i])
max_diff = max(max_diff, tasks[i])
if x <= max_diff - min_diff and l <= sum_dif <= r:
ans += 1
mask += 1
print(ans) | ASSIGN VAR VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
arr = list(map(int, input().split()))
def solve():
count = 0
for i in range(1 << n):
minv = float("inf")
maxv = 0
total = 0
for j in range(n):
if i & 1 << j:
total += arr[j]
minv = min(minv, arr[j])
maxv = max(maxv, arr[j])
if l <= total and total <= r and maxv - minv >= x:
count += 1
return count
print(solve()) | ASSIGN VAR VAR 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 FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | import sys
def answer(n, l, r, x, c):
num_ways = 0
ctr = 1
while ctr < 2**n:
s = bin(ctr)[2:].zfill(n)
t_ary = []
summ = 0
mx = 0
mn = 10**7
for i in range(n):
if s[i] == "1":
t_ary.append(c[i])
summ += c[i]
mx = max(mx, c[i])
mn = min(mn, c[i])
if len(t_ary) < 2:
ctr += 1
continue
if summ < l:
ctr += 1
continue
if summ > r:
ctr += 1
continue
if mx - mn < x:
ctr += 1
continue
num_ways += 1
ctr += 1
return num_ways
def main():
n, l, r, x = map(int, sys.stdin.readline().split())
c = tuple(map(int, sys.stdin.readline().split()))
print(answer(n, l, r, x, c))
return
main() | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR 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 FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | def isValidSet(
problemSet: list, minTotalDif: int, maxTotalDif: int, minDelta: int
) -> bool:
if len(problemSet) >= 2:
total = sum(problemSet)
myDelta = max(problemSet) - min(problemSet)
if minTotalDif <= total <= maxTotalDif and myDelta >= minDelta:
return True
return False
def countValidSubsets(
problems: list, minTotalDif: int, maxTotalDif: int, minDelta: int
) -> int:
def subsetBuilder(
problems: list, currentSubset: list, nextElementIndex: int
) -> None:
if isValidSet(currentSubset, minTotalDif, maxTotalDif, minDelta):
validSubsets.append(currentSubset)
for i in range(nextElementIndex, len(problems)):
currentSubset.append(problems[i])
subsetBuilder(problems, currentSubset, i + 1)
currentSubset.pop(-1)
index = 0
currentSubset = []
validSubsets = []
subsetBuilder(problems, currentSubset, index)
return len(validSubsets)
n, l, r, x = input().split()
n = int(n)
l = int(l)
r = int(r)
x = int(x)
probs = [int(prob) for prob in input().split()]
print(countValidSubsets(probs, l, r, x)) | FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF VAR VAR VAR VAR FUNC_DEF VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NONE ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
c = list(map(int, input().split()))
def check(a):
s = sum(a)
global l, r, x
return max(a) - min(a) >= x and s >= l and s <= r
res = 0
for t in range(1, 2**n):
a = [c[i] for i in range(n) if t >> i & 1 == 1]
if check(a):
res += 1
print(res) | ASSIGN VAR VAR 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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
def main():
n, l, r, x = [int(t) for t in input().split()]
c = [int(t) for t in input().split()]
def is_valid(candidate):
mx = max(candidate)
mn = min(candidate)
sm = sum(candidate)
return l <= sm <= r and mx - mn >= x
way = 0
for L in range(2, len(c) + 1):
for subset in combinations(c, L):
if is_valid(subset):
way += 1
print(way)
main() | FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
n, l, r, x = map(int, input().split())
a = list(map(int, input().split()))
c = []
for i in range(2, n + 1):
c += list(combinations(a, i))
cnt = 0
for t in c:
m = min(t)
M = max(t)
s = sum(t)
if M - m >= x and (s >= l and s <= r):
cnt += 1
print(cnt) | ASSIGN VAR VAR 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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from sys import stdin
inp = lambda: stdin.readline().strip()
def int2bin(integer, digits):
if integer >= 0:
return bin(integer)[2:].zfill(digits)
else:
return bin(2**digits + integer)[2:]
n, l, r, x = [int(x) for x in inp().split()]
a = [int(x) for x in inp().split()]
ans = 0
for i in range(2**n):
s = int2bin(i, n)
total = 0
minimum = float("inf")
maximum = -1
for j in range(n):
if s[j] == "1":
total += a[j]
minimum = min(minimum, a[j])
maximum = max(maximum, a[j])
if l <= total <= r and maximum - minimum >= x:
ans += 1
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR 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 FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | n, l, r, x = map(int, input().split())
li = list(map(int, input().split()))
t = (1 << n) - 1
ans = 0
while t != 0:
s, mi, mx = 0, 1000001, 0
for i in range(len(li)):
if t & 1 << i:
s += li[i]
mi = min(mi, li[i])
mx = max(mx, li[i])
if mx - mi >= x and (s >= l and s <= r):
ans += 1
t -= 1
print(ans) | ASSIGN VAR VAR 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 BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | ans = 0
n, l, r, x = map(int, input().split())
z = list(map(int, input().split()))
for i in range(3, 1 << len(z)):
lst = []
for j in range(25):
if i & 1 << j:
lst.append(z[j])
lst.sort()
if len(lst) > 1 and l <= sum(lst) <= r and lst[-1] - lst[0] >= x:
ans += 1
print(ans) | ASSIGN VAR NUMBER ASSIGN VAR VAR 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 NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made.
A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.
Find the number of ways to choose a problemset for the contest.
-----Input-----
The first line contains four integers n, l, r, x (1 β€ n β€ 15, 1 β€ l β€ r β€ 10^9, 1 β€ x β€ 10^6) β the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 β€ c_{i} β€ 10^6) β the difficulty of each problem.
-----Output-----
Print the number of ways to choose a suitable problemset for the contest.
-----Examples-----
Input
3 5 6 1
1 2 3
Output
2
Input
4 40 50 10
10 20 30 25
Output
2
Input
5 25 35 10
10 10 20 10 20
Output
6
-----Note-----
In the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.
In the second example, two sets of problems are suitable β the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.
In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable. | from itertools import combinations
from sys import stdin
n, l, r, x = map(int, stdin.readline().rstrip().split(" "))
li = list(map(int, stdin.readline().rstrip().split(" ")))
z = []
ans = 0
for i in range(2, n + 1):
z += list(combinations(li, i))
for i in z:
a = sorted(i)
if a[-1] - a[0] >= x and r >= sum(a) >= l:
ans += 1
print(ans) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER 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.