description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: * Empty string is a correct bracket sequence. * if s is a correct bracket sequence, then (s) is also a correct bracket sequence. * if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s. Joyce doesn't know anything about bracket sequences, so she asked for your help. Input The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000). Output Print the answer to Will's puzzle in the first and only line of output. Examples Input ((?)) Output 4 Input ??()?? Output 7 Note For the first sample testcase, the pretty substrings of s are: 1. "(?" which can be transformed to "()". 2. "?)" which can be transformed to "()". 3. "((?)" which can be transformed to "(())". 4. "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of s are: 1. "??" which can be transformed to "()". 2. "()". 3. "??()" which can be transformed to "()()". 4. "?()?" which can be transformed to "(())". 5. "??" which can be transformed to "()". 6. "()??" which can be transformed to "()()". 7. "??()??" which can be transformed to "()()()".
s = str(input()) n = len(s) ans = 0 dp = [[(0) for _ in range(n)] for _ in range(2)] for i in range(n - 1): if s[i] == ")": continue dp[0][i] = 1 dp[1][i] = 1 for j in range(i + 1, n): if s[j] == "(": dp[0][j] = dp[0][j - 1] + 1 dp[1][j] = dp[1][j - 1] + 1 elif s[j] == "?": dp[0][j] = dp[0][j - 1] + 1 dp[1][j] = max(dp[1][j - 1] - 1, 0) elif s[j] == ")" and 0 < dp[0][j - 1]: dp[0][j] = dp[0][j - 1] - 1 dp[1][j] = max(dp[1][j - 1] - 1, 0) else: break if (j - i) % 2 == 1 and dp[1][j] == 0: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING NUMBER VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: * Empty string is a correct bracket sequence. * if s is a correct bracket sequence, then (s) is also a correct bracket sequence. * if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s. Joyce doesn't know anything about bracket sequences, so she asked for your help. Input The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000). Output Print the answer to Will's puzzle in the first and only line of output. Examples Input ((?)) Output 4 Input ??()?? Output 7 Note For the first sample testcase, the pretty substrings of s are: 1. "(?" which can be transformed to "()". 2. "?)" which can be transformed to "()". 3. "((?)" which can be transformed to "(())". 4. "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of s are: 1. "??" which can be transformed to "()". 2. "()". 3. "??()" which can be transformed to "()()". 4. "?()?" which can be transformed to "(())". 5. "??" which can be transformed to "()". 6. "()??" which can be transformed to "()()". 7. "??()??" which can be transformed to "()()()".
s = input() l = len(s) ans = 0 for i in range(0, l): ln = n = 0 for j in range(i, l): if s[j] == "(": ln += 1 elif s[j] == ")": ln -= 1 else: n += 1 ln -= 1 if ln == 0: ans += 1 elif ln < 0: if n > 0: ln += 2 n -= 1 else: break print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: * Empty string is a correct bracket sequence. * if s is a correct bracket sequence, then (s) is also a correct bracket sequence. * if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s. Joyce doesn't know anything about bracket sequences, so she asked for your help. Input The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000). Output Print the answer to Will's puzzle in the first and only line of output. Examples Input ((?)) Output 4 Input ??()?? Output 7 Note For the first sample testcase, the pretty substrings of s are: 1. "(?" which can be transformed to "()". 2. "?)" which can be transformed to "()". 3. "((?)" which can be transformed to "(())". 4. "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of s are: 1. "??" which can be transformed to "()". 2. "()". 3. "??()" which can be transformed to "()()". 4. "?()?" which can be transformed to "(())". 5. "??" which can be transformed to "()". 6. "()??" which can be transformed to "()()". 7. "??()??" which can be transformed to "()()()".
s = input() res, n = 0, len(s) for i in range(n - 1): j, c, q = i, 0, 0 while j < n and c + q >= 0: if s[j] == "(": c += 1 elif s[j] == ")": c -= 1 else: q += 1 if c < q: c, q = q, c res += c == q j += 1 print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER WHILE VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. <image> Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: * Empty string is a correct bracket sequence. * if s is a correct bracket sequence, then (s) is also a correct bracket sequence. * if s and t are correct bracket sequences, then st (concatenation of s and t) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string s consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (l, r) such that 1 ≤ l ≤ r ≤ |s| and the string slsl + 1... sr is pretty, where si is i-th character of s. Joyce doesn't know anything about bracket sequences, so she asked for your help. Input The first and only line of input contains string s, consisting only of characters '(', ')' and '?' (2 ≤ |s| ≤ 5000). Output Print the answer to Will's puzzle in the first and only line of output. Examples Input ((?)) Output 4 Input ??()?? Output 7 Note For the first sample testcase, the pretty substrings of s are: 1. "(?" which can be transformed to "()". 2. "?)" which can be transformed to "()". 3. "((?)" which can be transformed to "(())". 4. "(?))" which can be transformed to "(())". For the second sample testcase, the pretty substrings of s are: 1. "??" which can be transformed to "()". 2. "()". 3. "??()" which can be transformed to "()()". 4. "?()?" which can be transformed to "(())". 5. "??" which can be transformed to "()". 6. "()??" which can be transformed to "()()". 7. "??()??" which can be transformed to "()()()".
s = input().strip() n = len(s) ques = ans = ini = 0 for i in range(n): ques = ini = 0 for j in range(i, n): c = s[j] if c == "?": ques += 1 elif c == "(": ini += 1 else: ini -= 1 if ini < 0: break if ques > ini: ques -= 1 ini += 1 if (j - i + 1) % 2 == 0 and ques == ini: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: * choose indexes i and j (i ≠ j) that haven't been chosen yet; * round element ai to the nearest integer that isn't more than ai (assign to ai: ⌊ ai ⌋); * round element aj to the nearest integer that isn't less than aj (assign to aj: ⌈ aj ⌉). Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference. Input The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. Output In a single line print a single real number — the required difference with exactly three digits after the decimal point. Examples Input 3 0.000 0.500 0.750 1.000 2.000 3.000 Output 0.250 Input 3 4469.000 6526.000 4864.000 9356.383 7490.000 995.896 Output 0.279 Note In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
n = int(input()) a = list(map(lambda x: int(x.split(".")[1]), input().split())) s = sum(a) - n * 1000 zero_cnt = a.count(0) min_add = max(0, zero_cnt - n) max_add = min(n, zero_cnt) answ = min(abs(s + i * 1000) for i in range(min_add, max_add + 1)) print("{:d}.{:0>3d}".format(answ // 1000, answ % 1000))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER
Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: * choose indexes i and j (i ≠ j) that haven't been chosen yet; * round element ai to the nearest integer that isn't more than ai (assign to ai: ⌊ ai ⌋); * round element aj to the nearest integer that isn't less than aj (assign to aj: ⌈ aj ⌉). Nevertheless, Jeff doesn't want to hurt the feelings of the person who gave him the sequence. That's why the boy wants to perform the operations so as to make the absolute value of the difference between the sum of elements before performing the operations and the sum of elements after performing the operations as small as possible. Help Jeff find the minimum absolute value of the difference. Input The first line contains integer n (1 ≤ n ≤ 2000). The next line contains 2n real numbers a1, a2, ..., a2n (0 ≤ ai ≤ 10000), given with exactly three digits after the decimal point. The numbers are separated by spaces. Output In a single line print a single real number — the required difference with exactly three digits after the decimal point. Examples Input 3 0.000 0.500 0.750 1.000 2.000 3.000 Output 0.250 Input 3 4469.000 6526.000 4864.000 9356.383 7490.000 995.896 Output 0.279 Note In the first test case you need to perform the operations as follows: (i = 1, j = 4), (i = 2, j = 3), (i = 5, j = 6). In this case, the difference will equal |(0 + 0.5 + 0.75 + 1 + 2 + 3) - (0 + 0 + 1 + 1 + 2 + 3)| = 0.25.
n = int(input()) a = map(float, input().split()) s = 0 m = 0 for val in a: s += val - int(val) m += val - int(val) > 0 v = 1000000000.0 for i in range(max(0, m - n), min(n, m) + 1): v = min(v, abs(s - i)) print("%.3f" % v)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR
Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $y$. Vlad decided to visit Nastya. However, he remembered that he had postponed for later $k$ things that he has to do before coming to Nastya. To do the $i$-th thing, he needs to come to the $a_i$-th house, things can be done in any order. In $1$ minute, he can walk from one house to another if they are connected by a road. Vlad does not really like walking, so he is interested what is the minimum number of minutes he has to spend on the road to do all things and then come to Nastya. Houses $a_1, a_2, \dots, a_k$ he can visit in any order. He can visit any house multiple times (if he wants). -----Input----- The first line of input contains an integer $t$ ($1 \le t \le 10^4$) — the number of input test cases. There is an empty line before each test case. The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 2\cdot 10^5$) — the number of houses and things, respectively. The second line of each test case contains two integers $x$ and $y$ ($1 \le x, y \le n$) — indices of the houses where Vlad and Nastya live, respectively. The third line of each test case contains $k$ integers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le n$) — indices of houses Vlad need to come to do things. The following $n-1$ lines contain description of city, each line contains two integers $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — indices of houses connected by road $j$. It is guaranteed that the sum of $n$ for all cases does not exceed $2\cdot10^5$. -----Output----- Output $t$ lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer — the minimum number of minutes Vlad needs on the road to do all the things and come to Nastya. -----Examples----- Input 3 3 1 1 3 2 1 3 1 2 6 4 3 5 1 6 2 1 1 3 3 4 3 5 5 6 5 2 6 2 3 2 5 3 1 3 3 4 3 5 5 6 5 2 Output 3 7 2 -----Note----- Tree and best path for the first test case: $1 \rightarrow 2 \rightarrow 1 \rightarrow 3$ Tree and best path for the second test case: $3 \rightarrow 1 \rightarrow 3 \rightarrow 5 \rightarrow 2 \rightarrow 5 \rightarrow 6 \rightarrow 5$ Tree and best path for the third test case: $3 \rightarrow 5 \rightarrow 2$
t = int(input()) for case in range(t): input() n, k = list(map(int, input().split())) x, y = list(map(int, input().split())) x -= 1 y -= 1 things = list(map(int, input().split())) things = set([(i - 1) for i in things]) adj = [[] for _ in range(n)] for i in range(n - 1): u, v = list(map(int, input().split())) u -= 1 v -= 1 adj[u].append(v) adj[v].append(u) pre = [-1] * n qu = [x] vis_node = set() vis_node.add(x) while qu: nq = [] for i in qu: vis_node.add(i) for u in adj[i]: if u not in vis_node: nq.append(u) pre[u] = i qu = nq res = 0 vis_node = set() vis_node.add(x) tmp = y while tmp not in vis_node: vis_node.add(tmp) tmp = pre[tmp] res += 1 for i in things: tmp = i while tmp not in vis_node: vis_node.add(tmp) tmp = pre[tmp] res += 2 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $y$. Vlad decided to visit Nastya. However, he remembered that he had postponed for later $k$ things that he has to do before coming to Nastya. To do the $i$-th thing, he needs to come to the $a_i$-th house, things can be done in any order. In $1$ minute, he can walk from one house to another if they are connected by a road. Vlad does not really like walking, so he is interested what is the minimum number of minutes he has to spend on the road to do all things and then come to Nastya. Houses $a_1, a_2, \dots, a_k$ he can visit in any order. He can visit any house multiple times (if he wants). -----Input----- The first line of input contains an integer $t$ ($1 \le t \le 10^4$) — the number of input test cases. There is an empty line before each test case. The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 2\cdot 10^5$) — the number of houses and things, respectively. The second line of each test case contains two integers $x$ and $y$ ($1 \le x, y \le n$) — indices of the houses where Vlad and Nastya live, respectively. The third line of each test case contains $k$ integers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le n$) — indices of houses Vlad need to come to do things. The following $n-1$ lines contain description of city, each line contains two integers $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — indices of houses connected by road $j$. It is guaranteed that the sum of $n$ for all cases does not exceed $2\cdot10^5$. -----Output----- Output $t$ lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer — the minimum number of minutes Vlad needs on the road to do all the things and come to Nastya. -----Examples----- Input 3 3 1 1 3 2 1 3 1 2 6 4 3 5 1 6 2 1 1 3 3 4 3 5 5 6 5 2 6 2 3 2 5 3 1 3 3 4 3 5 5 6 5 2 Output 3 7 2 -----Note----- Tree and best path for the first test case: $1 \rightarrow 2 \rightarrow 1 \rightarrow 3$ Tree and best path for the second test case: $3 \rightarrow 1 \rightarrow 3 \rightarrow 5 \rightarrow 2 \rightarrow 5 \rightarrow 6 \rightarrow 5$ Tree and best path for the third test case: $3 \rightarrow 5 \rightarrow 2$
def solve(N, K, vlad, nast, to_do, g): to_do.add(vlad) to_do.add(nast) S = [(vlad, 0)] prnt = (N + 1) * [-1] time = None while S: cur, t = S.pop() if cur == nast: time = t for nxt in g[cur]: if nxt != prnt[cur]: prnt[nxt] = cur S.append((nxt, t + 1)) hwss = list(to_do) edge_ct = 0 for hws in hwss: if hws != vlad and prnt[hws] not in to_do: to_do.add(prnt[hws]) hwss.append(prnt[hws]) if hws != vlad: edge_ct += 2 return edge_ct - time def get_input(): input() N, K = map(int, input().split()) vlad, nast = map(lambda x: int(x) - 1, input().split()) todo = set(map(lambda x: int(x) - 1, input().split())) g = [[] for _ in range(N)] for _ in range(N - 1): frm, to = map(lambda x: int(x) - 1, input().split()) g[frm].append(to) g[to].append(frm) return N, K, vlad, nast, todo, g for _ in range(int(input())): N, K, vlad, nast, todo, g = get_input() ans = solve(N, K, vlad, nast, todo, g) print(ans)
FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NONE WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vlad and Nastya live in a city consisting of $n$ houses and $n-1$ road. From each house, you can get to the other by moving only along the roads. That is, the city is a tree. Vlad lives in a house with index $x$, and Nastya lives in a house with index $y$. Vlad decided to visit Nastya. However, he remembered that he had postponed for later $k$ things that he has to do before coming to Nastya. To do the $i$-th thing, he needs to come to the $a_i$-th house, things can be done in any order. In $1$ minute, he can walk from one house to another if they are connected by a road. Vlad does not really like walking, so he is interested what is the minimum number of minutes he has to spend on the road to do all things and then come to Nastya. Houses $a_1, a_2, \dots, a_k$ he can visit in any order. He can visit any house multiple times (if he wants). -----Input----- The first line of input contains an integer $t$ ($1 \le t \le 10^4$) — the number of input test cases. There is an empty line before each test case. The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 2\cdot 10^5$) — the number of houses and things, respectively. The second line of each test case contains two integers $x$ and $y$ ($1 \le x, y \le n$) — indices of the houses where Vlad and Nastya live, respectively. The third line of each test case contains $k$ integers $a_1, a_2, \dots, a_k$ ($1 \le a_i \le n$) — indices of houses Vlad need to come to do things. The following $n-1$ lines contain description of city, each line contains two integers $v_j$ and $u_j$ ($1 \le u_j, v_j \le n$) — indices of houses connected by road $j$. It is guaranteed that the sum of $n$ for all cases does not exceed $2\cdot10^5$. -----Output----- Output $t$ lines, each of which contains the answer to the corresponding test case of input. As an answer output single integer — the minimum number of minutes Vlad needs on the road to do all the things and come to Nastya. -----Examples----- Input 3 3 1 1 3 2 1 3 1 2 6 4 3 5 1 6 2 1 1 3 3 4 3 5 5 6 5 2 6 2 3 2 5 3 1 3 3 4 3 5 5 6 5 2 Output 3 7 2 -----Note----- Tree and best path for the first test case: $1 \rightarrow 2 \rightarrow 1 \rightarrow 3$ Tree and best path for the second test case: $3 \rightarrow 1 \rightarrow 3 \rightarrow 5 \rightarrow 2 \rightarrow 5 \rightarrow 6 \rightarrow 5$ Tree and best path for the third test case: $3 \rightarrow 5 \rightarrow 2$
def solve(n, k, x, y, a, graph): a.add(x) a.add(y) stack = [(x, 0)] parent = (n + 1) * [-1] y_height = None while stack: node, height = stack.pop() if node == y: y_height = height for child in graph[node]: if child != parent[node]: parent[child] = node stack.append((child, height + 1)) lst = list(a) edge_ct = 0 for node in lst: if node != x and parent[node] not in a: a.add(parent[node]) lst.append(parent[node]) if node != x: edge_ct += 2 return edge_ct - y_height t = int(input()) for case in range(t): input() n, k = map(int, input().split()) x, y = map(int, input().split()) a = set(map(int, input().split())) graph = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) print(solve(n, k, x, y, a, graph))
FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NUMBER ASSIGN VAR NONE WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR
Chef has an array A of length N. He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}. Chef can perform the following operation at most once: Choose any [subsequence] of the array A and add any positive integer to all the elements of the chosen subsequence. Determine the maximum number of good indices Chef can get. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains a single integer N denoting the length of the array A. - The second line contains N space-separated integers denoting the array A. ------ Output Format ------ For each test case, output the maximum number of good indices Chef can get after performing the given operation at most once. ------ Constraints ------ $1 ≤ T ≤ 500$ $2 ≤ N ≤ 1000$ $1 ≤ A_{i} ≤ 1000$ - The sum of $N$ over all test cases won't exceed $2000$. ----- Sample Input 1 ------ 3 6 1 3 5 2 4 8 4 2 3 4 5 7 1 1 2 2 3 4 4 ----- Sample Output 1 ------ 4 4 7
for _ in range(int(input())): n = int(input()) a = sorted(list(map(int, input().split()))) freq = [0] * 1001 for x in a: freq[x] += 1 ans = 0 for d in range(1, 1001): cur = 0 mark = [0] * 1001 for x in a: if mark[x] == 1: continue ptr = x tot = 0 mx = 0 while ptr <= 1000: if freq[ptr] == 0: break mark[ptr] = 1 tot += freq[ptr] mx = max(mx, freq[ptr]) ptr += d if mx > 1 or tot % 2 == 0: cur += tot else: cur += tot - 1 ans = max(ans, cur) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has an array A of length N. He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}. Chef can perform the following operation at most once: Choose any [subsequence] of the array A and add any positive integer to all the elements of the chosen subsequence. Determine the maximum number of good indices Chef can get. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains a single integer N denoting the length of the array A. - The second line contains N space-separated integers denoting the array A. ------ Output Format ------ For each test case, output the maximum number of good indices Chef can get after performing the given operation at most once. ------ Constraints ------ $1 ≤ T ≤ 500$ $2 ≤ N ≤ 1000$ $1 ≤ A_{i} ≤ 1000$ - The sum of $N$ over all test cases won't exceed $2000$. ----- Sample Input 1 ------ 3 6 1 3 5 2 4 8 4 2 3 4 5 7 1 1 2 2 3 4 4 ----- Sample Output 1 ------ 4 4 7
for _ in range(int(input())): N = int(input()) A = [*map(int, input().split())] freq = [0] * 1001 for x in A: freq[x] += 1 D = {} for i in range(1001): if freq[i]: D[i] = freq[i] ans = sum(D[x] for x in D if D[x] > 1) for x in range(1, 1001): s, p, curr = [], {}, 0 for i in D: if i - x in D: p[i] = p[i - x] else: p[i] = len(s) s.append([]) s[p[i]].append(D[i]) for v in s: curr += sum(v) v.sort() if len(v) & 1 and v[-1] == 1: curr -= 1 ans = max(curr, ans) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST DICT NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Chef has an array A of length N. He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}. Chef can perform the following operation at most once: Choose any [subsequence] of the array A and add any positive integer to all the elements of the chosen subsequence. Determine the maximum number of good indices Chef can get. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains a single integer N denoting the length of the array A. - The second line contains N space-separated integers denoting the array A. ------ Output Format ------ For each test case, output the maximum number of good indices Chef can get after performing the given operation at most once. ------ Constraints ------ $1 ≤ T ≤ 500$ $2 ≤ N ≤ 1000$ $1 ≤ A_{i} ≤ 1000$ - The sum of $N$ over all test cases won't exceed $2000$. ----- Sample Input 1 ------ 3 6 1 3 5 2 4 8 4 2 3 4 5 7 1 1 2 2 3 4 4 ----- Sample Output 1 ------ 4 4 7
def soln(A): freq = {} for i in A: if i in freq.keys(): freq[i] += 1 else: freq[i] = 1 A = [*freq.keys()] A.sort() max_count = sum(freq[x] for x in freq if freq[x] > 1) for x in range(1, A[-1] - A[0] + 1): s, p, count = [], {}, 0 for i in A: if i - x in freq: p[i] = p[i - x] else: p[i] = len(s) s.append([]) s[p[i]].append(freq[i]) for v in s: count += sum(v) v.sort() if len(v) & 1 and v[-1] == 1: count -= 1 max_count = max(max_count, count) return max_count for _ in range(int(input())): n = int(input()) A = list(map(int, input().split())) print(soln(A))
FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST DICT NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Chef has an array A of length N. He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}. Chef can perform the following operation at most once: Choose any [subsequence] of the array A and add any positive integer to all the elements of the chosen subsequence. Determine the maximum number of good indices Chef can get. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains a single integer N denoting the length of the array A. - The second line contains N space-separated integers denoting the array A. ------ Output Format ------ For each test case, output the maximum number of good indices Chef can get after performing the given operation at most once. ------ Constraints ------ $1 ≤ T ≤ 500$ $2 ≤ N ≤ 1000$ $1 ≤ A_{i} ≤ 1000$ - The sum of $N$ over all test cases won't exceed $2000$. ----- Sample Input 1 ------ 3 6 1 3 5 2 4 8 4 2 3 4 5 7 1 1 2 2 3 4 4 ----- Sample Output 1 ------ 4 4 7
for _ in range(int(input())): n = int(input()) a = [int(x) for x in input().split()] a.sort() freq = [0] * 1001 ans = 0 for x in a: freq[x] += 1 for d in range(1, 1001): mark = [0] * 1001 Ans = 0 for x in a: pointer = x if mark[pointer] == 1: continue mx = 0 curAns = 0 while pointer <= 1000: if freq[pointer] == 0: break mark[pointer] = 1 curAns += freq[pointer] mx = max(mx, freq[pointer]) pointer += d if curAns % 2 == 0 or mx > 1: Ans += curAns else: Ans += curAns - 1 ans = max(ans, Ans) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxi = -sys.maxsize for i in range(0, n): maxi = max(maxi, Jobs[i].deadline) schedule = [(-1) for i in range(maxi + 1)] count = 0 maxProfit = 0 for i in range(0, n): currProfit = Jobs[i].profit currDeadline = Jobs[i].deadline currId = Jobs[i].id for k in range(currDeadline, 0, -1): if schedule[k] == -1: count += 1 maxProfit += currProfit schedule[k] = currId break return [count, maxProfit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): l = Jobs l.sort(reverse=True, key=lambda x: x.profit) max = 0 for i in l: if i.deadline > max: max = i.deadline l1 = [0] * max c = 0 for i in l: j = i.deadline - 1 while True: if l1[j] == 0: l1[j] = i.profit c = c + 1 break else: j -= 1 if j < 0: break if c == max: break c1 = 0 sum = 0 for i in l1: if i != 0: sum += i c1 += 1 return [c1, sum]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) vis = [-1] * n ans = 0 cnt = 0 for i in range(n): job = Jobs[i] if vis[job.deadline - 1] == -1: vis[job.deadline - 1] = job.id ans += job.profit cnt += 1 else: for curr in range(job.deadline - 2, -1, -1): if vis[curr] == -1: vis[curr] = job.id ans += job.profit cnt += 1 break return [cnt, ans]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): jobs.sort(key=lambda x: x.profit, reverse=True) maxDeadline = max(jobs, key=lambda x: x.deadline).deadline sequence = {} total_jobs = 0 total_profit = 0 for job in jobs: index = job.deadline - 1 while index >= 0 and index in sequence: index -= 1 if index >= 0: sequence[index] = job.id total_jobs += 1 total_profit += job.profit return total_jobs, total_profit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class DisjointSet: def __init__(self, n): self.parent = [i for i in range(n)] def find(self, x): if x == self.parent[x]: return x self.parent[x] = self.find(self.parent[x]) return self.parent[x] def merge(self, x, y): self.parent[y] = x class Solution: def findMaxDeadline(self, arr): ans = 0 for job in arr: if job.deadline > ans: ans = job.deadline return ans def JobScheduling(self, arr, n): arr = sorted(arr, key=lambda x: x.profit, reverse=True) m = self.findMaxDeadline(arr) dsu = DisjointSet(m + 1) count, profit = 0, 0 for job in arr: available_slot = dsu.find(job.deadline) if available_slot > 0: count += 1 profit += job.profit dsu.merge(dsu.find(available_slot - 1), available_slot) return count, profit
CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) no = 0 profit = 0 visited = [0] * n for i in Jobs: for j in range(i.deadline - 1, -1, -1): if visited[j] == 0: visited[j] = 1 no += 1 profit += i.profit break return no, profit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): s_jobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) maxV = max([job.deadline for job in Jobs]) arr = [-1] * (maxV + 1) sumV = 0 count = 0 for i in range(n): if arr[s_jobs[i].deadline] == -1: sumV += s_jobs[i].profit count += 1 arr[s_jobs[i].deadline] = s_jobs[i].id else: for j in range(s_jobs[i].deadline - 1, 0, -1): if arr[j] == -1: arr[j] = s_jobs[i].id sumV += s_jobs[i].profit count += 1 break return count, sumV
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): jobs.sort(key=lambda x: x.profit, reverse=True) slots = [False] * n max_profit = 0 num_jobs = 0 for i in range(n): for j in range(min(n, jobs[i].deadline) - 1, -1, -1): if not slots[j]: slots[j] = True max_profit += jobs[i].profit num_jobs += 1 break return num_jobs, max_profit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): stateMap = [(0) for _ in range(n)] sortedJobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) profitSum = 0 jobsDone = 0 for job in sortedJobs: for currState in range(job.deadline - 1, -1, -1): if not stateMap[currState]: stateMap[currState] = 1 profitSum += job.profit jobsDone += 1 break return jobsDone, profitSum
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): jobs.sort(key=lambda x: x.profit, reverse=True) maxi = jobs[0].deadline for i in range(1, len(jobs)): maxi = max(maxi, jobs[i].deadline) slot = [-1] * (maxi + 1) countJobs = 0 jobProfit = 0 for i in range(len(jobs)): for j in range(jobs[i].deadline, 0, -1): if slot[j] == -1: slot[j] = i countJobs += 1 jobProfit += jobs[i].profit break return countJobs, jobProfit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: -x.profit) slot = [False] * (n + 1) maxprofit = 0 cnt = 0 for i in range(n): for j in range(Jobs[i].deadline, 0, -1): if slot[j] == False: maxprofit += Jobs[i].profit slot[j] = True cnt += 1 break return [cnt, maxprofit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): max_d = max({x.deadline for x in Jobs}) Jobs.sort(key=lambda x: -x.profit) dp = [0] * max_d for i in range(len(Jobs)): for j in range(min(max_d - 1, Jobs[i].deadline - 1), -1, -1): if dp[j] == 0: dp[j] = Jobs[i].profit break jobs_done, max_p = 0, 0 for p in dp: if p > 0: jobs_done += 1 max_p += p return jobs_done, max_p
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) max_deadline = -1 for i in range(n): if Jobs[i].deadline > max_deadline: max_deadline = Jobs[i].deadline arr = [-1] * max_deadline count = 0 profit = 0 for i in range(n): if arr[Jobs[i].deadline - 1] == -1: arr[Jobs[i].deadline - 1] = Jobs[i].id count += 1 profit += Jobs[i].profit else: k = Jobs[i].deadline - 1 - 1 for x in range(k, -1, -1): if arr[x] == -1: arr[x] = Jobs[i].id count += 1 profit += Jobs[i].profit break return [count, profit]
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: -x.profit) max_deadline = Jobs[0].deadline for job in Jobs: max_deadline = max(max_deadline, job.deadline) deadlines = [-1] * (max_deadline + 1) max_profit = 0 cnt = 0 for job in Jobs: for i in range(job.deadline, 0, -1): if deadlines[i] == -1: deadlines[i] = job.deadline max_profit += job.profit cnt += 1 break return cnt, max_profit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): array = sorted(Jobs, key=lambda x: x.profit, reverse=True) visited = [0] * n day = 0 profit = 0 for i in range(n): j = min(n, array[i].deadline - 1) for j in range(j, -1, -1): if visited[j] == 0: visited[j] = 1 profit += array[i].profit day += 1 break return day, profit
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): jobs = [] for i in range(n): jobs.append([Jobs[i].deadline, Jobs[i].profit]) def sort(jobs): r = sorted(jobs, key=lambda x: x[1], reverse=True) return r arr = sort(jobs) visited = [False] * (len(jobs) + 1) pro = 0 co = 0 for i in range(n): if not visited[arr[i][0]]: visited[arr[i][0]] = True pro += arr[i][1] co += 1 else: for j in range(arr[i][0] - 1, 0, -1): if not visited[j]: pro += arr[i][1] visited[j] = True co += 1 break return co, pro
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): given = [] for i in range(n): given.append([Jobs[i].deadline, Jobs[i].profit]) given.sort(key=lambda x: x[1], reverse=True) jobsdone = [False] * n profit = [] for i in range(n): j = given[i][0] for k in range(j - 1, -1, -1): if jobsdone[k] is False: profit.append(given[i][1]) jobsdone[k] = True break return [len(profit), sum(profit)]
CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) done = [-1] * 101 cost = 0 ans = 0 count = 0 for i in range(n): cost = Jobs[i].profit serial = Jobs[i].id dead = Jobs[i].deadline for j in range(dead, 0, -1): if done[j] == -1: done[j] = serial ans += cost count += 1 break return count, ans
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): j = sorted(Jobs, key=lambda x: x.profit, reverse=True) max_d = 0 for jb in Jobs: max_d = max(max_d, jb.deadline) time = set() for i in range(1, max_d + 1): time.add(i) ans = 0 k = 0 for i in range(n): if len(time) == 0: break jb = j[i] dd = jb.deadline while dd > 0: if dd in time: k += 1 ans += jb.profit time.remove(dd) break else: dd -= 1 return k, ans
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxi = Jobs[0].deadline for i in range(n): maxi = max(maxi, Jobs[i].deadline) arr = [(0) for i in range(maxi)] count = 0 profits = 0 for i in range(n): for j in range(Jobs[i].deadline - 1, -1, -1): if arr[j] == 0: arr[j] = Jobs[i].id count += 1 profits += Jobs[i].profit break res = [count, profits] return res
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR LIST VAR VAR RETURN VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) places = [(False) for _ in range(n)] res = 0 count = 0 for i in range(n): for j in reversed(range(min(n - 1, Jobs[i].deadline - 1) + 1)): if places[j] == False: res += Jobs[i].profit places[j] = True count += 1 break return count, res
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): jobs.sort(key=lambda x: x.profit) jobs.reverse() maxDeadline = max(map(lambda x: x.deadline, jobs)) arr = [(True) for _ in range(maxDeadline)] count, profit = 0, 0 for job in jobs: for i in range(job.deadline - 1, -1, -1): if arr[i]: arr[i] = False count += 1 profit += job.profit break return [count, profit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): max_deadline = 0 Jobs.sort(key=lambda x: x.profit, reverse=True) for i in Jobs: max_deadline = max(max_deadline, i.deadline) possible_deadlines = [0] * max_deadline count = 0 for i in Jobs: if possible_deadlines[i.deadline - 1] == 0: possible_deadlines[i.deadline - 1] = i.profit else: for j in range(i.deadline - 1, -1, -1): if possible_deadlines[j] == 0: possible_deadlines[j] = i.profit break x = 0 for i in possible_deadlines: if i != 0: x += 1 return [x, sum(possible_deadlines)]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER RETURN LIST VAR FUNC_CALL VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxjobs = 0 for job in Jobs: if maxjobs < job.deadline: maxjobs = job.deadline arrans = [-1] * (maxjobs + 1) for job in Jobs: i = job.deadline while i > 0: if arrans[i] == -1: arrans[i] = job.profit break i = i - 1 ans = 0 c = 0 for a in arrans: if a != -1: c = c + 1 ans = ans + a return [c, ans]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): max_profit, n_jobs = 0, 0 Jobs.sort(reverse=True, key=lambda x: x.profit) max_deadline = 0 for i in Jobs: if i.deadline > max_deadline: max_deadline = i.deadline freq_arr = [-1] * (max_deadline + 1) for i in Jobs: for j in range(i.deadline, 0, -1): if freq_arr[j] == -1: freq_arr[j] = i.id n_jobs += 1 max_profit += i.profit break return [n_jobs, max_profit]
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): job_count = 0 profit = 0 Jobs.sort(key=lambda x: x.profit, reverse=True) max_time = max(Jobs, key=lambda x: x.deadline).deadline profit_list = [0] * max_time for job in Jobs: if job.deadline <= max_time: for j in range(job.deadline - 1, -1, -1): if profit_list[j] == 0: profit_list[j] = 1 profit = profit + job.profit job_count += 1 break return [job_count, profit]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): arr = [0] * n Jobs.sort(key=lambda x: x.profit, reverse=True) max_profit = 0 count = 0 for i in range(n): for j in range(Jobs[i].deadline - 1, -1, -1): if not arr[j]: arr[j] = True max_profit += Jobs[i].profit count += 1 break return [count, max_profit]
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): jobs = sorted(Jobs, key=lambda job: job.profit, reverse=True) number = 0 profit = 0 time = [None] * n for i in jobs: for j in range(i.deadline, 0, -1): if time[j - 1] == None: time[j - 1] = i.profit number += 1 profit += i.profit break return [number, profit]
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER NONE ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxDeadline = -1 for i in Jobs: if i.deadline > maxDeadline: maxDeadline = i.deadline result = [(-1) for i in range(maxDeadline + 1)] jobcount = 0 maxprofit = 0 for i in range(n): for j in range(Jobs[i].deadline, 0, -1): if result[j] == -1: result[j] = i jobcount += 1 maxprofit += Jobs[i].profit break return [jobcount, maxprofit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: -1 * x.profit) mxl = 10**5 occupied = [False] * (mxl + 1) ans = 0 count = 0 for i in range(n): jobs = Jobs[i] id = jobs.id p = jobs.profit dd = jobs.deadline for time in range(dd - 1, -1, -1): if occupied[time]: continue occupied[time] = True ans += p count += 1 break return count, ans
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: -x.profit) maxi = 0 for i in range(n): maxi = max(Jobs[i].profit, maxi) slots = [-1] * maxi p = 0 c = 0 for i in range(n): dead = Jobs[i].deadline - 1 for j in range(dead, -1, -1): if slots[j] == -1: slots[j] = Jobs[i].id p += Jobs[i].profit c += 1 break return [c, p]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Job = [[a.id, a.deadline, a.profit] for a in Jobs] Job.sort(key=lambda x: x[2], reverse=True) slots = [(False) for i in range(n)] tm = 0 prof = 0 for i in range(n): jb = Job[i] for j in range(jb[1] - 1, -1, -1): if slots[j] == False: slots[j] = True prof += jb[2] tm += 1 break return tm, prof
CLASS_DEF FUNC_DEF ASSIGN VAR LIST VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) time = [0] * max(Jobs, key=lambda x: x.deadline).deadline for job in Jobs: if time[job.deadline - 1] == 0: time[job.deadline - 1] = job.id, job.profit else: for i in reversed(range(job.deadline)): if time[i] == 0: time[i] = job.id, job.profit break max_profit = sum(i[1] for i in time if isinstance(i, tuple)) total_num = sum(1 for i in time if isinstance(i, tuple)) return [total_num, max_profit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) m = 0 for x in Jobs: if x.deadline > m: m = x.deadline r = [-1] * (m + 1) a = [0, 0] for i in Jobs: for j in range(i.deadline, 0, -1): if r[j] == -1: a[0] += 1 a[1] += i.profit r[j] = 1 break return a
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER RETURN VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): if not Jobs or Jobs == None or Jobs == {}: return [] maxi = 0 for i in Jobs: maxi = max(maxi, i.deadline) out = 0 cj = 0 Jobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) seq = [-1] * (maxi + 1) for i in Jobs: k = i.deadline - 1 while seq[k] != -1: k -= 1 if k >= 0: seq[k] = i.id cj += 1 out += i.profit return [cj, out]
CLASS_DEF FUNC_DEF IF VAR VAR NONE VAR DICT RETURN LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): jobs.sort(key=lambda x: x.profit, reverse=True) profit, totalJ = 0, 0 visited = [-1] * (n + 1) for i in range(n): for j in range(jobs[i].deadline, 0, -1): if visited[j] == -1: profit += jobs[i].profit totalJ += 1 visited[j] = jobs[i].id break return totalJ, profit
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxiDeadline = 0 for i in range(n): if Jobs[i].deadline > maxiDeadline: maxiDeadline = Jobs[i].deadline slot = [-1] * (maxiDeadline + 1) countJobs = 0 maxProfit = 0 for i in range(n): for j in reversed(range(1, Jobs[i].deadline + 1)): if slot[j] == -1: slot[j] = i countJobs += 1 maxProfit += Jobs[i].profit break return [countJobs, maxProfit]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): profits = [] length = 0 for i in range(n): length = max(length, Jobs[i].deadline) profits.append([Jobs[i].deadline, Jobs[i].profit]) profits.sort(key=lambda x: x[1], reverse=True) check = [0] * (length + 1) profit = counter = 0 for j in range(n): ind = profits[j][0] while ind > 0 and check[ind]: ind -= 1 if ind == 0: continue check[ind] = 1 counter += 1 profit += profits[j][1] if counter == length: break return [counter, profit]
CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): res, count = 0, 0 Jobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) result = [(0) for i in range(n)] slot = [(False) for i in range(n)] for i in range(n): for j in range(min(n, Jobs[i].deadline) - 1, -1, -1): if not slot[j]: result[j] = i slot[j] = True break for i in range(n): if slot[i]: res += Jobs[result[i]].profit count += 1 ans = [] ans.append(count) ans.append(res) return ans
CLASS_DEF FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(reverse=True, key=lambda x: x.profit) vac = [0] * n for job in Jobs: h = job.deadline - 1 l = 0 res = -1 for i in range(h, -1, -1): if not vac[i]: res = i break if res != -1: vac[res] = job.profit tot = 0 c = 0 for ele in vac: if ele: c += 1 tot += ele return [c, tot]
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR NUMBER VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): lookup = set() jobs.sort(key=lambda x: x.profit, reverse=True) mdl = jobs[0].deadline for jb in jobs: mdl = max(mdl, jb.deadline) is_worked = [False] * mdl count = 0 profit = 0 for jb in jobs: for j in range(jb.deadline - 1, -1, -1): if not is_worked[j]: profit += jb.profit count += 1 is_worked[j] = True break return count, profit
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): sr = sorted(Jobs, key=lambda job: job.profit, reverse=True) co = 0 pr = 0 st = set() for i in range(n): if sr[i].deadline not in st: pr += sr[i].profit co += 1 st.add(sr[i].deadline) else: t = self.findmin(st, sr[i].deadline) if t > 0: pr += sr[i].profit co += 1 st.add(t) return [co, pr] def findmin(self, st, dl): for i in range(dl, 0, -1): if i not in st: return i return 0
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN LIST VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR RETURN VAR RETURN NUMBER
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
import sys def func(x): return x.deadline sys.setrecursionlimit(10**6) class Solution: def helper(self, A, i, c): key = i, c if self.d.get(key) is not None: return self.d[key] if i == len(A): return 0, 0 if c < A[i].deadline: n1, c1 = self.helper(A, i + 1, c + 1) n2, c2 = self.helper(A, i + 1, c) if A[i].profit + c1 > c2: self.d[key] = n1 + 1, A[i].profit + c1 else: self.d[key] = n2, c2 else: self.d[key] = self.helper(A, i + 1, c) return self.d[key] def JobScheduling(self, A, n): visited = set() A.sort(key=lambda x: x.profit) profit = 0 for i in range(n - 1, -1, -1): time = A[i].deadline while time > 0 and time in visited: time -= 1 if time > 0: profit += A[i].profit visited.add(time) return len(visited), profit
IMPORT FUNC_DEF RETURN VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR IF FUNC_CALL VAR VAR NONE RETURN VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): jobday = [-1] * max(Jobs, key=lambda x: x.deadline).deadline profit = 0 count = 0 Jobs.sort(key=lambda x: [-x.profit]) for x in Jobs: id, dl, pr = x.id, x.deadline, x.profit j = dl - 1 while 0 <= j and jobday[j] != -1: j -= 1 if j == -1: continue jobday[j] = id profit += pr count += 1 if count == len(jobday): break return count, profit
CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): def sortProfit(x): return x.profit profit = 0 numberOfJobs = 0 slot = [-1] * (n + 1) slot[0] = 1 arr = list(Jobs) def checkSlot(d): for i in range(d, -1, -1): if slot[i] == -1: return i return -1 arr.sort(key=sortProfit, reverse=True) for i in range(n): s = checkSlot(arr[i].deadline) if s > -1: slot[s] = 1 numberOfJobs += 1 profit += arr[i].profit return [numberOfJobs, profit]
CLASS_DEF FUNC_DEF FUNC_DEF RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER RETURN VAR RETURN NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR VAR RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs.sort(key=lambda x: x.profit, reverse=True) maxDead = max(job.deadline for job in Jobs) slots = [(-1) for i in range(maxDead)] maxProf = 0 count = 0 for i in range(n): for j in range(Jobs[i].deadline - 1, -1, -1): if slots[j] == -1: slots[j] = Jobs[i].id count += 1 maxProf += Jobs[i].profit break return count, maxProf
CLASS_DEF FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR VAR RETURN VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): Jobs = sorted(Jobs, key=lambda x: x.profit, reverse=True) dead = -1 for i in range(n): if Jobs[i].deadline > dead: dead = Jobs[i].deadline ans = [-1] * dead maxp = 0 count = 0 for i in range(0, n): d = Jobs[i].deadline for j in range(d - 1, -1, -1): if ans[j] == -1: ans[j] = Jobs[i].id count = count + 1 maxp = maxp + Jobs[i].profit break l = [count, maxp] return l
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR VAR RETURN VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, Jobs, n): maxi = 0 arr = [] for i in range(n): maxi = max(maxi, Jobs[i].deadline) result = [(-1) for i in range(maxi)] total = 0 jobs_done = 0 for i in range(n): arr.append([Jobs[i].profit, Jobs[i].deadline]) arr.sort(reverse=True) for i in range(n): for j in range(arr[i][1] - 1, -1, -1): if result[j] == -1: result[j] = i jobs_done += 1 total += arr[i][0] break return [jobs_done, total]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER RETURN LIST VAR VAR
Given a set of N jobs where each job_{i} has a deadline and profit associated with it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit associated with job if and only if the job is completed by its deadline. Find the number of jobs done and the maximum profit. Note: Jobs will be given in the form (Job_{id}, Deadline, Profit) associated with that Job. Example 1: Input: N = 4 Jobs = {(1,4,20),(2,1,10),(3,1,40),(4,1,30)} Output: 2 60 Explanation: Job_{1} and Job_{3 }can be done with maximum profit of 60 (20+40). Example 2: Input: N = 5 Jobs = {(1,2,100),(2,1,19),(3,2,27), (4,1,25),(5,1,15)} Output: 2 127 Explanation: 2 jobs can be done with maximum profit of 127 (100+27). Your Task : You don't need to read input or print anything. Your task is to complete the function JobScheduling() which takes an integer N and an array of Jobs(Job id, Deadline, Profit) as input and returns the count of jobs and maximum profit as a list or vector of 2 elements. Expected Time Complexity: O(NlogN) Expected Auxilliary Space: O(N) Constraints: 1 <= N <= 10^{5} 1 <= Deadline <= N 1 <= Profit <= 500
class Solution: def JobScheduling(self, jobs, n): ma = 0 res = [] for i in range(0, len(jobs)): k = [jobs[i].deadline, jobs[i].profit] res.append(k) if jobs[i].deadline > ma: ma = jobs[i].deadline res.sort(key=lambda x: x[1], reverse=True) a = [(0) for z in range(0, ma)] p = 0 c = 0 for i in range(0, len(res)): for j in range(res[i][0] - 1, -1, -1): if a[j] == 0: a[j] = 1 p += res[i][1] c += 1 break return [c, p]
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN LIST VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
MOD, N = 10**9 + 7, 2 * 1001 * 1001 dp = [0] * N for i in range(3, N): dp[i] = (2 * dp[i - 2] + dp[i - 1] + 4 * (i % 3 == 0)) % MOD for _ in range(int(input())): print(dp[int(input())])
ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
from sys import stdin input = stdin.readline mod = 10**9 + 7 dp = [0, 0, 0, 4, 4, 12] for x in range(6, 2000001): if x % 6 == 3 or x % 6 == 5: dp.append((dp[-1] * 2 + 4) % mod) elif x % 6 == 4: dp.append((dp[-1] * 2 - 4) % mod) else: dp.append(dp[-1] * 2 % mod) for _ in range(int(input())): print(dp[int(input())])
ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**19 MOD = 10**9 + 7 def mat_pow(mat, init, K, MOD): def mat_dot(A, B, MOD): if not isinstance(A[0], list) and not isinstance(A[0], tuple): A = [A] if not isinstance(B[0], list) and not isinstance(A[0], tuple): B = [[b] for b in B] n1 = len(A) n2 = len(A[0]) _ = len(B) m2 = len(B[0]) res = list2d(n1, m2, 0) for i in range(n1): for j in range(m2): for k in range(n2): res[i][j] += A[i][k] * B[k][j] res[i][j] %= MOD return res def _mat_pow(mat, k, MOD): n = len(mat) res = list2d(n, n, 0) for i in range(n): res[i][i] = 1 while k > 0: if k & 1: res = mat_dot(res, mat, MOD) mat = mat_dot(mat, mat, MOD) k >>= 1 return res res = _mat_pow(mat, K, MOD) res = mat_dot(res, init, MOD) return [a[0] for a in res] for _ in range(INT()): N = INT() mat = [[5, 6, 0, 4], [3, 2, 0, 0], [1, 2, 0, 0], [0, 0, 0, 1]] init = [4, 0, 0, 1] if N % 3 == 0: res = mat_pow(mat, init, N // 3 - 1, MOD) ans = res[0] print(ans) else: res = mat_pow(mat, init, N // 3, MOD) ans = res[3 - N % 3] print(ans)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST VAR IF FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
l = [0, 0, 0] mod = int(1000000000.0) + 7 for i in range(3, 2000005): l.append((l[i - 1] + l[i - 2] * 2 + (4 if i % 3 == 0 else 0)) % mod) t = int(input()) for _ in range(t): n = int(input()) print(l[n])
ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
def gns(): return list(map(int, input().split())) t = int(input()) ns = [] ans = [0, 0, 0, 4, 4, 12] for _ in range(t): n = int(input()) ns.append(n) mx = max(ns) md = 10**9 + 7 for i in range(6, mx + 6): ans.append((ans[-2] * 2 + ans[-1] + (4 if i % 3 == 0 else 0)) % md) for ni in ns: print(ans[ni])
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
inp = lambda: int(input()) inpm = lambda: map(int, input().split()) inpl = lambda: list(inpm()) l2mn = lambda _n, _m: [[(0) for __ in range(_m)] for _ in range(_n)] l2n = lambda _n: l2mn(_n, _n) INF = int(1e18) MOD = int(1000000000.0) + 7 N = 2000009 dp = [0] * N for i in range(3, N): dp[i] = (dp[i - 2] * 2 + dp[i - 1] + (1 if i % 3 == 0 else 0)) % MOD def solve(): n = inp() print(dp[n] * 4 % MOD) def main(): t = inp() for i in range(t): solve() main()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
pe = [(0) for i in range(2000001)] for i in range(3, 2000001): if i % 3 == 0: pe[i] = (pe[i - 1] + pe[i - 2] * 2 + 1) % 1000000007 else: pe[i] = (pe[i - 1] + pe[i - 2] * 2) % 1000000007 for _ in range(int(input())): n = int(input()) print(pe[n] * 4 % 1000000007)
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
d = [(0) for _ in range(2000001)] d[3] = 4 for i in range(4, 2000001): if i % 3 == 0: d[i] = (2 * d[i - 2] + d[i - 1] + 4) % 1000000007 else: d[i] = (2 * d[i - 2] + d[i - 1]) % 1000000007 n = int(input()) while n > 0: x = int(input()) print(d[x]) n -= 1
ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
f = [0, 0, 0, 4, 4] for i in range(5, 2000001): f.append((2 * f[-2] + f[-1] + (4 if i % 3 == 0 else 0)) % 1000000007) for tt in range(int(input())): print(f[int(input())])
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
p = [0, 0, 4] n = 1000000007 for i in range(4, 2 * 1000000 + 1): p.append((p[-1] + 2 * p[-2] + (i % 3 == 0) * 4) % n) for i in range(int(input())): n = int(input()) print(p[n - 1])
ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
dp = [0, 0, 0, 4, 4, 12] for n in range(2000000 // 6): dp.append(dp[-1] * 2 % (10**9 + 7)) dp.append(dp[-1] * 2 % (10**9 + 7)) dp.append(dp[-1] * 2 % (10**9 + 7)) dp.append((dp[-1] * 2 + 4) % (10**9 + 7)) dp.append((dp[-1] * 2 - 4) % (10**9 + 7)) dp.append((dp[-1] * 2 + 4) % (10**9 + 7)) T = int(input()) for i in range(T): n = int(input()) print(dp[n] % (10**9 + 7))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
mod = 1000000007 MAX = 2000000 arr = [int(-1)] * (MAX + 1) arr[0] = 0 arr[1] = 0 arr[2] = 0 arr[3] = 4 arr[4] = 4 for i in range(5, MAX + 1): arr[i] = (arr[i - 1] + 2 * arr[i - 2] + 4 * (i % 3 == 0)) % mod t = int(input()) while t > 0: n = int(input()) print(arr[n]) t -= 1
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
import sys input = sys.stdin.readline mod = 10**9 + 7 ANS = [0, 0, 0, 4, 4] HEAD = [0, 0, 0, 1, 0] for i in range(2 * 10**6): if HEAD[-1] == 0 and HEAD[-2] == 0: ANS.append((ANS[-1] + ANS[-2] * 2 + 4) % mod) HEAD.append(1) else: ANS.append((ANS[-1] + ANS[-2] * 2) % mod) HEAD.append(0) t = int(input()) for tests in range(t): n = int(input()) print(ANS[n])
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
limit = 10**9 + 7 k = 2000001 A = [0] * k A[3] = 4 for i in range(4, 2000001): save = A[i - 1] + 2 * A[i - 2] if i % 3 == 0: save += 4 A[i] = save % limit for t in range(int(input())): n = int(input()) print(A[n])
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
from sys import maxsize, stdin, stdout def solve(): pass val = 10**9 + 7 dp = [0, 0, 0, 4] for n in range(4, 2 * 10**6 + 1): if n % 3 == 0: dp.append((dp[n - 1] + 2 * dp[n - 2] + 4) % val) else: dp.append((dp[n - 1] + 2 * dp[n - 2]) % val) test = 1 test = int(input()) for t in range(0, test): n = int(input()) print(dp[n]) ans = solve()
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
m = 1000000007 k = 2000001 x = [0] * k x[3] = 4 c = 3 for t in range(int(input())): n = int(input()) if n <= c: print(x[n]) else: for i in range(c + 1, n + 1): a = x[i - 1] + 2 * x[i - 2] if i % 3 == 0: a += 4 x[i] = a % m c = n print(x[n])
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
a = [0, 0, 1, 1] m = 10**9 + 7 for i in range(5, 2000001): x = a[i - 2] + 2 * a[i - 3] if i % 3 == 0: a.append((x + 1) % m) else: a.append(x % m) for _ in range(int(input())): n = int(input()) print(a[n - 1] * 4 % m)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
t = int(input()) dp = [(0) for i in range(2 * 10**6 + 1)] dp[0] = 0 dp[1] = 0 dp[2] = 0 dp[3] = 4 for i in range(4, 2 * 10**6 + 1): if i % 3 == 0: dp[i] = (dp[i - 2] * 2 + dp[i - 1] + 4) % (10**9 + 7) else: dp[i] = (dp[i - 2] * 2 + dp[i - 1]) % (10**9 + 7) for _ in range(t): n = int(input()) print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
t = int(input()) maxn = int(1000000.0 * 2 + 7) mod = int(1000000000.0 + 7) dp = list(bytearray(maxn)) for i in range(3, maxn): add4 = 4 if i % 3 == 0 else 0 dp[i] = (dp[i - 2] * 2 + dp[i - 1]) % mod + add4 for _ in range(t): n = int(input()) print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): md = 10**9 + 7 mx = 2000005 dp = [0] * mx dp[3] = dp[4] = 4 for i in range(5, mx): if i % 3 == 0: dp[i] = (dp[i - 2] * 2 + dp[i - 1] + 4) % md else: dp[i] = (dp[i - 2] * 2 + dp[i - 1]) % md for _ in range(II()): n = II() print(dp[n]) main()
IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
t = int(input()) dp = [] dp.append(0) dp.append(0) dp.append(0) dp.append(4) dp.append(4) mod = 10**9 + 7 for i in range(5, 2000001, 1): a = dp[i - 1] + 2 * dp[i - 2] if i % 3 == 0: a += 4 a %= mod dp.append(a) for i in range(t): n = int(input()) print(dp[n])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
import sys pprint = lambda s: print(" ".join(map(str, s))) input = lambda: sys.stdin.readline().strip() ipnut = input n = 2000000 dp = [0] * n mod = 1000000007 for i in range(2, n): dp[i] = (dp[i - 1] + 2 * dp[i - 2] + int(i % 3 == 2)) % mod for i in range(int(input())): print(dp[int(input()) - 1] * 4 % mod)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
k = 2000005 l = [0] * k l[1] = 0 l[2] = 0 l[3] = 4 l[4] = 4 def ans(): mod = 1000000000.0 + 7 for i in range(5, k): if i % 3 == 0: ans = l[i - 1] + 2 * l[i - 2] + 4 else: ans = l[i - 1] + 2 * l[i - 2] ans = ans % mod l[i] = int(ans) ans() for _ in range(int(input())): n = int(input()) print(l[n])
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
def preprocess(pref): mod = int(1000000000.0) + 7 for i in range(3, 2000005): pref.append((pref[i - 1] + pref[i - 2] * 2 + (4 if i % 3 == 0 else 0)) % mod) def main(): pref = [0, 0, 0] preprocess(pref) for _ in range(int(input())): print(pref[int(input())]) main()
FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
mod = 10**9 + 7 ans = [0, 0, 4, 4] t = int(input()) for i in range(5, 2000010): temp = ans[i - 2] + 2 * ans[i - 3] if i % 3 == 0: temp += 4 ans.append(temp % mod) for _ in range(t): n = int(input()) print(ans[n - 1])
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
mod = 1000000007 dp = [0, 0, 0, 1, 1] for i in range(5, 2000001): if i % 3 == 0: dp.append((dp[i - 1] + 2 * dp[i - 2] + 1) % mod) else: dp.append((dp[i - 1] + 2 * dp[i - 2]) % mod) t = int(input()) for i in range(t): n = int(input()) print(4 * dp[n] % mod)
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
solution = [0, 0, 0, 4, 4] def store(n): prev1, prev2, sol = 1, 1, 0 for i in range(5, n + 1): sol = 2 * prev2 + prev1 if i % 3 == 0: sol += 1 sol = sol % 1000000007 prev2, prev1 = prev1, sol solution.append(sol * 4 % 1000000007) t = int(input()) store(2000000) while t > 0: print(solution[int(input())]) t -= 1
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
max_s = 2000003 c = 1000000007 q = [0] * max_s for i in range(3, max_s): if not i % 3: q[i] = (q[i - 1] + 2 * q[i - 2] + 1) % c else: q[i] = (q[i - 1] + 2 * q[i - 2]) % c for _ in range(int(input())): print(q[int(input())] * 4 % c)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
mod = 1000000007 dp = [(0, 0), (0, 0)] for i in range(2, 2000001): dp.append( ((max(dp[-1]) + 2 * max(dp[-2])) % mod, (dp[-1][0] + 2 * dp[-2][0] + 1) % mod) ) for o in range(int(input())): print(max(dp[int(input()) - 1]) * 4 % mod)
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level $n$ as a rooted tree constructed as described below. A rooted dead bush of level $1$ is a single vertex. To construct an RDB of level $i$ we, at first, construct an RDB of level $i-1$, then for each vertex $u$: if $u$ has no children then we will add a single child to it; if $u$ has one child then we will add two children to it; if $u$ has more than one child, then we will skip it. [Image] Rooted Dead Bushes of level $1$, $2$ and $3$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw: [Image] The center of the claw is the vertex with label $1$. Lee has a Rooted Dead Bush of level $n$. Initially, all vertices of his RDB are green. In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow. He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $10^9+7$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ lines contain test cases — one per line. The first line of each test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^6$) — the level of Lee's RDB. -----Output----- For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $10^9 + 7$. -----Example----- Input 7 1 2 3 4 5 100 2000000 Output 0 0 4 4 12 990998587 804665184 -----Note----- It's easy to see that the answer for RDB of level $1$ or $2$ is $0$. The answer for RDB of level $3$ is $4$ since there is only one claw we can choose: $\{1, 2, 3, 4\}$. The answer for RDB of level $4$ is $4$ since we can choose either single claw $\{1, 3, 2, 4\}$ or single claw $\{2, 7, 5, 6\}$. There are no other claws in the RDB of level $4$ (for example, we can't choose $\{2, 1, 7, 6\}$, since $1$ is not a child of center vertex $2$). $\therefore$ Rooted Dead Bush of level 4.
def draw(n): MOD = 10**9 + 7 INV = 47619048 ADD = [6, -30, -18] def fpow(x, n): r = 1 while n > 1: if n & 1: r = r * x % MOD x = x * x % MOD n >>= 1 return x * r % MOD return (fpow(2, n + 3) + 14 * (2 * (n & 1) - 1) + ADD[n % 3]) * INV % MOD t = int(input()) for i in range(t): n = int(input()) print(draw(n))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
from sys import gettrace, stdin if not gettrace(): def input(): return next(stdin)[:-1] def main(): n = int(input()) aa = [int(a) for a in input().split()] rem = 0 black = 0 white = 0 for i, a in enumerate(aa): black += a // 2 white += a // 2 if a % 2 == 1: if i % 2 == 0: black += 1 else: white += 1 print(min(black, white)) main()
IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n = int(input()) l = [int(i) for i in input().split(" ")] tot = sum(i // 2 for i in l) stack = [] for i in range(n): l[i] &= 1 if not stack or stack[-1] != l[i]: stack.append(l[i]) else: tot += stack.pop() print(tot)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n = int(input()) arr = list(map(int, input().split())) ans_1 = 0 ans_2 = 0 for i in range(n): if i % 2 == 1: ans_1 += int(arr[i] / 2) + arr[i] % 2 ans_2 += int(arr[i] / 2) else: ans_1 += int(arr[i] / 2) ans_2 += int(arr[i] / 2) + arr[i] % 2 print(min(ans_1, ans_2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n = int(input()) a = list(map(int, input().split())) sol = 0 w = 0 b = 0 for i, ai in enumerate(a): w += ai // 2 b += ai // 2 if ai % 2: if i % 2: w += 1 else: b += 1 sol = min(w, b) print(sol)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n, m = 0, 0 l = int(input()) a = input().split() for i in range(l): a[i] = int(a[i]) for i in range(l): m += a[i] if i % 2 == 0: n += a[i] // 2 else: n += a[i] - a[i] // 2 m -= n print(min(n, m))
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n = int(input()) a = list(map(int, input().split())) black, white = 0, 0 for i in range(n): black += a[i] // 2 white += a[i] // 2 if i % 2: black += a[i] % 2 else: white += a[i] % 2 if white == black: print(white) else: print(min(black, white))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
import sys n = int(input()) a = list(map(int, input().split(" "))) parity = 0 even, odd = 0, 0 for x in a: even += x // 2 odd += x // 2 if x % 2 == 1: if parity == 0: even += 1 else: odd += 1 parity = 1 - parity print(min(even, odd))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a Young diagram. Given diagram is a histogram with n columns of lengths a_1, a_2, …, a_n (a_1 ≥ a_2 ≥ … ≥ a_n ≥ 1). <image> Young diagram for a=[3,2,2,2,1]. Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1 × 2 or 2 × 1 rectangle. Input The first line of input contain one integer n (1 ≤ n ≤ 300 000): the number of columns in the given histogram. The next line of input contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 300 000, a_i ≥ a_{i+1}): the lengths of columns. Output Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram. Example Input 5 3 2 2 2 1 Output 4 Note Some of the possible solutions for the example: <image> <image>
n = int(input()) a = list(map(int, input().split())) k = 1 white = 0 black = 0 for i in a: black += i // 2 + k * (i % 2) white += i // 2 + (1 - k) * (i % 2) k = 1 - k print(min(black, white))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR