description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries. Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berr...
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [None] b = [None] for _ in range(n): x, y = map(int, input().split()) a.append(x) b.append(y) dp = [([None] * 505) for _ in range(505)] totA = sum(a[1:]) totB = sum(b[1:]) dp[0][0] = True for i in range(1, n + 1): for j in range...
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NONE ASSIGN VAR LIST NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR...
Phoenix is picking berries in his backyard. There are $n$ shrubs, and each shrub has $a_i$ red berries and $b_i$ blue berries. Each basket can contain $k$ berries. But, Phoenix has decided that each basket may only contain berries from the same shrub or berries of the same color (red or blue). In other words, all berr...
n, k = map(int, input().split()) sumr = 0 sumb = 0 sumtot = 0 possr = [0] * k possr[0] = 1 for i in range(n): a, b = map(int, input().split()) sumr += a sumb += b sumtot += a sumtot += b tot = a + b poss2 = [0] * k for j in range(k): rest = a - j rest %= k if (res...
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for ss in range(int(input())): n, k = input().strip().split() n = int(n) k = int(k) list = [] ilist = [] klaar = True for i in range(10): m = 0 for t in range(k + 1): s = i + t if s >= 10: s = s - 9 m = m + s if i ==...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def sum_digit(x): s = 0 while x > 0: s += x % 10 x //= 10 return s def get_min(x): num9 = x // 9 r = x % 9 return (r + 1) * 10**num9 - 1 S = [[(0) for _ in range(10)] for _ in range(100)] dp = [[float("inf") for _ in range(10)] for _ in range(2000)] mid = [(10**i - 1) for i i...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING V...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def generate_prefix(su): pre = "" if su >= 8: pre += "8" su -= 8 if len(pre) > 0: nu = 9 else: nu = 8 while su > 0: while su >= nu: su -= nu pre += str(nu) nu -= 1 pre = pre[::-1] return pre def get_number(su, nines, d...
FUNC_DEF ASSIGN VAR STRING IF VAR NUMBER VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
t = int(input()) buf = [] INF = 10**18 for _ in range(t): n, k = list(map(int, input().split())) base = n - k * (k + 1) // 2 ans = INF l = k + 1 if base >= 0 and base % l == 0: ini = base // l if ini <= 9 - k: ans = min(ans, ini) else: tmp = ini - (9 -...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER BIN_OP VAR VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def get(sum): if sum < 9: return sum sum -= 8 ret = sum % 9 sum = sum - sum % 9 while sum > 0: ret = ret * 10 + 9 sum -= 9 return ret * 10 + 8 t = int(input()) while t > 0: t -= 1 n, k = [int(i) for i in input().split()] ok = 0 ans = 0 for dig in ran...
FUNC_DEF IF VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def f(x): ret = 0 while x: ret += x % 10 x //= 10 return ret def d(x, k): ret = 0 for i in range(k + 1): ret += f(x + i) return ret t = int(input()) while t: t -= 1 n, k = map(int, input().split()) fl = False s = 0 ans = "-1" for j in range(30)...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def sum_digits(number): return sum(int(digit) for digit in str(number)) nb_cases = int(input()) for case in range(nb_cases): n, k = [int(x) for x in input().split()] dp = ["-1"] * 151 dp[int(k * (k + 1) / 2)] = "0" for n1 in range(int(dp[1])): dp[n1] = "-1" for x in range(1, 10): ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER STRING FOR VAR FUNC...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys input = sys.stdin.readline t = int(input()) best = [[(-1) for x in range(10)] for y in range(151)] for pp in range(100000): total = 0 for kk in range(10): l = list(str(pp + kk)) l = [int(v) for v in l] total += sum(l) if total < 151 and best[total][kk] == -1: ...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def digitsum(n): ans = 0 while n > 0: ans += n % 10 n //= 10 return ans def construct_min_prefix(x): s = "" if x % 9 != 0: s += str(x % 9) s += "9" * (x // 9) return s def find_sum(x, k): done = 0 for i in range(k + 1): done += digitsum(int(x) + i)...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FU...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def digitsum(n): s = 0 while n: s += n % 10 n //= 10 return s for nitish in range(int(input())): ans = 10**30 str_arr = input().split(" ") arr = [int(num) for num in str_arr] n = arr[0] k = arr[1] for lastdigit in range(10): for numberofnine in range(100): ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR V...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
from sys import stdin input = stdin.readline INF = 10**9 + 7 MAX = 10**7 + 7 MOD = 10**9 + 7 def buildDigit(crs): s = "9" * (crs // 9) s += str(crs % 9) s = list(s) s.sort() return "".join(s) for Ti in range(int(input().strip())): n, k = [int(x) for x in input().strip().split()] d = lis...
ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR BIN_OP STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL STRING VAR FOR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
from sys import stdin, stdout def cont(n): res = 0 if n < 8: return n n -= 8 res += n % 9 n -= n % 9 while n: res *= 10 res += min(n, 9) n -= min(n, 9) res = res * 10 + 8 return res t = 1 t = int(stdin.readline()) for _ in range(t): n, k = list(map...
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR V...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def fun(x): if x < 9: return x ws = x // 9 res = x - 9 * ws for i in range(0, ws): res = res * 10 + 9 return res t = int(input()) for it in range(0, t): res = 0 sum = 0 ans = 4e18 n, k = map(int, input().split(" ")) for c in range(0, 10): if c + k < 10: ...
FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSI...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
tests = int(input()) INF = 10**20 for test in range(tests): n, w = map(int, input().split()) res = INF for k in range(17): for d in range(10): tmp = 0 for i in range(w + 1): if d + i <= 9: tmp += 9 * k + d + i else: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
T = int(input()) while T > 0: n, k = map(int, input().split()) res = float("inf") for last in range(0, 10): if last + k <= 9: al = (last + last + k) * (k + 1) // 2 left = n - al if left >= 0 and left % (k + 1) == 0: x = left // (k + 1) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBE...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): n, k = tuple(map(int, input().split())) ans = float("inf") for count_9 in range(100): for last_number in range(10): first_sum = count_9 * 9 + last_number have_sum = first_sum * (k + 1) + k * (k + 1) // 2 if last_number + k >= 10: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): n, k = map(int, input().split()) ans = float("inf") for i in range(10): SUM = 0 for j in range(i, i + k + 1): j %= 10 SUM += j a = min(9, i + k) - i + 1 b = k + 1 - a SUM += b nine = 0 while nine * ...
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 STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER BIN_OP VAR VAR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def cal(a, b, k): base = 9 * a su = (k - b) * (k - b + 1) // 2 + (k - b + 1) while b: su += base base -= 1 b -= 1 return su for _ in range(int(input())): n, k = map(int, input().split()) st = "" if n < k * (k + 1) // 2: print(-1) continue if (n -...
FUNC_DEF ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR S...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def num(l): sumi = 0 for i in l: sumi = sumi * 10 + i return sumi t = int(input()) for you in range(t): l = input().split() n = int(l[0]) k = int(l[1]) poss = 0 mina = [] for d in range(10): num1 = min(10 - d, k + 1) num2 = k + 1 - num1 for l in rang...
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NU...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
from sys import stdin input = stdin.buffer.readline inf = 10**100 def f(x): return sum(int(i) for i in str(x)) for _ in range(int(input())): n, k = map(int, input().split()) ans = inf for cnt in range(20): for lst in range(10): x = int("9" * cnt + str(lst)) s = 0 ...
ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR 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 VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
mat = [([0] * 10) for i in range(10)] def val(n): r = 0 while n: r, n = r + n % 10, n // 10 return r for k in range(10): for s in range(10): mat[s % 10][k] = sum([val(n) for n in range(s, s + k + 1)]) def get_k(k): return [m[k] for m in mat] def get_value(n, k, acc=0): n_...
ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
m = [] for k in range(10): t = [] for i in range(10): a = 0 for j in range(k + 1): a += (i + j) % 10 + (i + j) // 10 t.append(a) m.append(t) for _ in range(int(input())): n, k = [int(x) for x in input().split()] l = m[k] ans = [] for i in range(10): ...
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys def input(): return sys.stdin.readline().rstrip() def input_split(): return [int(i) for i in input().split()] def k_one(n): if n == 0: return 0 ans = "" lis = list(range(1, 10)) lis.reverse() for i in lis: if n == 0: return int(ans) div = ...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
MAX = 150 INF = float("inf") def compute_suffix(digit_sum): digit_sum += 1 digit_count = digit_sum // 9 return 10**digit_count * (digit_sum % 9) + (10**digit_count - 1) - 1 def compute_prefix_sum(first_digit, prefix_len, num_count): pre_count = min(num_count, 10 - first_digit) result = ( ...
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR BIN_OP BIN_OP B...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): n, k = map(int, input().split()) ans = float("inf") for m in range(20): for l in range(10): if k + l <= 9: dsum = n - k * (k + 1) // 2 if dsum % (k + 1) == 0: f = dsum // (k + 1) f -= l ...
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 STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER N...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def find_smallest(fx, allow_nine_end): if fx < 0: return None if fx == 0: return "" a = [] if not allow_nine_end: d = min(8, fx) a.append(d) fx -= d while fx: d = min(9, fx) a.append(d) fx -= d return "".join(map(str, a[::-1])) t ...
FUNC_DEF IF VAR NUMBER RETURN NONE IF VAR NUMBER RETURN STRING ASSIGN VAR LIST IF VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): N, K = map(int, input().split()) ans = float("inf") for i in range(100 - K): val = 0 for j in range(i, i + K + 1): val += sum(list(map(int, list(str(j))))) if (N - val) % (K + 1) == 0 and N >= val: x = int((N - val) // (K + 1)) ...
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 STRING FOR VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
from sys import exit, stderr, stdin def rl(): return [int(w) for w in stdin.readline().split()] def sumdigits(x): r = 0 while x > 0: r += x % 10 x //= 10 return r def f(x, k): return sum(sumdigits(y) for y in range(x, x + k + 1)) def search(n, k): for x0 in range(10): ...
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR B...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def func(n): res = 0 if n < 8: return n n -= 8 res += n % 9 n -= n % 9 while n > 0: res = res * 10 res += min(n, 9) n -= min(n, 9) res = res * 10 + 8 return res for _ in range(int(input())): n, k = list(map(int, input().split())) ans = 10**20 ...
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIG...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
t = int(input()) for _ in range(t): n, k = map(int, input().split()) ans = float("INF") for w in range(17): for d in range(10): count = 0 for i in range(k + 1): if d + i <= 9: count += 9 * w + d + i else: ...
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 STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def f(n): ans = 0 while n: ans += n % 10 n //= 10 return ans def get(n, k): ans = 0 for i in range(k + 1): ans += f(n + i) return ans t = int(input()) for tmp in range(t): w, k = map(int, input().split()) ans = -1 for last in range(10): c9 = 0 ...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP 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 FUNC_CALL FUNC_CALL VAR ASSIGN...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def solve(s): ans, ten = 0, 1 while s > 0: val = min(9, s) ans += ten * val ten *= 10 s -= val return ans def digit_sum(val): s = 0 while val > 0: s += val % 10 val = int(val / 10) return s def f(k): return int(k * (k - 1) / 2) def xsolve...
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR N...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def sumDigits(x): if x == 0: return 0 return x % 10 + sumDigits(x // 10) def create(x): ans = "" while x >= 9: ans = "9" + ans x -= 9 ans = str(x) + ans return int(ans) def create_ex(x, y): track = -1 for i in range(9, x + 1, 9): r = x - i if r...
FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUM...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def get(summ): return str(summ % 9) + "9" * int(summ // 9) for t in range(0, int(input())): n, k = map(int, input().split()) result = -1 for last_digit in range(10): last_digit_sum = 0 for i in range(k + 1): last_digit_sum += (last_digit + i) % 10 if last_digit_sum ...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
from sys import stdin, stdout def get(s): return str(s % 9) + "9" * (s // 9) def sum_of_digits(n, k): k += 1 res = 10**100 for d in range(10): end = 0 for i in range(k): end += (d + i) % 10 if end > n: continue if d + k > 10: for cn...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys def gen1(n): base = 10**n - 1 yield base for i in range(0, n): yield base - 10**i def gen2(n): for i in range(n): for x in gen1(i): for j in range(0, 10): yield j * 10**i + x def dsum(n): s = 0 while n > 0: s += n % 10 ...
IMPORT FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR BIN_OP VAR BIN_OP NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def read_list(): return list(map(int, input().strip().split(" "))) def print_list(l): print(" ".join(map(str, l))) INF = 10**18 N = int(input()) for _ in range(N): n, k = read_list() base = k * (k + 1) // 2 dlt = n - base res = INF if dlt >= 0 and dlt % (k + 1) == 0: tmp = [] ...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
t = int(input()) while t > 0: n, k = map(int, input().split()) best = -1 for pos in range(0, 10): for kol in range(0, 20): sm = 0 for i in range(0, k + 1): if i + pos <= 9: sm += 9 * kol + pos + i else: s...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NU...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): n, k = map(int, input().split()) ans = [] if n <= (18 - k) * (k + 1) // 2: for i in range(10): check = n for j in range(k + 1): if i + j > 9: break else: check -= i + j ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR IF VA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for i in range(int(input())): n, k = map(int, input().split()) ans = "a" * 100 for x in range(10): for d in range(n // 9 + 2): left = n for i in range(k + 1): left -= d * 9 + i + x if x + i > 9: left += (d + 1) * 9 ...
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 BIN_OP STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys input = sys.stdin.readline def suming(x, k): s = 0 for i in range(k + 1): xi = x + i while xi > 0: s += xi % 10 xi //= 10 return s for f in range(int(input())): n, k = map(int, input().split()) if k == 0: sol = 0 toad = 1 ...
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER VAR BIN_OP 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 IF VAR NUMBER ASSIGN VAR NUMBER ASSIG...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def make_ans(count_9, last_num, start): if start <= 8: ans_str = str(start) + "9" * count_9 + str(last_num) else: start -= 8 count_first_9 = 0 while start > 9: count_first_9 += 1 start -= 9 ans_str = ( (str(start) if start != 0 else "")...
FUNC_DEF IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR STRING BIN_OP STRING VAR STRING BIN_OP STRING VAR FUNC_CALL VAR VAR RETURN FUNC_CA...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def get(s): return str(s % 9) + "9" * (s // 9) for tc in range(int(input())): n, k = map(int, input().split()) k += 1 bst = 10**100 for d in range(10): ends = 0 for i in range(k): ends += (d + i) % 10 if ends > n: continue if d + k > 10: ...
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP 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 VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def digit_sum(n): tot = 0 while n: tot += n % 10 n //= 10 return tot def sum_f(n, k): tot = 0 for i in range(k + 1): tot += digit_sum(n + i) return tot t = int(input().split()[0]) for case in range(t): n, k = map(int, input().split()) ans = -1 for i in ran...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUN...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def func(x, d, n, k): ans = str(x) for i in range(d): ans = "9" + ans for i in range(k + 1): y = (x + i) % 10 if y >= x: n -= d * 9 + y else: n -= 1 + y if n < 0: return -1 if n % (k + 1) != 0: return -1 p = int(n / ...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + "\n") def wi(n): sys.stdout.write(str(n) + "\n") def wia(a): sys.stdout.write(" ".join([...
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING FUNC_DEF EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys input = sys.stdin.readline I = lambda: list(map(int, input().split())) (t,) = I() for _ in range(t): n, k = I() if k == 0: a = "9" * (n // 9) + (str(n % 9) if n % 9 else "") print(a[::-1]) continue mi = (k + 1) * k // 2 if n < mi: print(-1) else: a...
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
for _ in range(int(input())): n, k = map(int, input().split()) ans = float("inf") for i in range(10000): Sum = 0 for j in range(i, i + k + 1): tmp = j while tmp: Sum += tmp % 10 tmp //= 10 if (n - Sum) % (k + 1) == 0 and n >= Su...
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 STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP VAR ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def num(pref): if pref == 0: return str() if pref < 9: return str(pref) else: ans = [8] pref -= 8 while pref > 9: ans.append(9) pref -= 9 if pref > 0: ans.append(pref) ans.reverse() return "".join([str(i) for...
FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
t = int(input()) best = [[(-1) for x in range(10)] for y in range(151)] m = [0] n = 0 for a in range(2, 17): for p in range(9): n += 10**a m.append(n) for r in m: for h in range(105): p = r + h total = 0 for k in range(10): l = list(str(p + k)) l =...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
import sys sys.setrecursionlimit(10**6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [...
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def pre(n): if n <= 8: return n n -= 8 count = n // 9 n = n % 9 if n > 0: return int(str(n) + "9" * count + str(8)) else: return int("9" * count + str(8)) def answer(n, k): ans = 10**20 for i in range(17): for j in range(0, 10): t = min(10 - ...
FUNC_DEF IF VAR NUMBER RETURN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP STRING VAR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP STRING VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER FOR...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def f(x): return sum(map(int, str(x))) def subsolve(n, k, x): x = max(0, x - 20) ans = -1 for _ in range(41): s = 0 for i in range(k + 1): s += f(x + i) if s == n: ans = x break x += 1 return ans def solve(): n, k = map(int,...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def read_int(): return int(input()) def read_ints(): return list(map(int, input().split(" "))) d = [(i % 10) for i in range(20)] def one(n): digits = ["9" for i in range(n // 9)] if n % 9 != 0: digits.append(str(n % 9)) digits.reverse() return "".join(digits) def two(n): if n...
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER E...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def digsum(x): ret = 0 while x > 0: ret += x % 10 x //= 10 return ret tt = int(input()) for loop in range(tt): n, k = map(int, input().split()) ans = float("inf") if (n - k * (k + 1) // 2) % (k + 1) == 0: X = (n - k * (k + 1) // 2) // (k + 1) now = [] wh...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP 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 STRING IF BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUM...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def f(sm, nine): if sm < 0: return -1 if nine * 9 > sm: return -1 sm -= nine * 9 ret = nine * "9" if sm >= 8: sm -= 8 ret = "8" + ret ret = str(sm % 9) + sm // 9 * "9" + ret return int(ret) def g(sm, lstmax): mn = min(sm, lstmax) sm -= lstmax ret...
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER STRING VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR F...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
t = int(input()) def solve(n, k): ans = -1 for i in range(10): m = n // 9 if i + k < 10: m = 0 for j in range(m + 1): if i + k >= 10 and j == 0: continue cur_sum = (i + (i + k)) * (k + 1) // 2 if j != 0: be...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER I...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def findPref(targetDigitSum): assert targetDigitSum >= 0 if targetDigitSum == 0: return "" if targetDigitSum <= 8: return str(targetDigitSum) rem = targetDigitSum - 8 if rem % 9 == 0: return "9" * (rem // 9) + "8" return str(rem % 9) + "9" * (rem // 9) + "8" def findPre...
FUNC_DEF VAR NUMBER IF VAR NUMBER RETURN STRING IF VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP BIN_OP STRING BIN_OP VAR NUMBER STRING RETURN BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP VAR NUMBER STRING FUNC_DEF VAR NUMBER IF VAR NUMB...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def digitsum(n): ans = 0 while n > 0: ans += n % 10 n //= 10 return ans for vishal in range(int(input())): ans = 10**40 n, k = list(map(int, input().split(" "))) for lastdigit in range(10): for numberofnine in range(100): if lastdigit + 9 * numberofnine > n:...
FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR ...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
line = input() t = int(line) def helper(n): res = "" if n % 9 == 0 else str(n % 9) res += "9" * (n // 9) return res for _ in range(t): line = input() n, k = [int(i) for i in line.split(" ")] res = "" if k == 0: print(helper(n)) else: k += 1 a = sum(range(k)) ...
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP STRING BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR STRING IF VAR N...
Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test cases. Each test case consists of one line containing two integers...
def construct(fx, d, i): s = "9" * (i - 1) + str(d) fx -= d + 9 * (i - 1) if fx < 0: return 2**63 - 1 if fx >= 8: s = "8" + s fx -= 8 else: s = str(fx) + s fx = 0 while fx: if fx >= 9: s = "9" + s fx -= 9 else: ...
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP STRING VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR IF VAR NUMBER ASSI...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
import sys def solve(): inp = sys.stdin.readline n, a, b = map(int, inp().split()) x = list(map(int, inp().split())) s = sum(x) r = 0 now = 0 for i in range(n): s -= x[i] r += (x[i] - now) * b if (s - now * (n - i - 1)) * b >= (s - x[i] * (n - i - 1)) * b + ( ...
IMPORT FUNC_DEF ASSIGN VAR VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR IF BIN_OP BIN_OP VAR BIN...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for iii in range(int(input())): n, a, b = map(int, input().split()) q = list(map(int, input().split())) q1 = [0] + q for i in range(1, n + 1): q1[i] += q1[i - 1] bwd_sum = 0 shift_cap = 0 fwd = 0 summ = 123456789876543212345678 for i in range(n + 1): if i == 0: ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NU...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for test in range(int(input())): n, a, b = map(int, input().split()) x = list(map(int, input().split())) sm = sum(x) ans = sm * b s = 0 for i in range(n): s += x[i] ans = min(ans, (a + b) * x[i] + (sm - s - (n - i - 1) * x[i]) * b) print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BI...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) lst = list(map(int, input().split())) pos = 0 llstr = [0] s2 = sum(lst) mini = sum(lst) * b for i in range(n): llstr.append((a + b) * (lst[i] - pos) + llstr[-1]) pos = lst[i] s2 -= lst[i] s3 = s...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR F...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
cases = int(input()) for case in range(cases): n, b, a = map(int, input().split()) kingdoms = list(map(int, input().split())) total = a * sum(kingdoms) index = 0 cur = 0 for item in kingdoms: difference = (item - cur) * b - a * (item - cur) * (n - 1 - index) if difference < 0: ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) def solve(n, a, b, X): dists = [X[0]] for x in X[1:]: dists.append(x + dists[-1]) lowest = dists[-1] * b for i in range(n - 1): current = a * X[i] current += b * X[i + 1] current += (dists[-1] - dists[i + 1] - (n - i - 2) * X[i]) * b lowest = mi...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_O...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(): n, a, b = map(int, input().split()) x = [0] + list(map(int, input().split())) n += 1 s = sum(x[1:]) mx = float("inf") for i in range(n): v = x[i] cr = (a + b) * v s -= v cr += (s - (n - i - 1) * v) * b mx = min(mx, cr) print(mx) tc = int...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def mincost(nums): presum = [0] * (n + 1) for i in range(1, n + 1): presum[i] = presum[i - 1] + nums[i - 1] ans = b * presum[n] for i in range(n): tmp = ( b * nums[i] + a * nums[i] + b * (presum[n] - presum[i + 1]) - (n - i - 1) * b * nums[...
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VA...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for _ in range(0, t): inputs = [int(num) for num in input().split()] n = inputs[0] a = inputs[1] b = inputs[2] list1 = [int(num) for num in input().split()] c = 0 cost_now = 0 now = 0 cost = 0 for i in range(0, len(list1)): point = list1[i] cost +...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUM...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(): n, a, b = map(int, input().split()) x = list(map(int, input().split())) ans = 10**18 suffix = 0 for i in range(n - 1, -1, -1): prefix = x[i] ans = min(ans, (a + b) * prefix + b * suffix) if i == 0: suffix += x[i] * n else: suffix +...
FUNC_DEF 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 BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VA...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for _ in range(t): n, a, b = map(int, input().split()) arr = list(map(int, input().split())) help = [0] * n for i in reversed(range(n - 1)): help[i] = help[i + 1] + arr[i + 1] cost = b * arr[0] index = 0 capital = 0 while index < n - 1: if b * (help[index...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NU...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(): n, a, b = list(map(int, input().split(" "))) x = [0] + list(map(int, input().split(" "))) mn = float("inf") sum = x[n] for i in range(n - 1, -1, -1): res = b * x[i] + a * x[i] + b * (sum - (n - i) * x[i]) sum += x[i] mn = min(res, mn) print(mn) for t in ran...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) positions = [0] positions.extend(map(int, input().split())) cost = 0 capital = 0 for i in range(1, n + 1): if b * (n - i - 1) > a - b: cost += (a + b) * (positions[i] - positions[i - 1]) capital = p...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for qwer in range(t): n, a, b = map(int, input().split()) l = ["0"] + input().split() sp = list(map(int, l)) ind = 0 colvo = n for i in range(n - 1): c = sp[i + 1] - sp[ind] if c * (colvo - 1) * b > c * a: ind = i + 1 colvo -= 1 if a <= b:...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VA...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for _ in range(t): n, a, b = map(int, input().split()) x = list(map(int, input().split())) sumX = 0 for num in x: sumX += num sumPrev = 0 minimum = 2 * 10 ^ 13 + 1 for i in range(n - 1): if i != 0: sumPrev += x[i - 1] additional = a * x[i]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUN...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for i in range(t): n, a, b = map(int, input().split()) lst = list(map(int, input().split())) pre = [lst[0]] for j in range(1, n): pre.append(pre[-1] + lst[j]) ans = [] dif = [lst[0]] for j in range(1, n): dif.append(lst[j] - lst[j - 1]) ans.append(pre[-1]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST ASSIGN...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split(" ")) c = list(map(int, input().split(" "))) sc = sum(c) sci = 0 ans = b * sc for i in range(n): sc -= c[i] val = (a + b) * c[i] + b * (sc - c[i] * (len(c) - i - 1)) if val <= ans: ans = val pr...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) arr = [0] my = [int(i) for i in input().split()] arr.extend(my) tot = sum(arr) * b ans = 0 pre = 0 post = 1 for i in range(1, len(arr)): while post < i: save = (arr[post] - arr[pre]) * b * (len(arr)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for i in range(int(input())): l = list(map(int, input().split())) n = l[0] a = l[1] b = l[2] l = [0] l.extend(list(map(int, input().split()))) l1 = [b * sum(l)] a1 = 0 b1 = 1 for j in range(n): l1.append(l1[j] + a * (l[j + 1] - l[j]) - (n - j - 1) * b * (l[j + 1] - l[j]))...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP VAR FUNC_CALL VA...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def main(): T = int(input()) for _ in range(T): n, a, b = list(map(int, input().strip().split(" "))) v = list(map(int, input().strip().split(" "))) sum = 0 for i in range(len(v)): sum += v[i] res = 1e18 v.insert(0, 0) cur = 0 for i in r...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) l = list(map(int, input().split())) l = [0] + l ans = [(0) for i in range(n)] ans[0] = sum(l) * b for i in range(1, len(ans)): ans[i] = ans[i - 1] + (l[i] - l[i - 1]) * a - (n - i) * b * (l[i] - l[i - 1]) print(min(ans...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(): N, A, B = map(int, input().split()) x = list(map(int, input().split())) x.append(0) x.insert(0, 0) N += 1 COSTA = 0 COSTB = 0 COSTC = 0 ANS = 1 << 60 for i in range(N): COSTB += x[i] * B for i in range(0, N): COSTA = x[i] * A COSTB -= (N -...
FUNC_DEF 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 EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR V...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for i in range(t): n, a, b = [int(i) for i in input().split()] positions = [int(i) for i in input().split()] s = sum(positions) finals = [] neg = 0 for i in range(len(positions)): neg += positions[i] cost = 0 cost += positions[i] * (a + b) cost +=...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in " " * int(input()): n, a, b = map(int, input().split()) x = list(map(int, input().split())) sf = [0] * n pr = [0] * n sf[-1] = x[-1] pr[0] = x[0] for i in range(1, n): pr[i] = pr[i - 1] + x[i] for i in range(n - 2, -1, -1): sf[i] = sf[i + 1] + x[i] mnc = b * ...
FOR VAR BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CAL...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) while t: t -= 1 n, a, b = map(int, input().split()) x = [0] + [*map(int, input().split())] l = [sum(x) * b] for i in range(1, n): c = l[-1] + a * (x[i] - x[i - 1]) - (x[i] - x[i - 1]) * (n - i) * b if c > l[-1]: break l.append(c) print(l[-1])
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP V...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) v = list(map(int, input().split())) v = [0] + v s = sum(v) res = int(1e18) n += 1 for i in range(n): curr = (a + b) * v[i] s -= v[i] curr += (s - (n - i - 1) * v[i]) * b res = min(res, curr) ...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) for i in range(t): n, a, b = map(int, input().split()) ls = list(map(int, input().split())) ls.insert(0, 0) n += 1 sum = 0 x = ls[n - 1] lastCost = x * (a + b) for j in range(n - 1, -1, -1): x = ls[j] cost = x * (a + b) + b * (sum - (n - j - 1) * x) ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = [int(x) for x in input().split()] v = [int(x) for x in input().split()] v = [0] + v con = [0] * (n + 1) for i in range(1, n + 1): con[i] = b * (v[i] - 0) for i in range(n - 1, -1, -1): con[i] += con[i + 1] cost = 0 val = 0 ans =...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(): n, a, b = list(map(int, input().split())) arr = [0] + list(map(int, input().split())) second_arr = [0] + [abs(arr[i] - arr[i + 1]) for i in range(n)] s = sum(arr) iter_sum = 0 min_ = float("inf") n = len(arr) length = n for i in range(length): s -= arr[i] ...
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
for _ in range(int(input())): n, a, b = map(int, input().split()) array = list(map(int, input().split())) sm = sum(array) sums = [sm] for i in array: sm -= i sums.append(sm) mn = sums[0] * b for i in range(n): tp = array[i] * a tp += (sums[i + 1] - (n - i - 2)...
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
iter = int(input()) for _ in range(iter): lst = list(map(int, input().split())) kingdoms = list(map(int, input().split())) min_cost = 0 prefix = [0] * lst[0] prefix[0] = kingdoms[0] for i in range(1, lst[0]): prefix[i] += kingdoms[i] + prefix[i - 1] min_cost = lst[2] * prefix[-1] ...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
def solve(n, a, b, xs): S = sum(xs) res = b * S for i in range(n): S -= xs[i] tmp = a * xs[i] + b * (S - (n - i - 2) * xs[i]) res = min(res, tmp) return res for _ in range(int(input())): n, a, b = map(int, input().split()) xs = [*map(int, input().split())] res = sol...
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FU...
You are an ambitious king who wants to be the Emperor of The Reals. But to do that, you must first become Emperor of The Integers. Consider a number axis. The capital of your empire is initially at $0$. There are $n$ unconquered kingdoms at positions $0<x_1<x_2<\ldots<x_n$. You want to conquer all other kingdoms. The...
t = int(input()) while t > 0: c = input().split() n, a, b = int(c[0]), int(c[1]), int(c[2]) x = input().split() for i in range(n): x[i] = int(x[i]) x = [0] + x ans = 0 cur = 0 ind = 0 for i in range(1, n + 1): while ind < i - 1: if b * (x[ind + 1] - x[ind]...
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASS...
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the mi...
n, k, p = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() b.sort() def cost(j): if j < 0 or j + n - 1 >= k: return 1000000000000 maximum = 0 for i in range(n): t = abs(a[i] - b[i + j]) + abs(b[i + j] - p) maximum = max(maxi...
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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR RETURN NUMBER ASSIGN VAR NUMBER...
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the mi...
read = lambda: map(int, input().split()) n, k, p = read() a, b = sorted(read()), sorted(read()) print( min( max(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1) ) )
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR...
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else. You are to determine the mi...
n, k, p = [int(i) for i in input().split()] A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] A.sort() B.sort() ans = 10**18 for start in range(k): curmax = 0 curans = 10**18 if start + n > k: continue for i in range(n): curmax = max(curmax, abs(A[i] - B[start +...
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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NU...