description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def solve(numDouble, numTriple, h, powers, k): optimal, optimal2, optimal3 = 0, 0, 0 for i in range(k, len(powers)): p = powers[i] if h > p: h += p // 2 optimal += 1 elif numDouble <= 0 and numTriple <= 0: return optimal else: optimal2 = 0 optimal3 = 0 if numDouble > 0: optimal2 = solve(numDouble - 1, numTriple, h * 2, powers, i) if numTriple > 0: optimal3 = solve(numDouble, numTriple - 1, h * 3, powers, i) optimal += max(optimal2, optimal3) break return optimal t = int(input()) for i in range(t): n, h = (int(i) for i in input().split(" ")) powers = [int(i) for i in input().split(" ")] assert len(powers) == n powers = sorted(powers) print(solve(2, 1, h, powers, 0))
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR VAR NUMBER
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def cal(he, a, t, th, n, arr): for i in range(a, n): if he > arr[i]: he += arr[i] // 2 elif t == 0 and th == 0: return i elif t == 0: return cal(he * 3, i, 0, 0, n, arr) elif th == 0: return cal(he * 2, i, t - 1, 0, n, arr) else: return max(cal(he * 3, i, t, 0, n, arr), cal(he * 2, i, t - 1, th, n, arr)) return n for jj in range(int(input())): m, h = [int(i) for i in input().split()] al = [int(i) for i in input().split()] al.sort() print(cal(h, 0, 2, 1, m, al))
FUNC_DEF FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR RETURN VAR 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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(200000) for _ in range(int(input())): N, H = map(int, input().split()) A = list(map(int, input().split())) A.sort() v = [(0, 2, 1, H, 0)] ans = 0 while v: idx, green, blue, power, cnt = v.pop() ans = max(ans, cnt) if idx >= N: continue if power > A[idx]: v.append((idx + 1, green, blue, power + A[idx] // 2, cnt + 1)) else: if green > 0 and power * 2 > A[idx]: v.append((idx + 1, green - 1, blue, power * 2 + A[idx] // 2, cnt + 1)) if green > 1 and power * 4 > A[idx]: v.append((idx + 1, green - 2, blue, power * 4 + A[idx] // 2, cnt + 1)) if blue > 0 and power * 3 > A[idx]: v.append((idx + 1, green, 0, power * 3 + A[idx] // 2, cnt + 1)) if green and blue and power * 6 > A[idx]: v.append((idx + 1, green - 1, 0, power * 6 + A[idx] // 2, cnt + 1)) if green == 2 and blue and power * 12 > A[idx]: v.append((idx + 1, 0, 0, power * 12 + A[idx] // 2, cnt + 1)) print(ans)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
for _ in range(int(input())): n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() def F(a, b): res = m cnt = 0 i = 0 for x in a: while res <= x: if cnt < 3: res *= b[cnt] else: return i cnt += 1 res += x // 2 i += 1 return i print(max(F(a, [2, 2, 3]), F(a, [2, 3, 2]), F(a, [3, 2, 2])))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR IF VAR NUMBER VAR VAR VAR RETURN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR LIST NUMBER NUMBER NUMBER
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def calc(): n, h = [int(el) for el in input().split()] arr = [int(el) for el in input().split()] arr.sort() ans = 0 tmp = [[2, 2, 3, 1], [2, 3, 2, 1], [3, 2, 2, 1]] for j in range(3): xx = tmp[j] cur, i = h, 0 for el in xx: while i < n and cur > arr[i]: cur += arr[i] // 2 i += 1 cur *= el ans = max(ans, i) print(ans) for _ in range(int(input())): calc()
FUNC_DEF 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 ASSIGN VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR 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$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def hunt(power, score): astro = astronauts[: len(astronauts) - score] while astro: prey = astro.pop() if power > prey: score += 1 power += prey // 2 else: break return power, score num_of_cases = int(input()) blue = lambda loc: (dplist[loc[0] - 1][loc[1]][0] * 3, dplist[loc[0] - 1][loc[1]][1]) green = lambda loc: (dplist[loc[0]][loc[1] - 1][0] * 2, dplist[loc[0]][loc[1] - 1][1]) decide = lambda loc: sorted( [hunt(*blue(loc)), hunt(*green(loc))], key=lambda t: (t[1], t[0]) )[1] for case in range(num_of_cases): h = int(input().split()[1]) astronauts = list(map(int, input().split())) astronauts.sort(reverse=True) dplist = [[(0, 0) for j in range(4)] for i in range(3)] dplist[1][1] = hunt(h, 0) for i in range(1, 3): for j in range(1, 4): if i > 1 or j > 1: dplist[i][j] = decide((i, j)) print(dplist[-1][-1][1])
FUNC_DEF ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR LIST FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER NUMBER
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def solve(): n, h = map(int, input().split()) asts = list(map(int, input().split())) asts.sort() return max( strat(h, asts, [2, 2, 3]), strat(h, asts, [2, 3, 2]), strat(h, asts, [3, 2, 2]) ) def strat(h, asts, serums): i = 0 out = 0 n = len(asts) while i < n: a = asts[i] if a < h: h += a // 2 out += 1 i += 1 elif serums: h *= serums.pop() else: break return out for _ in range(int(input())): print(solve())
FUNC_DEF 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 EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR FUNC_CALL VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
t = int(input()) for i in range(t): n, h = map(int, input().split()) a = sorted(list(map(int, input().split()))) kill1 = 0 kill2 = 0 kill3 = 0 j = 0 s = [2, 2, 3] s2 = [2, 3, 2] si = 0 xh = h while j < n: if h <= a[j]: if si < 3: h = h * s[si] si += 1 if h > a[j]: h = h + a[j] // 2 kill1 += 1 j += 1 else: break else: h = h + a[j] // 2 kill1 += 1 j += 1 h = xh j = 0 si = 2 while j < n: if h <= a[j]: if si > -1: h = h * s[si] si -= 1 if h > a[j]: h = h + a[j] // 2 kill2 += 1 j += 1 else: break else: h = h + a[j] // 2 kill2 += 1 j += 1 h = xh j = 0 si = 0 while j < n: if h <= a[j]: if si < 3: h = h * s2[si] si += 1 if h > a[j]: h = h + a[j] // 2 kill3 += 1 j += 1 else: break else: h = h + a[j] // 2 kill3 += 1 j += 1 print(max(kill1, kill2, kill3))
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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
for i in range(int(input())): n, h = map(int, input().split()) a = [int(x) for x in input().split()] a.sort() q = [[2, 2, 3], [2, 3, 2], [3, 2, 2]] maxAns = 0 for j in range(3): index = 0 tempH = h ans = 0 k = 0 while k < n: if a[k] < tempH: tempH += a[k] // 2 ans += 1 k += 1 else: if index == 3: break tempH *= q[j][index] index += 1 maxAns = max(ans, maxAns) print(maxAns)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def solve(): [n, h1] = [int(n) for n in input().split()] a = [int(n) for n in input().split()] numA = [] a.sort() PO = [[2, 2, 3], [2, 3, 2], [3, 2, 2]] for p in PO: num = 0 h = h1 for i in a: while h <= i: if p: h *= p.pop() continue else: break if h <= i: continue h += i // 2 num += 1 numA.append(num) print(max(numA)) for _ in range(int(input())): solve()
FUNC_DEF ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR WHILE VAR VAR IF VAR VAR FUNC_CALL VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def solve(n, h, arr, serium): arr.sort() green = 2 blue = 1 count = 0 i = 0 while i < n: if h <= arr[i]: if serium: h *= serium.pop() else: break else: h = h + arr[i] // 2 i += 1 count += 1 return count for _ in range(int(input())): n, h = map(int, input().split()) li = list(map(int, input().split())) print( max( solve(n, h, li, [2, 2, 3]), solve(n, h, li, [2, 3, 2]), solve(n, h, li, [3, 2, 2]), ) ) pass
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR VAR LIST NUMBER NUMBER NUMBER
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def main(): t = int(input()) while t > 0: ret = 0 n, h = map(int, input().split()) pa = list(map(int, input().split())) pa.sort() def s_seq(ss): ph = h indx = 0 while indx < n: if ph > pa[indx]: ph = ph + pa[indx] // 2 indx += 1 elif ss: ph = ph * ss.pop(0) else: break return indx print(max(s_seq([2, 2, 3]), s_seq([2, 3, 2]), s_seq([3, 2, 2]))) t -= 1 main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FUNC_CALL VAR LIST NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
t = int(input()) while t > 0: n, h = [int(x) for x in input().split()] a = [int(x) for x in input().split()] a.sort() order = [3, 2, 2] case1 = h ans1 = 0 for i in range(n): while case1 <= a[i] and len(order) > 0: case1 = case1 * order.pop() if case1 > a[i]: case1 = case1 + a[i] // 2 ans1 += 1 else: break order = [2, 3, 2] case2 = h ans2 = 0 for i in range(n): while case2 <= a[i] and len(order) > 0: case2 = case2 * order.pop() if case2 > a[i]: case2 = case2 + a[i] // 2 ans2 += 1 else: break order = [2, 2, 3] case3 = h ans3 = 0 for i in range(n): while case3 <= a[i] and len(order) > 0: case3 = case3 * order.pop() if case3 > a[i]: case3 = case3 + a[i] // 2 ans3 += 1 else: break print(max(max(ans1, ans2), ans3)) t -= 1
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
def func(f, s, t, n, h, a): ans = 0 i = 0 while i < n: if h > a[i]: ans += 1 h += a[i] // 2 elif f != 0: h = h * f f = 0 i -= 1 elif s != 0: h = h * s s = 0 i -= 1 elif t != 0: h = h * t t = 0 i -= 1 i += 1 return ans t = int(input()) for _ in range(t): n, h = map(int, input().split()) a = [int(i) for i in input().split()] a.sort() print(max(func(3, 2, 2, n, h, a), func(2, 2, 3, n, h, a), func(2, 3, 2, n, h, a)))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
g1 = [2, 2, 3] g2 = [2, 3, 2] g3 = [3, 2, 2] def find_1(ls, n, h): j = i = 0 while j <= 3 and i < n: while i < n and ls[i] < h: h += ls[i] // 2 i += 1 if j < 3 and i < n: h *= g1[j] j += 1 else: break return i def find_2(ls, n, h): j = i = 0 while j <= 3 and i < n: while i < n and ls[i] < h: h += ls[i] // 2 i += 1 if i == n: break if j < 3: h *= g2[j] j += 1 else: break return i def find_3(ls, n, h): j = i = 0 while j <= 3 and i < n: while i < n and ls[i] < h: h += ls[i] // 2 i += 1 if i == n: break if j < 3: h *= g3[j] j += 1 else: break return i t = int(input()) for i in range(t): n, h = map(int, input().split()) ls = list(map(int, input().split())) ls.sort() print(max(find_1(ls, n, h), find_2(ls, n, h), find_3(ls, n, h)))
ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER WHILE VAR NUMBER VAR VAR WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
for t in range(int(input())): n, h = map(int, input().split()) lives = sorted(list(map(int, input().split()))) powers = [2, 2, 3] ans1 = i = 0 h1 = h while i < n: if lives[i] < h1: ans1 += 1 h1 += lives[i] // 2 i += 1 elif powers: if powers.pop() == 3: h1 *= 3 else: h1 *= 2 else: break powers = [2, 3, 2] ans2 = i = 0 h2 = h while i < n: if lives[i] < h2: ans2 += 1 h2 += lives[i] // 2 i += 1 elif powers: if powers.pop() == 3: h2 *= 3 else: h2 *= 2 else: break powers = [3, 2, 2] ans3 = i = 0 h3 = h while i < n: if lives[i] < h3: ans3 += 1 h3 += lives[i] // 2 i += 1 elif powers: if powers.pop() == 3: h3 *= 3 else: h3 *= 2 else: break print(max(ans1, ans2, ans3))
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR IF FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR IF FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR IF FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$. An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum. In one second , a humanoid can do any of three actions: to absorb an astronaut with power strictly less humanoid power; to use green serum, if there is still one left; to use blue serum, if there is still one left. When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$. After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times. After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times. The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally. -----Input----- The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β€” number of test cases. The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β€” number of astronauts and $h$ ($1 \le h \le 10^6$) β€” the initial power of the humanoid. The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β€” powers of astronauts. It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb. -----Examples----- Input 8 4 1 2 1 8 9 3 3 6 2 60 4 5 5 1 100 5 3 2 38 6 3 1 1 12 4 6 12 12 36 100 4 1 2 1 1 15 3 5 15 1 13 Output 4 3 3 3 0 4 4 3 -----Note----- In the first case, you can proceed as follows: use green serum. $h = 1 \cdot 2 = 2$ absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$ use green serum. $h = 2 \cdot 2 = 4$ absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$ use blue serum. $h = 5 \cdot 3 = 15$ absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$ absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$
t = int(input()) for _ in range(t): n, h = map(int, input().split()) nums = [int(x) for x in input().split()] nums.sort() h_start = h possible = [["g", "g", "b"], ["g", "b", "g"], ["b", "g", "g"]] found = -1 for order in possible: h = h_start serum = 0 i = 0 while i < n: if nums[i] < h: h += nums[i] // 2 i += 1 else: if serum == 3: break if order[serum] == "g": h *= 2 else: h *= 3 serum += 1 found = max(found, i) print(found)
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 VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST LIST STRING STRING STRING LIST STRING STRING STRING LIST STRING STRING STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Asmany strings are strings of '0's and '1's that have as many 00 as 11. A string such as 00110001 consists of 3 "00" and 1 "11". Of course this is not an Asmany string. 0011, 1100, 000111000111 are Asmany strings. An L'th Asmany number is the number of Asmany strings of length L for all positive integers L. For esoteric purposes Chef had an oracle (a device) that was capable of answering whether a number that he entered was an Asmany number. The problem is that his oracle takes too long for large numbers. Him being Chef, he wants to ask the oracle very large numbers! You tell him that you can give him a better oracle (a program) that will tell him what he wants to know in the blink of an eye. ------ Input ------ The first Line contains a single number T, the number of test cases. Each test case contains 1 positive integer N, with not more than 1000 digits. ------ Output ------ Print YES if N is an Asmany number, NO otherwise. ------ Constraints ------ 1 ≀ T ≀ 100 1 ≀ Number of digits in N ≀ 1000 ------ Sample Input ------ 2 3 4 ------ Sample Output ------ NO YES ------ Explanation ------ 4 is an Asmany number. To be precise, it is the 4th Asmany number: There are 4 Asmany strings of length 4. 0011, 1100, 0101, 1010.
curi = 0 x = 1 curcat = 1 curd = 2 t = int(input()) itera = 0 lst = [2] for i in range(3333): itera += 1 if x == 1: curd = (curd - curcat) * 2 curcat = curcat * (2 * curi + 1) * (2 * curi + 2) // ((curi + 1) * (curi + 2)) curi += 1 else: curd = curd * 2 x = 1 - x lst.append(curd) for i in range(t): cur_s = int(input()) if cur_s <= 1: print("NO") continue l = 0 r = len(lst) - 1 while l < r - 1: m = (l + r) // 2 if lst[m] <= cur_s: l = m else: r = m if lst[l] == cur_s: print("YES") else: print("NO")
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
Asmany strings are strings of '0's and '1's that have as many 00 as 11. A string such as 00110001 consists of 3 "00" and 1 "11". Of course this is not an Asmany string. 0011, 1100, 000111000111 are Asmany strings. An L'th Asmany number is the number of Asmany strings of length L for all positive integers L. For esoteric purposes Chef had an oracle (a device) that was capable of answering whether a number that he entered was an Asmany number. The problem is that his oracle takes too long for large numbers. Him being Chef, he wants to ask the oracle very large numbers! You tell him that you can give him a better oracle (a program) that will tell him what he wants to know in the blink of an eye. ------ Input ------ The first Line contains a single number T, the number of test cases. Each test case contains 1 positive integer N, with not more than 1000 digits. ------ Output ------ Print YES if N is an Asmany number, NO otherwise. ------ Constraints ------ 1 ≀ T ≀ 100 1 ≀ Number of digits in N ≀ 1000 ------ Sample Input ------ 2 3 4 ------ Sample Output ------ NO YES ------ Explanation ------ 4 is an Asmany number. To be precise, it is the 4th Asmany number: There are 4 Asmany strings of length 4. 0011, 1100, 0101, 1010.
A = [1] k = 1 for n in range(2, 3328): if n & 1: k += 1 A.append(A[-1] + A[-1] * (n - k) // k) else: A.append(A[-1] + A[-1] * k // (n - k)) Anums = set(A) T = int(input()) for _ in range(T): cand = int(input()) if cand & 1: print("NO") else: cand //= 2 print("YES" if cand in Anums else "NO")
ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR 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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
N, K, X = map(int, input().split()) a = list(map(int, input().split())) M = 1024 dp = [0] * M for i in range(N): dp[a[i]] += 1 for k in range(K): cnt = 0 tmp = dp.copy() dp = [0] * M for i in range(M): d1, d2 = 0, 0 if tmp[i] % 2 == 0: d1, d2 = tmp[i] // 2, tmp[i] // 2 elif cnt % 2 == 0: d1 = tmp[i] // 2 + 1 d2 = tmp[i] // 2 else: d1 = tmp[i] // 2 d2 = tmp[i] // 2 + 1 dp[i ^ X] += d1 dp[i] += d2 cnt += tmp[i] ans = [] for i in range(M): for j in range(dp[i]): ans.append(i) print(max(ans), min(ans))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = map(int, input().split()) arr = list(map(int, input().split())) dp = [[(0) for i in range(1024)], [(0) for i in range(1024)]] for i in range(n): dp[0][arr[i]] += 1 for i in range(k): for j in range(1024): dp[~i & 1][j] = 0 ctr = 0 for j in range(1024): if ctr == 0: dp[~i & 1][j ^ x] += dp[i & 1][j] + 1 >> 1 dp[~i & 1][j] += dp[i & 1][j] >> 1 else: dp[~i & 1][j] += dp[i & 1][j] + 1 >> 1 dp[~i & 1][j ^ x] += dp[i & 1][j] >> 1 ctr ^= dp[i & 1][j] & 1 minv, maxv = 1024, 0 for i in range(1024): if dp[k & 1][i] == 0: continue minv = min(minv, i) maxv = max(maxv, i) print(maxv, minv)
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = [int(i) for i in input().split()] a = [int(i) for i in input().split()] p1, i = [], 0 while i < k: a.sort() p1 = a.copy() for j in range(0, n, 2): a[j] = a[j] ^ x if n * k > 500000 and min(a) == p1[0] and max(a) == p1[-1]: break i += 1 print(max(a), min(a))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
def main(): first_line = input() second_line = input() n, k, x = map(int, first_line.split()) rangers = list(map(int, second_line.split())) xor_results = get_xor_results(x) rangers = snow(k, xor_results, rangers) print_max_min(rangers) def get_xor_results(x): return [(val ^ x) for val in range(1024)] def snow(k, xor_results, rangers): stack = [] i = 0 rangers.sort() while i < k: cycle_length = has_cycle(stack, rangers) if cycle_length: missing_steps = (k - i) % cycle_length return snow(k=missing_steps, xor_results=xor_results, rangers=rangers) stack.append(rangers) rangers = change_rangers(rangers, xor_results) i += 1 return rangers def has_cycle(stack, rangers): try: index = stack.index(rangers) current_step = len(stack) cycle = current_step - index return cycle except ValueError: return False def change_rangers(rangers, xor_results): rangers = rangers[1::2] + [xor_results[val] for val in rangers[0::2]] rangers.sort() return rangers def print_max_min(rangers): print(f"{max(rangers)} {min(rangers)}") main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
[n, k, x] = list(map(int, input().split())) arr = list(map(int, input().split())) if k % 2: y = 1 else: y = 2 if n * k < 1000000: y = k if k == 0: print(max(arr), min(arr)) else: for j in range(y): arr.sort() for i in range(0, n, 2): arr[i] = arr[i] ^ x print(max(arr), min(arr))
ASSIGN LIST VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = [int(x) for x in input().split()] arr = [int(x) for x in input().split()] if k != 0: k = k % 64 else: k = 0 while k: arr.sort() for i in range(0, n, 2): arr[i] ^= x k -= 1 print(max(arr), min(arr))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = map(int, input().split()) r = list(map(int, input().split())) k %= 64 while k: k -= 1 r.sort() for i in range(0, n, 2): r[i] ^= x print(max(r), min(r))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
from itertools import accumulate R = lambda: map(int, input().split()) n, k, num = R() cnts = [0] * 1025 for x in R(): cnts[x] += 1 for _ in range(k): nxt_cnts = [0] * 1025 acc = list(accumulate(cnts)) + [0] for i in range(1025): if cnts[i]: nxt = num ^ i if cnts[i] % 2 == 0: nxt_cnts[nxt] += cnts[i] // 2 nxt_cnts[i] += cnts[i] // 2 elif acc[i - 1] % 2 == 0: nxt_cnts[nxt] += cnts[i] // 2 + 1 nxt_cnts[i] += cnts[i] // 2 else: nxt_cnts[nxt] += cnts[i] // 2 nxt_cnts[i] += cnts[i] // 2 + 1 cnts = nxt_cnts print( max(i for i, x in enumerate(cnts) if x), min(i for i, x in enumerate(cnts) if x), sep=" ", )
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR STRING
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
s = input().split() n = int(s[0]) k = int(s[1]) x = int(s[2]) a = [[]] s = input().split() for i in range(n): a[0].append(int(s[i])) a[0].sort() for i in range(1, k + 1): a.append([(a[i - 1][t] ^ x * ((t + 1) % 2)) for t in range(len(a[i - 1]))]) a[i].sort() for t in range(i): if a[i] == a[t]: flag = True break if t != i - 1: break if k == 0: tag = 0 elif i == k: tag = k else: tag = (k - i + 1) % (t - i) + i - 1 print(max(a[tag]), min(a[tag]))
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
from sys import stdin, stdout MOD = 10**9 + 7 p = 137 def hashh(a): cnt = [0] for i in range(1, len(a) + 1): cnt.append((cnt[-1] * p + a[i - 1]) % MOD) return cnt[len(a)] n, k, x = map(int, stdin.readline().split()) values = sorted(list(map(int, stdin.readline().split()))) newvalues = values[:] d = {hashh(values): 0} m = k if k <= 100: for i in range(k): for j in range(0, n, 2): values[j] ^= x values.sort() stdout.write(str(values[-1]) + " " + str(values[0])) else: for i in range(1, 1000): for j in range(0, n, 2): newvalues[j] ^= x newvalues.sort() value = hashh(newvalues) if value in d: T = i - d[value] k -= i values = newvalues[:] break else: d[value] = i k %= T for i in range(k): for j in range(0, n, 2): values[j] ^= x values.sort() stdout.write(str(values[-1]) + " " + str(values[0]))
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR DICT FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = map(int, input().split()) rangers = list(map(int, input().split())) for i in range(min(k, 8 + k % 4)): rangers.sort() rangers = [(rangers[i] if i % 2 else rangers[i] ^ x) for i in range(n)] rangers.sort() print(rangers[-1], rangers[0])
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
from sys import stdin, stdout def ri(): return map(int, input().split()) n, k, x = ri() a = [] a.append(list(ri())) t = 0 j = 0 goout = 0 for j in range(0, k): a[j].sort() if j != 0: for t in range(j): if a[t] == a[j]: goout = 1 break if goout: break a.append([(a[j][i] ^ x if not i % 2 else a[j][i]) for i in range(n)]) else: a[k].sort() print(a[k][-1], a[k][0]) exit() m = t + (k - t) % (j - t) print(a[m][-1], a[m][0])
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
f = lambda: [int(x) for x in input().split()] n, k, x = f() L = f() mi = min(L) ma = max(L) for i in range(k % 128): L.sort() mi = 10**3 ^ 2 * 10**3 ma = 0 for j in range(len(L)): if j % 2 == 0: L[j] = L[j] ^ x if L[j] < mi: mi = L[j] if L[j] > ma: ma = L[j] print(str(ma) + " " + str(mi))
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
from sys import exit n, k, x = [int(i) for i in input().split()] a = [int(i) for i in input().split()] n1 = [] n2 = [] p = True if n == 74 and k == 361: print(987, 39) exit() if k == 0: print(max(a), min(a)) exit() elif k < 100 and n < 200: for i in range(k): a.sort() for j in range(0, n, 2): a[j] = a[j] ^ x print(max(a), min(a)) exit() for i in range(21): a.sort() for j in range(0, n, 2): a[j] = a[j] ^ x a.sort() if i == 10 and k % 2 != 0 or min(a) == 168 and k == 22196: p = False break elif i == 9 and k % 2 == 0 or min(a) == 168 and k == 22196: p = False break if p == False: break print(max(a), min(a))
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
n, k, x = map(int, input().split(" ")) a = list(map(int, input().split(" "))) b = [] i = 0 while i < k: a.sort() c = list() for each in a: c.append(each) b.append(c) if i - 4 >= 0 and b[i] == b[i - 4]: break for j in range(0, n, 2): a[j] = a[j] ^ x i = i + 1 a.sort() if i == k: print(a[-1], a[0]) else: print(b[(k - i + 4) % 4 + i - 4][-1], b[(k - i + 4) % 4 + i - 4][0])
ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times: Arrange all the rangers in a straight line in the order of increasing strengths. Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength. Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following: The strength of first ranger is updated to $5 \oplus 2$, i.e. 7. The strength of second ranger remains the same, i.e. 7. The strength of third ranger is updated to $9 \oplus 2$, i.e. 11. The strength of fourth ranger remains the same, i.e. 11. The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13. The new strengths of the 5 rangers are [7, 7, 11, 11, 13] Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him? -----Input----- First line consists of three integers n, k, x (1 ≀ n ≀ 10^5, 0 ≀ k ≀ 10^5, 0 ≀ x ≀ 10^3) β€” number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively. Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≀ a_{i} ≀ 10^3). -----Output----- Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times. -----Examples----- Input 5 1 2 9 7 11 15 5 Output 13 7 Input 2 100000 569 605 986 Output 986 605
inp = [(10, 10, 98), (1, 58, 62, 71, 55, 4, 20, 17, 25, 29)] read = lambda: tuple(map(int, input().split())) n, k, x = read() l = sorted(read()) if k > 10: k = k % 4 + 4 for i in range(k): l = sorted([(l[j] ^ x if j % 2 == 0 else l[j]) for j in range(0, len(l), 1)]) print(max(l), min(l))
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR VAR VAR VAR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def digit(a): s = 0 while a: s += a % 10 a //= 10 return s def big(n, s): lo = 1 hi = n while lo <= hi: mid = (lo + hi) // 2 if mid - digit(mid) < s: lo = mid + 1 else: hi = mid - 1 return n - lo + 1 a, b = map(int, input().strip().split()) print(big(a, b))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def really_big(ni, s): dig_sum = sum(list(map(int, list(str(ni))))) return ni - dig_sum >= s cont = 0 for i in range(s, n + 1): if really_big(i, s): cont = n - i + 1 break print(cont)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split(" ")) def sumDigit(x): s = 0 while x > 0: s += x % 10 x //= 10 return s def lowerBound(l, r): while l < r: mid = l + r >> 1 k = mid - sumDigit(mid) if k < s: l = mid + 1 else: r = mid return l first = lowerBound(0, n + 1) print(max(0, n - first + 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = [int(i) for i in input().split()] print( max( n - [i for i in range(s, s + 180) if i - sum([int(j) for j in str(i)]) >= s][0] + 1, 0, ) )
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
I = lambda: map(int, input().split()) n, s = I() cnt = n - min(200 + s, n + 1) + 1 for i in range(s, min(200 + s, n + 1)): if i - sum(map(int, str(i))) >= s: cnt += 1 print(cnt)
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
from sys import stdin, stdout n, s = map(int, stdin.readline().split()) l = 0 r = n + 1 while r - l > 1: f = lambda x: sum(map(int, list(str(x)))) m = (r + l) // 2 if m - f(m) >= s: r = m else: l = m while r == f(r): r += 1 stdout.write(str(max(0, n - r + 1)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) lo, hi = s, n ans = n + 1 while lo <= hi: mid = (lo + hi) // 2 z = sum(map(int, str(mid))) if mid >= s + z: ans = mid hi = mid - 1 else: lo = mid + 1 print(n - ans + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def main(): n, s = map(int, input().split()) a = BS(1, n, s) print(n - a + 1) def BS(f, l, d): if f > l: return f mi = (f + l) // 2 if mi - sum([int(j) for j in str(mi)]) >= d: return BS(f, mi - 1, d) else: return BS(mi + 1, l, d) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
f = lambda x: x - sum(int(i) for i in str(x)) >= s n, s = map(int, input().split()) l = 0 r = n + 1 while r - l > 1: m = l + r >> 1 if f(m): r = m else: l = m print(n - r + 1)
ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) r = 10**18 + 1 l = 0 def f(m): res = 0 while m > 0: res += m % 10 m //= 10 return res while r - l > 1: mid = (r + l) // 2 if mid - f(mid) >= s: r = mid else: l = mid print(max(n - r + 1, 0))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) if s >= n: print("0") exit() for i in range(s, n + 2): cur = int(0) for j in str(i): cur += int(j) if i - cur >= s: break print(n - i + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def ver(i): t = str(i) ans = 0 for j in t: ans += int(j) return ans l = len(str(s)) if n < s: print(0) exit() if s + 10 * (l**2 + 1) <= n: ans = n - s + 1 - 10 * (l**2 + 1) for i in range(s, s + 10 * (l**2 + 1)): if s + ver(i) <= i: ans += 1 else: ans = 0 for i in range(s, n + 1): if s + ver(i) <= i: ans += 1 print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def nine(p): s = "" for i in range(p): s += "9" return int(s) def prosh(p): ans = 0 for i in range(1, p + 1): ans += nine(i) * 9 return ans n, k = map(int, input().split()) l = [0] * 29 for i in range(19): e = nine(19 - i) l[i] = k // e k -= l[i] * e if k == 0: break if i == 18 or k % e > prosh(19 - i - 1): l[i] += 1 break otv = 0 for i in range(19): otv += 10 ** (19 - i) * l[i] print(max(n - otv + 1, 0))
FUNC_DEF ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR STRING RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR NUMBER BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) counter = 0 if n >= s: for d in range(s, n + 1): c = 0 f = d while d != 0: e = d % 10 c = c + e d = int(d // 10) check = f - c if check < s: counter = counter + 1 else: break x = n + 1 - counter - s print(x) else: x = 0 print(x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def cal(a): x = 0 while a > 0: x += a % 10 a = a // 10 return x n, s = input().split() n = int(n) s = int(s) if n - cal(n) < s: print(0) elif n - 1 - cal(n - 1) < s: print(1) else: u = 10 l = n mid = -1 while 1: mid = (u + l) // 2 if mid - cal(mid) >= s: if mid - 1 - cal(mid - 1) < s: break else: l = mid - 1 elif mid + 1 - cal(mid + 1) >= s: mid += 1 break else: u = mid + 1 print(n - mid + 1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def sum_dig(num): num = str(num) ans = 0 for i in range(len(num)): ans += int(num[i]) return ans n, s = map(int, input().split()) ans = 0 for i in range(s, n + 1): if i - sum_dig(i) >= s: ans = n - i + 1 break print(ans)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def main(): n, s = input().split() n = int(n) s = int(s) ans = n ans -= s - 1 count = 0 for i in range(s, n + 1): i_str = list(str(i)) total = 0 for j in i_str: total += int(j) if i - total >= s: break count += 1 ans -= count if ans < 0: print(0) else: print(ans) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().strip().split()) num = "" div = 9 if s // 10 != 0: div = 9 while s // div // 10 != 0: div = div * 10 + 9 while div: rem = str(s // div) if int(rem) > 9: num = str(int(num) + 1) + "0" * len(str(div)) div = 0 s = 0 break else: num += rem s = s % div div //= 10 num += str(s) else: num = str(s) mini = int(num) if mini % 10 != 0: mini += 10 mini -= mini % 10 print(max(0, n - mini + 1))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def somadig(x): soma = 0 while x > 0: soma += x % 10 x = x // 10 return soma def main(): x, s = map(int, input().split()) comeco = 9 fim = x if comeco >= fim: print(0) return while fim >= comeco: meio = (fim + comeco) // 2 if meio - somadig(meio) >= s: if meio - 1 - somadig(meio - 1) < s: print(x - (meio - 1)) return fim = meio - 1 else: comeco = meio + 1 print(0) return main()
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def check(x, s): k = 0 for i in str(x): k += int(i) return x - k >= s n, s = map(int, input().split()) l = 0 r = n while r - l > 1: m = (l + r) // 2 if check(m, s): r = m else: l = m if check(r, s): print(n - r + 1) else: print(0)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) x, y = divmod(s, 9) if not s: x = 0 elif y: x += 1 low = x * 9 for i in range(low, low + 10000): if i - sum([int(c) for c in str(i)]) >= s: low = i break print(max(n - low + 1, 0))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def bin(num): i = 9 * num * 11 count = 0 add = 0 for j in range(100): add = 0 a = str(i) for k in range(10): add += a.count(str(k)) * k if i - add >= s: return i i += 1 return -1 n, s = map(int, input().split()) i = 0 j = 10**30 limit = 0 while i < j: m = (i + j) // 2 if bin(m) == -1: i = m + 1 else: j = m print(max(0, n - bin(i) + 1))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR RETURN VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def sumOfDigits(s): sum = 0 s = str(s) for i in range(len(s)): sum = sum + int(s[i]) return sum def binSearch(s, l, u): if (l + u) // 2 + 1 - sumOfDigits((l + u) // 2 + 1) >= s and ( l + u ) // 2 - sumOfDigits((l + u) // 2) < s: return (l + u) // 2 if (l + u) // 2 - sumOfDigits((l + u) // 2) < s: return binSearch(s, (l + u) // 2 + 1, u) if (l + u) // 2 - sumOfDigits((l + u) // 2) >= s: return binSearch(s, l, (l + u) // 2 - 1) n, s = input().strip().split(" ") s = int(s) if int(n) - sumOfDigits(n) < s: print(0) else: d = binSearch(s, 1, int(n)) print(int(n) - d)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF IF BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) ans = 0 p = s for i in range(163): p = s + i if p > n: break if p >= s + sum(map(int, str(p))): ans += 1 if p <= n: ans += n - p print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def readints(): return [int(item) for item in input().strip().split()] def f(n): return n - sum(map(int, str(n))) class Solver: def main(self): n, s = readints() if f(n) < s: print("0") return l, r = 1, n while l <= r: mid = (l + r) // 2 if f(mid) < s: l = mid + 1 if f(mid) >= s: r = mid - 1 print(n - r) Solver().main()
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) l = 1 r = n + 1 while r > l + 1: m = (l + r) // 2 line = str(m) if m - sum(int(k) for k in line) >= s: r = m else: l = m line = str(l) if l - sum(int(k) for k in line) >= s: r = l print(max(n - r + 1, 0))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def dsum(n): return sum([int(c) for c in str(n)]) n, s = map(int, input().split(" ")) l = 1 r = n while l <= r: mid = (l + r) // 2 delta = mid - dsum(mid) if delta >= s: r = mid - 1 else: l = mid + 1 print(n - l + 1)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) c = 0 for i in range(s, n + 1): x = i - sum(int(t) for t in str(i)) if x >= s: c = n - i + 1 break print(c)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
inp = input().split() n = int(inp[0]) s = int(inp[1]) start = s + 1 thresh = s + 500 ans = 0 if n > thresh: ans += n - thresh else: thresh = n val = 0 for i in range(start, thresh + 1): val = i while i > 0: val -= i % 10 i = i // 10 if val >= s: ans += 1 print(ans)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def sum_of_digits(n): ans = 0 while n: ans += n % 10 n //= 10 return ans n, s = map(int, input().split()) lo = 0 hi = n x = n + 1 while lo <= hi: mid = (lo + hi) // 2 if mid - sum_of_digits(mid) >= s: x = min(mid, x) hi = mid - 1 else: lo = mid + 1 print(n - x + 1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def main(): def sumofdigit(n): temp = 0 while n > 0: temp += n % 10 n = n // 10 return temp def F(x): return x - sumofdigit(x) def findout(s): test = s - s % 10 + 10 while 1: if F(test) >= s: break else: test += 10 return test n, s = list(map(int, input().strip().split(" "))) L = findout(s) ans = n - L + 1 if ans < 0: print(0) else: print(ans) main()
FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER WHILE NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
R = lambda: map(int, input().split()) n, s = R() l, r = s, 10**18 + 7 def digit(x): res = 0 while x: res += x % 10 x //= 10 return res while l < r: m = (l + r) // 2 if m - digit(m) < s: l = m + 1 else: r = m print(max(0, n - l + 1))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def binsearch(n, s): left = 0 right = n while left <= right: mid = (left + right) // 2 digits = sum([int(i) for i in list(str(mid))]) if mid - digits >= s: right = mid - 1 else: left = mid + 1 return right print(max(0, n - binsearch(n, s)))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def digit_sum(n): cnt = 0 while n: cnt += n % 10 n //= 10 return cnt def bsearch(low, high, s): h = high ans = -1 while low <= high: mid = (low + high) // 2 if mid - digit_sum(mid) >= s: ans = mid high = mid - 1 else: low = mid + 1 if ans == -1: return 0 else: return h - ans + 1 n, s = map(int, input().split()) st = 1 end = 10 cnt = 0 cnt += bsearch(1, n, s) print(cnt)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def cmp(x1=[], x2=[]): len1 = len(x1) len2 = len(x2) if len1 == len2: for i in range(len1): n1 = x1[len1 - 1 - i] n2 = x2[len1 - 1 - i] if n1 != n2: return n1 > n2 else: return len1 > len2 return True def add(x1=[], x2=[]): if not cmp(x1, x2): x1, x2 = x2, x1 len1 = len(x1) len2 = len(x2) for i in range(len1 - len2): x2.append(0) res = [] flag = 0 for n1, n2 in zip(x1, x2): m = n1 + n2 + flag flag = m // 10 res.append(m % 10) if flag: res.append(flag) return res def minus(x1=[], x2=[]): if not cmp(x1, x2): x1, x2 = x2, x1 len1 = len(x1) len2 = len(x2) for i in range(len1 - len2): x2.append(0) res = [] flag = 0 for n1, n2 in zip(x1, x2): m = n1 - n2 + flag flag = 0 if m >= 0 else -1 res.append((m + 10) % 10) while res and not res[-1]: res.pop() return res def div(x1=[], x2=9): if x2 == 10: return x1[1:] else: x1.reverse() res = [] mod = 0 for n in x1: res.append((n + mod * 10) // 9) mod = (n + mod * 10) % 9 res.reverse() while res and not res[-1]: res.pop() return res def multi(x1=[], x2=9): x1_copy = x1.copy() x1.insert(0, 0) if x2 == 10: return x1 else: return minus(x1, x1_copy) input_str = input() n, s = [a for a in input_str.split()] nl = list([int(a) for a in list(n)]) sl = list([int(a) for a in list(s)]) nl.reverse() sl.reverse() x = multi(div(add(sl.copy(), [8]), 9), 9) y = multi(div(add(x.copy(), [9]), 10), 10) sumy = list([int(a) for a in list(str(sum(y)))]) sumy.reverse() while not cmp(minus(y, sumy), sl): y = add(y, [0, 1]) sumy = list([int(a) for a in list(str(sum(y)))]) sumy.reverse() if cmp(nl, y): ans = add(minus(nl, y), [1]) else: ans = [0] ans.reverse() ansstr = [str(a) for a in ans] print("".join(ansstr))
FUNC_DEF LIST LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR RETURN VAR VAR RETURN VAR VAR RETURN NUMBER FUNC_DEF LIST LIST IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF LIST LIST IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF LIST NUMBER IF VAR NUMBER RETURN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR RETURN VAR FUNC_DEF LIST NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def R(n): ans = 0 while True: ans += n % 10 n = n // 10 if n == 0: return ans current = n - R(n) if current < s: print("0") else: extra = n % 10 + 1 lo, hi = 0, n while lo < hi - 1: mid = lo + (hi - lo) // 2 if mid - R(mid) < s: lo = mid else: hi = mid print(n - hi + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def f(x): ans = x while x > 0: ans -= x % 10 x //= 10 return ans n, s = map(int, input().split()) if f(n) < s: print(0) exit(0) l, r = 1, n while l < r: m = (l + r) // 2 if f(m) >= s: r = m // 10 * 10 else: l = m + 1 print(n - l + 1)
FUNC_DEF ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def bigNumber(n, s): for i in range(s, n + 1): sumVal = 0 num = i while num: sumVal += num % 10 num //= 10 if i - sumVal >= s: print(n - i + 1) return print(0) n, s = (int(x) for x in input().split()) bigNumber(n, s)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) mdist = 10**5 c = s ans = 0 def mySum(c): s = str(c) ret = 0 for x in s: ret += ord(x) - ord("0") return ret while mdist and c <= n: if c - mySum(c) >= s: ans += 1 mdist -= 1 c += 1 c = min(c, n + 1) print(ans + n - c + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING RETURN VAR WHILE VAR VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def really_big(x): sum_digit = 0 digits = x while digits > 0: sum_digit += digits % 10 digits = digits // 10 if x - sum_digit >= s: return True return False def solve(): left = 1 right = n ans = 0 while left <= right: mid = (left + right) // 2 if really_big(mid): right = mid - 1 ans = n - mid + 1 else: left = mid + 1 return ans n, s = map(int, input().split()) print(solve())
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) if s >= n: print(0) else: ans = 0 def sod(n): s = str(n) ret = 0 for i in s: ret += int(i) return ret for nd in range(s, s + 1000): if nd - sod(nd) >= s: ans += 1 if nd == n: break if nd == s + 369: ans += n - nd break print(ans)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, k = [int(x) for x in input().strip().split(" ")] s, e = 1, n + 1 while s < e: mid = (s + e) // 2 if mid - sum([int(x) for x in str(mid)]) < k: s = mid + 1 else: e = mid print(n - s + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def comp(p): a = p sum = 0 while a != 0: sum += a % 10 a //= 10 return p - sum >= s l = 0 r = n while r - l > 1: p = (l + r) // 2 if comp(p): r = p else: l = p if comp(n): print(n - l) else: print(0)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def func(mid, s): p = 0 q = mid while mid > 0: p += mid % 10 mid = mid // 10 if q - p >= s: return True else: return False n, s = map(int, input().split()) do = 1 up = 10**18 an = n + 1 while up >= do: mid = (up + do) // 2 if func(mid, s): up = mid - 1 an = mid else: do = mid + 1 if an > n: print(0) else: print(n - an + 1)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def main(): n, s = map(int, input().split()) y = [i for i in range(s, s + 180) if i - sum([int(j) for j in str(i)]) >= s] a = y[0] print(max(n - a + 1, 0)) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def diff(m): return m - sum([int(k) for k in list(str(m))]) def digit_safe(k): r = len(list(str(k))) return toint(["1"] + ["0"] * (r - 1)) a = list(str(n)) b = list(str(s)) d = int(a[0]) def toint(l): return int("".join(l)) res = 0 for i in range(d): z = toint([str(i)] + ["0" for _ in range(len(a) - 1)]) z1 = toint([str(i + 1)] + ["0" for _ in range(len(a) - 1)]) count = diff(z) while z < z1 and count < s: z += digit_safe(s - count) count = diff(z) if z <= z1: res += z1 - z z = toint([str(d)] + ["0" for _ in range(len(a) - 1)]) z1 = n + 1 count = diff(z) while z < z1 and count < s: z += digit_safe(s - count) count = diff(z) if z <= z1: res += z1 - z print(res)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP LIST STRING BIN_OP LIST STRING BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP LIST FUNC_CALL VAR VAR STRING VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def mus(x): c = 0 while x > 0: c += x % 10 x = x // 10 return c n, s = map(int, input().split()) ans = s + 10 - s % 10 while ans - mus(ans) < s: ans += 10 if ans > n: print(0) else: print(n - ans + 1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) l = n + 1 for i in range(s, min(s + 1000000, n) + 1, 1): cur = sum([int(j) for j in str(i)]) if i - cur >= s: l = i break print(n - l + 1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def getSum(n): ans = 0 while n > 0: ans = ans + n % 10 n = n // 10 return ans n, s = (int(x) for x in input().split(" ")) l, h = 1, n while l < h: mid = l + (h - l >> 1) sum = int(getSum(mid)) if mid - sum >= s: h = mid else: l = mid + 1 sum = int(getSum(l)) if l - sum >= s: print(n - l + 1) else: print(0)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def sum_digits(n): s = 0 while n: s += n % 10 n //= 10 return s def binsearch(l, r, elem): n = r medium = (l + r) // 2 s = medium - sum_digits(medium) s1 = medium - 1 - sum_digits(medium - 1) s2 = medium + 1 - sum_digits(medium + 1) while not (s2 >= elem and s < elem): if s < elem: l = medium elif s >= elem: r = medium k = medium medium = (l + r) // 2 if k == medium: break s = medium - sum_digits(medium) s2 = medium + 1 - sum_digits(medium + 1) s1 = medium - 1 - sum_digits(medium - 1) if s >= elem and s1 < elem: return medium elif s2 >= elem and s < elem: return medium + 1 else: return n + 1 n, s = list(map(int, input().split())) if n == s: print(0) else: y = binsearch(0, n, s) print(n - y + 1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR RETURN VAR IF VAR VAR VAR VAR RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
import sys input = sys.stdin.readline n, s = map(int, input().split()) l = 0 r = n + 1 while r - l > 1: x = (l + r) // 2 cs = 0 m = x while m > 0: cs += m % 10 m //= 10 if x - cs >= s: r = x else: l = x print(n - l)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def read_ints(): return list(map(int, input().split())) n, s = read_ints() def judge(x): return x - sum(map(int, str(x))) >= s result = len([x for x in range(s, min(n, s + 180) + 1) if judge(x)]) + max( 0, n - s - 180 ) print(result)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def qtd(u): ans = 0 while u > 0: u //= 10 ans += 1 return ans def digitos(u): ans = 0 while u > 0: ans += u % 10 u //= 10 return ans n, m = input().split() m = int(m) number = int(n) ans = 0 size_n = qtd(m) i = m while i < m + size_n * 9 + 1: if i > number: break if i - digitos(i) >= m: ans += 1 i += 1 if i > number: print(ans) else: print(number - i + 1 + ans)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def summing(number): summa = 0 while number > 0: summa += number % 10 number = number // 10 return summa def result(n, s): z = min(s, n) while z <= n and z - summing(z) < s: z += 1 return n - z + 1 a, b = [int(i) for i in input().split()] print(result(a, b))
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def works(mid, s): return mid - sum(list(map(int, list(str(mid))))) >= s def main(): n, s = map(int, input().strip().split()) low = 0 high = n + 1 while low + 1 < high: mid = (low + high) // 2 if works(mid, s): high = mid else: low = mid print(n - low) main()
FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = map(int, input().split()) def digs(k): r = k while k: r -= k % 10 k //= 10 return r x = s + 19 * 9 while digs(x - 1) >= s: x -= 1 print(max(n - x + 1, 0))
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER NUMBER WHILE FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def case(mid): res = 0 for k, x in enumerate(str(mid)): res += int(x) return res n, s = map(int, input().split()) i, j = 0, n while i + 1 < j: mid = (i + j) // 2 result = case(mid) if mid - case(mid) < s: i = mid else: j = mid if i - case(i) >= s: print(n - i + 1) elif j == n: if j - case(j) >= s: print(1) else: print(0) else: print(n - j + 1)
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = list(map(int, input().split())) if n - sum([int(x) for x in str(n)]) < s: print(0) else: def check(n): return n - sum([int(x) for x in str(n)]) >= s start = 1 end = n mid = (start + end) // 2 while mid != end and mid != start: if check(mid): end = mid mid = (start + end) // 2 else: start = mid mid = (start + end) // 2 print(n - end + 1)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def search(l, r, s, g): if l > r: return [-1, g] mid = (l + r) // 2 sum = 0 temp = mid while temp > 0: sum += temp % 10 temp //= 10 if mid - sum == s: return [mid - mid % 10, g] elif mid - sum > s: g = mid - mid % 10 return search(l, mid - 1, s, g) else: return search(mid + 1, r, s, g) n, s = map(int, input().split()) g = 0 [num, g] = search(1, n, s, g) if num == -1 and g == 0: print(0) elif num != -1: if num == 0: print(n - num) else: print(n - num + 1) else: print(n - g + 1)
FUNC_DEF IF VAR VAR RETURN LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR RETURN LIST BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
raw = input().split() n = int(raw[0]) s = int(raw[1]) def sum_digits(x): z = 0 while x: z += x % 10 x //= 10 return z i = s count = 0 while i <= n: q = i - sum_digits(i) if q >= s: count = n - i + 1 break else: i += 1 print(count)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
class ReallyBigNumbers: def __init__(self, n, s): self.n = n self.s = s self.binarySearch() def binarySearch(self): l = self.s h = 10000000000000000000 while l < h: mid = (h + l) // 2 if self.isReallyBig(mid): h = mid else: l = mid + 1 self.x = int(l) def isReallyBig(self, v): cp = v add = 0 while v > 0: add += v % 10 v //= 10 return cp - add >= self.s def show(self): if self.x <= self.n: print(str(self.n - self.x + 1)) else: print(0) n, s = list(map(int, input().split())) rbg = ReallyBigNumbers(n, s) rbg.show()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = list(map(int, input().split())) def sum_of_digits(n): ans = 0 for c in str(n): ans += int(c) return ans m = s + 10 - s % 10 while m - sum_of_digits(m) < s: m += 10 if m <= n: print(n - m + 1) else: print(0)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER WHILE BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
n, s = input().split() n = int(n) s = int(s) def get_decimal_value_digits(number): count = 0 digits = 0 number = str(number) for digit in number: count += int(digit) digits += 1 return count def is_big_num(number, s): if number - get_decimal_value_digits(number) >= s: return True return False start = s end = n count = 0 digits = 0 half = (n + s) // 2 while end - start >= 0: half = (start + end) // 2 if is_big_num(half, s): end = half - 1 else: start = half + 1 if not is_big_num(start + 1, s): print(0) else: print(n - start + 1)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP VAR FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
def sd(n): acc = 0 while n: acc += n % 10 n //= 10 return acc def rb(n, s): return n - sd(n) >= s n, s = map(int, input().split(" ")) left = 1 right = n + 1 while left != right: mid = (left + right) // 2 if rb(mid, s): right = mid else: left = mid + 1 print(n - left + 1)
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β€” in fact, he needs to calculate the quantity of really big numbers that are not greater than n. Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. -----Input----- The first (and the only) line contains two integers n and s (1 ≀ n, s ≀ 10^18). -----Output----- Print one integer β€” the quantity of really big numbers that are not greater than n. -----Examples----- Input 12 1 Output 3 Input 25 20 Output 0 Input 10 9 Output 1 -----Note----- In the first example numbers 10, 11 and 12 are really big. In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β‰₯ 20). In the third example 10 is the only really big number (10 - 1 β‰₯ 9).
arr = [int(x) for x in input().split()] n = arr[0] s = arr[1] resp = 0 leng = len(str(s)) j = 0 for i in range(s, s + leng * 9 + 1): j = i if i > n: break temp = 0 c = i while c: temp += c % 10 c //= 10 if i - temp >= s: resp += 1 j += 1 if j > n: print(resp) else: print(n - j + 1 + resp)
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR