description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
from sys import stdin, stdout n = int(stdin.readline()) for nn in range(n): a, b, m = map(int, stdin.readline().split()) if a == b: stdout.write("{} {}\n".format(1, a)) else: for j in range(2, 51): if a + 1 << j - 2 <= b and b <= a + m << j - 2: B = b b -= a << j - 2 stdout.write("{} {}".format(j, a)) s = a for i in range(j - 2): left = 1 right = m while left < right: k = (left + right + 1) // 2 if b - (k << j - 3 - i) >= 1 << j - 3 - i: left = k else: right = k - 1 a = s + left stdout.write(" {}".format(a)) s += a b -= left << j - 3 - i stdout.write(" {}\n".format(B)) break else: stdout.write("-1\n")
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 IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR STRING
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
for _ in range(int(input())): a, b, m = [int(i) for i in input().split()] if a == b: print("1 " + str(a)) continue l = a + 1 r = a + m cnt = 1 while r < b: l += l r += r cnt += 1 if l > b: print(-1) continue ls = [1] * cnt p2 = [(2 ** (cnt - 2 - i)) for i in range(cnt - 1)] + [1] for i in range(cnt): tmp = min((b - l) // p2[i], m - 1) ls[i] += tmp l += tmp * p2[i] ans = [a] ps = a for i in ls: a = ps + i ps += a ans += [a] print(str(cnt + 1) + " " + " ".join(str(i) for i in ans))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR LIST VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input().strip()) for i in range(q): a, b, m = map(int, input().strip().split()) p = a + 1 q = a + m c = 1 pos = 0 q = 0 if b == a: print(1, a) else: while b / c > a + m: c = c << 1 q += 1 if b / c >= a + 1: pos = 1 if pos: d = c * a l = [(1) for i in range(q + 1)] ll = [(ii - 1) for ii in range(q + 1)] ll[0] += 1 s = b - d - c pp = q while s > 0: l[pp] += min(s // pow(2, ll[pp]), m - 1) s = s - (l[pp] - 1) * pow(2, ll[pp]) pp -= 1 ss = a po = a print(q + 2, end=" ") print(ss, end=" ") for i in range(q + 1): ss = po + l[q - i] print(ss, end=" ") po = po + ss print() else: print(-1)
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 ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR WHILE BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) powers = [1] for i in range(50): powers.append(powers[-1] * 2) for _ in range(q): a, b, m = [int(x) for x in input().split()] if a == b: print(1, a) elif m == 1: good = False for r in range(50): if powers[r] * (a + 1) > b: break elif powers[r] * (a + 1) == b: good = True power = r break if good: print(power + 2, end=" ") print(a, end=" ") for j in range(r): print((a + 1) * powers[j], end=" ") print((a + 1) * powers[r]) else: print(-1) else: terms = 0 for r in range(50): if powers[r] * (a + 1) > b: break elif powers[r] * (a + m) >= b: terms = r + 2 break if terms == 0: print(-1) else: components = terms - 1 p = components - 1 X = b - powers[p] * a C = [0] for q in range(components): if q != components - 1: C.append(min(X // powers[p - q - 1], m)) X -= powers[p - q - 1] * C[-1] if q < components - 1 and X < powers[p - q - 1]: X += powers[p - q - 1] C[-1] -= 1 else: C.append(X) T = [a, a + C[1]] for l in range(1, components): T.append(T[-1] * 2 + C[l + 1] - C[l]) print(terms, end=" ") for e in T: if e != T[-1]: print(e, end=" ") else: print(e)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING FOR VAR VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
def solve(a, b, m): if a == b: return [a] for _len in range(2, 51): l = (a + 1) * 2 ** (_len - 2) r = (a + m) * 2 ** (_len - 2) if b < l or b > r: continue res = [] res += [a] s = a for i in range(1, _len - 1): L = 0 R = m + 1 while R - L > 1: M = int((L + R) // 2) l = (s + s + M + 1) * 2 ** (_len - i - 2) r = (s + s + M + m) * 2 ** (_len - i - 2) if r < b: L = M else: R = M x = s + R res += [x] s += x res += [b] return res tc = int(input()) for _ in range(tc): a, b, m = map(int, input().split()) res = solve(a, b, m) if res: print(len(res), end=" ") for i in res: print(i, end=" ") print() else: print(-1)
FUNC_DEF IF VAR VAR RETURN LIST VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR LIST VAR LIST VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR LIST VAR VAR VAR VAR LIST VAR 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 IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) po = [1, 1, 2] l = 4 for i in range(55): po.append(l) l *= 2 while q > 0: q -= 1 a, b, m = map(int, input().split()) se = 0 for ub in range(1, 51): s = sum(po[: ub - 1]) if b < s + po[ub - 1] * a: print(-1) se = 2 break if b <= s * m + po[ub - 1] * a: k = b - po[ub - 1] * a - po[ub - 1] arr = [] for j in range(1, ub): i = k // po[ub - 1 - j] i = min(m - 1, i) k -= i * po[ub - 1 - j] arr.append(i + 1) print(ub, a, end=" ") s = a k = [] for i in arr: k.append(s + i) s += s + i print(" ".join([str(i) for i in k])) se = 2 break if se != 2: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) for u in range(q): a, b, m = map(int, input().split()) ranges = [(a, a)] bigsum = a smlsum = a while ranges[-1][1] < b: ranges.append((smlsum + 1, bigsum + m)) smlsum = 2 * smlsum + 1 bigsum = 2 * bigsum + m if b < ranges[-1][0]: print(-1) else: seq = [a] leng = len(ranges) power = 2 ** (leng - 3) curr = (a + 1) * 2 ** (leng - 2) sumi = a for i in range(leng - 2): seq.append(sumi + max(min((b - curr) // power + 1, m), 1)) power //= 2 sumi += seq[-1] curr = (sumi + 1) * 2 ** (leng - i - 3) if b != seq[-1]: seq.append(b) out = [leng] + seq out = [str(guy) for guy in out] print(" ".join(out))
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 LIST VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
def solve(): a, b, m = (int(x) for x in input().split()) if a == b: print(1, a) return curr = a curr_const = 1 steps_nr = 0 while b - curr > curr_const * m: curr *= 2 curr_const *= 2 steps_nr += 1 if b - curr < curr_const: print(-1) return left = b - curr - curr_const ans = [a] sum = a curr_const //= 2 while curr_const > 0: curr_try = left // curr_const curr_try = min(m - 1, curr_try) left -= curr_try * curr_const ans.append(sum + curr_try + 1) sum += ans[-1] curr_const //= 2 curr_const = 1 curr_try = left // curr_const curr_try = min(m - 1, curr_try) left -= curr_try * curr_const ans.append(sum + curr_try + 1) sum += ans[-1] curr_const //= 2 print(len(ans), *ans) q = int(input()) for _ in range(q): solve()
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
import sys from itertools import count def debug(*args, **kwargs): import sys def solve(a, b, m): if a == b: return [a] debug(a=a, b=b, m=m) for k in count(2): lo = 2 ** (k - 2) * a + 2 ** (k - 2) hi = 2 ** (k - 2) * a + 2 ** (k - 2) * m debug(k=k, lo=lo, hi=hi) if lo > b: break if b <= hi: ans = [a] + [(2 ** (i - 1) * a + 2 ** (i - 1)) for i in range(1, k)] debug("got one", start=ans) if m == 1: return ans for i in range(1, k - 1): deficit = b - ans[-1] quot = min(deficit // 2 ** (k - 2 - i), m - 1) ans[i] += quot for j in range(i + 1, k): ans[j] += 2 ** (j - i - 1) * quot ans[-1] = b return ans return None def check(a, b, m, ans): assert ans[-1] == b for i in range(1, len(ans)): assert 1 <= ans[i] - sum(ans[:i]) <= m def test_solve(a, b, m): if a > b: a, b = b, a ans = solve(a, b, m) if ans is None: return check(a, b, m, ans) def main(): q = int(input()) for _ in range(q): a, b, m = map(int, input().split()) ans = solve(a, b, m) debug(a=a, b=b, m=m, ans=ans) if ans: check(a, b, m, ans) print(len(ans), *ans) else: print(-1) main()
IMPORT FUNC_DEF IMPORT FUNC_DEF IF VAR VAR RETURN LIST VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR STRING VAR IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER VAR RETURN VAR RETURN NONE FUNC_DEF VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE RETURN EXPR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF 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 VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
def find_k(A, B, M): for k in range(2, 51): s = 2 ** (k - 2) if (A + 1) * s <= B and (A + M) * s >= B: return k return -1 def solve(A, B, M): if A == B: print("1", A) return k = find_k(A, B, M) if k == -1: print(-1) return print(k, end=" ") a = A print(A, end=" ") R = B - 2 ** (k - 2) * A for i in range(k - 3, -1, -1): s = 2**i r = min(R // s - 1, M) print(a + r, end=" ") a += a + r R -= r * s assert 0 < R <= M print(B) Q = int(input()) for case in range(Q): A, B, M = [int(x) for x in input().split()] solve(A, B, M)
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR STRING VAR RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
for _ in range(int(input())): a, b, m = map(int, input().split()) if a == b: print(1, a) continue for k in range(2, 51): pw = 1 << k - 2 mn = pw * (a + 1) mx = pw * (a + m) if mn <= b <= mx: r = [0] * (k + 1) add = b - mn r[1] = a for i in range(2, k): r[i] = min(m - 1, add // (1 << k - i - 1)) add -= r[i] * (1 << k - i - 1) r[i] += 1 r[k] = add + 1 x = [0] * (k + 1) s = 0 for i in range(1, k + 1): x[i] = s + r[i] s += x[i] print(k, *x[1:], sep=" ") break else: print(-1)
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 VAR EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) for i in range(q): a, b, m = list(map(int, input().split())) l = a + 1 r = a + m c = 0 poziom = 0 if a == b: print(1, a, end="\n") continue while True: if l > b: print(-1) break if b <= r and b >= l: c = 1 last = [l, r] break poziom += 1 l *= 2 r *= 2 if c == 1: mat = [((a + 1) * 2**i) for i in range(poziom + 1)] sumka = a for i in range(poziom + 1): if mat[-1] == b: break elif i == poziom: mat[-1] = b break else: pom = min(sumka + m - mat[i], (b - mat[-1]) // 2 ** (poziom - i - 1)) mat[i] += pom for j in range(i + 1, poziom + 1): mat[j] += pom * 2 ** (j - i - 1) sumka += mat[i] print(len(mat) + 1, end=" ") print(a, end=" ") for i in range(len(mat)): if i < len(mat) - 1: print(mat[i], end=" ") else: print(mat[i], end="\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR STRING WHILE NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR STRING
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) def prepare_sequence(a, b, curr_two_pow, m): sequence = [a] curr_pow = 1 diff = b - curr_two_pow * a while curr_two_pow > 1: m_candidate = 1 diff -= m_candidate while diff > curr_two_pow // 2: m_candidate *= 2 diff = diff - (m_candidate - m_candidate // 2) if diff < curr_two_pow // 2: m_candidate //= 2 diff = diff + m_candidate curr_candidate = m_candidate // (curr_two_pow // 2) if curr_candidate > m: diff = diff + (curr_candidate - m) * (curr_two_pow // 2) curr_candidate = m sequence.append(sum(sequence) + curr_candidate) curr_pow *= 2 curr_two_pow //= 2 sequence.append(b) return sequence def satisfies(a, b, m): if a == b: return [a] curr_two_pow = 1 while curr_two_pow * a < b: diff = b - curr_two_pow * a if diff >= curr_two_pow and diff <= curr_two_pow * m: return prepare_sequence(a, b, curr_two_pow, m) curr_two_pow *= 2 return None for i in range(q): a, b, m = map(int, input().split()) res = satisfies(a, b, m) if res: print("%s %s" % (len(res), " ".join(map(str, res)))) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR WHILE VAR NUMBER ASSIGN VAR NUMBER VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN LIST VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER RETURN NONE 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 IF VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
from sys import stdin, stdout for q in range(int(input())): a, b, m = map(int, input().split()) if a == b: print(1, a) continue k = 2 while k <= 50 and not (1 << k - 2) * (a + 1) <= b <= (1 << k - 2) * (a + m): k += 1 if k > 50: print(-1) continue t = b - (1 << k - 2) * (a + 1) add = [1] * (k - 1) add[0] = a for i in range(1, k - 1): l = 1 r = m while r - l > 1: x = l + r >> 1 if t >= (1 << k - 2 - i) * (x - 1): l = x else: r = x - 1 add[i] = r if t >= (1 << k - 2 - i) * (r - 1) else l t -= (1 << k - 2 - i) * (add[i] - 1) ans = [a] * (k - 1) for i in range(1, k - 1): ans[i] = ans[i - 1] * 2 - add[i - 1] + add[i] print(k, " ".join(str(i) for i in ans), b)
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 VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
def creat_r(X, k, m, p): q = X // p[k] r = X % p[k] R = [] for _ in range(k + 1): R.append(q) s = bin(r)[2:] for i in range(1, len(s) + 1): if s[-i] == "1": R[-(i + 1)] += 1 return R i = 1 p = [1] for _ in range(50): i *= 2 p.append(i) T = int(input()) ans = [] for _ in range(T): a, b, m = map(int, input().split()) if a == b: print(1, a) continue flg = False for i in range(50): if p[i] * a >= b: break k = i X = b - p[i] * a if X >= p[k] and X <= p[k] * m: flg = True R = creat_r(X, k, m, p) sR = 0 A = [a] for _ in range(k + 1): A.append(p[_] * a + sR + R[_]) sR += sR + R[_] print(len(A), end=" ") for x in A: print(x, end=" ") print() break if flg == False: print(-1)
FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
import sys input = sys.stdin.readline q = int(input()) Q = [list(map(int, input().split())) for i in range(q)] for a, b, m in Q: MIN = [a] MAX = [a] SUMMIN = a SUMMAX = a flag = 1 for k in range(51): if MIN[-1] <= b <= MAX[-1]: break MIN.append(SUMMIN + 1) MAX.append(SUMMAX + m) SUMMIN += MIN[-1] SUMMAX += MAX[-1] if MIN[-1] > 10**14 or MIN[-1] > b: flag = 0 break if flag == 0: print(-1) continue SA = b - MIN[-1] PLUS = [0] * k for j in range(k): x = SA // max(1, 2 ** (k - j - 2)) if x > m - 1: x = m - 1 PLUS[j] = x + 1 SA -= x * max(1, 2 ** (k - j - 2)) ANS = [a] SUM = a for j in range(k): ANS.append(SUM + PLUS[j]) SUM += ANS[-1] print(len(ANS), *ANS)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER BIN_OP NUMBER NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Given a positive integer $m$, we say that a sequence $x_1, x_2, \dots, x_n$ of positive integers is $m$-cute if for every index $i$ such that $2 \le i \le n$ it holds that $x_i = x_{i - 1} + x_{i - 2} + \dots + x_1 + r_i$ for some positive integer $r_i$ satisfying $1 \le r_i \le m$. You will be given $q$ queries consisting of three positive integers $a$, $b$ and $m$. For each query you must determine whether or not there exists an $m$-cute sequence whose first term is $a$ and whose last term is $b$. If such a sequence exists, you must additionally find an example of it. -----Input----- The first line contains an integer number $q$ ($1 \le q \le 10^3$)Β β€” the number of queries. Each of the following $q$ lines contains three integers $a$, $b$, and $m$ ($1 \le a, b, m \le 10^{14}$, $a \leq b$), describing a single query. -----Output----- For each query, if no $m$-cute sequence whose first term is $a$ and whose last term is $b$ exists, print $-1$. Otherwise print an integer $k$ ($1 \le k \leq 50$), followed by $k$ integers $x_1, x_2, \dots, x_k$ ($1 \le x_i \le 10^{14}$). These integers must satisfy $x_1 = a$, $x_k = b$, and that the sequence $x_1, x_2, \dots, x_k$ is $m$-cute. It can be shown that under the problem constraints, for each query either no $m$-cute sequence exists, or there exists one with at most $50$ terms. If there are multiple possible sequences, you may print any of them. -----Example----- Input 2 5 26 2 3 9 1 Output 4 5 6 13 26 -1 -----Note----- Consider the sample. In the first query, the sequence $5, 6, 13, 26$ is valid since $6 = 5 + \bf{\color{blue} 1}$, $13 = 6 + 5 + {\bf\color{blue} 2}$ and $26 = 13 + 6 + 5 + {\bf\color{blue} 2}$ have the bold values all between $1$ and $2$, so the sequence is $2$-cute. Other valid sequences, such as $5, 7, 13, 26$ are also accepted. In the second query, the only possible $1$-cute sequence starting at $3$ is $3, 4, 8, 16, \dots$, which does not contain $9$.
q = int(input()) for _ in range(q): a, b, m = [int(x) for x in input().split()] if a == b: print("1 ", a) continue found = 0 for n in range(2, 51): lo = 2 ** (n - 2) * (a + 1) hi = 2 ** (n - 2) * (a + m) if lo <= b and b <= hi: b -= lo print(n, a, "", end="") acc = a for i in range(2, n + 1): p = 1 if i + 1 >= n else 2 ** (n - i - 1) left = 1 right = m res = 1 while left <= right: mid = (left + right) // 2 if p * mid - p <= b: res = max(res, mid) left = mid + 1 else: right = mid - 1 b += p b -= p * res print(acc + res, "", end="") acc += acc + res print("") found = 1 break if not found: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING STRING VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t >= 1: t -= 1 n = int(input()) arr = [(0) for i in range(n + 2)] ind = [(True) for i in range(n + 2)] for i in range(n): l, r = map(int, input().split(" ")) arr[l] += 1 arr[r + 1] -= 1 if i + 1 >= l and i + 1 <= r: ind[i + 1] = False ans = 0 l = [] for i in range(1, n + 1): arr[i] += arr[i - 1] if arr[i] == n - 1 and ind[i] == True: ans += 1 l.append(i) print(ans) for each in l: print(each)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) def update(l, r, range_sum): if l > r: return range_sum[l] += 1 range_sum[r + 1] -= 1 while t: t -= 1 n = int(input()) range_sum = [0] * (n + 1) curr_person = 0 notthief = set() while curr_person < n: l, r = [int(x) for x in input().split(" ")] l -= 1 r -= 1 if curr_person >= l and curr_person <= r: notthief.add(curr_person) update(l, curr_person - 1, range_sum) update(curr_person + 1, r, range_sum) else: update(l, r, range_sum) curr_person += 1 cum_sum = 0 result = [] for curr in range_sum[:-1]: cum_sum += curr result.append(cum_sum) maybe_theif = [] for idx, freq in enumerate(result): if freq == n - 1: if idx not in notthief: maybe_theif.append(idx) print(len(maybe_theif)) for theif in maybe_theif: print(theif + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for _ in range(t): n = int(input()) a = [] for i in range(n): a.append(list(map(int, input().split()))) newa = set() j = 1 for i in a: if i[0] <= j and i[1] >= j: newa.add(j) j += 1 now = [(0) for i in range(n)] for i in a: now[i[0] - 1] += 1 if i[1] < n: now[i[1]] -= 1 for i in range(1, n): now[i] = now[i] + now[i - 1] ans = [] for i in newa: now[i - 1] = 0 c = max(now) for i in range(n): if now[i] == c: ans.append(i + 1) ans.sort() print(len(ans)) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def solve(n, qr): arr = [(0) for i in range(n + 1)] for val in qr: arr[val[0] - 1] += 1 arr[val[1]] -= 1 for i in range(1, n + 1): arr[i] += arr[i - 1] return arr def ans(arr, qr, n): te = [] for i in range(n): if qr[i][0] - 1 <= i <= qr[i][1] - 1: arr[i] -= 1 if arr[i] == n: te.append(i + 1) arr[i] += 1 else: arr[i] += 1 if arr[i] == n: te.append(i + 1) arr[i] -= 1 return te for i in range(int(input())): n = int(input()) quer = [] for i in range(n): v1, v2 = map(int, input().split()) quer.append((v1, v2)) arr = solve(n, quer) sol = ans(arr, quer, n) print(len(sol)) for val in sol: print(val)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) freq = [(0) for i in range(n + 1)] l = n h = 0 d1 = {} for i in range(1, n + 1): a, b = map(int, input().split()) if a < l: l = a if b > h: h = b freq[a] = freq[a] + 1 if b < n: freq[b + 1] = freq[b + 1] - 1 if i >= a and b >= i: d1[i] = 1 for i in range(l, h + 1): freq[i] = freq[i] + freq[i - 1] ans = 0 l1 = [] for i in range(1, n + 1): if freq[i] == n - 1 and d1.get(i) == None: ans += 1 l1.append(i) print(ans) for i in l1: print(i) print()
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NONE VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) arr = [0] * (n + 1) d = dict() for i in range(n): l, r = map(int, input().split()) l, r = l - 1, r - 1 arr[l] += 1 arr[r + 1] -= 1 d[i] = l, r cur = arr[0] for i in range(1, n + 1): arr[i] = cur + arr[i] cur = arr[i] res = [] for i in range(n): if arr[i] == n - 1: u, v = d[i] if not (i >= u and i <= v): res.append(i + 1) print(len(res)) for i in res: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t > 0: n = int(input()) a = [] for i in range(n): a.append([int(i) for i in input().split()]) ls = [a[i][0] for i in range(len(a))] rs = [a[i][1] for i in range(len(a))] ls, rs = sorted(ls), sorted(rs) k = [] for i in range(1, n + 1): if i < a[i - 1][0] or i > a[i - 1][1]: l, r = ls[-1], rs[0] if a[i - 1][0] == ls[-1]: l = ls[-2] if a[i - 1][1] == rs[0]: r = rs[1] if i <= r and i >= l: k.append(i) print(len(k)) k = sorted(k) for i in range(len(k)): print(k[i]) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST 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 NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) thief = [0] * (n + 1) lst = [] for x in range(n): x, y = map(int, input().split()) lst.append([x, y]) thief[x - 1] += 1 thief[y] -= 1 for x in range(1, n + 1): thief[x] += thief[x - 1] rslt = [] cnt = 0 for x in range(1, 1 + n): y = lst[x - 1][0] z = lst[x - 1][1] if thief[x - 1] == n - 1 and (x < y or x > z): rslt.append(x) cnt += 1 print(cnt) print(*rslt, sep="\n")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER 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 LIST VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) arr = [0] * (n + 1) s = set() for i in range(n): a, b = map(int, input().split()) if a <= i + 1 <= b: s.add(i + 1) arr[a - 1] += 1 arr[b] -= 1 for i in range(1, n + 1): arr[i] += arr[i - 1] ans = [] for i in range(len(arr)): if arr[i] == n - 1 and i + 1 not in s: ans += [i + 1] print(len(ans)) print(*ans, sep="\n")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for _ in range(t): n = int(input()) votes = [0] * (n + 1) candidates = [] for i in range(n): left, right = list(map(int, input().split())) left -= 1 right -= 1 votes[left] += 1 votes[right + 1] -= 1 if i < left or i > right: candidates.append(i + 1) for i in range(1, n + 1): votes[i] += votes[i - 1] res = [] for candidate in candidates: if votes[candidate - 1] == n - 1: res.append(candidate) print(len(res)) for candidate in res: print(candidate)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP 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 VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) ans = [] nums = [] people = [0] * (n + 1) for i in range(n): l, r = map(int, input().split()) nums.append([l, r]) people[l] += 1 if r < n: people[r + 1] -= 1 for i in range(2, n + 1): people[i] += people[i - 1] for i in range(1, n + 1): if people[i] == n - 1 and (i < nums[i - 1][0] or i > nums[i - 1][1]): ans.append(i) print(len(ans)) for i in ans: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for _ in range(t): n = int(input()) l1 = [] ans = [] for i in range(n): j, k = map(int, input().split()) l1.append([j, k]) for i in range(0, n): l, r = l1[i][0], l1[i][1] if i + 1 >= l and i + 1 <= r: continue temp = l1.copy() temp.pop(i) for y in temp: l, r = y[0], y[1] if i + 1 < l or i + 1 > r: break else: ans.append(i + 1) print(len(ans)) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for h in range(int(input())): n = int(input()) x = [0] * (n + 1) z = [] v = [] for i in range(n): a, b = map(int, input().split()) a, b = a - 1, b - 1 z.append([a, b]) x[a] += 1 x[b + 1] -= 1 x[-1] = 0 for i in range(n): x[i] += x[i - 1] if x[i] == n - 1 and (i < z[i][0] or i > z[i][1]): v.append(i + 1) print(len(v)) for i in v: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t: k = int(input()) m = [0] * (k + 2) low = [0] high = [0] r = [] for g in range(1, k + 1): i, j = map(int, input().split()) low.append(i) high.append(j) m[i] += 1 m[j + 1] -= 1 for i in range(1, k + 1): m[i] += m[i - 1] for i in range(1, k + 1): if m[i] == k - 1: if not (low[i] <= i and high[i] >= i): r.append(i) print(len(r)) for i in sorted(r): print(i, end="\n") t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
from itertools import groupby T = int(input()) for _ in range(T): N = int(input()) events = [] a = [] for i in range(N): L, R = list(map(int, input().split())) a.append((L, R)) events.append((L, 1)) events.append((R + 1, -1)) for i in range(1, N + 1): events.append((i, 0)) events.sort() cnt = 0 answer = [] for i, group in groupby(events, key=lambda x: x[0]): for x in group: cnt += x[1] if i != N + 1: answer.append(cnt) K = 0 possible = [] for i in range(N): if answer[i] == N - 1 and (i + 1 < a[i][0] or i + 1 > a[i][1]): possible.append(i + 1) K += 1 print(K) for p in possible: print(p)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST 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 VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for _ in range(t): n = int(input()) L = [0] * (n + 1) M = [] for i in range(n): a, b = map(int, input().split()) M.append((a, b)) for i in range(n): a, b = M[i] j = i + 1 L[a - 1] += 1 L[b] -= 1 for i in range(1, n): L[i] += L[i - 1] for i in range(n): a, b = M[i] j = i + 1 if j < a or j > b: L[i] += 1 else: L[i] -= 1 ans = [] for i in range(n): if L[i] == n: ans.append(i + 1) print(len(ans)) for i in range(len(ans)): print(ans[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for i in range(t): n = int(input()) votes = [(0) for i in range(n)] cand = [] for i in range(n): l, r = list(map(int, input().split())) l -= 1 r -= 1 votes[l] = votes[l] + 1 if r + 1 < n: votes[r + 1] = votes[r + 1] - 1 if i < l or i > r: cand.append(i + 1) for i in range(1, n): votes[i] = votes[i - 1] + votes[i] li = [] cnt = 0 for i in range(len(votes)): if votes[i] == n - 1 and i + 1 in cand: cnt += 1 li.append(i + 1) li.sort() print(cnt) for i in li: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
import sys input = sys.stdin.readline M = int(1000000000.0) + 7 def solve(): n = int(input()) lr = [[(int(x) - 1) for x in input().split()] for _ in range(n)] pre = [0] * (n + 1) for i, j in lr: pre[i] += 1 pre[j + 1] -= 1 for i in range(1, n + 1): pre[i] += pre[i - 1] ans = [] for i in range(n): if pre[i] == n - 1: if lr[i][0] <= i and i <= lr[i][1]: continue ans.append(i + 1) print(len(ans)) for i in ans: print(i) for _ in range(int(input())): solve()
IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) a = [0] * (n + 1) nth = set() for i in range(1, n + 1): l, r = map(int, input().split()) a[l - 1] += 1 a[r] -= 1 if l <= i <= r: nth.add(i) for i in range(n): a[i + 1] += a[i] th = [] for i in range(1, n + 1): if i not in nth and a[i - 1] == n - 1: th.append(i) print(len(th)) for t in th: print(t)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for _ in range(t): n = int(input()) arr = [(0) for _ in range(n + 2)] ranges = {} for i in range(n): l, r = map(int, input().split()) arr[l] += 1 arr[r + 1] -= 1 ranges[i + 1] = [l, r] thieves = [] ans = 0 for i in range(1, n + 1): ans += arr[i] if (i < ranges[i][0] or i > ranges[i][1]) and ans == n - 1: thieves.append(i) print(len(thieves)) for t in thieves: print(t)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER LIST VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
T = int(input()) for i in range(T): N = int(input()) rlist = [] vals = [] for theta in range(N): L, R = map(int, input().split(" ")) rlist.append((L, R, theta + 1)) rlist.sort(key=lambda x: x[0]) ub = N for delta in range(N - 1): ub = min(ub, rlist[delta][1]) if rlist[-1][2] in range(rlist[-2][0], min(ub + 1, rlist[-1][0])): vals.append(rlist[-1][2]) rlist.sort(key=lambda x: x[1]) lb = 0 for epsilon in range(1, N): lb = max(lb, rlist[epsilon][0]) if rlist[0][2] in range(max(rlist[0][1] + 1, lb), rlist[1][1] + 1): vals.append(rlist[0][2]) print(len(vals)) vals.sort() for alpha in range(len(vals)): print(vals[alpha])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) a = [0] * (n + 2) s = set() for i in range(1, n + 2): a[i] = 0 if 443434 == 343434: print("Tanmay") for i in range(1, n + 1): l, r = [int(x) for x in input().split()] a[l] += 1 a[r + 1] -= 1 if i >= l and i <= r: s.add(i) for i in range(1, n + 1): a[i] += a[i - 1] aa = [] for i in range(1, n + 1): if a[i] == n - 1 and i not in s: aa.append(i) print(len(aa)) for i in aa: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) l = [(0) for i in range(n + 1)] q = [] for i in range(n): a, b = map(int, input().split()) q.append((a, b)) l[a - 1] += 1 l[b] -= 1 ans = [] for i in range(n): if i > 0: l[i] += l[i - 1] if q[i][0] - 1 <= i <= q[i][1] - 1: l[i] -= 1 if l[i] == n: ans.append(i + 1) l[i] += 1 else: l[i] += 1 if l[i] == n: ans.append(i + 1) l[i] -= 1 print(len(ans)) for val in ans: print(val)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER 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 VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t: n = int(input()) arr = [0] * (n + 1) l = [-1] * (n + 1) r = [-1] * (n + 1) for i in range(1, n + 1): li, ri = [int(x) for x in input().split()] l[i] = li r[i] = ri arr[li] += 1 if ri < n: arr[ri + 1] -= 1 for i in range(1, n + 1): arr[i] += arr[i - 1] ans = [] for i in range(1, n + 1): if arr[i] == n - 1 and not (l[i] <= i and i <= r[i]): ans.append(i) print(len(ans)) for el in ans: print(el) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER BIN_OP 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 ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
import sys def gcd(a, b): a, b = max(a, b), min(a, b) if b == 0: return a return gcd(b, a % b) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() t = int(input()) for _ in range(t): n = int(input()) pre = [(0) for i in range(n)] isThief = [(True) for i in range(n)] def solve(): for i in range(n): l, r = get_ints() l -= 1 r -= 1 pre[l] += 1 if r != n - 1: pre[r + 1] -= 1 if i >= l and i <= r: isThief[i] = False cnt = [pre[0] for _ in range(n)] for i in range(1, n): cnt[i] = cnt[i - 1] + pre[i] for i in range(n): if cnt[i] != n - 1: isThief[i] = False res = isThief.count(True) print(res) for i in range(n): if isThief[i]: print(i + 1) solve()
IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def update(D, l, r, x): D[l] += x D[r + 1] -= x t = int(input()) for tt in range(t): n = int(input()) a = [list(map(int, input().split())) for i in range(n)] a1 = [0] * (n + 1) for r in a: update(a1, r[0] - 1, r[1] - 1, 1) ans = 0 aa = [] for j in range(1, n): a1[j] = a1[j] + a1[j - 1] for k in range(n): if a1[k] == n - 1 and (a[k][0] > k + 1 or a[k][1] < k + 1): ans += 1 aa += [k + 1] print(ans) for y in aa: print(y)
FUNC_DEF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR LIST BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for i in range(int(input())): a = int(input()) l = [] for i in range(a): l.append(list(map(int, input().split(" ")))) r = [0] * (a + 2) choose = [] for i in range(a): if i + 1 < l[i][0] or i + 1 > l[i][1]: choose.append(i + 1) for i in range(a): r[l[i][0] - 1] += 1 r[l[i][1]] -= 1 sum = [0] * (a + 1) k = 0 for i in range(a + 1): k += r[i] sum[i] = k cnt = 0 ans = [] for i in range(len(choose)): if sum[choose[i] - 1] == a - 1: ans.append(choose[i]) print(len(ans)) print(*ans, sep="\n")
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) a = [] b = [] c = [] for j in range(n + 1): a.append(0) for i in range(n): j, k = map(int, input().split()) j -= 1 k -= 1 a[j] += 1 a[k + 1] -= 1 if i < j or i > k: b.append(1) else: b.append(0) for i in range(n): a[i + 1] = a[i] + a[i + 1] if a[i] == n - 1 and b[i] == 1: c.append(i + 1) print(len(c)) for i in c: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def fun(l, r, out, x, y, i): if x > r or y < l: if i >= l and i <= r: out.append(i) return if l < x: if i >= l and i < x: out.append(i) return if y < r: if i > y and i <= r: out.append(i) return for t in range(int(input())): n = int(input()) a = [list(int(i) for i in input().split()) for i in range(n)] f = [[0, 0] for i in range(n)] prev = [1, n] for i in range(n): f[i][0] = max(prev[0], a[i][0]) f[i][1] = min(prev[1], a[i][1]) prev[0] = f[i][0] prev[1] = f[i][1] b = [[0, 0] for i in range(n)] b.append([-n - 1, n + 1]) prev = [1, n] for i in range(n - 1, -1, -1): b[i][0] = max(prev[0], a[i][0]) b[i][1] = min(prev[1], a[i][1]) prev[0] = b[i][0] prev[1] = b[i][1] out = [] for i in range(1, n): l = max(f[i - 1][0], b[i + 1][0]) r = min(f[i - 1][1], b[i + 1][1]) if l <= r: fun(l, r, out, a[i][0], a[i][1], i + 1) if b[1][0] <= b[1][1]: fun(b[1][0], b[1][1], out, a[0][0], a[1][0], 1) c = len(out) out.sort() print(c) for i in range(c): print(out[i])
FUNC_DEF IF VAR VAR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def mi(): return map(int, input().split()) def li(): return list(mi()) def si(): return str(input()) def ni(): return int(input()) for T in range(int(input())): n = ni() final = [0] * (n + 1) potential = [] for i in range(n): l, r = mi() if not (l <= i + 1 and r >= i + 1): potential.append(i) final[l - 1] += 1 final[r] -= 1 for i in range(1, len(final)): final[i] += final[i - 1] final = final[:-1] count = [] for i in potential: if final[i] == n - 1: count.append(i + 1) print(len(count)) for i in count: print(i)
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
import sys input = lambda: sys.stdin.readline() T = int(input()) for _ in range(T): n = int(input().strip()) L = [(0) for i in range(n + 2)] dic = {} for i in range(n): l, r = map(int, input().strip().split()) dic[i] = [l, r] L[l] += 1 L[r + 1] -= 1 count = 0 ans = 0 M = [] for i in range(1, n + 1): count += L[i] if count == n - 1 and (dic[i - 1][1] < i or dic[i - 1][0] > i): ans += 1 M.append(i) print(ans) for i in M: print(i)
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def craet(n): arr = [] for i in range(n): arr.append(list(map(int, input().split()))) x = {} for i in arr: a = i[0] b = i[1] if a not in x: x[a] = [0, 0] if b not in x: x[b] = [0, 0] x[a][0] += 1 x[b][1] += 1 count = {} c = 0 for i in range(1, n + 1): if i in x: c += x[i][0] count[i] = c if i in x: c -= x[i][1] ans = [] for i in count: if count[i] == n - 1 and (i < arr[i - 1][0] or i > arr[i - 1][1]): ans.append(str(i)) print(len(ans)) print("\n".join(ans)) for i in range(int(input())): craet(int(input()))
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR LIST NUMBER NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t > 0: t -= 1 n = int(input()) arr = [(0) for _ in range(n + 1)] temp = [] for _ in range(n): l, r = list(map(int, input().split())) l -= 1 arr[l] += 1 arr[r] -= 1 temp.append([l, r - 1]) for i in range(1, n + 1): arr[i] += arr[i - 1] ans = [] for i in range(n): if i >= temp[i][0] and i <= temp[i][1]: continue if arr[i] == n - 1: ans.append(i + 1) print(len(ans)) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP 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 VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
from itertools import accumulate as acc def miis(): return map(int, input().split()) for _ in range(int(input())): n = int(input()) a = list(list(miis()) for i in range(n)) pref = [(0) for i in range(n + 1)] for i in a: l, r = i pref[l - 1] += 1 pref[r] -= 1 ac = list(acc(pref)) th = [] for i in range(n): if ac[i] == n - 1 and (a[i][0] > i + 1 or a[i][1] < i + 1): th.append(i + 1) print(len(th)) print(*th, sep="\n")
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) diff = [(0) for i in range(n + 1)] ranges = [] for i in range(n): u, v = [(int(x) - 1) for x in input().split()] ranges.append([u, v]) diff[u] += 1 diff[v + 1] -= 1 thieves = [] for i in range(1, n + 1): diff[i] += diff[i - 1] for i in range(n): if diff[i] == 0 or i >= ranges[i][0] and i <= ranges[i][1]: continue if diff[i] == n - 1: thieves.append(i + 1) print(len(thieves)) for x in thieves: print(x)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t > 0: t -= 1 n = int(input()) suspicion = [0] * n interogations = [] for i in range(n): x, y = [int(x) for x in input().split()] interogations.append((x - 1, y - 1)) x -= 1 suspicion[x] += 1 if y < n: suspicion[y] -= 1 curSum = 0 for i in range(n): curSum += suspicion[i] suspicion[i] = curSum suspects = [] for i in range(n): if suspicion[i] == n - 1 and ( interogations[i][0] > i or interogations[i][1] < i ): suspects.append(i + 1) print(len(suspects)) for i in suspects: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def initializeDiffArray(A): n = len(A) D = [(0) for i in range(0, n + 1)] D[0] = A[0] D[n] = 0 for i in range(1, n): D[i] = A[i] - A[i - 1] return D def update(D, l, r, x): D[l] += x D[r + 1] -= x def printArray(A, D): arr = [] for i in range(0, len(A)): if i == 0: A[i] = D[i] else: A[i] = D[i] + A[i - 1] arr.append(A[i]) return arr T = int(input()) while T > 0: T -= 1 n = int(input()) k = [] d = [] A = [0] * (n + 1) D = initializeDiffArray(A) for i in range(1, n + 1): l, r = map(int, input().split()) if l <= i <= r: pass else: d.append(i) update(D, l, r, 1) p = printArray(A, D) ans = [] for i in d: if p[i] == n - 1: ans.append(i) print(len(ans)) print(*ans, sep="\n")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR STRING
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) while t > 0: n = int(input()) arr = [(0) for _ in range(n + 2)] ma = {} for i in range(1, n + 1): [l, r] = [int(x) for x in input().split()] arr[l] += 1 arr[r + 1] -= 1 if i >= l and i <= r: ma[i] = True ct = 0 for i in range(1, n + 1): arr[i] += arr[i - 1] if arr[i] == n - 1 and i not in ma: ct += 1 print(str(ct)) for i in range(1, n + 1): if arr[i] == n - 1 and i not in ma: print(str(i)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def solve(intervals): start, end = intervals.pop() ans = [[start, end]] while intervals: start_temp, end_temp = intervals.pop() start = max(start, start_temp) end = min(end, end_temp) ans.append([start, end]) return ans t = int(input()) for i in range(t): N = int(input()) intervals = [] lstt = [] ans = [] faltu = [] for i in range(N): arr = [int(i) for i in input().split()] intervals.append(arr) lstt.append(arr) faltu.append(arr) arr1 = solve(intervals) lstt = lstt[::-1] arr2 = solve(lstt) z = 0 for i in range(N): if i == 0: realinfo = arr1[N - 2] elif i == N - 1: realinfo = arr2[N - 2] else: info = solve([arr2[i - 1], arr1[N - i - 2]]) realinfo = info[-1] if realinfo[1] < realinfo[0]: pass elif realinfo[0] <= i + 1 <= realinfo[1]: if faltu[i][0] <= i + 1 <= faltu[i][1]: pass else: ans.append(i + 1) z += 1 else: pass print(z) for i in ans: print(i)
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for i in range(0, t): n = int(input()) d = {} for j in range(0, n + 1): d[j] = 0 s = set() for j in range(0, n): a, b = map(int, input().split(" ")) if a <= j + 1 <= b: s.add(j + 1) d[a - 1] += 1 d[b] -= 1 ans = [] for j in range(1, n + 1): d[j] += d[j - 1] for j in range(0, n): if d[j] == n - 1 and j + 1 not in s: ans.append(j + 1) print(len(ans)) for j in ans: print(j)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def segf(arr, n): temp = [(0) for i in range(n + 1)] for lst in arr: l = lst[0] r = lst[1] temp[l - 1] += 1 temp[r] -= 1 for i in range(1, n + 1): temp[i] += temp[i - 1] count = 0 ans = [] for i in range(1, n + 1): lst = arr[i - 1] if (i < lst[0] or i > lst[1]) and temp[i - 1] == n - 1: count += 1 ans.append(i) print(count) for e in ans: print(e) t = int(input()) for i in range(t): n = int(input()) arr = [] for i in range(n): temp = list(map(int, input().split())) arr.append(temp) segf(arr, n)
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
t = int(input()) for x in range(t): n = int(input()) queries = [] a = [(0) for _ in range(n + 2)] for i in range(n): l, r = map(int, input().split()) queries.append((l, r)) a[l] += 1 a[r + 1] -= 1 for i in range(1, n + 1): a[i] += a[i - 1] st = set() for i in range(1, n + 1): if a[i] == n - 1: l, r = queries[i - 1] if l <= i <= r: continue st.add(i) ans = sorted(st) print(len(ans)) for i in ans: print(i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) l = [] call = [] mark = [0] mp = {} for i in range(1, n + 1): l.append(i) mp[i] = 0 mark.append(0) for i in range(n): a, b = map(int, input().split()) mark[a - 1] += 1 mark[b] -= 1 if i + 1 <= b and i + 1 >= a: call.append(-1) else: call.append(1) for i in range(1, n): mark[i] += mark[i - 1] max_ = 0 for i in range(n): mark[i] += call[i] max_ = max(max_, mark[i]) for i in range(n): mp[l[i]] = mark[i] ans = [] for i in range(n): if mp[l[i]] == max_: ans.append(l[i]) print(len(ans)) for i in range(len(ans)): print(ans[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
def main(): n = int(input()) prefix = [0] * (n + 10) notThief = set() for i in range(1, n + 1): l, r = map(int, input().split()) if i >= l and i <= r: notThief.add(i) prefix[l] += 1 prefix[r + 1] -= 1 arr = [] curr = 0 for i in range(1, n + 1): curr += prefix[i] arr.append(curr) ans = [] for i in range(n): if i + 1 in notThief: continue if arr[i] == n - 1: ans.append(i + 1) print(len(ans)) for z in ans: print(z) return for _ in range(int(input())): main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) arr = [] for i in range(n): arr.append(list(map(int, input().split()))) suff = [[0, 0]] * n a, b = 1, n for i in range(n - 1, -1, -1): a, b = max(a, arr[i][0]), min(b, arr[i][1]) if a <= b: suff[i] = [a, b] suff.append([1, n]) a, b = 1, n ans = [] for i in range(n): if suff[i + 1] != [0, 0]: c, d = max(a, suff[i + 1][0]), min(b, suff[i + 1][1]) if not arr[i][0] <= i + 1 <= arr[i][1] and c <= i + 1 <= d: ans.append(i + 1) a, b = max(a, arr[i][0]), min(b, arr[i][1]) print(len(ans)) for e in ans: print(e)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST LIST NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) arr, ll, rl, lr = ( [i for i in range(1, n + 1)], [(0) for i in range(n)], [(0) for i in range(n)], [], ) for i in range(n): l, r = map(int, input().split()) lr.append([l, r]) ll[l - 1] += 1 rl[r - 1] += 1 ans, l1, r1 = [max(ll[0], rl[0])], ll[0], rl[0] for i in range(1, n): ans.append(l1 + ll[i] - r1) l1 += ll[i] r1 += rl[i] ans1 = [] for i in range(1, n + 1): if lr[i - 1][0] <= i <= lr[i - 1][1]: continue if ans[i - 1] == n - 1: ans1.append(i) print(len(ans1)) for i in ans1: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR LIST FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
import sys def _input(): return sys.stdin.readline().strip() def main(): for _ in range(int(_input())): n = int(_input()) l = [None] for i in range(n): x = tuple(map(int, _input().split())) l.append(x) ans = [] for i in range(1, n + 1): x1 = l[i][0] y1 = l[i][1] if i >= x1 and i <= y1: pass else: check = True for j in range(1, n + 1): if i != j: x2 = l[j][0] y2 = l[j][1] if i >= x2 and i <= y2: pass else: check = False break if check: ans.append(i) print(len(ans)) for i in ans: print(i) main()
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
There are N people numbered from 1 to N such that: Exactly one of these people is a thief and always lies; All the others are honest and always tell the truth. If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cdots, R_{i}, determine how many people could be the thief. It is guaranteed that at least one person can be the thief. ------ Input Format ------ - First line will contain T, the number of test cases. Then the test cases follow. - First line of each test case will contain N, the number of people. N lines follow. - The i^{th} line contains two space-separated integers - L_{i} and R_{i}, the range of people amongst which the i^{th} person claims the thief is. ------ Output Format ------ - For each test case, in the first line, output K, the number of possible thieves. - In the next K lines, output the list of people that could be the thieves, in ascending order. ------ Constraints ------ $1 ≀ T ≀ 10^{5}$ $3 ≀ N ≀ 10^{5}$ $1 ≀ L_{i} ≀ R_{i} ≀ N$ - Sum of $N$ over all test cases does not exceed $10^{5}$. - It is guaranteed that at least one person can be the thief. ----- Sample Input 1 ------ 1 4 2 2 1 1 1 3 1 3 ----- Sample Output 1 ------ 2 1 2 ----- explanation 1 ------ Test case $1$: Two people (numbered $1$ and $2$) can be thief: - Person $1$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $2$ is the thief. - Person $2$ may be the thief because, the other $3$ people claim that he may be the thief, whereas, he lies and claims that person $1$ is the thief. - Person $3$ cannot be the thief because, he claims that the thief lies in the range $[1, 3]$. If he were the thief, then his statement should be false. However, since 3 lies in $[1, 3]$, his statement would be true, which results in a contradiction. Furthermore, the first $2$ people do not claim that he is the thief. Therefore, he cannot be the thief. - Person $4$ cannot be the thief because the first $3$ people do not claim that he is the thief.
for _ in range(int(input())): n = int(input()) arr = [0] * (n + 1) mapp = {} for i in range(n): s, e = map(int, input().split()) mapp[i] = s - 1, e - 1 arr[s - 1] += 1 arr[e] -= 1 s, e = mapp[0] ans = [1] if arr[0] == n - 1 and not s <= 0 <= e else [] for i in range(1, n): arr[i] += arr[i - 1] s, e = mapp[i] if arr[i] == n - 1 and not s <= i <= e: ans.append(i + 1) print(len(ans)) for i in ans: print(i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR LIST NUMBER LIST FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
T = int(input()) for i in range(0, T): N, Q = map(int, input().split()) s = [int(x) for x in input().split()] L = sorted(s) G = L[::-1] for j in range(0, Q): x, y = map(int, input().split()) ans1 = abs(s[y - 1] - s[x - 1]) + y - x print(ans1, end=" ") pos1 = 0 pos2 = N for k in range(0, len(L)): if L[k] < min(s[x - 1], s[y - 1]): pos1 = k elif L[k] == min(s[x - 1], s[y - 1]): pos1 = k break else: break for k in range(0, len(L)): if G[k] > max(s[x - 1], s[y - 1]): pos2 = N - k - 1 elif G[k] == max(s[x - 1], s[y - 1]): pos2 = N - k - 1 break else: break print(pos2 - pos1 + 1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
t = int(input()) for _ in range(t): n, q = list(map(int, input().split())) v = list(map(int, input().split())) vv = v[:] vv = [[j, i] for j, i in enumerate(v)] vv.sort(key=lambda x: x[1]) vvv = [] for jj, i in enumerate(vv): v[i[0]] = [jj, i[1]] for i in range(q): x, y = list(map(int, input().split())) x -= 1 y -= 1 xx = v[x][0] yy = v[y][0] if xx < yy: le = yy - xx + 1 cost = v[y][1] - v[x][1] cost += y - x elif xx == yy: le = 1 cost = 0 else: le = xx - yy + 1 cost = v[x][1] - v[y][1] cost -= x - y print(cost, le)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER LIST VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
def query(x1, y1, d): x, y = x1, y1 if d[y1][3] < d[x1][3]: x, y = y1, x1 summ = y1 - x1 + abs(d[y][0] - d[x][0]) mlen = d[y][2] - d[x][1] + 1 return summ, mlen INF = 10**10 t = int(input()) for tt in range(t): n, q = [int(x) for x in input().split()] v = [int(x) for x in input().split()] v.append(INF) indexed = [(i, [x, 0, 0, 0]) for x, i in zip(v, range(1, n + 2))] indexed.sort(key=lambda x: x[1][0]) scores = [x[1][0] for x in indexed] curr_left = 0 curr_right = 0 for i in range(1, n + 1): indexed[i][1][3] = i if scores[i] == scores[i - 1] and i != n: curr_right = i continue for j in range(curr_left, curr_right + 1): indexed[j][1][1] = curr_left indexed[j][1][2] = curr_right curr_left = i curr_right = i d = dict(indexed) for qq in range(q): x, y = [int(x) for x in input().split()] ans = query(x, y, d) print(ans[0], end=" ") print(ans[1])
FUNC_DEF ASSIGN VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER 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 VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST VAR NUMBER NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 VAR EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
t = int(input()) for i in range(t): n, q = input().split() cities = [int(x) for x in input().split()] cities_sort = cities.copy() cities_sort.sort() for j in range(int(q)): q1, q2 = [int(x) for x in input().split()] a = cities[q1 - 1] b = cities[q2 - 1] if a > b: c = a a = b b = c pos_a = cities_sort[::1].index(a) pos_b = len(cities_sort) - 1 - cities_sort[::-1].index(b) print(q2 - q1 + b - a, pos_b - pos_a + 1)
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 VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
def bs(arr, l, r, x, g): while l <= r: mid = l + (r - l) // 2 if arr[mid] == x: if not g: mid -= 1 while mid >= 0 and arr[mid] == x: mid -= 1 return mid + 1 else: mid += 1 while mid <= r and arr[mid] == x: mid += 1 return mid - 1 elif arr[mid] < x: l = mid + 1 else: r = mid - 1 return -1 T = int(input()) for t in range(T): N, Q = map(int, input().split()) V = list(map(int, input().split())) S = sorted(V) for q in range(Q): a, b = map(int, input().split()) a -= 1 b -= 1 mini = min(V[b], V[a]) maxi = max(V[b], V[a]) C = b - a + (maxi - mini) f = bs(S, 0, N - 1, mini, False) L = 2 + bs(S, f, N - 1, maxi, True) - f - 1 print(C, L)
FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR IF VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
for _ in range(int(input())): n, q = [int(a) for a in input().split()] v = list(map(int, input().split())) s = list(range(1, n + 1)) index_s = [x for _, x in sorted(zip(v, s))] sorted_v = sorted(v) for i in range(q): x, y = [int(a) for a in input().split()] check1 = min(x, y) get_index1 = index_s.index(check1) vx = sorted_v[get_index1] check2 = max(x, y) get_index2 = index_s.index(max(x, y)) vy = sorted_v[get_index2] length = get_index2 - get_index1 + 1 ans = vy - vx + y - x print(ans, length)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR 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 ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Firdavs is living on planet F. There are $N$ cities (numbered $1$ through $N$) on this planet; let's denote the value of city $i$ by $v_i$. Firdavs can travel directly from each city to any other city. When he travels directly from city $x$ to city $y$, he needs to pay $f(x, y) = |v_y-v_x|+y-x$ coins (this number can be negative, in which case he receives $-f(x, y)$ coins). Let's define a simple path from city $x$ to city $y$ with length $k \ge 1$ as a sequence of cities $a_1, a_2, \ldots, a_k$ such that all cities in this sequence are different, $a_1 = x$ and $a_k = y$. The cost of such a path is $\sum_{i=1}^{k-1} f(a_i, a_{i+1})$. You need to answer some queries for Firdavs. In each query, you are given two cities $x$ and $y$, and you need to find the minimum cost of a simple path from city $x$ to city $y$. Then, you need to find the length of the longest simple path from $x$ to $y$ with this cost. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $N$ and $Q$. - The second line contains $N$ space-separated integers $v_1, v_2, \ldots, v_N$. - The following $Q$ lines describe queries. Each of these lines contains two space-separated integers $x$ and $y$. -----Output----- For each query, print a single line containing two space-separated integers ― the minimum cost and the maximum length. -----Constraints----- - $1 \le T \le 100$ - $1 \le N, Q \le 2 \cdot 10^5$ - $0 \le v_i \le 10^9$ for each valid $i$ - $1 \le x, y \le N$ - the sum of $N$ in all test cases does not exceed $5 \cdot 10^5$ - the sum of $Q$ in all test cases does not exceed $5 \cdot 10^5$ -----Subtasks----- Subtask #1 (30 points): - $1 \le N, Q \le 1,000$ - $v_1 < v_2 < \ldots < v_N$ - the sum of $N$ in all test cases does not exceed $5,000$ - the sum of $Q$ in all test cases does not exceed $5,000$ Subtask #2 (70 points): original constraints -----Example Input----- 2 4 2 4 2 5 7 2 3 3 4 2 1 1 1 2 1 -----Example Output----- 4 3 3 2 -1 2 -----Explanation----- Example case 1: For the first query, there are two paths with cost $4$ from city $2$ to city $3$: - $2 \rightarrow 1 \rightarrow 3$: cost $(|4-2|+1-2)+(|5-4|+3-1) = 4$, length $3$ - $2 \rightarrow 3$: cost $|5-2|+3-2 = 4$, length $2$ All other paths have greater costs, so the minimum cost is $4$. Among these two paths, we want the one with greater length, which is $3$.
t = int(input()) for i in range(t): n, q = list(map(int, input().split())) cities = list(map(int, input().split())) for j in range(int(q)): q1, q2 = list(map(int, input().split())) a = cities[q1 - 1] b = cities[q2 - 1] if a > b: c = a a = b b = c size = 0 for c in cities: if c >= a and c <= b: size += 1 print(q2 - q1 + b - a, size)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
I = input R = str.replace P = range D = lambda: P(int(I())) T = {} d = {} def rf(s): print(s.split()) for _ in D(): s = R(R(I(), "void", ""), " ", "") t = s.find("(") k = s[:t] d[k] = d.get(k, []) + [s[t + 1 : -1].split(",")] for _ in D(): a, b = I().split() T[b] = a for _ in D(): s = R(I(), " ", "") t = s.find("(") s, v = s[:t], s[t + 1 : -1].split(",") r = 0 for p in d.get(s, []): if len(v) == len(p): for i in P(len(v)): if p[i] != "T" and p[i] != T[v[i]]: break else: r += 1 print(r)
ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR LIST LIST FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING FOR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR LIST IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
func = int(input()) fnames = [] fargs = [] for i in range(func): s = input().strip()[:-1].split("(") fnames.append(s[0].split()[1]) arr = [j.strip() for j in s[1].split(",")] fargs.append(arr) something = [] types = [] t = int(input()) for i in range(t): s = input().split() types.append(s[0]) something.append(s[1]) togive = int(input()) for i in range(togive): ss = input().strip()[:-1].split("(") fun = ss[0].strip() arr = [j.strip() for j in ss[1].split(",")] res = 0 for j in range(len(arr)): arr[j] = types[something.index(arr[j])] for f in range(func): if fnames[f] == fun and len(arr) == len(fargs[f]): sign = 0 for aaa in range(len(arr)): if arr[aaa] != fargs[f][aaa] and fargs[f][aaa] != "T": sign = 1 if sign == 0: res += 1 print(res)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
n = int(input()) funcnames = [] funcs = [] for i in range(n): x = input() funcnames.append(list(list(x.split("("))[0].split())[1].strip()) x = list(x.split("("))[1].strip()[:-1] x = list(map(str.strip, list(x.split(",")))) funcs.append(x) k = int(input()) types = {} for i in range(k): x = list(input().split()) x = list(map(str.strip, x)) types[x[1]] = x[0] m = int(input()) ans = [] for i in range(m): x = input() fname = list(x.split("("))[0].strip() fargs = list(map(str.strip, list(x.split("("))[1].strip()[:-1].split(","))) count = 0 for j in range(n): if fname == funcnames[j]: con = True for t in range(len(fargs)): if ( len(fargs) == len(funcs[j]) and t < len(funcs[j]) and (funcs[j][t] == "T" or funcs[j][t] == types[fargs[t]]) ): pass else: con = False break if con: count += 1 print(count)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR STRING NUMBER NUMBER STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR STRING VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
n = int(input()) v = dict() f, f1 = [], [] for i in range(n): t = input() t1 = "" k = t.find("d") + 1 while t[k] == " ": k += 1 t = t[k:] for i in t: if i != " ": t1 += i t = t1 t = t.split(",") t[-1] = t[-1][: str(t[-1]).find(")")] r1, r2 = t[0].split("(") t = [r1] + [r2] + t[1:] f.append(t) n = int(input()) for i in range(n): t = input() k = 0 while t[k] == " ": k += 1 t = t[k:] k = len(t) - 1 while t[k] == " ": k -= 1 t = t[: k + 1] v[t[t.rfind(" ") + 1 :]] = t[: t.find(" ")] n = int(input()) for i in range(n): t = input() t1 = "" for i in t: if i != " ": t1 += i t = t1 t = t.split(",") t[-1] = t[-1][: str(t[-1]).find(")")] r1, r2 = t[0].split("(") t = [r1] + [r2] + t[1:] ans = 0 for i in range(len(f)): if len(f[i]) == len(t): if f[i][0] == t[0]: kek = 0 for j in range(1, len(f[i])): if f[i][j] != "T": if f[i][j] != v[t[j]]: break else: kek += 1 else: kek += 1 if kek == len(f[i]) - 1: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR STRING NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP LIST VAR LIST VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR STRING VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR IF VAR STRING VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER FUNC_CALL FUNC_CALL VAR VAR NUMBER STRING ASSIGN VAR VAR FUNC_CALL VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP LIST VAR LIST VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING IF VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
n = int(input()) fu = [ input().replace(" ", "")[4:].replace("(", ",").replace(")", "").split(",") for i in range(n) ] m = int(input()) v = [input().strip().split() for i in range(m)] vd = {l[1]: l[0] for l in v} k = int(input()) c = [ input().strip().replace(" ", "").replace("(", ",").replace(")", "").split(",") for i in range(k) ] for f in c: a = 0 for f2 in fu: if f2[0] != f[0] or len(f) != len(f2): continue w = 1 for x, y in zip(f[1:], f2[1:]): if y != "T" and vd[x] != y: w = 0 break a += w print(a)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER STRING STRING STRING STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING STRING STRING VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR STRING VAR VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Recently, Valery have come across an entirely new programming language. Most of all the language attracted him with template functions and procedures. Let us remind you that templates are tools of a language, designed to encode generic algorithms, without reference to some parameters (e.g., data types, buffer sizes, default values). Valery decided to examine template procedures in this language in more detail. The description of a template procedure consists of the procedure name and the list of its parameter types. The generic type T parameters can be used as parameters of template procedures. A procedure call consists of a procedure name and a list of variable parameters. Let's call a procedure suitable for this call if the following conditions are fulfilled: * its name equals to the name of the called procedure; * the number of its parameters equals to the number of parameters of the procedure call; * the types of variables in the procedure call match the corresponding types of its parameters. The variable type matches the type of a parameter if the parameter has a generic type T or the type of the variable and the parameter are the same. You are given a description of some set of template procedures. You are also given a list of variables used in the program, as well as direct procedure calls that use the described variables. For each call you need to count the number of procedures that are suitable for this call. Input The first line contains a single integer n (1 ≀ n ≀ 1000) β€” the number of template procedures. The next n lines contain the description of the procedures specified in the following format: "void procedureName (type_1, type_2, ..., type_t)" (1 ≀ t ≀ 5), where void is the keyword, procedureName is the procedure name, type_i is the type of the next parameter. Types of language parameters can be "int", "string", "double", and the keyword "T", which denotes the generic type. The next line contains a single integer m (1 ≀ m ≀ 1000) β€” the number of used variables. Next m lines specify the description of the variables in the following format: "type variableName", where type is the type of variable that can take values "int", "string", "double", variableName β€” the name of the variable. The next line contains a single integer k (1 ≀ k ≀ 1000) β€” the number of procedure calls. Next k lines specify the procedure calls in the following format: "procedureName (var_1, var_2, ..., var_t)" (1 ≀ t ≀ 5), where procedureName is the name of the procedure, var_i is the name of a variable. The lines describing the variables, template procedures and their calls may contain spaces at the beginning of the line and at the end of the line, before and after the brackets and commas. Spaces may be before and after keyword void. The length of each input line does not exceed 100 characters. The names of variables and procedures are non-empty strings of lowercase English letters and numbers with lengths of not more than 10 characters. Note that this is the only condition at the names. Only the specified variables are used in procedure calls. The names of the variables are distinct. No two procedures are the same. Two procedures are the same, if they have identical names and identical ordered sets of types of their parameters. Output On each of k lines print a single number, where the i-th number stands for the number of suitable template procedures for the i-th call. Examples Input 4 void f(int,T) void f(T, T) void foo123 ( int, double, string,string ) void p(T,double) 3 int a string s double x123 5 f(a, a) f(s,a ) foo (a,s,s) f ( s ,x123) proc(a) Output 2 1 0 1 0 Input 6 void f(string,double,int) void f(int) void f ( T ) void procedure(int,double) void f (T, double,int) void f(string, T,T) 4 int a int x string t double val 5 f(t, a, a) f(t,val,a) f(val,a, val) solve300(val, val) f (x) Output 1 3 0 0 2
n = int(input()) funcs = [input().replace(" ", "")[4:] for i in range(n)] funcs2 = [f.replace("(", ",").replace(")", "").split(",") for f in funcs] m = int(input()) vars = [input().strip().split() for i in range(m)] vard = {l[1]: l[0] for l in vars} k = int(input()) calls = [input().strip().replace(" ", "") for i in range(k)] calls2 = [f.replace("(", ",").replace(")", "").split(",") for f in calls] for f in calls2: ans = 0 for f2 in funcs2: if f2[0] != f[0] or len(f) != len(f2): continue w = 1 for x, y in zip(f[1:], f2[1:]): if y != "T" and vard[x] != y: w = 0 break ans += w print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING STRING VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR STRING VAR VAR VAR ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm. Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new number to the end of the sequence or takes l first elements of the current sequence and adds them c times to the end. More formally, if we represent the current sequence as a1, a2, ..., an, then after we apply the described operation, the sequence transforms into a1, a2, ..., an[, a1, a2, ..., al] (the block in the square brackets must be repeated c times). A day has passed and Sereja has completed the sequence. He wonders what are the values of some of its elements. Help Sereja. Input The first line contains integer m (1 ≀ m ≀ 105) β€” the number of stages to build a sequence. Next m lines contain the description of the stages in the order they follow. The first number in the line is a type of stage (1 or 2). Type 1 means adding one number to the end of the sequence, in this case the line contains integer xi (1 ≀ xi ≀ 105) β€” the number to add. Type 2 means copying a prefix of length li to the end ci times, in this case the line further contains two integers li, ci (1 ≀ li ≀ 105, 1 ≀ ci ≀ 104), li is the length of the prefix, ci is the number of copyings. It is guaranteed that the length of prefix li is never larger than the current length of the sequence. The next line contains integer n (1 ≀ n ≀ 105) β€” the number of elements Sereja is interested in. The next line contains the numbers of elements of the final sequence Sereja is interested in. The numbers are given in the strictly increasing order. It is guaranteed that all numbers are strictly larger than zero and do not exceed the length of the resulting sequence. Consider the elements of the final sequence numbered starting from 1 from the beginning to the end of the sequence. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Print the elements that Sereja is interested in, in the order in which their numbers occur in the input. Examples Input 6 1 1 1 2 2 2 1 1 3 2 5 2 1 4 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output 1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
MAX_LEN = int(100000.0) n = int(input()) a = [list(map(int, input().split())) for i in range(n)] m = int(input()) b = list(map(lambda x: int(x) - 1, input().split())) curr, k, c, res = 0, 0, [], [] for i in range(n): t = a[i] last = curr if t[0] == 1: curr += 1 if len(c) < MAX_LEN: c.append(t[1]) if k < m and b[k] == curr - 1: res.append(t[1]) k += 1 else: curr += t[1] * t[2] while t[2] > 0 and len(c) < MAX_LEN: c.extend(c[: t[1]]) t[2] -= 1 while k < m and last <= b[k] < curr: res.append(c[(b[k] - last) % t[1]]) k += 1 print(" ".join(map(str, res[:m])))
ASSIGN VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER WHILE VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≀ 0 and the same time Master Yang's HP > 0, Master Yang wins. Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF. Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win. Input The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively. Output The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. Examples Input 1 2 1 1 100 1 1 100 100 Output 99 Input 100 100 100 1 1 1 1 1 1 Output 0 Note For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left. For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
R = lambda: map(int, input().split()) yH, yA, yD = R() mH, mA, mD = R() h, a, d = R() Q = 10**20 for A in range(max(0, mD - yA + 1), max(0, mH + mD - yA) + 1): for D in range(max(0, mA - yD) + 1): H = yH - (mH + yA + A - mD - 1) // (yA + A - mD) * max(0, mA - yD - D) Q = min(A * a + D * d + max(0, h * (1 - H)), Q) print(Q)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≀ 0 and the same time Master Yang's HP > 0, Master Yang wins. Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF. Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win. Input The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively. Output The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. Examples Input 1 2 1 1 100 1 1 100 100 Output 99 Input 100 100 100 1 1 1 1 1 1 Output 0 Note For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left. For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
hp_y, at_y, df_y = map(int, input().split()) hp_m, at_m, df_m = map(int, input().split()) cst_hp, cst_at, cst_df = map(int, input().split()) ans = 2e18 for ati in range(201): for dfi in range(201): if ati + at_y > df_m: k = hp_m // (at_y + ati - df_m) if hp_m % (at_y + ati - df_m) != 0: k += 1 t = max(0, k * (at_m - df_y - dfi) - hp_y + 1) cost = cst_hp * t + cst_df * dfi + cst_at * ati ans = min(ans, cost) print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≀ 0 and the same time Master Yang's HP > 0, Master Yang wins. Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF. Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win. Input The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively. Output The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. Examples Input 1 2 1 1 100 1 1 100 100 Output 99 Input 100 100 100 1 1 1 1 1 1 Output 0 Note For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left. For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
H_y, A_y, D_y = map(int, input().split()) H_m, A_m, D_m = map(int, input().split()) h, a, d = map(int, input().split()) ans = 10**20 for A_buy in range(max(0, H_m + D_m - A_y) + 1): for D_buy in range(max(0, A_m - D_y) + 1): damage = A_y + A_buy - D_m cost = A_buy * a + D_buy * d if damage > 0 and cost < ans: time = (H_m + damage - 1) // damage H_left = H_y - time * max(0, A_m - D_y - D_buy) if H_left <= 0: cost += h * (1 - H_left) if cost < ans: ans = cost print(ans)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for i in range(0, t): n = int(input()) a = list(map(int, input().split())) d = dict() maxans1 = [0] * (n + 1) maxans2 = [0] * (n + 1) minans = [0] * (n + 1) for j in range(0, len(a)): if a[j] not in d.keys(): d[a[j]] = 1 else: d[a[j]] = d[a[j]] + 1 if a[j] != 0: maxans1[0] = maxans1[0] + (n - (a[j] - 1)) minans[0] = minans[0] + 1 maxans2[n] = maxans2[n] + (n - a[j]) for j in range(1, n): if j in d.keys(): maxans1[j] = maxans1[j - 1] - d[j] * (n - (j - 1)) minans[j] = minans[j - 1] - d[j] else: maxans1[j] = maxans1[j - 1] minans[j] = minans[j - 1] for j in range(n - 1, -1, -1): if j in d.keys(): maxans2[j] = maxans2[j + 1] - d[j] * (n - j) else: maxans2[j] = maxans2[j + 1] for j in range(0, n): print(minans[j], end=" ") print(maxans1[j] + maxans2[j])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
def update(D, l, r, x): D[l] += x D[r + 1] -= x t = int(input()) for tt in range(t): n = int(input()) a = list(map(int, input().split())) a1 = [0] * (n + 1) a2 = [0] * (n + 1) for r in range(n): if a[r] >= 1 and a[r] < n: update(a1, a[r] + 1, n - 1, n - a[r]) update(a1, 0, a[r] - 1, n - a[r] + 1) update(a2, 0, a[r] - 1, 1) elif a[r] == n: update(a2, 0, a[r] - 1, 1) update(a1, 0, n - 1, 1) else: update(a1, a[r] + 1, n - 1, n - a[r]) for i in range(1, n): a1[i] += a1[i - 1] a2[i] += a2[i - 1] for j in range(n): print(a2[j], a1[j])
FUNC_DEF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for _ in range(t): n = int(input()) arr = [int(i) for i in input().split()] mini, maxl, maxr = [0] * (n + 1), [0] * (n + 1), [0] * (n + 1) for i in range(n): k = arr[i] mini[0] += 1 mini[k] -= 1 maxl[0] += n - k + 1 maxl[k] -= n - k + 1 maxr[n - 1] += n - k maxr[k] -= n - k for i in range(1, n + 1): mini[i] += mini[i - 1] maxl[i] += maxl[i - 1] for i in range(n - 1, -1, -1): maxr[i] += maxr[i + 1] for i in range(n): print(mini[i], maxl[i] + maxr[i])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) x = [int(x) for x in input().split()] mn = [0] * (n + 1) mx = [0] * (n + 1) mr = [0] * (n + 1) for i in range(n): mn[0] += 1 mn[x[i]] -= 1 mx[0] += n - x[i] + 1 mx[x[i]] -= n - x[i] + 1 mr[n - 1] += n - x[i] mr[x[i]] -= n - x[i] for i in range(n): mn[i + 1] += mn[i] mx[i + 1] += mx[i] for i in range(n - 1, -1, -1): mr[i] += mr[i + 1] for i in range(n): print(mn[i], end=" ") print(mx[i] + mr[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
n = int(input()) for w in range(n): n = int(input()) li = list(map(int, input().split(" "))) minn = [(0) for i in range(n + 1)] maxx = [(0) for i in range(n + 1)] maxxr = [(0) for i in range(n + 1)] for i in range(n): minn[0] += 1 minn[li[i]] -= 1 maxx[0] += n - li[i] + 1 maxx[li[i]] -= n - li[i] + 1 maxxr[n - 1] += n - li[i] maxxr[li[i]] -= n - li[i] for i in range(1, n): minn[i] += minn[i - 1] maxx[i] += maxx[i - 1] for i in reversed(range(n)): maxxr[i] += maxxr[i + 1] for i in range(n): xx = maxx[i] + maxxr[i] print(minn[i], xx)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for t in range(int(input())): n = int(input()) mex = list(map(int, input().strip().split())) mex.sort() freq = [(0) for i in range(n + 1)] atl = [] atm = [] extra = 0 for m in mex: freq[m] += 1 extra += n - m j = 0 for i in range(n): j += freq[i] atl.append(n - j) atm.append(extra + atl[i] - freq[i] * (n - i)) print("\n".join(map(lambda x, y: f"{x} {y}", atl, atm)))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR STRING VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) a = [*map(int, input().split())] q = [0] * (n + 1) r = 0 w = [0] * (n + 1) for i in range(n): q[a[i]] += 1 w[a[i]] += n - a[i] r = sum(w) for i in range(n): q[n - 1 - i] += q[n - i] for i in range(n): print(q[i + 1], q[i + 1] + r - w[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
def func(): inp1 = int(input()) let_dp = [0] * (inp1 + 5) let_dp1 = [0] * (inp1 + 5) count = 0 list_ = list(map(int, input().split())) for i in list_: var_b = inp1 - i let_dp[i] += 1 let_dp1[i] += var_b count += var_b var_c = let_dp for i in reversed(range(inp1)): var_c[i] += var_c[i + 1] for i in range(inp1): var_y = count - let_dp1[i] + var_c[i + 1] var_x = var_c[i + 1] print(var_x, var_y) for i in range(int(input())): func()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) reqd = [0] * (n + 1) bad = [0] * (n + 1) extra = 0 for x in a: if x > 0: reqd[x - 1] += 1 bad[x] += n - x extra += n - x for i in range(n): reqd[n - i - 1] += reqd[n - i] for i in range(n): print(reqd[i], reqd[i] + extra - bad[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) arr = list(map(int, input().split())) res = 0 arr1, arr2 = [0] * (n + 9), [0] * (n + 9) for i in range(n): temp = n - arr[i] arr1[arr[i]] += 1 arr2[arr[i]] += temp res += temp arr3 = arr1.copy() for i in range(n, -1, -1): arr3[i] += arr3[i + 1] for i in range(0, n): ans1 = res - arr2[i] + arr3[i + 1] ans = arr3[i + 1] print(ans, ans1) count = 0 for i in range(n): count += 1 for i in range(n): count -= 1
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) while t: k = int(input()) j = 0 l = list(map(int, input().split())) m, p, q = [0] * (k + 1), [0] * (k + 1), [0] * (k + 1) while j < k: m[0] = m[0] + 1 m[l[j]] = m[l[j]] - 1 p[0] = p[0] + (k - l[j] + 1) p[l[j]] = p[l[j]] - (k - l[j] + 1) q[k - 1] = q[k - 1] + (k - l[j]) q[l[j]] = q[l[j]] - (k - l[j]) j += 1 s = 1 while s < k: p[s], m[s] = p[s] + p[s - 1], m[s] + m[s - 1] s += 1 v = k - 1 while v >= 0: q[v] = q[v] + q[v + 1] v -= 1 a = 0 while a < k: print(m[a], p[a] + q[a]) a += 1 t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) s = [int(x) for x in input().split()] mi = [(0) for i in range(n + 2)] ma = [(0) for i in range(n + 2)] for i in range(n): mi[0] += 1 mi[s[i]] -= 1 ma[0] += n - s[i] + 1 ma[s[i]] -= n - s[i] + 1 ma[s[i] + 1] += n - s[i] for i in range(1, n): mi[i] += mi[i - 1] ma[i] += ma[i - 1] for i in range(n): print(*[mi[i], ma[i]])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for _ in range(t): n = int(input()) arr = list(map(int, input().split())) atleast = [(0) for i in range(n)] atmost = [(0) for i in range(n)] d = {} for ele in arr: d[ele] = d.get(ele, 0) + 1 atleast[0] = n - d.get(0, 0) for i in range(1, n): atleast[i] = atleast[i - 1] - d.get(i, 0) atleast[i] = max(0, atleast[i]) tm = n * n - sum(arr) for i in range(n): atmost[i] = tm + atleast[i] - d.get(i, 0) * (n - i) for i in range(n): a, b = atleast[i], atmost[i] print(a, b)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for k in range(t): n = int(input()) mex = input().split(" ") for i in range(n): mex[i] = int(mex[i]) mex.sort() pref_l = [mex[0]] cur_l = mex[0] pref_r = [mex[len(mex) - 1]] * n cur_r = mex[len(mex) - 1] for i in range(1, len(mex)): cur_l += mex[i] pref_l.append(cur_l) for i in range(len(mex) - 2, -1, -1): cur_r += mex[i] pref_r[i] = cur_r for i in range(n): t = i l = 0 r = len(mex) - 1 ind = -1 while l <= r: mid = l + (r - l) // 2 if mex[mid] <= t: l = mid + 1 else: ind = mid r = mid - 1 l = 0 r = len(mex) - 1 ind1 = -1 while l <= r: mid = l + (r - l) // 2 if mex[mid] >= t: r = mid - 1 else: ind1 = mid l = mid + 1 least = 0 most = 0 if ind == -1: least = 0 else: least += len(mex) - 1 - ind + 1 if ind == -1 and ind1 == -1: most = 0 elif ind != -1 and ind1 == -1: most += ( n * (len(mex) - 1 - ind + 1) - pref_r[ind] + (len(mex) - 1 - ind + 1) ) elif ind == -1 and ind1 != -1: most += n * (ind1 + 1) - pref_l[ind1] else: most += ( n * (len(mex) - 1 - ind + 1) - pref_r[ind] + (len(mex) - 1 - ind + 1) + (n * (ind1 + 1) - pref_l[ind1]) ) print(str(least) + " " + str(most))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for i in range(t): N = int(input()) k1 = list(map(int, input().split())) LPB = [0] * (N + 5) UPB = [0] * (N + 5) value = 0 for i in range(N): b = N - k1[i] LPB[k1[i]] += 1 UPB[k1[i]] += b value += b short = LPB for i in range(N, -1, -1): short[i] += short[i + 1] for i in range(N): y = value - UPB[i] + short[i + 1] x = short[i + 1] print(x, y)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP 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 ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) vals = {} for x in a: if x in vals: vals[x] += 1 else: vals[x] = 1 tot = sum(a) lessValues = 0 for i in range(n): if i not in vals: mini = n - lessValues maxi = n * n - tot + (n - lessValues) else: mini = n - vals[i] - lessValues worktot = tot - i * vals[i] maxi = n * n - worktot - vals[i] * n + (n - lessValues - vals[i]) lessValues += vals[i] print(str(mini) + " " + str(maxi))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
t = int(input()) while t > 0: n = int(input()) a = [int(x) for x in input().split()] blanks = sum([(n - i) for i in a]) countI = [(0) for i in range(n + 1)] minR = [(0) for i in range(n)] for i in range(n): countI[a[i]] += 1 r = 0 for i in range(n, 0, -1): r += countI[i] minR[i - 1] = r for i in range(n): print(minR[i], " ", minR[i] + blanks - countI[i] * (n - i)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER
There are N hidden integer arrays of length N each. You are given the mex of each of these N arrays. Ashish likes lower bounds and Kryptonix likes upper bounds. So, for each 0 ≀ i ≀ N-1, find: The least possible number of occurrences of i across all the arrays The most possible number of occurrences of i across all the arrays Note that these values must be computed independently, i.e, it is allowed to choose different configurations of arrays to attempt to minimize/maximize the number of occurrences of different integers. Please see the samples for an example. Recall that the mex of an array is the smallest non-negative integer that is not present in it. For example, the mex of [0, 2, 4, 1, 1, 5] is 3, and the mex of [3, 8, 101, 99, 100] is 0. ------ Input Format ------ - The first line of input contains a single integer T β€” the number of test cases. Then the test cases follow. - The first line of each test case contains an integer N β€” the size of the array. - The second line of each test case contains N space-separated integers A_{1}, A_{2}, \dots, A_{N}, denoting the mexes of the N arrays. ------ Output Format ------ For each test case, output N lines, each containing two space-separated integers. The i-th line should contain the least and the most possible number of occurrences of i across all the arrays. ------ Constraints ------ $1 ≀ T ≀ 10^{4}$ $1 ≀ N ≀ 3\cdot10^{5}$ $0 ≀ A_{i} ≀ N$ - The sum of $N$ over all test cases does not exceed $3\cdot10^{5}$ ----- Sample Input 1 ------ 3 2 1 0 5 3 1 5 0 2 3 1 2 1 ----- Sample Output 1 ------ 1 2 0 2 4 13 3 13 2 13 1 13 1 15 3 8 1 2 0 4 ----- explanation 1 ------ Test case $1$: We have the following: - For $i = 0$, the two arrays can be $[0, 3]$ and $[2, 4]$ giving us one zero, or $[0, 0]$ and $[3, 1]$ giving us $2$ zeros. - For $i = 1$, $[0, 4]$ and $[3, 4]$ give no ones, while $[0, 9]$ and $[1, 1]$ give $2$ ones. Test case $3$: We have the following: - For $i = 0$, the arrays $[0, 3, 2], [1, 0, 4], [5, 0, 2]$ give the least number of zeros (i.e, $3$), and the arrays $[0, 0, 0], [1, 0, 0], [0, 0, 0]$ give the most. - For $i = 1$, the arrays $[5, 7, 0], [0, 3, 1], [6, 0, 3]$ give the least number of ones and the arrays $[0, 3, 2], [1, 1, 0], [5, 0, 2]$ give the most. - For $i = 2$, the arrays $[3, 0, 9], [0, 0, 1], [0, 0, 0]$ give the least number of twos and the arrays $[2, 0, 2], [0, 1, 0], [2, 2, 0]$ give the most.
for _ in range(int(input())): n = int(input()) temp1 = [0] * (n + 5) temp2 = [0] * (n + 5) l = list(map(int, input().split())) for i in range(n): temp1[l[i]] += 1 temp2[l[i]] += n - l[i] for i in range(n, -1, -1): temp1[i] += temp1[i + 1] ans = n * n - sum(l) for i in range(n): print(temp1[i + 1], ans + temp1[i + 1] - temp2[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR