description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
pair = []
def transform(val):
count = 0
while val != 1:
val = val / 2 if val % 2 == 0 else 3 * val + 1
count += 1
return count
for i in range(lo, hi + 1):... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def __recur(self, dp, num):
if num in dp:
return dp[num]
res = 0
if num % 2 == 0:
res = self.__recur(dp, int(num / 2)) + 1
else:
res = self.__recur(dp, int(num * 3) + 1) + 1
dp[num] = res
return res
def getKth(... | CLASS_DEF FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF VAR VAR VAR ASSIGN VAR DIC... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo, hi, k):
dic = {}
for n in range(lo, hi + 1):
steps = self.countStep(n)
dic[n] = steps
return sorted(dic.items(), key=lambda x: (x[1], x[0]))[k - 1][0]
def countStep(self, m):
step = 0
while m != 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def getPower(num):
if num == 1:
return 1
count = 0
while num != 1:
if num % 2 == 0:
num = num / 2
count += 1
else:
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
power_dic = {}
power_dic_sub = {}
for i in range(lo, hi + 1):
power_dic_sub[i] = self.getPower(i, 0, [], power_dic)
result_tmp = sorted(power_dic_sub.items(), key=lambda kv: kv[1], reverse=False)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER LIST VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF IF VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def __init__(self):
self.d = {}
def solve(self, x):
if x == 1:
return 0
if self.d.get(x, 0) != 0:
return self.d[x]
if x % 2 == 0:
self.d[x] = 1 + self.solve(x // 2)
return self.d[x]
else:
self.d... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR VAR FUNC... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def getPow(n):
c = 0
while n != 1:
if n % 2 == 0:
n //= 2
else:
n = 3 * n + 1
c += 1
return c
def func():
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR F... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | dp = {}
class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
result = [(num, self.getPowerValue(num)) for num in range(lo, hi + 1)]
result.sort(key=lambda x: (x[1], x[0]))
return result[k - 1][0]
def getPowerValue(self, num) -> int:
if num == 1:
retu... | ASSIGN VAR DICT CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, z: int) -> int:
d = {}
def dfs(k):
if k == 1:
return
elif k % 2 == 0:
c[0] += 1
dfs(k // 2)
else:
c[0] += 1
dfs(3 * k + 1)
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR NUMBER RETURN IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR VAR A... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, m: int) -> int:
a = [i for i in range(lo, hi + 1)]
z = []
def cv(s, c, k):
if s in k:
k[s] = k[s] + 1
elif s % 2 == 0:
s = s / 2
c = c + 1
else:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def fun(n):
if n == 1:
return 0
ans = 0
while n > 1:
if n % 2 == 0:
n //= 2
else:
n = n * 3 + 1
ans... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def getPower(n):
step = 0
while n != 1:
n = 3 * n + 1 if n % 2 else n / 2
step += 1
return step
powers = sorted(
[(i, getPower(i)) for i in range(lo, ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER NUMBER... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
p = {}
for i in range(lo, hi + 1):
temp = 0
copy_i = i
if copy_i == 1:
p[i] = 0
while copy_i != 1:
if copy_i % 2 == 0:
copy_i /= 2
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
count = 0
answers = []
numbers = []
memo = {}
for number in range(lo, hi + 1):
original = number
numbers.append(numbers)
count = 0
while number != 1:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BI... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def key_func(val):
def recur(val):
if val <= 1:
return 0
if val % 2 == 0:
return recur(val / 2) + 1
return recur(val * 3 + 1) + 1
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
input = list(range(lo, hi + 1))
output = []
def getPower(val, currPower):
if val == 1:
output.append(currPower)
return None
elif val % 2 == 0:
val /= 2... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN NONE IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
dic = {}
for i in range(lo, hi + 1):
z = self.getTheP(i)
dic[i] = self.getTheP(i)
return sorted(list(dic.items()), key=lambda x: (x[1], x[0]))[k - 1][0]
def getTheP(self, q: int) -> int:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBE... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def power(self, n):
c = 0
while n != 1:
if n % 2:
n = n * 3 + 1
else:
n //= 2
c += 1
return c
def getKth(self, lo: int, hi: int, k: int) -> int:
e = [i for i in range(lo, hi + 1)]
e.sort... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
@staticmethod
def compute_power(x, d={}):
if x in d:
return d[x]
xcopy, steps = x, 0
while x != 1 and x not in d:
x = 3 * x + 1 if x % 2 else x // 2
steps += 1 + d[x] if x in d else 1
d[xcopy] = steps
return steps
... | CLASS_DEF FUNC_DEF DICT IF VAR VAR RETURN VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NU... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def num_count(self, x, count):
if x == 1:
return count
count += 1
if x % 2 == 0:
x = x // 2
else:
x = x * 3 + 1
if x in self.dp:
return count + self.dp[x]
return self.num_count(x, count)
def getKth(... | CLASS_DEF FUNC_DEF IF VAR NUMBER RETURN VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUN... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
lst = []
def power(s) -> int:
count = 0
while s != 1:
if s % 2 == 0:
s = s // 2
count = count + 1
else:
s = 3 * s +... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUN... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | def power_value(num: int, counter=0):
if num % 2 == 0:
num = num / 2
else:
num = 3 * num + 1
counter += 1
if num == 1:
return counter
else:
return power_value(num, counter=counter)
class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
to_so... | FUNC_DEF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR VAR CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR FUNC_CALL VAR VA... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
arr_of_powers = {}
def get_int_power(num):
pwr = 0
temp = num
while temp != 1:
pwr += 1
if temp % 2 == 0:
temp /= 2
elif temp %... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIG... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
a = {}
def check(n, a):
ct = 0
while n != 1:
if n % 2 == 0:
n = n / 2
else:
n = 3 * n + 1
if n in a:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
dp = {}
def findPower(self, num):
way = [num]
ops = 0
while num != 1 and num not in self.dp:
if num % 2 == 0:
num /= 2
else:
num = num * 3 + 1
way.append(num)
ops += 1
if num in self.... | CLASS_DEF ASSIGN VAR DICT FUNC_DEF ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FOR ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
d = {}
for i in range(lo, hi + 1):
self.pow(i, i, d, 0)
d1 = OrderedDict(sorted(list(d.items()), key=lambda x: x[1]))
l = list(d1.keys())
return l[k - 1]
def pow(self, n1, n, d, c):
i... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR RETURN VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR NUMBER ASSIGN VAR VAR VAR... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
res = []
self.inc = {(1): 0}
while lo <= hi:
heapq.heappush(res, (self.find_power(lo), lo))
lo += 1
for i in range(k):
ans = heapq.heappop(res)[1]
return ans
def find_... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT NUMBER NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL V... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
d = {}
def getPowerValue(x):
if x in d:
return d[x]
steps = 0
original = x
while x != 1:
if x % 2:
x = 3 * x + 1
el... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FUNC_DEF IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BI... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
power_dic = {}
powers = []
for num in range(lo, hi + 1):
powers.append([self.powerOf(num, 0, power_dic), num])
return sorted(powers, key=lambda x: x[0])[k - 1][1]
def powerOf(self, x, steps, power_di... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN VAR IF BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR BIN_OP V... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def __init__(self):
self.memo = {}
def getKth(self, lo: int, hi: int, k: int) -> int:
power = [(0) for i in range(lo, hi + 1)]
for i in range(lo, hi + 1):
if i in self.memo:
power[i - lo] = self.memo[i]
else:
power... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR RETURN VA... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
res = []
dict1 = {}
for i in range(lo, hi + 1, 1):
c = 0
r = []
v = 0
p = i
while c == 0:
if i == 1:
c = 1
elif ... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER WHILE BIN_OP VAR NUMBE... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
i = 0
pow2Dict = {(1): 0}
pow2Now = 1
while i < 32:
i += 1
pow2Now *= 2
pow2Dict[pow2Now] = i
visited = {}
stack = [(0, i, i) for i in range(lo, hi + 1)]
wh... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def power(x):
r = 0
while x > 1:
if x % 2 == 0:
x >>= 1
else:
x = 3 * x + 1
r += 1
return r
array = (i for... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR BIN_OP VAR NUMBER VAR |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
x = {}
for i in range(lo, hi + 1):
j = []
g = i
while i != 1:
if i % 2 == 0:
i = i / 2
j.append(i)
else:
... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR AS... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def power(num):
res = 0
while num != 1:
if num % 2 == 0:
num = num / 2
else:
num = 3 * num + 1
res += 1
return res
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
res = []
def power(num):
if num == 2:
return 1
elif num % 2 == 0:
return 1 + power(num // 2)
else:
return 1 + power(3 * num + 1)
dic = col... | CLASS_DEF FUNC_DEF VAR VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL ... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def getPower(x):
count = 0
while x != 1:
if x % 2 == 0:
x /= 2
count += 1
else:
x = 3 * x + 1
count += ... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VA... |
The power of an integer x is defined as the number of steps needed to transform x into 1 using the following steps:
if x is even then x = x / 2
if x is odd then x = 3 * x + 1
For example, the power of x = 3 is 7 because 3 needs 7 steps to become 1 (3 --> 10 --> 5 --> 16 --> 8 --> 4 --> 2 --> 1).
Given three integers ... | class Solution:
def getKth(self, lo: int, hi: int, k: int) -> int:
def getF(x):
if x == 1:
return 0
return getF(3 * x + 1) + 1 if x % 2 == 1 else getF(x // 2) + 1
weights = list(range(lo, hi + 1))
weights = sorted(weights, key=lambda x: getF(x))
... | CLASS_DEF FUNC_DEF VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN... |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | l, r = map(int, input().split())
ans, t = 0, dict({(l - 1): 0, r: 0})
if l == r:
exit(print(1 if str(l)[0] == str(l)[-1] else 0))
for num in [l - 1, r]:
le = 1
while True:
if len(str(num)) > le:
if le < 3:
t[num] += 9
else:
t[num] += 10 ** (le ... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR DICT BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE NUMBER IF FUNC_CALL... |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | def func(b):
n2 = len(b)
ans = 0
for i in range(1, n2):
if i == 1:
ans += 9
else:
ans += 9 * 10 ** (i - 2)
for i in range(0, n2 - 1):
if n2 > 2:
if i == 0:
tmp = (int(b[i]) - 1) * 10 ** (n2 - 2 - i)
else:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP... |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | l, r = map(int, input().split())
def upto_x(n):
if n < 10:
return n
sm = n // 10 + 9
if str(n)[-1] < str(n)[0]:
sm -= 1
return sm
print(upto_x(r) - upto_x(l - 1)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | l, r = map(int, input().split())
result = 0
for digit in range(1, 10):
d_str = str(digit)
for length in range(3, 19):
if (
int(d_str + (length - 2) * "0" + d_str) <= r
and int(d_str + (length - 2) * "9" + d_str) >= l
):
a, b, c = 0, int((length - 2) * "9"), 0
... | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER STRING VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER STRING VAR V... |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | def get(x):
return x if x < 10 else x // 10 + 9 - (0 if str(x)[0] <= str(x)[-1] else 1)
l, r = map(int, input().split())
print(get(r) - get(l - 1)) | FUNC_DEF RETURN VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | l, r = list(map(int, input().split()))
def cnt(x):
ret = 0
for i in range(1, x + 1):
s = str(i)
if s[0] == s[-1]:
ret += 1
return ret
def cnt2(x):
ret = 0
s = str(x)
L = len(s)
if L >= 2 and x == 10 ** (L - 1):
return cnt2(10 ** (L - 1) - 1)
if L <... | 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 NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ... |
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be inclu... | a1 = list(map(int, input().split()))
if (a1[0] < 10) & (a1[1] < 10):
print(a1[1] - a1[0] + 1)
elif a1[0] < 10:
b = a1[1] - int(str(a1[1])[-1])
ans = 10 - a1[0] + b // 10
if str(a1[1])[0] > str(a1[1])[len(str(a1[1])) - 1]:
ans -= 1
else:
pass
print(ans)
else:
b1 = a1[0] - int(... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | dp = []
def fun(n, a):
dp[0] = 1
for i in range(1, n):
l, r = 0, i - 1
while l <= r:
m = l + r >> 1
if a[i][0] - a[m][0] <= a[i][1]:
r = m - 1
else:
l = m + 1
dp[i] = dp[r] + 1
n = int(input())
dp = [(0) for i in ran... | ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
maxn = 1000000.0 + 5
mx = 0
b = [0] * int(maxn)
for i in range(n):
a1, b1 = map(int, input().split())
b[a1] = b1
dp = [0] * int(maxn)
if b[0] > 0:
dp[0] = 1
for i in range(1, int(maxn)):
if b[i] == 0:
dp[i] = dp[i - 1]
elif b[i] >= i:
dp[i] = 1
else:
dp[i... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR N... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
p = []
for i in range(n):
a, b = map(int, input().split())
p.append([a, b])
p.sort()
ans = []
for i in range(n):
ans.append(1)
for i in range(1, n):
l = -1
r = i
f = False
while r - l > 1:
m = (l + r) // 2
if p[m][0] >= p[i][0] - p[i][1]:
r = m
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR V... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
dp = [0] * 1000007
majak = [0] * 1000007
q = 1000007
p = 0
for i in range(n):
a, b = map(int, input().split())
q = min(q, a)
majak[a] = b
dp[q] = 1
ma = 1
for i in range(q + 1, 1000003, 1):
if majak[i] == 0:
dp[i] = dp[i - 1]
else:
dp[i] = dp[i - majak[i] - 1] + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUM... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | N = int(1000000.0 + 3)
c = [0] * N
n = int(input())
for _ in range(n):
a, b = map(int, input().split())
c[a] = b
for i in range(N):
if c[i] >= i and c[i] > 0:
c[i] = 1
elif c[i] > 0:
c[i] = c[i - c[i] - 1] + 1
else:
c[i] = c[i - 1]
print(n - max(c)) | ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASS... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
li = [[]]
l = [-1] * 1000001
maxi = 0
for i in range(0, n):
li = list(map(int, input().split()))
l[li[0]] = li[1]
if li[0] > maxi:
maxi = li[0]
k = 0
a = [0] * (maxi + 1)
for i in range(0, maxi + 1):
if l[i] == -1:
a[i] = k
continue
if i - l[i] < 1:
a... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | class CodeforcesTask607ASolution:
def __init__(self):
self.result = ""
self.beacons_count = 0
self.beacons = [(0) for x in range(1000005)]
def read_input(self):
self.beacons_count = int(input())
for x in range(self.beacons_count):
a_b = [int(x) for x in inpu... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
lighthouses = [0] * (1000000 + 2)
count = [0] * (1000000 + 2)
for i in range(n):
a, b = map(int, input().split())
lighthouses[a] = b
if lighthouses[0] > 0:
count[0] = 1
for i in range(1, 1000000 + 1):
if lighthouses[i] == 0:
count[i] = count[i - 1]
elif lighthouses[i] >= i:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER 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 VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BI... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | N = int(input())
d = [(0) for i in range(1000005)]
Memo = [(0) for i in range(1000005)]
max_pos = 0
for i in range(N):
subList = input().split()
index = int(subList[0])
d[index] = int(subList[1])
max_pos = max(index, max_pos)
if d[0] != 0:
Memo[0] = 1
result = N
result = min(result, N - Memo[0])
for... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | R = lambda: map(int, input().split())
n = int(input())
v = []
for _ in range(n):
a, b = R()
v.append((a, b))
v = sorted(v)
def find(v, x, i, j):
if v[i][0] >= x:
return -1
if i == j:
return i
if i == j - 1:
return j if v[j][0] < x else i
m = (i + j) // 2
return find... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR NUMBER VAR RETURN NUMBER IF VAR VAR RETURN VAR IF VAR BIN_OP VAR NUMBER RETURN VA... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
p = [(-(10**6), 0)] + sorted([tuple(map(int, input().split())) for i in range(n)])
dp = [0] * (n + 1)
for i in range(1, n + 1):
l, r = 0, i
while r - l > 1:
mid = l + r >> 1
if p[i][0] - p[i][1] <= p[mid][0]:
r = mid
else:
l = mid
dp[i] = i - ... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
__author__ = "MoonBall"
T = 1
def process():
N = int(input())
a = [-1] * 1100000
d = [-1] * 1100000
for _ in range(N):
_a, _b = list(map(int, input().split()))
a[_a] = _b
for i in range(1100000):
if a[i] < 0:
d[i] = d[i - 1] if i > 0 else 0
... | IMPORT ASSIGN VAR STRING ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST 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 VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
cp = [0] * n
for i in range(n):
cp[i] = tuple(map(int, input().split()))
cp.sort()
maxman = [-1] * n
for i in range(1, n):
left = -1
right = i
while right - left > 1:
m = (right + left) // 2
if cp[i][0] - cp[i][1] <= cp[m][0]:
right = m
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASS... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
a = [0] * (10**6 + 5)
dp = [0] * (10**6 + 5)
maxx = -1
for i in range(n):
b, c = map(int, input().split())
a[b] = c
for i in range(len(a)):
if i == 0:
if a[0] > 0:
dp[0] = 1
elif a[i] == 0:
dp[i] = dp[i - 1]
elif a[i] >= i:
dp[i] = 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
b = []
for i in range(n):
b.append(list(map(int, input().split())))
b.sort()
D = [0] * n
D[0] = 0
def binSearch(target, data, init_end):
start = 0
end = init_end
while start <= end:
mid = (start + end) // 2
if data[mid][0] == target:
return mid
elif... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR V... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
h = [-1] * 1000010
m = 0
for i in range(n):
a, b = map(int, input().split())
if a > m:
m = a
h[a] = b
dp = [1 if h[0] != -1 else 0]
for i in range(1, m + 1):
if h[i] != -1:
if i - h[i] - 1 < 0:
dp.append(1)
else:
dp.append(dp[i - h[i] - 1]... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
if False:
inp = open("C.txt", "r")
else:
inp = sys.stdin
maxn = 10**6 + 10
dp = [(0) for i in range(maxn)]
beacons = [(0) for i in range(maxn)]
total = [(0) for i in range(maxn)]
ans = maxn
n = int(inp.readline())
for i in range(n):
a, b = map(int, inp.readline().split())
beacons[a] = b
... | IMPORT IF NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASS... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | t = int(input())
a = {}
b = {}
for _ in range(t):
a1, b1 = list(map(int, input().split()))
a[a1] = 1
b[a1] = b1
dp = [(0) for _ in range(max(a) + 1)]
for i in range(0, max(a) + 1):
if i in a:
if i - b[i] - 1 < 0:
dp[i] = 1
else:
dp[i] = dp[i - b[i] - 1] + 1
el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CA... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
a = [0] * 1000001
last = 0
for i in range(n):
x, p = map(int, input().split())
a[x] = p
last = max(last, x)
dp = [0] * (last + 1)
if a[0] != 0:
dp[0] = 1
for i in range(1, last + 1):
if a[i] == 0:
dp[i] = dp[i - 1]
elif i - a[i] >= 0:
dp[i] = dp[i - a[i] - 1] + 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMB... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
N = 1000001
num_beacons = int(sys.stdin.readline())
beacons = [(0) for x in range(N)]
dp = [(0) for x in range(N)]
for x in range(num_beacons):
position, power_lv = map(int, sys.stdin.readline().split())
beacons[position] = power_lv
dp[0] = beacons[0] != 0
for y in range(1, N):
if beacons[y] == ... | IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VA... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
def inp():
return sys.stdin.readline().strip()
n = int(input())
x = dict()
mm = -1
for i in range(n):
a, b = map(int, input().split())
x[a] = b
mm = max(a, mm)
if 0 in x:
otv = [1]
else:
otv = [0]
ma = -1
for i in range(1, mm + 2):
if i not in x:
otv.append(otv[i - 1])... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF NUMBER VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUM... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | from sys import stdin
test = stdin.readlines()
n = int(test[0])
beacons = []
for i in range(1, n + 1):
ai, bi = map(int, test[i].split())
beacons.append((ai, bi))
beacons.sort()
pmax = beacons[-1][0]
beacons_pos = [0] * (pmax + 1)
for ai, bi in beacons:
beacons_pos[ai] = bi
acc = [0]
for i in range(pmax + ... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR VAR VAR ASSIGN... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
maxN = 10**6 + 5
dp = [0] * maxN
b = [0] * maxN
N = int(sys.stdin.readline())
for _ in range(N):
beacon = [int(x) for x in sys.stdin.readline().split()]
b[beacon[0]] = beacon[1]
if b[0] > 0:
dp[0] = 1
for i in range(1, maxN):
if b[i] == 0:
dp[i] = dp[i - 1]
elif b[i] >= i:
... | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBE... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def bin(mas, x):
l = 0
r = len(mas)
while r > l + 1:
m = (r + l) // 2
if x < mas[m]:
r = m
else:
l = m
return l
n = int(input())
a = [-9999999]
b = [9999999]
dp = [0] * (n + 1)
for i in range(n):
x, y = [int(i) for i in input().split()]
a.append(... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR 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 RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
lis = [0] * 1000004
dp = [0] * 1000004
for i in range(n):
a, b = map(int, input().split())
lis[a] = b
if lis[0] > 0:
dp[0] = 1
for i in range(1, 1000002):
if lis[i] > 0:
dp[i] = dp[max(-1, i - lis[i] - 1)] + 1
else:
dp[i] = dp[i - 1]
print(n - max(dp)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIG... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def sol(arr, n):
if n < 0:
return 0
if n == 0:
if arr[n] == 0:
return 0
return 1
if arr[n] == 0:
return sol(arr, n - 1)
return max(1 + sol(arr, n - arr[n] - 1), sol(arr, n - 1))
n = int(input())
arr = [(0) for i in range(1000001)]
m = 0
for i in range(n):
... | FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR BIN_OP NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR A... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def bisect_left(A, ele):
l = 0
r = len(A) - 1
while r > l:
mid = (l + r) // 2
if A[mid][0] >= ele:
r = mid
else:
l = mid + 1
return r
def answer(n, A):
A.sort(key=lambda x: x[0])
dp = [0] * n
for i in range(1, n):
ele = A[i][0] - A[i]... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BI... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
lista = []
for i in range(n):
lista.append([int(x) for x in input().split()])
lista.sort()
diccionario = dict()
nada = True
last = 0
maximo = 0
for x, i in lista:
if nada == True:
for c in range(0, x):
diccionario[c] = 0
diccionario[x] = 1
maximo = 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VA... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
a = []
b = []
d = {}
for i in range(n):
x, y = map(int, input().split())
d[x] = y
a.append(x)
b.append(y)
m = max(a)
ans = [0] * (m + 1)
for i in range(m + 1):
if d.get(i, -1) == -1:
ans[i] = ans[i - 1]
else:
ans[i] = 1 + (ans[i - d[i] - 1] if i - d[i] - 1 >= 0 e... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | from sys import stdin
input = stdin.readline
n = int(input())
a = []
for _ in range(n):
aa, bb = [int(x) for x in input().split()]
aa -= 1
a.append((aa, bb))
a.sort()
a, b = zip(*a)
dp = []
for i in range(n):
v = a[i] - b[i]
if v <= a[0]:
dp.append(i)
continue
r = i
l = 0
... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR V... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def bsearch(ar, x):
low = 0
high = len(ar) - 1
ans = -1
while low <= high:
mid = (low + high) // 2
if ar[mid][0] >= x:
ans = mid
high = mid - 1
else:
low = mid + 1
return ans
n = int(input())
ls = []
for i in range(n):
x, y = map(int,... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
n = int(sys.stdin.readline().rstrip())
a = [0] * 1000040
dp = [0] * 1000040
for i in range(0, n):
pos = 0
r = 0
temp = sys.stdin.readline().rstrip()
temp2 = temp.split(" ")
a[int(temp2[0])] = int(temp2[1])
f = 0
posf = 0
for i in range(0, 1000001):
if a[i] == 0:
dp[i] = dp[i ... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | read = lambda: map(int, input().split())
n = int(input())
p = sorted([tuple(read()) for i in range(n)])
a = [0] * (n + 1)
b = [0] * (n + 1)
for i in range(1, n + 1):
a[i], b[i] = p[i - 1]
a[0] = int(-10000000.0)
dp = [0] * (n + 1)
for i in range(1, n + 1):
L = 0
R = n + 1
while R - L > 1:
M = (L... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
N = 1 << 20
ar = [0] * N
dp = [0] * N
n = int(input())
for i in range(0, n):
inp = input().split()
ar[int(inp[0]) + 1] = int(inp[1])
for i in range(N):
dp[i] = (1 if ar[i] >= i else dp[i - ar[i] - 1] + 1) if ar[i] else dp[i - 1]
print(n - max(dp)) | IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIG... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | class Beacon:
def __init__(self, pos, span):
self.pos, self.span = pos, span
n = int(input())
beacons = [Beacon(*map(int, input().split())) for i in range(n)]
beacons.sort(key=lambda beacon: beacon.pos)
limit = beacons[-1].pos
slide = (limit + 1) * [None]
beacon = beacons[0]
beacon_index = 1
while beacon... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER LIST NONE ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIG... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | import sys
def chain_reaction(n, beacons):
table = [0] * n
for i in range(n):
position = beacons[i][0]
power = beacons[i][1]
destroyed = 0
r = position - power
b = 0
lo = 0
hi = len(beacons) - 1
while lo <= hi:
mid = int(lo + (hi - lo... | IMPORT FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR V... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
dp, li, ans = [0] * 1000010, [0] * 1000010, 0
for i in range(n):
a, b = map(int, input().split())
li[a] = b
for i in range(1000010):
if li[i]:
dp[i] = dp[i - li[i] - 1] + 1
else:
dp[i] = dp[i - 1]
ans = max(ans, dp[i])
print(n - ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NU... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
a = [0] * 1000001
b = [0] * 1000001
for i in range(n):
l = list(map(int, input().split()))
a[l[0]] = 1
b[l[0]] = l[1]
notdestroyed = [0] * 1000001
if a[0] == 1:
notdestroyed[0] = 1
for i in range(1, 1000001):
if a[i] == 1:
notdestroyed[i] = notdestroyed[i - b[i] - 1] + 1
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER N... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def bsearch(arr, num, start, end):
mid = int((start + end) / 2)
if start > end:
return start, 0
if arr[mid] == num:
return mid, 1
elif arr[mid] < num:
return bsearch(arr, num, mid + 1, end)
else:
return bsearch(arr, num, start, mid - 1)
t = int(input())
A = []
B = [... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR RETURN VAR NUMBER IF VAR VAR VAR RETURN VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def countGreater(arr, n, k):
l = 0
r = n - 1
leftGreater = n
while l <= r:
m = int(l + (r - l) // 2)
if arr[m] > k:
leftGreater = m
r = m - 1
else:
l = m + 1
return n - leftGreater
n = int(input())
ls = []
for i in range(n):
a, b = ma... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR V... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
Becone = [list(map(int, input().split())) for i in range(n)]
Becone.sort(key=lambda x: x[0])
dp = [0] * 1000001
if Becone[0][0] == 0:
dp[0] = 1
Becone.pop(0)
ans = n - dp[0]
for i in range(1, 1000001):
if not Becone:
break
if i != Becone[0][0]:
dp[i] = dp[i - 1]
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def value():
n = int(input())
power = [0] * 1100000
for i in range(n):
a, b = input().split()
a, b = int(a), int(b)
power[a] = b
best = 10000000000000
under = dict()
for i in range(1100000):
v = i - power[i] - 1
if v < 0:
under[i] = 0
e... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
a = []
m = []
for i in range(n):
a.append([int(i) for i in input().split()])
a.sort(key=lambda s: s[0])
l = 0
for b in a:
l = max(l, b[0])
j = 0
for i in range(l + 1):
if a[j][0] == i:
if a[j][1] >= i:
m.append(1)
else:
m.append(m[i - a[j][1] - 1] + 1... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | maxN = 1000001
b = [0] * maxN
dp = [0] * maxN
n = int(input())
mxA = 0
for i in range(n):
a, p = [int(i) for i in input().split()]
b[a] = p
mxA = max(a, mxA)
if b[0]:
dp[0] = 1
mxSvd = 0
for i in range(mxA + 1):
if not b[i]:
dp[i] = dp[i - 1]
elif b[i] >= i:
dp[i] = 1
else:
... | ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | def main():
n = int(input())
bb = [0] * 1000001
for _ in range(n):
a, b = map(int, input().split())
bb[a] = b
a = 0
for i, b in enumerate(bb):
if b:
a = bb[i - b - 1] + 1 if i > b else 1
bb[i] = a
print(n - max(bb))
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIG... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
pos = []
for i in range(n):
pos.append(tuple(map(int, input().strip().split())))
nLine = {}
maxi = max(pos)[0]
for i in pos:
nLine[i[0]] = i[1]
temp = [(0) for i in range(maxi + 1)]
pins = []
no = 0
for i in range(maxi, -1, -1):
if i in nLine:
no += 1
pins.append(i)
temp... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASS... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
powers = sorted([tuple(map(int, input().split())) for _ in range(n)])
def find_smaller_than_in_asc_sorted(x, l, s, e):
if s == e or l[s] > x:
return None, None
if l[e - 1] < x:
return l[e - 1], e - 1
if e - s == 1:
if l[s] < x:
return l[s], s
el... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF VAR VAR VAR VAR VAR RETURN NONE NONE IF VAR BIN_OP VAR NUMBER VAR RETURN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR VA... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
pos_blast = [list(map(int, input().split())) for _ in range(n)]
MAX_N = max(pos_blast, key=lambda x: x[0])[0] + 2
power = [(0) for _ in range(MAX_N)]
tower = [(False) for _ in range(MAX_N)]
can_destroy = [(0) for _ in range(MAX_N)]
for pos, blast in pos_blast:
pos += 1
tower[pos] = True
pow... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR... |
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti... | n = int(input())
bb = [0] * 1000001
for i in range(n):
a, b = map(int, input().split())
bb[a] = b
a = 0
m = 0
for index, value in enumerate(bb):
if value > 0:
if index - value > 0:
a = 1 + bb[index - value - 1]
else:
a = 1
bb[index] = a
print(n - max(bb)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP B... |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | from sys import stdin
s = stdin.readline().rstrip()
k = -1
l = [-1]
for c in s:
while k != -1 and s[k] != c:
k = l[k]
k += 1
l += [k]
q = l[-1]
if l.count(q) < 2:
q = l[q]
print(s[:q] if q > 0 else "Just a legend") | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR LIST VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR STRING |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | s = input()
n = len(s)
if n == 1 or n == 2:
print("Just a legend")
else:
lista = []
for i in range(n):
lista.append(0)
l = 0
lista[0] = 0
i = 1
while i < n:
if s[i] == s[l]:
l += 1
lista[i] = l
i += 1
elif l != 0:
l = li... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBE... |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | s, j, next = input(), -1, [-1]
for c in s:
while j != -1 and c != s[j]:
j = next[j]
j += 1
next.append(j)
a = next[-1]
if next.count(a) < 2:
a = next[a]
print(s[:a] if a > 0 else "Just a legend") | ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER LIST NUMBER FOR VAR VAR WHILE VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR VAR STRING |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | def prefixfunction(txt, m, lps):
l = 0
lps[0] = 0
i = 1
while i < m:
if txt[i] == txt[l]:
l += 1
lps[i] = l
i += 1
elif l != 0:
l = lps[l - 1]
else:
lps[i] = 0
i += 1
s = input().strip()
longitud = len(s)
i... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FU... |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | def solve(s):
n = len(s)
lps = [0] * n
count = [0] * (n + 1)
for i in range(1, n):
l = lps[i - 1]
while l > 0 and s[i] != s[l]:
l = lps[l - 1]
if s[i] == s[l]:
l += 1
lps[i] = l
if i < n - 1:
count[l] += 1
l = lps[n - 1]
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR BIN_OP VAR N... |
Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | def computeLPSArray(pat, M, lps):
len = 0
lps[0]
i = 1
while i < M:
if pat[i] == pat[len]:
len += 1
lps[i] = len
i += 1
elif len != 0:
len = lps[len - 1]
else:
lps[i] = 0
i += 1
return lps
s = input()
m... | FUNC_DEF ASSIGN VAR NUMBER EXPR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.