description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
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(" "))) b = list() total = 0 for i in range(1, 1 << n): for j in range(0, n): if i & 1 << j != 0: b.append(a[j]) if len(b) >= 2: if sum(b) >= l and sum(b) <= r and max(b) - min(b) >= x: total = total + 1 b = list() print(total)
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 FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR 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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL 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.
from itertools import * n, least, highest, x = map(int, input().split()) l = [*map(int, input().split())] cnt = 0 for i in range(2, n + 1): combination = [*map(list, combinations(l, i))] for j in range(len(combination)): combination[j].sort() total = sum(combination[j]) if ( total >= least and total <= highest and combination[j][-1] - combination[j][0] >= x ): cnt += 1 print(cnt)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF 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.
def solve(): n, l, r, x = map(int, input().split(" ")) c = list(map(int, input().split(" "))) ans = 0 for bitmask in range(2**n): if bin(bitmask).count("1") > 1: res, _min, _max = 0, float("+inf"), float("-inf") for c_i, bit_i in zip(c, (1 & int(bitmask) >> i for i in range(n))): if bit_i: res += c_i * bit_i if c_i < _min: _min = c_i if c_i > _max: _max = c_i if l <= res <= r and _max - _min >= x: ans += 1 print(ans) solve()
FUNC_DEF 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 NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR IF FUNC_CALL FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING FOR VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF 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.
res = 0 n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) msk = 1 while msk <= 1 << n: mn = 1 << 31 mx = -1 sum = 0 cnt = 0 for y in range(0, n): if msk & 1 << y: cnt += 1 sum += a[y] mx = max(mx, a[y]) mn = min(mn, a[y]) res += mx - mn >= x and sum >= l and sum <= r and cnt > 1 msk = msk + 1 print(res)
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 ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER 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.
n, l, r, x = map(int, input().split()) cs = list(map(int, input().split())) def subsets(x): if len(x) == 0: return [[]] a = subsets(x[1:]) b = [([x[0]] + c) for c in a] return a + b sets = subsets(cs) ans = 0 for s in sets: if len(s) < 2: continue if not l <= sum(s) <= r: continue if max(s) - min(s) < 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 VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN LIST LIST ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR VAR VAR RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR 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, x = map(int, input().split()) c = [int(i) for i in input().split()] ans = 0 for i in range(2**n): s = bin(i)[2:] s = "0" * (n - len(s)) + s cnt = 0 for j in s: if j == "1": cnt += 1 if cnt < 2: continue diff = 0 ma = -1 mi = 10**10 for j in range(len(s)): if s[j] == "1": diff += c[j] if c[j] > ma: ma = c[j] if c[j] < mi: mi = c[j] if l <= diff <= r and ma - mi >= x: ans += 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 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 NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING 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 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.
print( (lambda go, n, l, r, x, a: go(go, 0, n, l, r, x, a, 0, 10**9, -1))( lambda self, i, n, l, r, x, a, s, mi, ma: ( int(l <= s <= r and ma - mi >= x) if i >= n else self(self, i + 1, n, l, r, x, a, s, mi, ma) + self(self, i + 1, n, l, r, x, a, s + a[i], min(mi, a[i]), max(ma, a[i])) ), *map(int, input().split()), list(map(int, input().split())) ) )
EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER BIN_OP NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL 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.
c = 0 def backtracking(actuales, restantes, l, r, x): global c if sum(actuales) <= r and sum(actuales) >= l: if max(actuales) - min(actuales) >= x: c += 1 if restantes: for i in range(len(restantes)): backtracking(actuales + [restantes[i]], restantes[i + 1 :], l, r, x) return 0 def main(): n, l, r, x = input().split(" ") n, l, r, x = int(n), int(l), int(r), int(x) difficulties = input().split(" ") for i in range(len(difficulties)): difficulties[i] = int(difficulties[i]) difficulties.sort() backtracking([], difficulties, l, r, x) global c return c print(main())
ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR 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 itertools n, l, r, x = input().split(" ") n = int(n) l = int(l) r = int(r) x = int(x) num = [int(i) for i in input().split()] count = 0 for i in range(2, n + 1): for j in itertools.combinations(num, i): if max(j) - min(j) >= x and l <= sum(j) <= r: count += 1 print(count)
IMPORT ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR 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.
result = 0 a = list(map(int, input().split())) b = list(map(int, input().split())) b.sort() jojo = [] for i in range(2 ** len(b)): for j in range(len(b)): if bool(i & 1 << j) == bool(1): jojo.append(b[j]) if len(jojo) > 0: if ( jojo[len(jojo) - 1] - jojo[0] >= a[3] and sum(jojo) <= a[2] and sum(jojo) >= a[1] ): result += 1 jojo = [] print(result)
ASSIGN VAR NUMBER ASSIGN 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR 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.
def subsets(S): sets = [] len_S = len(S) for i in range(1 << len_S): subset = [S[bit] for bit in range(len_S) if i & 1 << bit] sets.append(subset) return sets n, l, r, x = list(map(int, input().split())) problems = list(map(int, input().split())) res = 0 for m in subsets(problems): if l <= sum(m) <= r and max(m) - min(m) >= x: res += 1 print(res)
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN VAR 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 VAR 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 n, l, r, x = map(int, input().split()) c = list(map(int, input().split())) cnt = 0 for i in range(2, n + 1): combinations = itertools.combinations(c, i) for comb in combinations: max_ = 0 min_ = 10**6 sum_ = 0 for co in comb: sum_ += co if co > max_: max_ = co if co < min_: min_ = co cnt += 1 if l <= sum_ <= r and max_ - min_ >= x else 0 print(cnt)
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 NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR 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.
import itertools n, l, x1, r = map(int, input().split()) li = [int(i) for i in input().split()] a = [] for i in range(1, n + 1): x = itertools.combinations(li, i) a += x count = 0 for j in a: if sum(list(j)) <= x1 and sum(list(j)) >= l: if max(j) - min(j) >= r: count += 1 print(count)
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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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.
from itertools import * def powerset(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)) def solve(c, l, r, x): res = 0 for ss in powerset(c): if len(ss) >= 2 and l <= sum(ss) <= r and max(ss) - min(ss) >= x: res += 1 return res assert solve([1, 2, 3], 5, 6, 1) == 2 assert solve([10, 20, 30, 25], 40, 50, 10) == 2 assert solve([10, 10, 20, 10, 20], 25, 35, 10) == 6 n, l, r, x = map(int, input().split()) c = list(map(int, input().split())) print(solve(c, l, r, x))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 RETURN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER 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 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.
def find(a, b): cc = 2 for i in range(1, 1 << len(a)): sx = 0 minn = 100000000 maxn = -1 for j in range(0, len(a)): if i & 1 << j: sx += a[j] minn = min(minn, a[j]) maxn = max(maxn, a[j]) if sx >= b[1] and sx <= b[2] and maxn - minn >= b[3]: cc += 1 if cc < 2: return 2 else: return cc - 2 b = list(map(int, input().split())) a = list(map(int, input().split())) print(find(a, b))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER 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 NUMBER VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER ASSIGN 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 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.
from itertools import combinations num, min_dif, max_dif, easy_hard_dif = map(int, input().split(" ")) arr = [int(m) for m in input().split(" ")] all_combinations = [] for x in range(2, num + 1): combs = combinations(arr, x) for abc in combs: all_combinations.append(list(abc)) possible_answers = 0 for a in all_combinations: if sum(a) >= min_dif and sum(a) <= max_dif and max(a) - min(a) >= easy_hard_dif: possible_answers += 1 print(possible_answers)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR 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()) c = list(map(int, input().split())) count = 0 def backtrack(s, l, r, x, c, i, level, min, max): if s > r: return 0 if s >= l and max - min >= x: global count count += 1 for j in range(i, len(c)): new = c[j] nmax, nmin = max, min if new > max: nmax = new if new < min: nmin = new backtrack(s + new, l, r, x, c, j + 1, level + 1, nmin, nmax) backtrack(0, l, r, x, c, 0, 0, 9999999999, 0) print(count)
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 ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR VAR NUMBER 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.
n, ll, r, x = map(int, input().split(" ")) l = list(map(int, input().split(" "))) subset = [] for i in range(1, 2**n): sub = [] for j in range(n): if 1 << j & i > 0: sub.append(l[j]) subset.append(sub) c = 0 for i in subset: if len(i) > 1: su = sum(i) if (su >= ll and su <= r) and max(i) - min(i) >= x: c += 1 print(c)
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 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 NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER 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.
import itertools n, l, r, x = map(int, input().split()) a = [int(i) for i in input().split()] count = 0 s = sum(a) if s >= l and s <= r and max(a) - min(a) >= x: count += 1 for i in range(2, n): b = list(itertools.combinations(a, i)) for j in range(0, len(b)): s = sum(b[j]) if s >= l and s <= r and max(b[j]) - min(b[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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL 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 check_bits(x, n): total = 0 for i in range(n): if x & 1 << i: total += 1 return total >= 2 def check_compex(x, data, l, r, diff): total_c = 0 min_c = None max_c = None for i in range(len(data)): if x & 1 << i: total_c += data[i] if min_c is None or min_c > data[i]: min_c = data[i] if max_c is None or max_c < data[i]: max_c = data[i] return l <= total_c <= r and max_c - min_c >= diff def __starting_point(): n, l, r, diff = list(map(int, input().split())) data = list(map(int, input().split())) total = 0 for i in range(2**n): if check_bits(i, n) and check_compex(i, data, l, r, diff): total += 1 print(total) __starting_point()
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR VAR IF VAR NONE VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NONE VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR VAR BIN_OP VAR VAR VAR 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 IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR 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.
kk = lambda: map(int, input().split()) ll = lambda: list(kk()) n, l, r, d = kk() p, t = ll(), 0 for v in range(2**n): s = [] for i in range(n): if v & 2**i: s.append(p[i]) if l <= sum(s) <= r and max(s) - min(s) >= d: t += 1 print(t)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR 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 solve(n, l, r, x, L): res = 0 def inner(a): p_list = [] tl = 0 for i in range(n): if 1 << i & a == 0: p_list.append(L[i]) tl += L[i] p_list.sort() if tl >= l and tl <= r and p_list[-1] - p_list[0] >= x and len(p_list) > 1: return True return False for i in range(1, 2**n + 1): if inner(i): res += 1 return res n, l, r, x = map(int, input().split()) L = list(map(int, input().split())) print(solve(n, l, r, x, L))
FUNC_DEF ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF FUNC_CALL 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.
from itertools import combinations [n, l, r, x] = [int(x) for x in input().split()] c = [int(x) for x in input().split()] c.sort() k = 0 for i in range(n): for j in range(i + 1, n): if c[j] - c[i] >= x: if sum(c[i : j + 1]) < l: continue elif c[i] + c[j] > r: continue else: if c[i] + c[j] >= l and c[i] + c[j] <= r: k += 1 for p in range(1, j - i): for m in combinations(c[i + 1 : j], p): if sum(m) + c[i] + c[j] >= l and sum(m) + c[i] + c[j] <= r: k += 1 print(k)
ASSIGN LIST 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 VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP FUNC_CALL 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 itertools import combinations as cmb n, l, r, x = map(int, input().split()) (*a,) = map(int, input().split()) b = [] a.sort() for i in range(2, n + 1): b.extend(cmb(a, i)) ans = 0 for i in b: if sum(i) >= l and sum(i) <= r: if i[-1] - i[0] >= x: ans += 1 print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF 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 = list(map(int, input().split())) c = list(map(int, input().split())) k = 0 for i in range(3, 1 << n): a = [] for j in range(n): if i >> j & 1 == 1: a.append(c[j]) a.sort() if len(a) >= 2: if sum(a) >= l and sum(a) <= r and a[-1] - a[0] >= x: k += 1 print(k)
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 NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER 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 sys input = [] input_index = 0 def next(type, number=None): def next(): global input, input_index while input_index == len(input): if sys.stdin: input = sys.stdin.readline().split() input_index = 0 else: raise Exception() input_index += 1 return input[input_index - 1] if number is None: result = type(next()) else: result = [type(next()) for _ in range(number)] return result def fac(a): return 1 if a <= 1 else fac(a - 1) * a n, l, r, x = next(int, 4) cs = next(int, n) cs = sorted(cs) groups = [[]] for c in cs: new_groups = [] for group in groups: new_groups.append(group) new_groups.append(group + [c]) groups = new_groups counter = 0 for group in groups: if len(group) >= 2: if group[-1] - group[0] >= x: if l <= sum(group) <= r: counter += 1 print(counter)
IMPORT ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF NONE FUNC_DEF WHILE VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR BIN_OP VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF RETURN VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER 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.
import itertools n, l, r, x = list(map(int, input().split())) C = sorted(map(int, input().split())) ans = 0 if len(C) > 1: for i in range(2, len(C) + 1): for j in itertools.combinations(C, i): if l <= sum(j) <= r and max(j) - min(j) >= x: ans += 1 print(ans)
IMPORT 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 IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR 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.
n, l, r, x = map(int, input().split()) C = list(map(int, input().split())) C.sort() z = 0 for i in range(2**n): b = bin(i)[2:] while len(b) < n: b = "0" + b S = 0 D = [] for j in range(len(b)): if b[j] == "1": S = S + C[j] D.append(C[j]) if S >= l and S <= r and max(D) - min(D) >= x and len(D) > 1: z = z + 1 print(z)
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 NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER 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 GSB(x): counter = 0 while x != 0: counter += 1 x = x >> 1 return counter problems, minimum, maximum, difference = [int(x) for x in input().split()] array = [int(x) for x in input().split()] combinations = [int(x) for x in range(2**problems)] total = 0 for i in combinations: checker = [x for x in array] + ["a"] j = 0 z = GSB(i) check = 1 while j != z and i != 0: if i & 1 == 1: checker[j] = "a" check += 1 i = i >> 1 j += 1 for i in range(check): checker.remove("a") checker.sort() if ( minimum <= sum(checker) <= maximum and len(checker) >= 2 and checker[-1] - checker[0] >= difference ): total += 1 print(total)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP 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 VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER 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 chain, combinations def powerset(iterable): s = list(iterable) return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)) N, L, R, X = map(int, input().split(" ")) C = map(int, input().split(" ")) def is_ok(c): if len(c) < 2: return False if not L <= sum(c) <= R: return False if max(c) - min(c) < X: return False return True print(sum([(1) for c in powerset(C) if is_ok(c)]))
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER 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.
[n, l, r, x] = list(map(int, input().strip().split())) Cs = list(sorted(map(int, input().strip().split()))) probs = 0 for i in range(1, 2**n): currsub = [Cs[j] for j in range(n) if i & 1 << j] probs += ( len(currsub) > 1 and l <= sum(currsub) <= r and currsub[-1] - currsub[0] >= x ) print(probs)
ASSIGN LIST VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER 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.
from itertools import chain, combinations def powerset(x): s = list(x) return chain.from_iterable(combinations(s, r) for r in range(len(s) + 1)) n, l, r, x = [int(s) for s in input().split(" ")] c = [int(s) for s in input().split(" ")] cnt = 0 for a in powerset(c): if a and max(a) - min(a) >= x and l <= sum(a) <= r: cnt += 1 print(cnt)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR IF VAR 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.
n, l, w, x = map(int, input().split()) arr = list(map(int, input().split())) n = len(arr) ans = 0 for r in range(2, n + 1): show = list(range(r)) data = [0] * r while max(show) <= n - 1: for i in range(r): data[i] = arr[show[i]] if l <= sum(data) <= w and max(data) - min(data) >= x: ans += 1 for q in range(1, r): if show[q] == n - r + q: show[q - 1] += 1 for j in range(q, r): show[j] = 1 + show[j - 1] break if q == r - 1: show[-1] += 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR 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.
cnt = 0 def condition(arr, l, r, x): if not arr: return False s = sum(arr) ma = max(arr) mi = min(arr) if s <= r and s >= l and ma - mi >= x: return True return False def dp(i, n, st, arr, l, r, x): global cnt if i == n: result = [] for i in range(len(st)): if st[i] == "1": result.append(arr[i]) if condition(result, l, r, x): cnt += 1 return dp(i + 1, n, st + "0", arr, l, r, x) dp(i + 1, n, st + "1", arr, l, r, x) def main(): n, l, r, x = [int(t) for t in input().split(" ")] arr = [int(t) for t in input().split(" ")] dp(0, n, "", arr, l, r, x) print(cnt) main()
ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF IF VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR STRING VAR VAR VAR VAR FUNC_DEF 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 EXPR FUNC_CALL VAR NUMBER VAR STRING VAR 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.
from itertools import combinations n, l, r, x = map(int, input().split()) p = [int(x) for x in input().split()] p = sorted(p) s = 0 result_list = sum([list(map(list, combinations(p, i))) for i in range(len(p) + 1)], []) for i in result_list: if l <= sum(i) <= r and max(i) - min(i) >= x: s += 1 print(s)
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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER LIST FOR VAR VAR 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 gen(n): if n == 1: yield "0" yield "1" else: for s in gen(n - 1): yield s + "0" yield s + "1" n, l, r, x = map(int, input().split()) cnt = 0 C = list(map(int, input().split())) for pos in gen(n): A = [] for i in range(n): if pos[i] == "1": A.append(C[i]) A.sort() if len(A): if l <= sum(A) <= r and A[-1] - A[0] >= x: cnt += 1 print(cnt)
FUNC_DEF IF VAR NUMBER EXPR STRING EXPR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR BIN_OP VAR STRING EXPR BIN_OP VAR STRING 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 FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF 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.
from itertools import combinations n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) result = sum( [ sum([(max(j) - min(j) >= x and l <= sum(j) <= r) for j in combinations(a, i)]) for i in range(2, n + 1) ] ) print(result)
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 FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER 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 calc(str, n, mn, mx, dif): end = 2**n binary = "" index = -1 mnx = 100000000 mxx = -1 sum = 0 count = 0 for i in range(end): binary = "{0:015b}".format(i)[::-1] binary = binary[:n] index = -1 sum = 0 mnx = 100000000 mxx = -1 for k in binary: index += 1 if k == "1": sum += str[index] mnx = min(mnx, str[index]) mxx = max(mxx, str[index]) if sum <= mx and sum >= mn and mxx - mnx >= dif: count += 1 return count n, mn, mx, dif = map(int, input().split()) x = list(map(int, input().split())) print(calc(x, n, mn, mx, dif))
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER 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 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.
n, l, r, hard = list(map(int, input().split())) val = list(map(int, input().split())) arr = [] for i in range(0, 2**n): x = bin(i) x = x.split("b")[1] x = "0" * (n - len(x)) + x arr.append(x) ans = 0 for i in arr: if i.count("1") >= 2: cur = i temp = [] for j in range(n): if cur[j] == "1": temp.append(val[j]) p, q = max(temp), min(temp) t = sum(temp) if p - q >= hard and (t >= l and t <= r): ans += 1 print(ans)
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 FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR 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.
import itertools n, l, kk, x = input().split() n = int(n) l = int(l) kk = int(kk) x = int(x) arr = list(map(int, input().split())) cnt = 0 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: lll = [] for j in range(r): lll.append(data[j]) ans.append(lll) 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 ans = [] for r in range(2, n + 1): printCombination(arr, n, r) for i in ans: if sum(i) >= l: if sum(i) <= kk: if max(i) - min(i) >= x: cnt = cnt + 1 print(cnt)
IMPORT 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR 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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR 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.
n, l, r, x = 0, 0, 0, 0 c, sumC = [], [] def solve(step, totalC, num, maxC, minC): if step == n: if totalC >= l and totalC <= r and num >= 2 and maxC - minC >= x: return 1 else: return 0 if totalC > r: return 0 if totalC + sumC[step] < l: return 0 return solve(step + 1, totalC, num, maxC, minC) + solve( step + 1, totalC + c[step], num + 1, max(maxC, c[step]), min(minC, c[step]) ) n, l, r, x = [int(x) for x in input().strip().split()] c = [int(x) for x in input().strip().split()] c.sort(reverse=True) sumC = [sum(c[i:]) for i in range(0, n)] sumC.append(0) print(solve(0, 0, 0, 0, 10**6 + 1))
ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST LIST FUNC_DEF IF VAR VAR IF VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER 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.
n, l, r, x = list(map(int, input().split())) b = list(map(int, input().split())) if len(b) == 1: print(0) else: w = ["0", "1"] e = 0 t = len(b) while t - 1 > 0: k = [] for i in w: k.append("0" + i) for i in w: k.append("1" + i) w = k t = t - 1 for i in k: a = [] for j in range(n): if i[j] == "1": a.append(b[j]) s = sum(a) if len(a) > 1 and s >= l and s <= r and max(a) - min(a) >= x: e = e + 1 print(e)
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 IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST STRING STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR 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 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.
n, l, r, x = map(int, input().split()) c = list(map(int, input().split())) cnt = 0 def f(i, total, mx, mn, num): global cnt if i == n: if l <= total <= r and mx - mn >= x and num >= 2: cnt += 1 return f(i + 1, total + c[i], max(mx, c[i]), min(mn, c[i]), num + 1) f(i + 1, total, mx, mn, num) f(0, 0, 0, 99999999999, 0) 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 NUMBER FUNC_DEF IF VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER 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.
n, l, r, x = (int(x) for x in input().split()) seq = [int(x) for x in input().split()] seq.sort() count = 0 def get_bit(i, n): ele = bin(i)[2:] ele = [int(x) for x in ele] ele = (n - ele.__len__()) * [0] + ele return ele for i in range(1, 2**n): situ = get_bit(i, n) summing = 0 maxj = 0 minj = 100 for j in range(n): summing += situ[j] * seq[j] if situ[j] == 1: maxj = max(maxj, j) minj = min(j, minj) gap = seq[maxj] - seq[minj] if summing <= r and summing >= l and gap >= x: count += 1 print(count)
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 FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR LIST NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR 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.
n, l, r, x = map(int, input().split()) d = list(map(int, input().split())) ans = 0 for i in range(pow(2, n) - 1, -1, -1): s = bin(i)[2:] while len(s) < n: s = "0" + s diff = 0 t = [] for j in range(n): if s[j] == "1": diff += d[j] t.append(d[j]) t.sort() if l <= diff <= r and t[-1] - t[0] >= 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 FUNC_CALL VAR NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR IF 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.
def gen(k, n, p): if k == n: ans.append(p) return gen(k + 1, n, p + [1]) gen(k + 1, n, p + [0]) n, l, r, x = map(int, input().split()) m = list(map(int, input().split())) ans = [] count = 0 gen(0, n, []) for i in range(len(ans)): now = [] for j in range(len(ans[i])): if ans[i][j] == 1: now.append(m[j]) now.sort() sum = 0 for i in now: sum += i if len(now) > 0: if now[-1] - now[0] >= x and sum >= l and sum <= r: count += 1 print(count)
FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR LIST NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR LIST 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 ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER 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 generate(made, lis): if made == n: nonlocal res s = sum(lis) if l <= s and s <= r and len(lis) >= 2 and lis[-1] - lis[0] >= x: res += 1 else: generate(made + 1, lis + [a[made]]) generate(made + 1, lis) n, l, r, x = list(map(int, input().split())) a = sorted(map(int, input().split())) res = 0 generate(0, []) print(res)
FUNC_DEF IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR 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 EXPR FUNC_CALL VAR 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.
s = input().split(" ") n, l, r, d = [int(x) for x in s] arr = input().split(" ") arr = [int(x) for x in arr] arr.sort() ans = 0 for x in range(2**n + 1): m = 0 sum = 0 t = x for i in range(n): if t % 2 == 1: if m == 0: m = arr[i] sum += arr[i] M = arr[i] t = t // 2 if sum <= r and sum >= l and M - m >= d: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 = map(int, input().split()) c = list(map(int, input().split())) c.sort() all_sub = [] for i in range(2**n): subset = [] for j in range(n): if i & 1 << j != 0: subset.append(c[j]) all_sub.append(subset) final = 0 for i in all_sub[1:]: if i[-1] - i[0] >= x and sum(i) >= l and sum(i) <= r: final += 1 print(final)
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 LIST 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 EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL 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 gray(n): if n == 1: return ["0", "1"] l1 = gray(n - 1) l2 = reversed(l1) l1 = [(a + "0") for a in l1] l2 = [(a + "1") for a in l2] return l1 + l2 n, l, r, x = list(map(int, input().split())) a = list(map(int, input().split())) ps = gray(n) ans = 0 for i in ps: ma = -1 mi = 10000000 s = 0 k = 0 for j in range(n): if i[j] == "1": k += 1 s += a[j] mi = min(mi, a[j]) ma = max(ma, a[j]) if s >= l and s <= r and ma - mi >= x and k > 1: ans += 1 print(ans)
FUNC_DEF IF VAR NUMBER RETURN LIST STRING STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR STRING VAR VAR RETURN BIN_OP VAR VAR 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 FUNC_CALL VAR 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 VAR VAR STRING 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.
import itertools __author__ = "victormion" def function(): res = 0 for i in range(2, len(vet) + 1): temp = itertools.combinations(vet, i) for case in temp: sum = 0 minimum = None maximum = None for j in case: sum += int(j) val = int(j) if minimum == None or val < minimum: minimum = val if maximum == None or val > maximum: maximum = val if sum >= l and sum <= r and maximum - minimum >= x: res += 1 return res n, l, r, x = input().strip().split() n, l, r, x = int(n), int(l), int(r), int(x) vet = input().strip().split() print(function())
IMPORT ASSIGN VAR STRING FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL 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.
def subsets(L, i): if i == len(L): yield [] else: for s in subsets(L, i + 1): yield s yield [L[i]] + s def computeValidProblemsets(problems, l, r, x): isValid = lambda ps: len(ps) > 1 and l <= sum(ps) <= r and ps[-1] - ps[0] >= x print(sum(isValid(problemset) for problemset in subsets(sorted(problems), 0))) n, l, r, x = map(int, input().split()) problems = list(map(int, input().split())) computeValidProblemsets(problems, l, r, x)
FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR VAR EXPR BIN_OP LIST VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 EXPR 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.
I = lambda: map(int, input().split()) n, l, r, x = I() t = sorted(I()) k = [0] def f(n, q, w, e): if n < 0: k[0] += q and w - q >= x and l <= e <= r return f(n - 1, q, w, e) if w: q = t[n] else: w = t[n] f(n - 1, q, w, e + t[n]) f(n - 1, 0, 0, 0) print(k[0])
ASSIGN VAR 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 LIST NUMBER FUNC_DEF IF VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER 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 n, l, r, x = map(int, input().split()) c = [*map(int, input().split())] print( sum( [ sum( [ (1 if max(j) - min(j) >= x and l <= sum(j) <= r else 0) for j in combinations(c, i) ] ) for i in range(1, n + 1) ] ) )
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP 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.
n, l, r, x = map(int, input().split()) arr = list(map(int, input().split())) count = 0 for mask in range(0, 1 << n): max_total = 0 min_total = 0 diff = 0 temp_arr = [] for i in range(n): if mask & 1 << i: temp_arr.append(arr[i]) if ( l <= sum(temp_arr) <= r and max(temp_arr) - min(temp_arr) >= x and len(temp_arr) >= 2 ): 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 NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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 mlt(): return map(int, input().split()) x, l, r, df = mlt() s = sorted(list(mlt())) def f(x): global s, l, r, df tm = [] for n in range(len(s)): if x % 2: tm.append(s[n]) x //= 2 return int(sum(tm) >= l and sum(tm) <= r and max(tm) - min(tm) >= df) res = 0 for n in range(1 << x): res += f(n) print(res)
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 FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR FUNC_CALL 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.
from itertools import combinations n, l, r, x = list(map(int, input().split())) c = list(map(int, input().split())) ans = 0 for i in range(2, len(c) + 1): all = combinations(c, i) for j in all: sum = 0 mn = 10000000 mx = 0 for k in j: mn = min(mn, k) mx = max(mx, k) sum += k if sum >= l and sum <= r and mx - mn >= x: ans += 1 print(ans)
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 NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL 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.
from itertools import combinations a, b, c, d = map(int, input().split()) l = list(map(int, input().split())) ans = 0 fl = [] for i in range(2, a + 1): tl = list(list(e) for e in combinations(l, i)) for e in tl: fl.append(e) for e in fl: n = len(e) e = sorted(e) t = 0 if max(e) - min(e) >= d: pass else: t = 1 if t == 0 and len(e) >= 2: s = sum(e) if s >= b and s <= c: ans = 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 LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR 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.
a = [] def fn(x, n, l, r, k): sum = 0 v = [] for j in range(20): if 1 << j & x: v.append(a[j]) sum += a[j] if len(v) < 2: return 0 elif v[len(v) - 1] - v[0] >= k and sum >= l and sum <= r: return 1 else: return 0 n, l, r, k = input().split() b = input().split() for i in b: a.append(int(i)) a.sort() ans = 0 for i in range(1 << int(n)): ans = ans + fn(i, int(n), int(l), int(r), int(k)) print(ans)
ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER IF BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL 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.
I = lambda: map(int, input().split()) n, l, r, x = I() C, k = [*I()], 0 for i in range(2**n): W = [w for w, b in zip(C, bin(i)[2:].zfill(n)) if b == "1"] if l <= sum(W) <= r and max(W) - min(W) >= x: k += 1 print(k)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR STRING 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 n, l, r, x = input().split() n = int(n) l = int(l) r = int(r) x = int(x) numbers = [int(z) for z in input().split()] numbers = sorted(numbers) count = 0 for z in range(2, len(numbers) + 1): for subset in itertools.combinations(numbers, z): total = sum(subset) if total >= l and total <= r and subset[-1] - subset[0] >= x: count += 1 print(count)
IMPORT 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 ASSIGN 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 ASSIGN VAR FUNC_CALL VAR VAR IF VAR 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 s1 = input() s1 = s1.split() s2 = input() s2 = s2.split() nlrx = [int(x) for x in s1] nci = [int(x) for x in s2] result = [ seq for i in range(0, len(nci) + 1) for seq in itertools.combinations(nci, i) if sum(seq) >= nlrx[1] and sum(seq) <= nlrx[2] and max(seq) - min(seq) >= nlrx[3] ] print(len(result))
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR 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.
def combinations(arr, n): if n == 0: return [[]] l = [] for i in range(len(arr)): m = arr[i] rem = arr[i + 1 :] for j in combinations(rem, n - 1): l.append([m] + j) return l def solve(arr, n, l, r, x): subset = [] for i in range(2, n + 1): for j in combinations(arr, i): if sum(j) >= l and sum(j) <= r: subset.append(j) count = 0 for i in subset: mn = min(i) mx = max(i) if mx - mn >= x: count += 1 return count n, l, r, x = map(int, input().split()) arr = list(map(int, input().split())) print(solve(arr, n, l, r, x))
FUNC_DEF IF VAR NUMBER RETURN LIST LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF 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.
from itertools import combinations n, l, r, x = input().split() n = int(n) l = int(l) r = int(r) x = int(x) a = list(map(int, input().strip().split()))[:n] sublist = [] for i in range(2, len(a) + 1): for j in list(combinations(a, i)): sublist.append(j) ans = 0 for i in sublist: if len(i) == 1: continue sum_ = 0 for j in i: sum_ += j if max(i) - min(i) >= x: if sum_ >= l: if sum_ <= r: ans += 1 print(ans)
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF 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 suma_o_resta(a, b): return a & 1 << b def diferencia(s1, d): if s1: s1.sort() if s1[-1] - s1[0] >= d: return s1 else: return diferencia(s1.remove(s1[-1]), d) return s1 def no_sets(v, n, l, r, d): s = [] cont = 0 for x in range(1 << n): for i in range(n): if suma_o_resta(x, i) > 0: s.append(v[i]) s = diferencia(s, d) if s: if sum(s) >= l and sum(s) <= r: cont += 1 s = [] return cont n, l, r, x = map(int, input().split()) v = list(map(int, input().split())) print(str(no_sets(v, n, l, r, x)))
FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF IF VAR EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR RETURN VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST 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 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.
import itertools limits = [int(x) for x in input().split()] problems = [int(x) for x in input().split()] n = limits[0] l = limits[1] r = limits[2] x = limits[3] kinds = 0 problems.sort() for i in range(2, n + 1): sublists = list(itertools.combinations(problems, i)) for sublist in sublists: sublist = list(sublist) if sum(sublist) < l or sum(sublist) > r: continue if sublist[len(sublist) - 1] - sublist[0] >= x: kinds += 1 print(kinds)
IMPORT 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 VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP FUNC_CALL VAR 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 sys mod = 1000000007 def factorial_p(n, p): ans = 1 if n <= p // 2: for i in range(1, n + 1): ans = ans * i % p else: for i in range(1, p - n): ans = ans * i % p ans = pow(ans, p - 2, p) if n % 2 == 0: ans = p - ans return ans def nCr_p(n, r, p): ans = 1 while n != 0 or r != 0: a, b = n % p, r % p if a < b: return 0 ans = ( ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p ) n //= p r //= p return ans def prime_sieve(n): flag = n % 6 == 2 sieve = bytearray((n // 3 + flag >> 3) + 1) for i in range(1, int(n**0.5) // 3 + 1): if not sieve[i >> 3] >> (i & 7) & 1: k = 3 * i + 1 | 1 for j in range(k * k // 3, n // 3 + flag, 2 * k): sieve[j >> 3] |= 1 << (j & 7) for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k): sieve[j >> 3] |= 1 << (j & 7) return sieve def prime_list(n): res = [] if n > 1: res.append(2) if n > 2: res.append(3) if n > 4: sieve = prime_sieve(n + 1) res.extend( 3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1 ) return res def binary(number): result = 0 while number: result = result + 1 number = number & number - 1 return result def is_prime(n): if n < 5 or n & 1 == 0 or n % 3 == 0: return 2 <= n <= 3 s = (n - 1 & 1 - n).bit_length() - 1 d = n >> s for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]: p = pow(a, d, n) if p == 1 or p == n - 1 or a % n == 0: continue for _ in range(s): p = p * p % n if p == n - 1: break else: return False return True def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n, l, r, x = get_ints() Arr = get_array() ans = 0 for i in range(1 << n): B = [] for j in range(n): if i >> j & 1: B.append(Arr[j]) if len(B) >= 2 and l <= sum(B) <= r and max(B) - min(B) >= x: ans += 1 print(ans)
IMPORT ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER RETURN NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN 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 LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER EXPR 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.
from sys import stdin, stdout def read(): return stdin.readline().rstrip() def readint(): return int(read()) def readints(): return [int(i) for i in read().split()] _, l, r, x = readints() xs = sorted(readints()) total = 0 for i in range(1 << len(xs)): ans = [xs[moves] for moves in range(len(xs)) if i & 1 << moves] if not ans: continue seq = ans[-1] - ans[0] >= x if l <= sum(ans) <= r and len(ans) > 1 and seq: total += 1 print(total)
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL 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.
ways = 0 def solve(i, l, r, x, max1, min1, sum, flag): global ways if flag == 0: if max1 != min1 and (max1 != -99999999999999 and min1 != 99999999999999): if sum > r: return elif sum >= l and max1 - min1 >= x: ways += 1 if i < 0: return solve(i - 1, l, r, x, max(max1, a[i]), min(min1, a[i]), sum + a[i], 0) solve(i - 1, l, r, x, max1, min1, sum, 1) n, l, r, x = map(int, input().split()) a = list(map(int, input().split())) solve(n - 1, l, r, x, -99999999999999, 99999999999999, 0, 0) print(ways)
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN IF VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR 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 EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER 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.
from itertools import * n, l, r, x = map(lambda x: int(x), input().split()) c = sorted(list(map(lambda x: int(x), input().split()))) variants = [] for i in range(2, n + 1): variants.extend(list(combinations(c, i))) counter = 0 for i in range(len(variants)): sum_var = sum(variants[i]) if sum_var >= l and sum_var <= r and variants[i][-1] - variants[i][0] >= x: counter += 1 print(counter)
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 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 EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF 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.
n, l, r, x = tuple(map(int, input().split())) cs = sorted(list(map(int, input().split()))) def findSet(s, minc, maxc, depth, rest, left, n, l, r, x): if s > r or left >= n and s < l: return 0 ans = 0 if s >= l and s <= r and depth >= 2 and minc + x <= maxc: ans = 1 for i in range(left, n): c = rest[i] if minc == 0: ans += findSet(s + c, c, c, depth + 1, rest, i + 1, n, l, r, x) else: ans += findSet(s + c, minc, c, depth + 1, rest, i + 1, n, l, r, x) return ans print(findSet(0, 0, 0, 0, cs, 0, n, l, r, x))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER VAR NUMBER 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.
from itertools import chain, combinations def powerset(iterable): xs = list(iterable) return list(chain.from_iterable(combinations(xs, n) for n in range(2, len(xs) + 1))) n, l, r, x = map(int, input().split()) sett = list(map(int, input().split())) psett = powerset(sett) count = 0 for i in psett: k = sorted(i) j = sum(k) if j >= l and j <= r and k[-1] - k[0] >= x: count += 1 print(count)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR 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 criteria = input() items_weights = input() n, m, k, p = map(int, criteria.split()) _items_weights = list(map(int, items_weights.split())) if ( not 1 <= n <= 15 or not 1 <= m <= k <= 10**9 or not 1 <= p <= 10**6 or not n == len(_items_weights) ): print("ошибка ввода данных") exit(1) def is_ok(m, k, p, items): return m <= sum(items) <= k and max(items) - min(items) >= p answer = 0 for r in range(n): tmp = itertools.combinations(_items_weights, r=r + 1) for el in tmp: if is_ok(m, k, p, el): answer += 1 print(answer)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF NUMBER VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR 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().strip().split()) c = [int(v) for v in input().strip().split()] ans = 0 for mask in range(1, 1 << n): cur = 0 mn = max(c) mx = min(c) for j in range(n): if mask & 1 << j > 0: cur += c[j] mn = min(mn, c[j]) mx = max(mx, c[j]) if cur >= l and cur <= r and mx - mn >= x: ans += 1 print(ans)
ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER 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 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 find(n, l, r, x, contests, lista): if n == 0: s = sum(lista) if s >= l and s <= r and max(lista) - min(lista) >= x: return 1 else: return 0 c = 0 for i in range(len(contests)): c += find(n - 1, l, r, x, contests[i + 1 :], lista + [contests[i]]) return c n, l, r, x = list(map(int, input().split())) contests = list(map(int, input().split())) c = 0 for i in range(2, n + 1): c += find(i, l, r, x, contests, []) print(c)
FUNC_DEF IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR LIST VAR VAR RETURN VAR 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 NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR 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.
def combine(n, k, w=1, out=[], result=[]): if k == 0: result.append(out) for i in range(w, n + 1): new_out = out[:] new_out.append(i) combine(n, k - 1, i + 1, new_out) return result def main(): n, l, r, x = [int(i) for i in input().split()] c = [int(i) for i in input().split()] if n < 2: print(0) return result = None for i in range(2, n + 1): if i == n: result = combine(n, i) else: combine(n, i) for i in range(len(result)): comb = result[i] for j in range(len(comb)): comb[j] = c[comb[j] - 1] cnt = 0 for i in range(len(result)): sm = sum(result[i]) if sm >= l and sm <= r and max(result[i]) - min(result[i]) >= x: cnt += 1 print(cnt) main()
FUNC_DEF NUMBER LIST LIST IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR 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 IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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.
vet = [] aux = [] cont = 0 def fa(i, f): global aux, cont if i <= f: aux.append(vet[i]) if len(aux) >= 2 and menor <= sum(aux) <= maior and max(aux) - min(aux) >= diff: cont += 1 for k in range(i, f): fa(k + 1, f) aux.pop() n, menor, maior, diff = map(int, input().split()) vet = list(map(int, input().split())) for i in range(n): fa(i, n - 1) print(cont)
ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR EXPR 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 FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL 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 FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR 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 GETBIT(x, bit): return x >> bit & 1 n, l, r, dif = map(int, input().split()) a = list(map(int, input().split())) rs = 0 for i in range(1, 1 << n): lst = [] for j in range(n): if GETBIT(i, j) == 1: lst.append(a[j]) if max(lst) - min(lst) >= dif: if sum(lst) >= l and sum(lst) <= r: rs += 1 print(rs)
FUNC_DEF RETURN BIN_OP BIN_OP VAR 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL 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.
n, l, r, x = [int(y) for y in input().split()] c = [int(y) for y in input().split()] c.sort() ans = [0] def solve(ans, tasklist=[], e=0): if ( sum(tasklist) <= r and sum(tasklist) >= l and len(tasklist) >= 2 and max(tasklist) - min(tasklist) >= x ): ans[0] += 1 for i in range(e, n): tasklist.append(c[i]) solve(ans, tasklist, i + 1) del tasklist[len(tasklist) - 1] solve(ans) print(ans[0])
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 LIST NUMBER FUNC_DEF LIST NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
input() colour = {"R": 0, "G": 1, "B": 2, "Y": 3, "W": 4} cards = {(colour[c], ord(v) - ord("1")) for c, v in input().split()} def ok(cs, vs): return len( {(c if cs >> c & 1 else -1, v if vs >> v & 1 else -1) for c, v in cards} ) == len(cards) print( min( bin(cs).count("1") + bin(vs).count("1") for cs in range(1 << 5) for vs in range(1 << 5) if ok(cs, vs) ) )
EXPR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
from itertools import combinations n = int(input()) colors = {"R": 0, "G": 1, "B": 2, "Y": 3, "W": 4} letters = {"1": 0, "2": 1, "3": 2, "4": 3, "5": 4} l = list(set(list(input().split()))) def checker(hint, cards): for i in cards: for j in cards: if i == j: continue if i[0] == j[0]: if i[1] not in hint and j[1] not in hint: return False elif i[1] == j[1]: if i[0] not in hint and j[0] not in hint: return False elif ( i[0] not in hint and i[1] not in hint and j[0] not in hint and j[1] not in hint ): return False return True result = [] for i in l: if i[0] not in result: result.append(i[0]) if i[1] not in result: result.append(i[1]) all_hints = [] for i in range(1, len(result) + 1): comb = combinations(result, i) all_hints += comb min_hint = len(result) if len(l) == 1: print(0) else: for i in all_hints: if checker(i, l): min_hint = min(len(i), min_hint) print(min_hint)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR DICT STRING STRING STRING STRING STRING NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
import itertools def read(mode=2): inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return [int(x) for x in inputs.split()] def write(s="\n"): if isinstance(s, list): s = " ".join(map(str, s)) s = str(s) print(s, end="") covers = itertools.product([0, 1], repeat=10) (n,) = read() s = read(1) a = [0] * 25 colors = "RGBYW" for i in s: a[colors.index(i[0]) * 5 + int(i[1]) - 1] |= 1 def check(cover): global a unknowns = [0] * 11 for i in range(25): if not a[i]: continue id = -1 if not cover[i % 5]: id = 5 + i // 5 if not cover[5 + i // 5]: if id == -1: id = i % 5 else: id = 10 if id > -1: if unknowns[id]: return False unknowns[id] = 1 return True mn = 99 for i in covers: if check(i): mn = min(mn, sum(i)) print(mn)
IMPORT FUNC_DEF NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
from itertools import * power = lambda i: chain.from_iterable(combinations(i, r) for r in range(len(i) + 1)) input() cards = set(input().split()) print( min( len(s) for s in power("RGBYW12345") if len(set(str(set(s) & set(t)) for t in cards)) == len(cards) ) )
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
n = int(input()) colour = dict(zip("RGBYW", range(5, 10))) cards = list({(2 ** colour[c] + 2 ** (ord(v) - ord("1"))) for c, v in input().split()}) ans = 10 n = len(cards) if n > 1: for bit in range(2**10): ok = True for i in range(n - 1): for j in range(i + 1, n): if cards[i] & cards[j] == 0: if (cards[i] | cards[j]) & bit == 0: ok = False break elif cards[i] != cards[j]: if (cards[i] ^ cards[j]) & bit == 0: ok = False break if not ok: break if ok: ans = min(bin(bit).count("1"), ans) print(ans) else: print(0)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
import itertools input() cards = tuple(set(str.split(input()))) n = len(cards) if n == 1: print(0) return symbols = "RGBYW12345" for l in range(1, 10): for comb in itertools.combinations(symbols, l): positions = [cards] * n for symbol in comb: for i in range(n): if symbol in cards[i]: positions[i] = tuple([c for c in positions[i] if symbol in c]) else: positions[i] = tuple([c for c in positions[i] if symbol not in c]) if sum(map(len, positions)) == n: print(l) return
IMPORT EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
input() p = {((1 << "RGBYW".index(c)) + (1 << int(k) + 4)) for c, k in input().split()} mn = 20 res = 90 for i in range(1024): if len(p) == len(set(i & j for j in p)): mn = min(mn, bin(i).count("1")) print(mn)
EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL STRING VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
import sys n = int(sys.stdin.readline()) cards = list(set(sys.stdin.readline().split())) m = 10 def count_ones(n): cnt = 0 while n > 0: if n & 1: cnt += 1 n //= 2 return cnt def split(l, c): a, b = [], [] for card in l: if c in card: a.append(card) else: b.append(card) return a, b def is_clear(cards, h): cl = [cards] namig = "RGBYW12345" for i in range(10): hint = h & 1 == 1 h //= 2 if not hint: continue cl2 = [] for c in cl: a, b = split(c, namig[i]) if len(a) >= 2: cl2.append(a) if len(b) >= 2: cl2.append(b) cl = cl2 cl = [x for x in cl if len(x) >= 2] return len(cl) == 0 for h in range(2**10): hints = count_ones(h) if is_clear(cards, h): m = min(m, hints) print(m)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
def Checker(hint, card): for a in card: for b in card: if a == b: continue elif a[0] == b[0]: if a[1] not in hint and b[1] not in hint: return False elif a[1] == b[1]: if a[0] not in hint and b[0] not in hint: return False elif ( a[0] not in hint and a[1] not in hint and b[0] not in hint and b[1] not in hint ): return False return True user_input = int(input()) user_input = input() Card = user_input.split(" ") possible_chars = "RGBYW12345" final_answer = 10 card_set = set(Card) if len(card_set) == 1: print("0") else: for i in range(1024): hint = "" counter = 0 for j in range(9, -1, -1): if i - 2**j > 0: hint += possible_chars[j] i -= 2**j counter += 1 if Checker(hint, card_set): final_answer = min(final_answer, counter) print(final_answer)
FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
def check(hint, Card): for i in Card: for j in Card: if i == j: continue elif i[0] == j[0]: if i[1] not in hint and j[1] not in hint: return False elif i[1] == j[1]: if i[0] not in hint and j[0] not in hint: return False elif ( i[0] not in hint and i[1] not in hint and j[0] not in hint and j[1] not in hint ): return False return True HH = "RGBYW12345" n = int(input()) Card = list(input().split(" ")) ans = 20 for i in range(1024): hint = "" cnt = 0 for j in range(10): if 2**j & i > 0: hint += HH[j] cnt += 1 if check(hint, Card): ans = min(ans, cnt) print(ans)
FUNC_DEF FOR VAR VAR FOR VAR VAR IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewhat complicated by the fact that everybody sees Borya's cards except for Borya himself. Borya knows which cards he has but he knows nothing about the order they lie in. Note that Borya can have multiple identical cards (and for each of the 25 types of cards he knows exactly how many cards of this type he has). The aim of the other players is to achieve the state when Borya knows the color and number value of each of his cards. For that, other players can give him hints. The hints can be of two types: color hints and value hints. A color hint goes like that: a player names some color and points at all the cards of this color. Similarly goes the value hint. A player names some value and points at all the cards that contain the value. Determine what minimum number of hints the other players should make for Borya to be certain about each card's color and value. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of Borya's cards. The next line contains the descriptions of n cards. The description of each card consists of exactly two characters. The first character shows the color (overall this position can contain five distinct letters — R, G, B, Y, W). The second character shows the card's value (a digit from 1 to 5). Borya doesn't know exact order of the cards they lie in. -----Output----- Print a single integer — the minimum number of hints that the other players should make. -----Examples----- Input 2 G3 G3 Output 0 Input 4 G4 R4 R3 B3 Output 2 Input 5 B1 Y1 W1 G1 R1 Output 4 -----Note----- In the first sample Borya already knows for each card that it is a green three. In the second sample we can show all fours and all red cards. In the third sample you need to make hints about any four colors.
input() colour = dict(zip("RGBYW", range(5))) cards = {(colour[c], ord(v) - ord("1")) for c, v in input().split()} print( min( bin(cs).count("1") + bin(vs).count("1") for cs in range(1 << 5) for vs in range(1 << 5) if len({(c if cs >> c & 1 else -1, v if vs >> v & 1 else -1) for c, v in cards}) == len(cards) ) )
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL FUNC_CALL VAR VAR STRING FUNC_CALL FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
from itertools import chain class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: start_mask = start while start_mask: start_mask >>= 1 start ^= start_mask out = [(x ^ x >> 1) for x in chain(range(start, 2**n), range(start))] return out
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: gc = [0] for i in range(1, 2**n): gc.append(gc[-1] ^ i & -i) l = len(gc) for i in range(l): fe = gc[0] if fe == start: break else: gc.append(gc.pop(0)) return gc
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: def extendPerm(arr): arr.extend([("1" + num) for num in arr[::-1]]) for i in range(len(arr) // 2): arr[i] = "0" + arr[i] arr = ["0", "1"] for i in range(n - 1): extendPerm(arr) nums = [int(num, 2) for num in arr] index = nums.index(start) return nums[index:] + nums[:index]
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP STRING VAR VAR ASSIGN VAR LIST STRING STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: def dfs(i): if len(p) == 1 << n: a = p[0] ^ p[1] return a and a & a - 1 == 0 j = 1 for _ in range(n): k = i ^ j if k not in visited: visited.add(k) p.append(k) if dfs(k): return True visited.remove(k) p.pop() j <<= 1 return False visited = {start} p = [start] dfs(start) return p
CLASS_DEF FUNC_DEF VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: bi = str(bin(start))[2:].zfill(n) def get_perm(bi_start, l): a = bi_start[-1 * l] b = str(1 - int(a)) if l == 1: return [a, b] perms = get_perm(bi_start, l - 1) return [(a + e) for e in perms] + [(b + e) for e in perms[::-1]] return list(map(lambda x: int(x, 2), get_perm(bi, len(bi))))
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR IF VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: ans = [] lastNumberSet = set([(start ^ 1 << i) for i in range(n)]) nMax = 2**n visited = set() visited.add(start) def helper(preNum, ni): if ni == nMax: if preNum in lastNumberSet: return True return False for i in range(n): nextNum = preNum ^ 1 << i if nextNum not in visited: visited.add(nextNum) if helper(nextNum, ni + 1): ans.append(nextNum) return True visited.remove(nextNum) return False helper(start, 1) return [start] + ans[::-1]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN BIN_OP LIST VAR VAR NUMBER VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: used = {start} two = [(2**i) for i in range(n)] res = [start] while len(res) < 2**n: i = 0 a = res[-1] ^ two[i] while a in used: i += 1 a = res[-1] ^ two[i] used.add(a) res.append(a) return res
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR WHILE FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: gray_code = [1, 0] for i in range(1, n): next_gray_code = [] increase = 1 << i for num in gray_code: next_gray_code.append(num + increase) for num in reversed(gray_code): next_gray_code.append(num) gray_code = next_gray_code idx = gray_code.index(start) return gray_code[idx:] + gray_code[:idx]
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR VAR VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: original_list = [None for _ in range(1 << n)] original_list[0] = 0 original_list[1] = 1 for i in range(1, n): num_elements = 1 << i for j in range(num_elements): original_list[j] <<= 1 for j in range(num_elements): original_list[num_elements + j] = ( original_list[num_elements - j - 1] + 1 ) result_list = [None for _ in range(1 << n)] current = 0 while original_list[current] != start: current += 1 for i in range(1 << n): result_list[i] = original_list[(current + i) % (1 << n)] return result_list
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NONE VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR RETURN VAR VAR VAR
Given 2 integers n and start. Your task is return any permutation p of (0,1,2.....,2^n -1) such that : p[0] = start p[i] and p[i+1] differ by only one bit in their binary representation. p[0] and p[2^n -1] must also differ by only one bit in their binary representation.   Example 1: Input: n = 2, start = 3 Output: [3,2,0,1] Explanation: The binary representation of the permutation is (11,10,00,01). All the adjacent element differ by one bit. Another valid permutation is [3,1,0,2] Example 2: Input: n = 3, start = 2 Output: [2,6,7,5,4,0,1,3] Explanation: The binary representation of the permutation is (010,110,111,101,100,000,001,011).   Constraints: 1 <= n <= 16 0 <= start < 2 ^ n
class Solution: def circularPermutation(self, n: int, start: int) -> List[int]: used = set() result = [None] * int(2**n) result[0] = start used.add(start) for i in range(1, len(result)): for x in range(n): bit = bool(result[i - 1] & 1 << x) if bit: val = result[i - 1] - (1 << x) else: val = result[i - 1] + (1 << x) if val not in used: used.add(val) result[i] = val break return result
CLASS_DEF FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR VAR