description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
t = int(input()) for i in range(t): l, r = map(int, input().strip().split(" ")) def calculate(n): n = str(n) res = 0 for i in range(len(n) - 1): res += int(n[i] * (len(n) - i - 1)) res += int(n) return res print(calculate(r) - calculate(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def num_change(n): sum_ = 0 while n != 0: sum_ = sum_ + n n = int(n / 10) return sum_ T = int(input()) while T != 0: a, b = map(int, input().split()) print(num_change(b) - num_change(a)) T -= 1
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def _i(): return int(input()) def _f(): return float(input()) def _iln(): ln = input().split(" ") return [int(i) for i in ln] def _ln(): return input().split(" ") def upto(n): k = n dp = [] while n: dp.append(n % 10) n = (n - dp[-1]) // 10 n = k for i in range(len(dp) - 2, -1, -1): dp[i] += sum(dp[i + 1 :]) * 9 return sum((i + 1) * dp[i] for i in range(len(dp))) def solve(tt): l, r = _iln() print(upto(r) - upto(l)) t = _i() for i in range(1, t + 1): solve(i)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
for _ in range(int(input())): l, r = map(int, input().split()) nl = len(str(l)) rl = len(str(r)) ansl = l % 10 + 11 * (l // 10) ansr = r % 10 + 11 * (r // 10) for i in range(2, nl): temp = 10**i ansl += l // temp for i in range(2, rl): temp = 10**i ansr += r // temp print(ansr - ansl)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
import sys input = sys.stdin.readline t = int(input()) c = [1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111] for _ in range(t): l, r = map(int, input().split()) aa = 0 a = len(str(r)) r = str(r) for i in range(a): aa += int(r[i]) * c[a - i - 1] bb = 0 b = len(str(l)) l = str(l) for i in range(b): bb += int(l[i]) * c[b - i - 1] print(aa - bb)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
for _ in range(int(input())): l, r = map(int, input().split()) arr = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000] ans = 0 for i in arr: ans += r // i - l // i print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
import sys input = sys.stdin.readline T = int(input()) for i in range(T): n, m = map(int, input().split()) s = 0 while m: s += m m = m // 10 while n: s -= n n = n // 10 print(s)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def f(n): if n < 10: return n else: return n + f(n // 10) n = int(input()) for test in range(n): l, r = map(int, input().split()) print(f(r) - f(l))
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
for ii in range(int(input())): l, r = map(int, input().split()) cr = 0 while r != 0: cr += r r //= 10 cl = 0 while l != 0: cl += l l //= 10 print(cr - cl)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
T = int(input()) for _ in range(T): a, b = input().split() n = len(b) a = a.zfill(n) i = 0 while i < n and a[i] == b[i]: i += 1 if i == n: print(0) continue cost = 0 i = n - 1 delta = 1 carry = 0 while i > 0: if carry or a[i] != "0": cost += delta * (10 - int(a[i]) - carry) + 1 carry = 1 delta = delta * 10 + 1 i -= 1 cost += delta * (int(b[0]) - int(a[0]) - carry) delta //= 10 for i in range(1, n): cost += delta * int(b[i]) delta //= 10 print(cost)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR STRING VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
t = int(input()) for i in range(t): l, r = input().split() bigger = len(r) m = "0" * (bigger - len(l)) + l total = int(r) - int(l) for j in range(bigger - 1): total = total + int(r[: -1 - j]) - int(m[: -1 - j]) print(total)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
import sys pl = 2 sys.setrecursionlimit(10**5) if pl: input = sys.stdin.readline else: sys.stdin = open("input.txt", "r") sys.stdout = open("outpt.txt", "w") def li(): return [int(xxx) for xxx in input().split()] def fi(): return int(input()) def si(): return list(input().rstrip()) def mi(): return map(int, input().split()) def ff(): sys.stdout.flush() t = fi() def f(a): ans = a c = "" for i in range(11): c += "9" if int(c) >= a: break l = 0 r = 10**10 res = 0 while l <= r: mid = (l + r) // 2 if mid * 10 ** len(c) + int(c) < a: res = mid + 1 l = mid + 1 else: r = mid - 1 ans += res return ans while t > 0: t -= 1 a, b = mi() print(f(b) - f(a))
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR STRING IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def solve(n): temp = 1 ans = 0 for i in range(0, 12): ans += n // temp temp *= 10 return ans t = int(input()) l, r = 1, 1000000 for _ in range(t): n1, n2 = map(int, input().split()) n1, n2 = n2, n1 n1, n2 = n2, n1 print(solve(n2) - solve(n1))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
for _ in range(int(input())): l, r = input().split() l = "0" * (len(r) - len(l)) + l out = 0 for i in range(len(r)): out += int(r[: len(r) - i]) - int(l[: len(r) - i]) print(out)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def func(n): ans = 0 while n != 0: ans += n n = n // 10 return ans t = int(input()) for _ in range(t): l, r = [int(i) for i in input().strip().split()] print(func(r) - func(l))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def noc(x, y, d): n = y - x + 1 n += x % d if (y + 1) % d != 0: n += d - (y + 1) % d return int(n / d) - 1 for tc in range(int(input())): x, y = map(int, input().split()) ans = 0 i = 0 while True: temp = noc(x, y, 10**i) ans += temp i += 1 if temp == 0 or i > 100: break print(ans)
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
for _ in range(int(input())): l, r = list(map(int, input().split())) cnt = 0 for i in range(11): cnt += r // pow(10, i) cnt2 = 0 for i in range(11): cnt2 += l // pow(10, i) print(cnt - cnt2)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
k = int(input()) for x in range(k): ans = 0 x = str(input()) x = x.split() r = int(x[1]) l = int(x[0]) while r != 0 or l != 0: ans += r - l l = l // 10 r = r // 10 k += 1 if k == 1: print() print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
t = int(input()) def get(idk): ans = 0 temp = idk while temp: ans += temp temp //= 10 return ans for _ in range(t): l, r = map(int, input().split()) print(get(r) - get(l))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
t = int(input()) for w in range(t): inp = input().split() left = int(inp[0]) right = int(inp[1]) ans = 0 while left > 0 or right > 0: ans += right - left left = left // 10 right = right // 10 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
q = int(input()) for _ in range(q): n, m = map(int, input().split()) first = 0 second = 0 for i in range(10): first += n // 10**i second += m // 10**i print(second - first)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
t = int(input()) for i in range(t): x = input() l = int(x.split()[0]) r = int(x.split()[1]) if r // 10 == 0 and l // 10 == 0: print(r - l) continue k = r while k // 10 >= 1: r += k // 10 k = k // 10 k = l while k // 10 >= 1: l += k // 10 k = k // 10 print(r - l) continue
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def f(x): r = 0 while x: r += x x //= 10 return r for s in [*open(0)][1:]: l, r = map(int, s.split()) print(f(r) - f(l))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
ll = [0, 1, 11, 111, 1111, 11111, 111111, 1111111, 11111111, 111111111, 1111111111] for _ in range(int(input())): l, r = map(int, input().split()) x = str(l) y = str(r) if len(x) == 1: ans1 = l else: b = len(x) ans1 = 0 c = b for i in x: ans1 += int(i) * ll[c] c -= 1 if len(y) == 1: ans2 = r else: b = len(y) ans2 = 0 c = b for i in y: ans2 += int(i) * ll[c] c -= 1 print(ans2 - ans1)
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def f(x): return sum([(x // pow(10, i)) for i in range(11)]) for _ in range(int(input())): l, r = map(int, input().split()) print(f(r) - f(l))
FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given two integers $l$ and $r$, where $l < r$. We will add $1$ to $l$ until the result is equal to $r$. Thus, there will be exactly $r-l$ additions performed. For each such addition, let's look at the number of digits that will be changed after it. For example: if $l=909$, then adding one will result in $910$ and $2$ digits will be changed; if you add one to $l=9$, the result will be $10$ and $2$ digits will also be changed; if you add one to $l=489999$, the result will be $490000$ and $5$ digits will be changed. Changed digits always form a suffix of the result written in the decimal system. Output the total number of changed digits, if you want to get $r$ from $l$, adding $1$ each time. -----Input----- The first line contains an integer $t$ ($1 \le t \le 10^4$). Then $t$ test cases follow. Each test case is characterized by two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, calculate the total number of changed digits if you want to get $r$ from $l$, adding one each time. -----Examples----- Input 4 1 9 9 10 10 20 1 1000000000 Output 8 2 11 1111111110 -----Note----- None
def solve(l, r): ans = 0 while l != 0 or r != 0: ans += r - l l //= 10 r //= 10 return ans for _ in range(int(input())): l, r = map(int, input().split()) print(solve(l, r))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys firstline = sys.stdin.readline().split() n = int(firstline[0]) w = int(firstline[1]) h = int(firstline[2]) envelopes = [(w, h)] locations = {(w, h): 0} for i in range(n): e = tuple(map(int, sys.stdin.readline().split())) if e[0] > w and e[1] > h: locations[e] = i + 1 envelopes.append(e) envelopes.sort() dp_lengths = [0] * len(envelopes) dp_nexts = [None] * len(envelopes) for i in reversed(range(len(envelopes))): for j in range(i + 1, len(envelopes)): if envelopes[j][0] > envelopes[i][0] and envelopes[j][1] > envelopes[i][1]: if dp_lengths[j] + 1 >= dp_lengths[i]: dp_lengths[i] = dp_lengths[j] + 1 dp_nexts[i] = j print(dp_lengths[0]) current = dp_nexts[0] while current: print(locations[envelopes[current]], end=" ") current = dp_nexts[current]
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR DICT VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys class Envelope: def __init__(self, w=0, h=0, e_id=0, pre=0, num=0): self.w = w self.h = h self.e_id = e_id self.pre = pre self.num = num def __str__(self): return "Envelope: w is % s, h is % s, id is %s" % (self.w, self.h, self.e_id) def compare(a, b): if a.w != b.w: return a.w < b.w else: return a.h < b.h def get_envelopes(): data = [line.rstrip().split() for line in sys.stdin.readlines()] data = [[int(x) for x in row] for row in data] n = data[0][0] w = data[0][1] h = data[0][2] envelopes = [Envelope()] * (n + 1) dp = [Envelope()] * (n + 1) for i in range(1, n + 1): wi = data[i][0] hi = data[i][1] e = Envelope(w=wi, h=hi, e_id=i) envelopes[i] = e envelopes.sort(key=lambda x: (x.w, x.h)) for i in range(1, n + 1): if envelopes[i].w <= w or envelopes[i].h <= h: continue else: e = Envelope() e.w = envelopes[i].w e.h = envelopes[i].h e.num = 1 e.pre = 0 e.e_id = envelopes[i].e_id dp[i] = e for j in range(1, i): if ( dp[j].num > 0 and envelopes[i].w > dp[j].w and envelopes[i].h > dp[j].h and dp[j].num + 1 > dp[i].num ): dp[i].pre = j dp[i].num = dp[j].num + 1 dp[i].w = envelopes[i].w dp[i].h = envelopes[i].h dp[i].e_id = envelopes[i].e_id maxL = 0 i_d = 0 for i in range(1, n + 1): if dp[i].num > maxL: maxL = dp[i].num i_d = i print(maxL) ans = [] while i_d != 0: ans.append(dp[i_d].e_id) i_d = dp[i_d].pre ans.reverse() print(*ans) get_envelopes()
IMPORT CLASS_DEF FUNC_DEF NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP STRING VAR VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys def log(*args): print(*args, file=sys.stderr) def line(): return sys.stdin.readline().split() def main(): n, w, h = (int(x) for x in line()) d = [[int(x) for x in line()] for _ in range(n)] e = sorted(range(n), key=lambda x: d[x]) c = [None for _ in range(n)] for i in range(n): if d[e[i]][0] <= w or d[e[i]][1] <= h: c[i] = [] continue cmax = [] for j in range(i): if d[e[j]][0] < d[e[i]][0] and d[e[j]][1] < d[e[i]][1]: if len(c[j]) > len(cmax): cmax = c[j] c[i] = cmax + [e[i]] cmax = [] for i in c: if len(i) > len(cmax): cmax = i print(len(cmax)) if len(cmax) > 0: print(*(i + 1 for i in cmax)) main()
IMPORT FUNC_DEF EXPR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR ASSIGN VAR VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys def get_ints(): return map(int, sys.stdin.readline().split()) n, w, h = get_ints() A = [] for i in range(n): x, y = get_ints() if x > w and y > h: A.append([x, y, i + 1]) A = sorted(A, key=lambda x: (x[0], x[1])) n1 = len(A) if n1 == 0: print(0) elif n1 == 1: print(1) print(A[0][2]) else: dp = [1] * n1 a = [0] * n1 for i in range(0, n1): a1 = [] a11 = -1 for j in range(i - 1, -1, -1): if A[i][0] > A[j][0] and A[i][1] > A[j][1]: if dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 a11 = j if a11 > -1: for kkk in a[a11]: a1.append(kkk) a1.append(A[i][2]) a[i] = a1 maxx = 0 for i in range(n1): if dp[i] > maxx: maxx = dp[i] ind = i print(dp[ind]) for k in a[ind]: print(k, end=" ")
IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
inputi = [int(i) for i in input().split(" ")] amt = inputi[0] cardW = inputi[1] cardH = inputi[2] envelopes = [] cur_amt = 1 for i in range(amt): inputi = [int(i) for i in input().split(" ")] if inputi[0] > cardW and inputi[1] > cardH: envelopes.append((inputi[0], inputi[1], inputi[0] * inputi[1], cur_amt)) cur_amt += 1 envelopes = sorted(envelopes, key=lambda x: x[2]) amounts = [(1) for a in envelopes] back_pointers = [(-1) for a in envelopes] for c in range(len(envelopes)): cur_tuple = envelopes[c] for prev in range(c): compare_tuple = envelopes[prev] if ( cur_tuple[0] > compare_tuple[0] and cur_tuple[1] > compare_tuple[1] and amounts[prev] + 1 > amounts[c] ): amounts[c] = amounts[prev] + 1 back_pointers[c] = prev max_amt = None max_idx = None for c in range(len(envelopes)): cur_tuple = envelopes[c] if max_amt == None or amounts[c] > max_amt: max_idx = c max_amt = amounts[c] if max_amt == None: print(0) else: print(max_amt) tmp_back_ptr = back_pointers[max_idx] back_ptr_list = [] back_ptr_list.append(envelopes[max_idx][3]) while tmp_back_ptr != -1: back_ptr_list.append(envelopes[tmp_back_ptr][3]) tmp_back_ptr = back_pointers[tmp_back_ptr] for a in range(len(back_ptr_list)): print(back_ptr_list[len(back_ptr_list) - a - 1], end=" ")
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NONE VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER STRING
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, x, y = map(int, input().strip().split()) envs = [] for h in range(n): envs.append(list(map(int, input().strip().split())) + [h]) envs.sort(key=lambda x: (x[0], x[1])) dp = [(1) for i in range(n)] anc = [(-1) for i in range(n)] flag = 0 for i in range(n): if envs[i][0] > x and envs[i][1] > y: flag = 1 for j in range(i): if envs[j][1] < envs[i][1] and envs[j][0] < envs[i][0]: if dp[i] < dp[j] + 1: dp[i] = dp[j] + 1 anc[i] = j else: dp[i] = 0 if flag: maxi = [0, -1] for i in range(n): if dp[i] > maxi[0]: maxi = [dp[i], i] ans = [] print(maxi[0]) start = maxi[1] while start != -1: ans.append(envs[start][2] + 1) start = anc[start] print(*ans[::-1]) else: print(0)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
[n, W, H] = [int(a) for a in input().split(" ")] arr = [] for i in range(n): [w, h] = [int(a) for a in input().split(" ")] arr.append((w, h, i, 0, 0)) arr.sort() arr.append((10000000, 10000000, n, 0, 0)) cnt = 0 for i in range(n + 1): w, h, x, a, pre = arr[i] a = 0 pre = -1 if W < w and H < h: a = 1 cnt1 = 0 for j in arr: if cnt == cnt1: break w1, h1, x0, a0, t = j if a0 > 0 and a < a0 + 1 and w1 < w and h1 < h: a = a0 + 1 pre = cnt1 cnt1 += 1 cnt += 1 arr[i] = w, h, x, a, pre print(arr[-1][3] - 1) idx = len(arr) - 1 l = [] for i in range(arr[-1][3] - 1): idx = arr[idx][4] l.append(str(arr[idx][2] + 1)) l.reverse() print(" ".join(l))
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, max_width, max_height = map(int, input().split()) array_w_h_i = list() array_w_h_i.append([max_width, max_height, 0]) for i in range(n): width, height = map(int, input().split()) if width > max_width and height > max_height: array_w_h_i.append([width, height, i + 1]) array_w_h_i.sort() length = len(array_w_h_i) lis = [0] * length path = [0] * (n + 1) lis_answer = 0 idx = 0 for i in range(1, length): for j in range(0, i): if ( array_w_h_i[i][0] > array_w_h_i[j][0] and array_w_h_i[i][1] > array_w_h_i[j][1] ): if lis[j] + 1 > lis[i]: lis[i] = lis[j] + 1 path[array_w_h_i[i][2]] = array_w_h_i[j][2] if lis[i] > lis_answer: lis_answer = lis[i] idx = array_w_h_i[i][2] print(lis_answer) s = [] while idx > 0: s.append(idx) idx = path[idx] print(" ".join(str(i) for i in s[::-1]))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
def f(L): return L[0] * L[1] ln = input().split(" ") n = int(ln[0]) w = int(ln[1]) h = int(ln[2]) nums = dict() envs = [] x_max = 0 y_max = 0 start = w, h envs.append(start) blank = 0, [] nums[start] = 0 for i in range(1, n + 1): w1, h1 = [int(x) for x in input().split(" ")] if w1 <= w or h1 <= h: continue e = w1, h1 nums[e] = i envs.append(e) n = len(envs) envs = sorted(envs, key=f, reverse=True) opt = [0] * n prev = [-1] * n for i in range(1, n): curr = envs[i] for j in range(i): comp = envs[j] if comp[0] > curr[0] and comp[1] > curr[1]: if opt[j] + 1 > opt[i]: opt[i] = opt[j] + 1 prev[i] = j best_ind = prev[n - 1] print(opt[-1]) if opt[-1] != 0: while best_ind != -1: print(nums[envs[best_ind]], end=" ") best_ind = prev[best_ind]
FUNC_DEF RETURN BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR STRING ASSIGN VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
def solution(a): if len(a) <= 1: return a dp = [1] * len(a) back = {} maxval = 0 for j in range(len(a)): for i in range(j): if a[i][0] < a[j][0] and a[i][1] < a[j][1]: if dp[i] + 1 > dp[j]: dp[j] = dp[i] + 1 back[j] = i maxval = max(maxval, dp[j]) j = 0 for i in range(len(dp)): if dp[i] == maxval: j = i break res = [] while j in back: res.append(a[j]) j = back[j] res.append(a[j]) return res[::-1] N, W, H = input().split() cnt = 1 dic = {} res = [] for _ in range(int(N)): w, h = input().split() if int(W) < int(w) and int(H) < int(h): res.append([int(w), int(h)]) dic[int(w), int(h)] = cnt cnt += 1 res = sorted(res, key=lambda x: (x[0], x[1])) li = solution(res) if not li: print(0) else: print(len(li)) for x, y in li: print(dic[x, y], end=" ")
FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR STRING
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
class Envelope: def __init__(self, w, h, n, prev): self.w = w self.h = h self.n = n self.prev = prev def max_chain_size(envelopes, w, h): dp = list() dp.append(0) for i in range(1, len(envelopes) + 1): dp.append(1) env = envelopes[i - 1] env.prev = None for j in range(1, i): if env.h > envelopes[j - 1].h and env.w > envelopes[j - 1].w: if dp[j] + 1 > dp[i]: env.prev = envelopes[j - 1] dp[i] = dp[j] + 1 max_elem = 0 max_index = 0 index = 0 for d in dp: if d > max_elem: max_elem = max(max_elem, d) max_index = index index += 1 return max_elem, max_index input_line = input().split() n = int(input_line[0]) card_width = int(input_line[1]) card_height = int(input_line[2]) envelopes = list() for i in range(0, n): envelope_dim = input().split() env = Envelope(int(envelope_dim[0]), int(envelope_dim[1]), i + 1, None) envelopes.append(env) envelopes = sorted(envelopes, key=lambda envelope: envelope.w) envelopes = list( filter( lambda envelope: envelope.w > card_width and envelope.h > card_height, envelopes ) ) chain = list() res = max_chain_size(envelopes, card_width, card_height) print(res[0]) if res[1] - 1 >= 0: start_env = envelopes[res[1] - 1] result = list() env = start_env while env: result.append(env) env = env.prev result.reverse() for res in result: print(res.n, end=" ") elif len(envelopes): print(envelopes[0].n)
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NONE EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys input = sys.stdin.readline n, w, h = map(int, input().split()) a = [] for i in range(n): x, y = map(int, input().split()) if x > w and y > h: a.append([x, y, i + 1]) a.sort() n = len(a) dp = [[1, i] for i in range(n)] for i in range(1, n): for j in range(i): if a[j][0] < a[i][0] and a[j][1] < a[i][1]: if dp[j][0] + 1 > dp[i][0]: dp[i][0] = dp[j][0] + 1 dp[i][1] = j m = 0 for i in range(n): if dp[i][0] > m: m = dp[i][0] ind = i print(m) ans = [] while m: ans.append(a[ind][-1]) m -= 1 ind = dp[ind][1] print(*ans[::-1])
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
def contains(a, b): if a[0] > b[0] and a[1] > b[1]: return True return False n, w, h = map(int, input().split(" ")) postcard = w, h envelopes = [] for _ in range(n): w, h = map(int, input().split(" ")) envelopes += [(w, h)] eh = sorted(enumerate(envelopes), key=lambda p: p[1]) envelopes = [e[1] for e in eh] indices = [(e[0] + 1) for e in eh] chain = [-1] * n max_envelopes = [0] * n for i, e1 in enumerate(envelopes): if not contains(e1, postcard): continue for j, e2 in enumerate(envelopes[:i]): if contains(e1, e2) and max_envelopes[i] < max_envelopes[j]: max_envelopes[i] = max_envelopes[j] chain[i] = j max_envelopes[i] += 1 max_index, max_value = max(enumerate(max_envelopes), key=lambda p: p[1]) print(max_value) i = max_index if max_value > 0: out = [indices[i]] while chain[i] != -1: out += [indices[chain[i]]] i = chain[i] out.reverse() print(" ".join(map(str, out)))
FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR LIST VAR VAR WHILE VAR VAR NUMBER VAR LIST VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) whi = [(list(map(int, input().split())) + [_ + 1]) for _ in range(n)] whi.sort(key=lambda _: _[0]) whi = list(filter(lambda _: _[0] > w and _[1] > h, whi)) whi = [(w, h, 0)] + whi answer = [(0, 0) for _ in range(n + 1)] n = len(whi) for i in range(0, n): for j in range(i + 1, n): if ( whi[i][0] < whi[j][0] and whi[i][1] < whi[j][1] and answer[j][0] <= answer[i][0] ): answer[j] = answer[i][0] + 1, i if len(whi) > 1: pos = list(map(lambda _: _[0], answer)).index(max(map(lambda _: _[0], answer))) depth = answer[pos][0] path = str(whi[pos][2]) while answer[pos][1] != 0: path = str(whi[answer[pos][1]][2]) + " " + path pos = answer[pos][1] print(depth) print(path) else: print(0)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER STRING VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
class Envelope: def __init__(self, w, h, i): self.w = w self.h = h self.i = i self.a = w * h n, w, h = list(map(int, input().split())) card = Envelope(w, h, -1) envs = [] for i in range(n): w, h = list(map(int, input().split())) envs.append(Envelope(w, h, i)) envs = sorted(envs, key=lambda env: env.a) fits = lambda e1, e2: e1.h < e2.h and e1.w < e2.w dp = [(0) for _ in range(n)] parents = {} for i in range(n): if envs[i].a < card.a: continue if fits(card, envs[i]): maxEnvs = 1 maxIdx = -1 for j in range(i): if fits(envs[j], envs[i]) and dp[j] + 1 > maxEnvs: maxEnvs = dp[j] + 1 maxIdx = j dp[i] = maxEnvs parents[i] = maxIdx maxEnvs = 0 maxIdx = -1 for i in range(n): if dp[i] > maxEnvs: maxEnvs = dp[i] maxIdx = i print(maxEnvs) idxs = [] while maxIdx != -1: idxs.append(envs[maxIdx].i + 1) maxIdx = parents[maxIdx] while len(idxs) > 0: print(idxs.pop(), end=" ") print()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
import sys input = sys.stdin.readline RI = lambda: [int(x) for x in sys.stdin.readline().strip().split()] rw = lambda: input().strip().split() n, w, h = RI() l = [] d = {} for i in range(n): a, b = RI() l.append((a, b, i)) l.sort() index = -1 for i in range(n): if l[i][0] > w and l[i][1] > h: index = i break if index == -1: print(0) else: temp = [0] * n parent = [0] * n temp[index] = 1 parent[index] = index for i in range(index + 1, n): parent[i] = i if l[i][0] > w and l[i][1] > h: temp[i] = 1 else: continue for j in range(index, i): if l[i][0] > l[j][0] and l[i][1] > l[j][1]: if temp[j] + 1 > temp[i]: temp[i] = temp[j] + 1 parent[i] = j maxo = max(temp) ans = [] for i in range(n): if temp[i] == maxo: j = i while parent[j] != j: ans.append(l[j][2] + 1) j = parent[j] ans.append(l[j][2] + 1) break print(maxo) print(*ans[::-1])
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
cards = [] a, w, h = map(int, input().split(" ")) for i in range(a): w1, h1 = map(int, input().split(" ")) if w < w1 and h < h1: cards.append([w1, h1, i + 1]) if len(cards) == 0: print(0) quit() cards.sort() rem = len(cards) dp = [1] * rem seq = [[cards[_][2]] for _ in range(rem)] for i in range(rem): best = 1 add = -1 for j in range(i): if cards[j][0] < cards[i][0] and cards[j][1] < cards[i][1]: if dp[j] + 1 > best: best = dp[j] + 1 add = seq[j] if add != -1: dp[i] = best seq[i] = add + seq[i] m = 0 finalseq = [] for i in range(rem): if dp[i] > m: finalseq = seq[i] m = dp[i] print(m) print(" ".join([str(x) for x in finalseq]))
ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) arr = [] for i in range(0, n): x, y = map(int, input().split()) if x > w and y > h: arr.append((x, y, i)) arr.sort(key=lambda x: (x[0], -x[1])) n = len(arr) dp = [(1, -1) for i in range(0, n)] res = 0 end = 0 for i in range(0, n): x, y, _ = arr[i] for j in range(0, i): if arr[j][0] < x and arr[j][1] < y and dp[j][0] + 1 > dp[i][0]: dp[i] = dp[j][0] + 1, j if dp[i][0] > res: res = dp[i][0] end = i if res == 0: print(0) else: print(res) chain = [] while end >= 0: chain.insert(0, arr[end][2] + 1) end = dp[end][1] print(" ".join(map(str, chain)))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
class Size: def __init__(self, width, height, id=""): self._w = width self._h = height self.id = id def __lt__(self, other): return self._w < other._w and self._h < other._h def __str__(self): return "({}, {})".format(self._w, self._h) num, cardWidth, cardHeight = [int(d) for d in input().split(" ")] cardSize = Size(cardWidth, cardHeight) envolopes = [] for i in range(num): w, h = [int(d) for d in input().split(" ")] es = Size(w, h, str(i + 1)) if cardSize < es: envolopes.append(es) if len(envolopes) == 0: print(0) else: envolopes = sorted(envolopes, key=lambda x: x._h * x._w) dp = [(1, -1)] * len(envolopes) for i in range(1, len(envolopes)): tmp = [] for j in range(0, i): if envolopes[j] < envolopes[i]: tmp.append((dp[j][0], j)) if len(tmp) > 0: prev = max(tmp) dp[i] = prev[0] + 1, prev[1] else: dp[i] = 1, -1 lastNodeIdx = 0 for i in range(1, len(dp)): if dp[i][0] > dp[lastNodeIdx][0]: lastNodeIdx = i chainLen = dp[lastNodeIdx][0] chainIds = [] p = lastNodeIdx while p != -1: chainIds.append(envolopes[p].id) p = dp[p][1] print(chainLen) print(" ".join(reversed(chainIds)))
CLASS_DEF FUNC_DEF STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF RETURN VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL STRING VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
class A: def solve(self): n = int(input()) other = n - 2 if other > 0 and other % 2 == 0: print("YES") else: print("NO") class B: def solve(self): [d, w] = [int(x) for x in input().split(" ")] times = [] for i in range(d): times.append(tuple([int(x) for x in input().split(" ")])) sum_l = sum([t[0] for t in times]) sum_h = sum([t[1] for t in times]) if not sum_l <= w <= sum_h: print("NO") return print("YES") for l, h in times: lb = l sum_l -= l sum_h -= h while lb <= h: if sum_l <= w - lb <= sum_h: break else: lb += 1 print("{} ".format(lb), end="") w -= lb class C: def solve(self): n = int(input()) name_index = {} for i in range(n): name = input() if name not in name_index: print("OK") name_index[name] = 1 else: print("{}{}".format(name, name_index[name])) name_index[name] += 1 class D: def solve(self): [n, w, h] = [int(x) for x in input().split(" ")] envelopes = [] envelope_indices = {} for i in range(n): envelopes.append(tuple([int(x) for x in input().split(" ")])) envelope_indices[envelopes[-1]] = i sorted_envelopes = sorted(envelopes, key=lambda x: x[1]) sorted_envelopes = sorted(sorted_envelopes, key=lambda x: x[0]) lis = [(0) for x in range(n)] back = [(0) for x in range(n)] for k in range(n): if sorted_envelopes[k][0] <= w or sorted_envelopes[k][1] <= h: continue lis[k] = 1 back[k] = -1 for i in range(k): if ( sorted_envelopes[i][0] > w and sorted_envelopes[i][1] > h and sorted_envelopes[i][0] < sorted_envelopes[k][0] and sorted_envelopes[i][1] < sorted_envelopes[k][1] and lis[i] + 1 > lis[k] ): lis[k] = lis[i] + 1 back[k] = i max_val = max(lis) if max_val == 0: print("0") else: print(max_val) max_index = -1 for i in range(n): if lis[i] == max_val: max_index = i break back_val = back[max_index] n_seq = [max_index] while back_val != -1: n_seq.append(back_val) back_val = back[back_val] n_seq = list(reversed(n_seq)) selected_evelopes = [sorted_envelopes[i] for i in range(n) if i in n_seq] for e in selected_evelopes: print("{} ".format(envelope_indices[e] + 1), end="") D().solve()
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING CLASS_DEF FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING FOR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR STRING VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR 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 IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP VAR VAR NUMBER STRING EXPR FUNC_CALL FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) A = [] for i in range(n): wi, hi = map(int, input().split()) if wi > w and hi > h: A.append((wi, hi, i + 1)) A.sort() n = len(A) Length = [(10000000, -1)] * (n + 1) Length[0] = 0, -1 Before = [-1] * 5000 def bs(h): beg, last = 0, n while 1: mid = (last + beg) // 2 if beg + 1 >= last: if Length[last][0] < h: return last else: return beg if Length[mid][0] < h and Length[mid + 1][0] >= h: return mid elif Length[mid][0] > h: last = mid - 1 else: beg = mid i = 0 while i < n: start = i last = start + 1 while last < n and A[last][0] == A[start][0]: last += 1 for k in range(last - 1, start - 1, -1): h = A[k][1] Id = bs(h) if Length[Id + 1][0] > h and Length[Id][0] < h: Length[Id + 1] = h, k Before[k] = Length[Id][1] i = last Max = 0 iMax = -1 for k in range(n, -1, -1): if Length[k][1] != -1: Max = k iMax = Length[k][1] break print(Max) R = [-1] * Max while iMax != -1: R[Max - 1] = A[iMax][2] Max -= 1 iMax = Before[iMax] for i in R: print(i, end=" ") print()
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR RETURN VAR RETURN VAR IF VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR IF VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, cw, ch = map(int, input().split()) envs = [] for i in range(n): w, h = map(int, input().split()) if w > cw and h > ch: envs.append((w, h, i + 1)) envs.sort() l = len(envs) if l > 0: adj = [[1, -1] for _ in range(l)] mx, x = 1, 0 for i in range(l - 2, -1, -1): m = 0 for j in range(i + 1, l): if envs[i][0] < envs[j][0] and envs[i][1] < envs[j][1] and adj[j][0] > m: m = adj[j][0] adj[i][0] = m + 1 adj[i][1] = j if m + 1 > mx: mx = m + 1 x = i print(mx) while x >= 0: print(envs[x][2], end=" ") x = adj[x][1] else: print(0)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = list(map(int, input().split())) x = [] for i in range(n): a, b = map(int, input().split()) x.append((a, b, i + 1)) x.sort() dp = [0] * (n + 1) p = [-1] * (n + 1) found = False for i in range(n): if x[i][0] > w and x[i][1] > h: dp[i] = 1 found = True for j in range(i): if dp[j] and x[i][0] > x[j][0] and x[i][1] > x[j][1] and dp[j] + 1 > dp[i]: dp[i] = dp[j] + 1 p[i] = j if not found: print(0) exit(0) anw = [] m = 0 for i in range(n): if dp[i] > dp[m]: m = i while p[m] != -1: anw.append(x[m][2]) m = p[m] anw.append(x[m][2]) print(len(anw)) for x in anw[::-1]: print(x, end=" ")
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
def main(): n, w, h = map(int, input().split()) cards = [] for i in range(n): wi, hi = map(int, input().split()) if wi > w and hi > h: cards.append((wi, hi, i + 1)) cards.sort() if not cards: print(0) return ans = [] dp = [1] * len(cards) backpointer = [-1] * len(cards) for i in range(1, len(cards)): w1, h1 = cards[i][0], cards[i][1] for j in range(i): w2, h2 = cards[j][0], cards[j][1] if w2 < w1 and h2 < h1: if dp[j] + 1 > dp[i]: dp[i] = max(dp[i], dp[j] + 1) backpointer[i] = j index = dp.index(max(dp)) while index >= 0: ans.append(cards[index][2]) index = backpointer[index] ans.reverse() print(len(ans)) for i in ans: print(i, end=" ") main()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
def lis(arr): n = len(arr) lis = [1] * n back = [] for i in range(0, n): back.append(i) for i in range(1, n): for j in range(0, i): if arr[i][0] > arr[j][0] and arr[i][1] > arr[j][1] and lis[i] < lis[j] + 1: lis[i] = lis[j] + 1 back[i] = j maximum = 0 ptr = 0 for i in range(n): if maximum < lis[i]: ptr = i maximum = max(maximum, lis[i]) ans = [] while ptr != back[ptr]: ans.append(arr[ptr][2] + 1) ptr = back[ptr] ans.append(arr[ptr][2] + 1) ans = ans[::-1] return ans n, w, h = map(int, input().split()) L1 = [] L2 = [] pos = [0] * (n + 1) kk = dict() for i in range(n): wi, hi = map(int, input().split()) if wi > w and hi > h and kk.get((wi, hi)) == None: L1.append((wi, hi, i)) kk[wi, hi] = 1 L1.sort() if len(L1) == 0: print(0) else: ans = lis(L1) print(len(ans)) print(*ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST WHILE VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NONE EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = [int(j) for j in input().split()] e = list() e.append([0, w, h, 0]) mwi, mhi = 0, 0 for i in range(n): wi, hi = [int(j) for j in input().split()] mwi = max(mwi, wi) mhi = max(mhi, hi) e.append([i + 1, wi, hi, 0]) if w >= mwi or h >= mhi: print(0) exit() s = sorted(e, key=lambda x: x[1], reverse=True) h = [[s[0]]] for u in s[1:]: f = True j = len(h) - 1 while j >= 0: if u[2] < h[j][0][2]: fg = True for g in h[j]: if g[1] > u[1] and g[2] > u[2]: fg = False u[3] = g[0] break if fg: j -= 1 continue if j + 1 < len(h): h[j + 1].append(u) h[j + 1].sort(key=lambda x: x[2], reverse=True) else: h.append([u]) f = False break else: j -= 1 if f: h[0].append(u) h[0].sort(key=lambda x: x[2], reverse=True) if u[0] == 0: break t = e[0] res = list() while t[3] != 0: res.append(str(t[3])) t = e[t[3]] print(len(res)) print(" ".join(res))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST LIST VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER IF VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) a = [] for i in range(n): x, y = map(int, input().split()) if x > w and y > h: a.append([x, y, i + 1]) r = [1] * len(a) p = [0] * (n + 1) ans = 0 a.sort() for j in range(len(a)): for i in range(j): if a[j][0] > a[i][0] and a[j][1] > a[i][1]: if r[j] < r[i] + 1: r[j] = r[i] + 1 p[a[j][2]] = a[i][2] if r[j] > ans: ans = r[j] q = a[j][2] c = [] if len(a) != 0: while q != 0: c.append(q) q = p[q] c.reverse() print(ans) print(*c)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) ans = [] for i in range(n): x, y = map(int, input().split()) if x > w and y > h: ans.append([x, y, i + 1]) ans.sort() dp = [(1) for i in range(len(ans))] index = [[ans[i][2]] for i in range(len(ans))] for i in range(len(ans)): cover = 1 end = -1 for j in range(len(ans)): if ans[j][0] < ans[i][0] and ans[j][1] < ans[i][1]: if dp[j] + 1 > cover: cover = dp[j] + 1 end = index[j] if end != -1: index[i] = end + index[i] dp[i] = len(index[i]) if len(dp) == 0: print(0) exit() maxa = dp.index(max(dp)) print(dp[maxa]) print(*index[maxa])
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
n, w, h = map(int, input().split()) g = [] for i in range(n): g.append(list(map(int, input().split())) + [i]) g.sort() dp = [0] * n par = [-1] * n for i in range(n): if g[i][0] > w and g[i][1] > h: dp[i] = 1 for i in range(n): for j in range(i): if ( g[i][0] > g[j][0] and g[i][1] > g[j][1] and g[j][0] > w and g[j][1] > h and dp[j] + 1 > dp[i] ): par[i] = j dp[i] = dp[j] + 1 mx = 0 for i in range(n): if dp[i] > dp[mx]: mx = i res = [] print(dp[mx]) for i in range(dp[mx]): res.append(g[mx][2]) mx = par[mx] res = reversed(res) for i in res: print(i + 1, end=" ")
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain. Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes. Peter has very many envelopes and very little time, this hard task is entrusted to you. Input The first line contains integers n, w, h (1 ≀ n ≀ 5000, 1 ≀ w, h ≀ 106) β€” amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi β€” width and height of the i-th envelope (1 ≀ wi, hi ≀ 106). Output In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers. If the card does not fit into any of the envelopes, print number 0 in the single line. Examples Input 2 1 1 2 2 2 2 Output 1 1 Input 3 3 3 5 4 12 11 9 8 Output 3 1 3 2
R = lambda: map(int, input().split()) n, w, h = R() arr = [] for i in range(n): wi, hi = R() if wi > w and hi > h: arr.append((wi, hi, i)) if not arr: print(0) exit(0) arr.sort() ls = [0] * n for x in arr: ls[x[-1]] = 1 ps = [-1] * n for i in range(len(arr)): wi, hi, idxi = arr[i] for j in range(i): wj, hj, idxj = arr[j] if wi > wj and hi > hj and ls[idxj] + 1 > ls[idxi]: ls[idxi] = ls[idxj] + 1 ps[idxi] = idxj idx = max((x, i) for i, x in enumerate(ls))[1] res = [] while idx >= 0: res.append(idx) idx = ps[idx] print(len(res)) print(" ".join(map(str, (x + 1 for x in res[::-1]))))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER
Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are given a weighted directed graph with n vertices and m edges. You need to find a path (perhaps, non-simple) with maximum number of edges, such that the weights of the edges increase along the path. In other words, each edge of the path must have strictly greater weight than the previous edge in the path. Help Pashmak, print the number of edges in the required path. -----Input----- The first line contains two integers n, m (2 ≀ n ≀ 3Β·10^5;Β 1 ≀ m ≀ min(nΒ·(n - 1), 3Β·10^5)). Then, m lines follows. The i-th line contains three space separated integers: u_{i}, v_{i}, w_{i} (1 ≀ u_{i}, v_{i} ≀ n;Β 1 ≀ w_{i} ≀ 10^5) which indicates that there's a directed edge with weight w_{i} from vertex u_{i} to vertex v_{i}. It's guaranteed that the graph doesn't contain self-loops and multiple edges. -----Output----- Print a single integer β€” the answer to the problem. -----Examples----- Input 3 3 1 2 1 2 3 1 3 1 1 Output 1 Input 3 3 1 2 1 2 3 2 3 1 3 Output 3 Input 6 7 1 2 1 3 2 5 2 4 2 2 5 2 2 6 9 5 4 3 4 3 4 Output 6 -----Note----- In the first sample the maximum trail can be any of this trails: $1 \rightarrow 2,2 \rightarrow 3,3 \rightarrow 1$. In the second sample the maximum trail is $1 \rightarrow 2 \rightarrow 3 \rightarrow 1$. In the third sample the maximum trail is $1 \rightarrow 2 \rightarrow 5 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 6$.
from sys import * a = list(map(int, stdin.read().split())) n = a[0] m = a[1] inf = 10**5 + 1 g = [[] for i in range(inf)] for i in range(2, len(a), 3): b, c, w = a[i : i + 3] g[w].append((c, b)) n += 1 s = [0] * n for l in g: for i, k in [(i, s[j]) for i, j in l]: s[i] = max(s[i], k + 1) print(max(s))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. -----Input----- The first line of the input contains a single integer n (1 ≀ n ≀ 3000)Β β€” the length of the array. Next line contains n integer a_{i} (1 ≀ a_{i} ≀ 10^9). -----Output----- Print the minimum number of operation required to make the array strictly increasing. -----Examples----- Input 7 2 1 5 11 5 9 11 Output 9 Input 5 5 4 3 2 1 Output 12 -----Note----- In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
n = int(input()) a = list(map(int, input().split())) for i in range(n): a[i] -= i sorted_a = sorted(a) dp = [0.0] * n dp2 = [0.0] * n for i in range(n): mn_prev_state = 10000000000000.0 for j in range(n): mn_prev_state = min(mn_prev_state, dp[j]) dp2[j] = mn_prev_state + abs(a[i] - sorted_a[j]) for j in range(n): dp[j] = dp2[j] print(int(min(dp)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. -----Input----- The first line of the input contains a single integer n (1 ≀ n ≀ 3000)Β β€” the length of the array. Next line contains n integer a_{i} (1 ≀ a_{i} ≀ 10^9). -----Output----- Print the minimum number of operation required to make the array strictly increasing. -----Examples----- Input 7 2 1 5 11 5 9 11 Output 9 Input 5 5 4 3 2 1 Output 12 -----Note----- In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
N = int(input()) s = list(map(int, input().split())) for i in range(N): s[i] -= i X = sorted(s) dp = [0] * N for i in s: mi = 7e77 for j in range(N): mi = min(mi, dp[j]) dp[j] = mi + abs(i - X[j]) print(min(dp))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
from sys import stdin, stdout T = 2001 INF = int(1000000000.0) n = int(stdin.readline()) items = [] for i in range(n): c, d, t = map(int, stdin.readline().split()) items.append((d, c, t, i + 1)) items.sort() dp = [[None for i in range(T)] for j in range(n)] def solve(pos, time): if pos >= n or time >= T: return 0 if dp[pos][time] is not None: return dp[pos][time] d, c, t, i = items[pos] ans = solve(pos + 1, time) if time + c < d: ans = max(ans, solve(pos + 1, time + c) + t) dp[pos][time] = ans return ans ans = [] def recover(pos, time): global ans if pos >= n or time >= T: return d, c, t, i = items[pos] if solve(pos + 1, time) == solve(pos, time): recover(pos + 1, time) else: ans.append(i) recover(pos + 1, time + c) stdout.write(str(solve(0, 0)) + "\n") recover(0, 0) stdout.write(str(len(ans)) + "\n") for i in ans: stdout.write(str(i) + " ") stdout.write("\n")
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER IF VAR VAR VAR NONE RETURN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR VAR RETURN ASSIGN VAR VAR VAR VAR VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
from sys import stdin, stdout n = int(stdin.readline()) items = [] for i in range(n): t, d, p = map(int, stdin.readline().split()) items.append((d, p, t, i + 1)) items.sort() N = 2000 + 1 dp = [(0) for i in range(N)] cur = [[] for i in range(N)] for d, p, t, it in items: for i in range(d - 1, t - 1, -1): if dp[i - t] + p > dp[i]: dp[i] = dp[i - t] + p cur[i] = cur[i - t] + [it] best = 0 for i in range(N): if dp[i] > dp[best]: best = i stdout.write("{}\n".format(dp[best])) stdout.write("{}\n".format(len(cur[best]))) stdout.write(" ".join([str(x) for x in cur[best]]) + "\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR STRING
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
P = [0] * 2001 S = [[] for i in range(2001)] q = [(list(map(int, input().split())) + [str(i + 1)]) for i in range(int(input()))] q.sort(key=lambda q: q[1]) for t, d, p, i in q: for x in range(t, d)[::-1]: if P[x] < P[x - t] + p: P[x] = P[x - t] + p S[x] = S[x - t] + [i] k = P.index(max(P)) print("\n".join([str(P[k]), str(len(S[k])), " ".join(S[k])]))
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING LIST FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL STRING VAR VAR
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
n = int(input()) a = [] for i in range(n): t, d, p = map(int, input().split()) a.append([t, d, p, i + 1]) a.sort(key=lambda x: x[1]) d = {(0): [0, []]} for i in a: e = {} for j in d: if d[j][0] + i[0] < i[1]: if j + i[2] in d: if d[j][0] + i[0] < d[j + i[2]][0]: e[j + i[2]] = [d[j][0] + i[0], d[j][1] + [i[3]]] else: e[j + i[2]] = [d[j][0] + i[0], d[j][1] + [i[3]]] d.update(e) t = max(d) print(t) k = d[t][1] print(len(k)) k = list(map(str, k)) print(" ".join(k))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT NUMBER LIST NUMBER LIST FOR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER LIST BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER LIST VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER LIST BIN_OP VAR VAR NUMBER VAR NUMBER BIN_OP VAR VAR NUMBER LIST VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(2 * 10**5 + 10) write = lambda x: sys.stdout.write(x + "\n") debug = lambda x: sys.stderr.write(x + "\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) tdp = [list(map(int, input().split())) for _ in range(n)] index = list(range(n)) index.sort(key=lambda i: tdp[i][1]) T = max([item[1] for item in tdp]) dp = [0] * (T + 1) ps = [] for ind in range(n): i = index[ind] t, d, p = tdp[i] ndp = dp[:] prv = [(k, -1) for k in range(T + 1)] for j in range(T + 1): if j + t < d: if ndp[j + t] < dp[j] + p: ndp[j + t] = dp[j] + p prv[j + t] = j, i dp = ndp ps.append(prv) ans = max(dp) res = [] for j in range(T + 1)[::-1]: if dp[j] == ans: for i in range(n)[::-1]: jj, ii = ps[i][j] if ii >= 0: res.append(ii + 1) j = jj break res = res[::-1] print(ans) print(len(res)) write(" ".join(map(str, res)))
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
from sys import stdin input = stdin.readline n = int(input()) T = 2001 t, d, p, idx = [], [], [], [] ans = [] arr = [] for i in range(n): a, b, c = map(int, input().split()) arr.append([a, b, c, i]) arr.sort(key=lambda x: x[1]) for i in arr: t.append(i[0]) d.append(i[1]) p.append(i[2]) idx.append(i[3]) dp = [[(0) for j in range(n)] for i in range(T)] for time in range(1, T): for i in range(n): dp[time][i] = dp[time][i - 1] if d[i] > time >= t[i]: if i: dp[time][i] = max(dp[time][i], p[i] + dp[time - t[i]][i - 1]) else: dp[time][i] = p[i] b = [0, [0, 0]] for i in range(T): for j in range(n): if b[0] < dp[i][j]: b = [dp[i][j], [i, j]] print(b[0]) b = b[1] while dp[b[0]][b[1]] and b[0] > -1: if b[1] and dp[b[0]][b[1]] != dp[b[0]][b[1] - 1]: ans.append(b[1]) b[0] -= t[b[1]] elif b[1] == 0: if dp[b[0]][b[1]]: ans.append(b[1]) break b[1] -= 1 print(len(ans)) for i in ans[::-1]: print(idx[i] + 1, end=" ")
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR LIST LIST LIST LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR NUMBER NUMBER IF VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER STRING
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
n = int(input()) items = [] max_time = 0 for i in range(1, n + 1): t, d, p = map(int, input().split()) max_time = max(max_time, d) items.append((t, d, p, i)) items.sort(key=lambda x: x[1]) dp = [[(0, []) for _ in range(n + 1)] for _ in range(max_time + 1)] for time in range(1, max_time + 1): for it in range(1, n + 1): if time < items[it - 1][0] or time >= items[it - 1][1]: dp[time][it] = max(dp[time][it - 1], dp[time - 1][it]) else: pick = dp[time - items[it - 1][0]][it - 1][0] + items[it - 1][2] if dp[time][it - 1][0] > pick: dp[time][it] = max(dp[time][it - 1], dp[time - 1][it]) else: dp[time][it] = dp[time - items[it - 1][0]][it - 1][0] + items[it - 1][ 2 ], list(dp[time - items[it - 1][0]][it - 1][1]) dp[time][it][1].append(items[it - 1][3]) res = max(dp[max_time]) print(res[0]) print(len(res[1])) print(*res[1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
Polycarp is in really serious trouble β€” his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take t_{i} seconds to save i-th item. In addition, for each item, he estimated the value of d_{i} β€” the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if t_{i} β‰₯ d_{i}, then i-th item cannot be saved. Given the values p_{i} for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in t_{a} seconds, and the item b β€” in t_{a} + t_{b} seconds after fire started. -----Input----- The first line contains a single integer n (1 ≀ n ≀ 100) β€” the number of items in Polycarp's house. Each of the following n lines contains three integers t_{i}, d_{i}, p_{i} (1 ≀ t_{i} ≀ 20, 1 ≀ d_{i} ≀ 2 000, 1 ≀ p_{i} ≀ 20) β€” the time needed to save the item i, the time after which the item i will burn completely and the value of item i. -----Output----- In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m β€” the number of items in the desired set. In the third line print m distinct integers β€” numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them. -----Examples----- Input 3 3 7 4 2 6 5 3 7 6 Output 11 2 2 3 Input 2 5 6 1 3 3 5 Output 1 1 1 -----Note----- In the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11. In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.
from sys import stdin n = int(stdin.readline()) items = [] for i in range(n): t, d, p = [int(x) for x in stdin.readline().split()] items.append((d, t, p, i)) items.sort() mem = [{} for x in range(n)] mem2 = [{} for x in range(n)] def best(time, x): time += items[x][1] if time in mem[x]: return mem[x][time] if time >= items[x][0]: mem[x][time] = 0 mem2[x][time] = -1 return 0 top = 0 top2 = -1 for i in range(x + 1, n): temp = best(time, i) if temp > top: top = temp top2 = i mem[x][time] = top + items[x][2] mem2[x][time] = top2 return mem[x][time] top = -1 l = [] for x in range(n): b = best(0, x) if b > top: top = b l = [] c = x time = 0 while c != -1: time += items[c][1] l.append(items[c][3]) if time in mem2[c]: c = mem2[c][time] else: c = -1 print(top) if top != 0: print(len(l)) print(" ".join([str(x + 1) for x in l])) else: print(0) print()
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR FUNC_DEF VAR VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo i has a contrast v_{i}. In order for the processing to be truly of high quality, the application must receive at least k photos with contrasts which differ as little as possible. Evlampiy already knows the contrast v_{i} for each of his n photos. Now he wants to split the photos into groups, so that each group contains at least k photos. As a result, each photo must belong to exactly one group. He considers a processing time of the j-th group to be the difference between the maximum and minimum values of v_{i} in the group. Because of multithreading the processing time of a division into groups is the maximum processing time among all groups. Split n photos into groups in a such way that the processing time of the division is the minimum possible, i.e. that the the maximum processing time over all groups as least as possible. -----Input----- The first line contains two integers n and k (1 ≀ k ≀ n ≀ 3Β·10^5) β€” number of photos and minimum size of a group. The second line contains n integers v_1, v_2, ..., v_{n} (1 ≀ v_{i} ≀ 10^9), where v_{i} is the contrast of the i-th photo. -----Output----- Print the minimal processing time of the division into groups. -----Examples----- Input 5 2 50 110 130 40 120 Output 20 Input 4 1 2 3 4 1 Output 0 -----Note----- In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division is less than 20. In the second example the photos should be split into four groups, each containing one photo. So the minimal possible processing time of a division is 0.
def f(m): nonlocal dp, sdp l = 0 for i in range(n): while l < n and v[l] < v[i] - m: l += 1 if l - 1 > i - k: dp[i] = False else: dp[i] = sdp[i - k + 1] != sdp[l - 1] sdp[i + 1] = sdp[i] + (1 if dp[i] else 0) return dp[n - 1] n, k = map(int, input().split()) dp = [(False) for i in range(n + 2)] sdp = [(0) for i in range(n + 2)] dp[-1] = True sdp[0] = 1 v = list(map(int, input().split())) v.sort() le = -1 r = v[-1] - v[0] while r - le > 1: m = (r + le) // 2 if f(m): r = m else: le = m print(r)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER NUMBER RETURN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Fatal Eagle has finally teamed up with Arjit to take on this weird army of zombies and vampires. And they are coming up with strategies to beat these guys on a roll. The simple thing they figured out is that these creatures attack everything by the method of brute force - i.e., the total power they have while attacking is the sum of their individual powers. Bangalore City has two entrances which are located adjacent to each other. And the members of enemy's army are going to rush over to both the entrances to attack the city. The heroes, though, know that they will be facing N enemies who have different individual powers from Power1 to Powern. The enemies attack at a particular entrance if they see a hero standing on that entrance. So basically, the heroes can manipulate an enemy into attacking one particular entrance. All the enemies attack one by one, and whenever they see someone standing on one particular entrance, they run attack that particular entrance. Our heroes need to know the number of ways in which they can trick the enemies and beat them! Fatal Eagle and Arjit have to make sure that the enemies are tricked in such a way - that the sum of the powers of enemies on the 1^st entrance of the city is NEVER greater than the 2^nd entrance of the city. The number of such ways possible is the number of ways in which they can defeat the enemies. In any case, if the sum of the powers of the enemies (Brute force!) is greater than or equal to the number of ways in which they can be defeated, print "Got no way out!" otherwise "We will win!" needs to be printed. Input format: The first line contains an integer N denoting the number of enemies. On the next line, there will be N integers denoting the individual powers of the N enemies. Output format: On the first line of the output print two integers separated by a space, the first one denoting the number of ways in which the task can be performed, the second one denoting the total power the enemies have while attacking. In the next line of the output, you've to print the message as We will win! or Got no way out! accordingly. Constraints: 0 ≀ N ≀ 8 0 ≀ Poweri ≀ 500 SAMPLE INPUT 3 1 2 13 SAMPLE OUTPUT 15 16 Got no way out! Explanation The thing to remember is that all the enemies come one by one, and their order matters. Some of the possible ways which are valid would be: - 1, 2 and 13 all on the 2^nd entrance. Final result: 1-2-13. - Firstly, 13 on the 2^nd entrance, then 1 on the 1^st entrance. And then, 2 on the 2^nd entrance. Final result: 13-2 1.
from itertools import permutations doors = [0, 0] powers_sum = 0 arrangement_sum = 0 def recurse(item, idx): if idx == len(item): global arrangement_sum arrangement_sum += 1 return for i in range(2): if i == 0 and doors[0] + item[idx] > doors[1]: continue doors[i] += item[idx] recurse(item, idx + 1) doors[i] -= item[idx] N = int(input()) if N == 0: print("%i %i" % (1, 0)) print("We will win!") else: L = list(map(int, input().strip().split(" "))) powers_sum = sum(L) from itertools import permutations patterns = list(map(list, permutations(L))) for item in patterns: doors = [0, 0] recurse(item, 0) print("%i %i" % (arrangement_sum, powers_sum)) print("We will win!" if arrangement_sum >= powers_sum else "Got no way out!")
ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
n = int(input()) primes = [] is_prime = [1] * (n + 1) for i in range(2, n + 1): if is_prime[i]: for j in range(2 * i, n + 1, i): is_prime[j] = 0 primes.append(i) def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - b // a * y, y def modinv(a, m): g, x, y = egcd(a, m) if g == 1: return x % m return None s = 1 ans = [1] myprimes = [] orig_n = n for p in primes: if n % p == 0: myprimes.append(p) while n % p == 0: n //= p if n != 1: myprimes.append(n) for i in range(2, orig_n): for p in myprimes: if i % p == 0: break else: ans.append(i) cur = 1 for v in ans: cur *= v cur %= orig_n if cur != 1: assert modinv(cur, orig_n) == cur ans.remove(modinv(cur, orig_n)) print(len(ans)) print(*ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR VAR RETURN NONE ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR NUMBER FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
n = int(input()) x = n kek = set() i = 2 while i * i <= n: while n % i == 0: kek.add(i) n //= i i += 1 if n != 1: kek.add(n) ans = 0 num = 1 keku = 0 keke = [] bebe = [] for i in range(1, x): flag = True for elem in kek: if i % elem == 0: flag = False break if flag: keku += 1 bebe.append(i) num *= i num %= x if num == 1: ans = keku for i in range(ans): keke.append(bebe[i]) print(ans) print(*keke)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR WHILE BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
D = {} q = 2 plist = [] while q < 100000: if q not in D: plist.append(q) D[q * q] = [q] else: for p in D[q]: D.setdefault(p + q, []).append(p) del D[q] q += 1 n = int(input()) a = [(True) for _ in range(n)] a[0] = False for p in plist: if n % p == 0: for x in range(p, n, p): a[x] = False while True: result = 1 for x in range(1, n): if a[x]: result = result * x % n if result == 1: break else: for x in range(n - 1, 0, -1): if a[x]: a[x] = False break print(sum(a)) final = [] for x in range(1, n): if a[x]: final.append(x) print(*final)
ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR LIST VAR FOR VAR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR BIN_OP VAR VAR LIST VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def prod(arr): p = 1 for i in arr: p = p * i % n return p n = int(input()) lst = [0] * n for i in range(2, n // 2 + 1): if not n % i: j = i while j < n: lst[j] = 1 j += i arr = [i for i in range(1, n) if lst[i] == 0] x = prod(arr) if x != 1: arr.pop() print(len(arr)) print(*arr)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def ld(n): i = 1 p = n**0.5 l = [] while i <= p: if n % i == 0: if n / i == i: if i != 1: l.append(i) else: if i != 1: l.append(i) l.append(n // i) i = i + 1 l.sort() return l n = int(input()) stk = [] lis = ld(n) h = len(lis) for i in range(1, n): t = False for j in range(h): if i % lis[j] == 0: t = True break if not t: stk.append(i) k = 1 for j in range(len(stk)): k *= stk[j] k %= n lo = True if k % n != 1: lo = False h = len(stk) if lo: print(h) else: print(h - 1) for i in range(h): if i == h - 1: if lo: print(stk[i], end=" ") else: print(stk[i], end=" ")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
lim = 10**5 + 1 isPrime = [True] * lim p = [] for i in range(2, lim): if isPrime[i]: p.append(i) for j in range(i * i, lim, i): isPrime[j] = False n = int(input()) facts = set() for prime in p: if n % prime == 0: facts.add(prime) ans = set() prod = 1 for i in range(1, n): good = True for fact in facts: if i % fact == 0: good = False break if good: ans.add(i) prod = prod * i % n if prod != 1: ans.remove(prod) print(len(ans)) print(*sorted(ans))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def computeGCD(x, y): while y: x, y = y, x % y return x n = int(input()) prod = 1 H = [0] * 100005 for i in range(1, n + 1): if computeGCD(n, i) == 1: H[i] = 1 prod = prod * i % n if prod != 1: H[prod] = 0 print(H.count(1)) for i in range(1, n): if H[i]: print(i, end=" ")
FUNC_DEF WHILE VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def get_mod(n, r): c = 1 for e in r: c = c * e % n return c def solve(n): def factorize(n): v = [] p = 2 while n > 1: if n % p == 0: v.append(p) while n % p == 0: n //= p p += 1 return v v = set(range(1, n)) factors = factorize(n) for i in range(2, n): if any(i % x == 0 for x in factors): v.discard(i) r = sorted(v) while True: m = get_mod(n, r) if m == 1: break r.remove(m) return r n = int(input()) r = solve(n) print(len(r)) print(" ".join(str(x) for x in r))
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def gcd(a, b): if b == 0: return a return gcd(b, a % b) res = [] n = int(input()) if n == 2: print(1) print(1) else: prod = 1 res = [x for x in range(n) if gcd(x, n) == 1] for i in res: prod = prod * i % n if prod != 1: res.pop() print(len(res)) print(*res)
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
from sys import stdin, stdout get_string = lambda: stdin.readline().strip(" ") get_intmap = lambda: map(int, get_string().split(" ")) def testcase(): n = n1 = int(input()) prime_factors = [] for i in range(2, int(n**0.5) + 4): q, r = divmod(n1, i) if r == 0: prime_factors.append(i) while r == 0: n1 = q q, r = divmod(n1, i) if n1 > 1: prime_factors.append(n1) coprimes, prod = [], 1 for i in range(1, n): ok = True for prime in prime_factors: ok = i % prime if prime > i or not ok: break if ok: coprimes.append(i) prod = prod * i % n if prod != 1: coprimes.remove(prod) print(len(coprimes)) print(" ".join([str(i) for i in coprimes])) testcase() quit() for t in range(int(input())): testcase()
ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
N = int(input()) divs = set() m = 2 while m * m <= N: if N % m == 0: divs.add(m) divs.add(N // m) m += 1 ans = set(range(1, N)) for d in divs: for n in range(d, N, d): if n in ans: ans.remove(n) ans = sorted(ans) r = 1 for a in ans: r *= a r %= N if r == 1: print(len(ans)) print(*ans) exit() ans.pop() r = 1 for a in ans: r *= a r %= N if r == 1: print(len(ans)) print(*ans) else: print(len(ans)) print(*ans) assert False
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def gcd(a, b): while b != 0: a = a % b a, b = b, a return a n = int(input()) res = [1] prod = 1 for i in range(2, n): if gcd(n, i) == 1: res.append(i) prod = prod * i % n if prod != 1: res.remove(prod) print(len(res)) print(" ".join(str(r) for r in res))
FUNC_DEF WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def f(n): l = [] i = 2 while i <= n**0.5: if n % i != 0: i += 1 else: l.append(i) n //= i if n != 1: l.append(n) if len(l) == 1: x = 2 elif l == [2, 2]: x = 2 elif len(l) == 2: if l[0] == 2: x = 2 elif l[0] == l[1]: x = 2 else: x = 4 elif l[2] == 2: x = 4 elif l[0] == l[-1]: x = 2 elif l[0] == 2 and l[1] == l[-1]: x = 2 else: x = 4 return [x, l] n = int(input()) l = [] m = f(n) x = set(m[1]) for i in range(1, n): y = 0 for j in x: if i % j == 0: y = 1 if y == 0: l.append(i) a = "" if n == 2: print(1) print(1) elif m[0] == 2: for i in l[:-1]: a += str(i) + " " print(len(l) - 1) print(a[:-1]) else: for i in l: a += str(i) + " " print(len(l)) print(a[:-1])
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN LIST VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER NUMBER FOR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
def gcd(a, b): if a == 0: return b return gcd(b % a, a) def f(N): result = [1] p = 1 for i in range(2, N): if gcd(i, N) == 1: p *= i p %= n if i == N - 1: if p % N == 1: result.append(i) else: result.append(i) return result n = int(input()) ans = f(n) h = len(ans) print(len(ans)) for i in range(h): print(ans[i], end=" ")
FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
n = int(input()) def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) length = 0 product = 1 P = [] for i in range(1, n): if gcd(i, n) == 1: product = product * i % n P.append(i) length += 1 if product == n - 1 and n != 2: P.pop() length -= 1 print(length) print(*P)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Now you get Baby Ehab's first words: "Given an integer $n$, find the longest subsequence of $[1,2, \ldots, n-1]$ whose product is $1$ modulo $n$." Please solve the problem. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly all) elements. The product of an empty subsequence is equal to $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- The first line should contain a single integer, the length of the longest subsequence. The second line should contain the elements of the subsequence, in increasing order. If there are multiple solutions, you can print any. -----Examples----- Input 5 Output 3 1 2 3 Input 8 Output 4 1 3 5 7 -----Note----- In the first example, the product of the elements is $6$ which is congruent to $1$ modulo $5$. The only longer subsequence is $[1,2,3,4]$. Its product is $24$ which is congruent to $4$ modulo $5$. Hence, the answer is $[1,2,3]$.
import sys input = sys.stdin.readline def egcd(a, b): if a == 0: return b, 0, 1 else: g, y, x = egcd(b % a, a) return g, x - b // a * y, y def modinv(a, m): g, x, y = egcd(a, m) if g != 1: return 0 else: return x % m n = int(input()) a = [1] b = [] for i in range(2, n): x = modinv(i, n) if x != 0: if x != i: a.append(i) else: b.append(i) l = len(b) if l > 1: a.extend(b) a.sort() print(len(a)) print(*a)
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
from sys import stdin input = stdin.buffer.readline for _ in range(int(input())): n, l, r = map(int, input().split()) l -= 1 r -= 1 flag, tmp, s = 1, 0, 0 ans = [] x, y = n, n - 1 for i in range(1, n): s += 2 * (n - i) if l < s and flag: x, tmp = i, (i > 1) * (s - 2 * (n - i)) l -= tmp flag = 0 if r < s: y = i r -= tmp break if x > y: l, r = 0, 0 for i in range(x, y + 1): for j in range(i + 1, n + 1): ans.append(i) ans.append(j) ans.append(1) print(*ans[l : r + 1])
ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
t = int(input()) def query(i, n, x): if x % 2 == 1: return i else: return i + x // 2 for _ in range(t): n, l, r = map(int, input().split()) i = 1 s = 0 includeOne = False if r == n * (n - 1) + 1: includeOne = True r -= 1 if l == n * (n - 1) + 1: print(1) continue while s + 2 * (n - i) < l: s += 2 * (n - i) i += 1 newS = s allIs = [i] while newS + 2 * (n - i) < r: newS += 2 * (n - i) i += 1 allIs.append(i) allIin = 0 answer = [] i = allIs[0] for x in range(l, r + 1): r = query(i, n, x - s) if r == n: s += 2 * (n - i) i += 1 answer.append(r) if includeOne: answer.append(1) print(*answer)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys readline = sys.stdin.readline def overlap(a, b, c, d): if b <= c or d <= a: return False return True T = int(readline()) Ans = [None] * T for qu in range(T): N, l, r = map(int, readline().split()) l -= 1 ans = [] num = [0] + [(2 * (N - i - 1)) for i in range(N - 1)] + [1] for i in range(1, N + 1): num[i] += num[i - 1] started = False ended = False for j in range(N): xp = num[j] xn = num[j + 1] if overlap(xp, xn, l, r): started = True if started: cnt = j + 2 for k in range(2 * (N - j - 1)): if xp + k + 1 <= l: if k & 1: cnt += 1 continue if xp + k + 1 <= r: if k % 2 == 0: ans.append(j + 1) else: ans.append(cnt) cnt += 1 else: ended = True break if ended: break if r == N * (N - 1) + 1: ans.append(1) Ans[qu] = " ".join(map(str, ans)) print("\n".join(map(str, Ans)))
IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys t = int(sys.stdin.readline()) for _ in range(t): n, l, r = map(int, sys.stdin.readline().split()) prev = 0 cur = 0 start = 1 if l == r and l == n * (n - 1) + 1: print(1) else: ans = [] while True: cur += (n - start) * 2 if l <= cur: pos = l - prev total = r - l + 1 if pos % 2 == 1: ans.append(start) total -= 1 x = start + pos // 2 + 1 while total > 0: ans.append(x) if x == n: start += 1 if start == n: start = 1 x = start total -= 1 if total > 0: ans.append(start) total -= 1 x += 1 else: x = start + pos // 2 while total > 0: ans.append(x) if x == n: start += 1 if start == n: start = 1 x = start total -= 1 if total > 0: ans.append(start) total -= 1 x += 1 break prev = cur start += 1 print(*ans)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
for _ in range(int(input())): n, left, right = tuple(map(int, input().split())) maximal = n * (n - 1) + 1 if left == maximal: print("1") continue if right == maximal: end_1 = True else: end_1 = False a = [] summa = 0 i = (n - 1) * 2 cnt = 0 while summa + i < left: summa += i i -= 2 cnt += 1 left -= summa right -= summa summa = 0 while left <= right: while left <= summa + i and left <= right: if left % 2 == 1: print(cnt + 1, end=" ") else: print(cnt + left // 2 + 1, end=" ") left += 1 left -= i right -= i summa = 0 i -= 2 cnt += 1 if i == 0 and end_1: print(1, end=" ") break print() if left > right: continue
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER STRING VAR NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
def go(): n, l, r = map(int, input().split()) tot = n * (n - 1) + 1 add = [] if r == tot: add = ["1"] r -= 1 res = [] if l <= r: cur = 0 nextg = n - 1 while cur + 2 * nextg < l: cur += 2 * nextg nextg -= 1 g = n - nextg shift = l - cur - 1 pair, par = divmod(shift, 2) pair += g + 1 while l <= r: if par == 0: res.append(g) par += 1 else: res.append(pair) par = 0 if pair < n: pair += 1 else: g += 1 pair = g + 1 l += 1 res = res + add return " ".join(map(str, res)) t = int(input()) ans = [] for _ in range(t): ans.append(str(go())) print("\n".join(ans))
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST IF VAR VAR ASSIGN VAR LIST STRING VAR NUMBER ASSIGN VAR LIST IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
T = int(input().strip()) for t in range(T): n, l, r = map(int, input().strip().split()) if l == n * (n - 1) + 1: print(1) continue k = int((2 * n - 1 - ((2 * n - 1) ** 2 - 4 * l) ** 0.5) / 2) if l <= 2 * k * n - k * (k + 1): k -= 1 if l > 2 * (k + 1) * n - (k + 1) * (k + 2): k += 1 m = 2 * k * n - k * (k + 1) s = [] k += 1 j = (l - m - 1) // 2 + k while l <= r: if l % 2 == 1: if k == n: s.append(1) else: s.append(k) else: j += 1 s.append(j) if j == n: k += 1 j = k l += 1 print(" ".join(map(str, s)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def stupid(x, n): k = (n - 1) * 2 r = 0 while x >= k: x -= k r += 1 k -= 2 return r def findl(x, n): l, r = 0, n while r - l > 1: c = (l + r) // 2 if (2 * n - 1 - c) * c <= x: l = c else: r = c return l def solve(): n, l, r = mints() res = [] f = r == n * (n - 1) + 1 r -= l + f - 1 l -= 1 x = findl(l, n) l -= (2 * n - 1 - x) * x k = (n - 1 - x) * 2 x += 1 while False: print(l, k) l -= k x += 1 k -= 2 y = x + 1 + l // 2 if l % 2: while r >= 2: res.append(y) if y == n: x += 1 y = x + 1 else: y += 1 res.append(x) r -= 2 if r != 0: res.append(y) else: while r >= 2: res.append(x) res.append(y) if y == n: x += 1 y = x + 1 else: y += 1 r -= 2 if r != 0: res.append(x) if f: res.append(1) print(" ".join(map(str, res))) for i in range(mint()): solve()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys def oracle(n, start, end): nod = 0 t = n - 1 ii = 0 while start - ii > t * 2: if t == 0: nod += 1 break nod += 1 ii += t * 2 t -= 1 if t < -10: import sys sys.exit() R = [] for cur in range(nod, n): for v in range(cur + 1, n): ii += 1 if start <= ii <= end: R.append(cur + 1) ii += 1 if start <= ii <= end: R.append(v + 1) if ii > end: return R ii += 1 if start <= ii <= end: R.append(1) return R t = int(input()) for _ in range(t): a, b, c = map(int, input().split()) x = oracle(a, b, c) print(*x)
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER IMPORT EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR RETURN VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
for i in range(int(input())): n, l, r = map(int, input().split()) l -= 1 r -= 1 c = 0 for j in range(n): if c + (n - j - 1) * 2 < l or c > r: c += (n - j - 1) * 2 continue for k in range(j + 1, n): if l <= c <= r: print(j + 1, end=" ") c += 1 if l <= c <= r: print(k + 1, end=" ") c += 1 if l <= c <= r: print(1) else: print("")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) begin = 1 while l > (n - begin) * 2 + 1: if begin == n: break l -= (n - begin) * 2 r -= (n - begin) * 2 begin += 1 if begin == n: ans = [n, 1] else: ans = [] while len(ans) <= r: if begin == n: ans.append(1) break for j in range(begin + 1, n + 1): ans.append(begin) ans.append(j) begin += 1 print(*ans[l - 1 : r])
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
def check(x, n, l): val = 2 * n * x - x * x - x if val < l: return True return False def solve(n, l, r, ans): low = 1 high = n - 1 x = 0 while low <= high: mid = (low + high) // 2 if check(mid, n, l): x = mid low = mid + 1 else: high = mid - 1 val = 2 * n * x - x * x - x rem = l - val temp = True prev = True for i in range(rem - 1): if prev: if temp: x += 1 y = x else: y += 1 temp = False if y == n: temp = True prev = not prev arr = [] for i in range(r - l + 1): if prev: if temp: x += 1 y = x if x == n: x = 1 arr.append(x) else: temp = False y += 1 arr.append(y) if y == n: temp = True prev = not prev ans.append(arr) def main(): t = int(input()) ans = [] for i in range(t): n, l, r = map(int, input().split()) solve(n, l, r, ans) for i in ans: for j in i: print(j, end=" ") print() main()
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
def solve(): n, l, r = [int(i) for i in input().split()] seq = [] i = 1 while l <= r: while l > 2 * n - 2: if l == 3: i = 1 break l -= 2 * n - 2 r -= 2 * n - 2 n -= 1 i += 1 if l % 2 == 0: seq.append(l // 2 + i) else: seq.append(i) l += 1 return " ".join(str(i) for i in seq) T = int(input()) for _ in range(T): print(solve())
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR WHILE VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n, l, r = map(int, input().split()) lb, ub = 0, n while ub - lb > 1: m = (lb + ub) // 2 if m * (2 * n - m - 1) < l: lb = m else: ub = m i = ub s = lb * (2 * n - lb - 1) + 1 j = (l - s + 1) // 2 + i ans = [] for k in range(l, r + 1): if i == n: i = 1 if (k - s) % 2 == 0: ans.append(i) j += 1 else: ans.append(j) if j == n: s = k + 1 i += 1 j = i print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given a complete directed graph $K_n$ with $n$ vertices: each pair of vertices $u \neq v$ in $K_n$ have both directed edges $(u, v)$ and $(v, u)$; there are no self-loops. You should find such a cycle in $K_n$ that visits every directed edge exactly once (allowing for revisiting vertices). We can write such cycle as a list of $n(n - 1) + 1$ vertices $v_1, v_2, v_3, \dots, v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1$ β€” a visiting order, where each $(v_i, v_{i + 1})$ occurs exactly once. Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists. Since the answer can be too large print its $[l, r]$ segment, in other words, $v_l, v_{l + 1}, \dots, v_r$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 100$) β€” the number of test cases. Next $T$ lines contain test cases β€” one per line. The first and only line of each test case contains three integers $n$, $l$ and $r$ ($2 \le n \le 10^5$, $1 \le l \le r \le n(n - 1) + 1$, $r - l + 1 \le 10^5$) β€” the number of vertices in $K_n$, and segment of the cycle to print. It's guaranteed that the total sum of $n$ doesn't exceed $10^5$ and the total sum of $r - l + 1$ doesn't exceed $10^5$. -----Output----- For each test case print the segment $v_l, v_{l + 1}, \dots, v_r$ of the lexicographically smallest cycle that visits every edge exactly once. -----Example----- Input 3 2 1 3 3 3 6 99995 9998900031 9998900031 Output 1 2 1 1 3 2 3 1 -----Note----- In the second test case, the lexicographically minimum cycle looks like: $1, 2, 1, 3, 2, 3, 1$. In the third test case, it's quite obvious that the cycle should start and end in vertex $1$.
def genGroup(lo, n): if lo == n: return [1] s = [] for i in range(lo + 1, n + 1): s.append(lo) s.append(i) return s for tc in range(int(input())): n, beg, end = map(int, input().split()) if beg == n * (n - 1) + 1: print(1) else: past = 0 i = 1 while past + 2 * (n - i) < beg: past += 2 * (n - i) i += 1 group = i s = genGroup(group, n) pos = beg - past - 1 res = [] for i in range(end - beg + 1): res.append(s[pos]) pos += 1 if pos == len(s): pos = 0 group += 1 s = genGroup(group, n) print(*res)
FUNC_DEF IF VAR VAR RETURN LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR