description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | n, s = map(int, input().split())
def nod(n):
res = 0
while n > 0:
res += 1
n //= 10
return res
def sod(n):
res = 0
while n > 0:
res += n % 10
n //= 10
return res
def maxsod(n):
if (n + 1) % 10 ** (nod(n) - 1) == 0:
return 9 * (nod(n) - 1) + n // 10 ** (nod(n) - 1)
else:
return 9 * (nod(n) - 1) + (n - 1) // 10 ** (nod(n) - 1)
num = max(n - s, 0)
for i in range(s + 1, min(s + maxsod(n), n) + 1):
if i - sod(i) < s:
num -= 1
print(num) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER RETURN BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def calc(n):
val = n
cnt = 0
while val:
cnt += val % 10
val //= 10
return n - cnt
n, s = list(map(int, input().split()))
if n <= s:
print(0)
return
val = s
val //= 10
if val == 0:
print(n - 9 if n >= 9 else 0)
return
val *= 10
while calc(val) < s:
val += 10
if val > n:
print(0)
break
else:
print(n - val + 1) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def somaDigitos(x):
resp = 0
while x > 0:
resp += x % 10
x = x // 10
return resp
def isReallyBigNumber(x):
return x - somaDigitos(x) >= s
n, s = input().split(" ")
n = int(n)
s = int(s)
count = 0
ini = 1
fim = n
i = 0
ans = False
while ini <= fim:
meio = (ini + fim) // 2
if isReallyBigNumber(meio):
ans = meio
fim = meio - 1
else:
ini = meio + 1
if ans:
print(n - ans + 1)
else:
print(0) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | a = input()
a = a.split(" ")
a = list(map(int, a))
def really_big(n, s):
if s >= n:
return 0
i = s + 1
while i <= n:
t, b = i, 0
while t > 0:
b = b + t % 10
t = t // 10
if i - b >= s:
return n - i + 1
break
else:
i += 1
return 0
print(really_big(a[0], a[1])) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def digisum(n):
count = 0
while n > 0:
count += n % 10
n = n // 10
return count
n, s = list(map(int, input().split()))
l, r = 1, n
flag = 0
while l < r:
m = l + (r - l) // 2
digi_sum = digisum(m)
num = m
if num - digi_sum >= s:
flag = 1
cur = m
r = m
else:
l = m + 1
if r - l == 1:
digi_sum = digisum(l)
num = l
if num - digi_sum >= s:
flag = 1
cur = l
break
digi_sum = digisum(r)
num = r
if num - digi_sum >= s:
flag = 1
cur = r
break
if flag == 0:
digi_sum = digisum(l)
num = l
if num - digi_sum >= s:
flag = 1
cur = l
if flag == 0:
print(0)
else:
print(n - cur + 1) | FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | n, s = list(map(int, input().split(" ")))
def sumd(d):
sd = 0
while d != 0:
sd += d % 10
d //= 10
return sd
st, ed = 1, n
r = 0
while True:
if st == ed:
r = st
break
x = (st + ed) // 2
if x - sumd(x) < s:
st = x + 1
else:
ed = x
if r - sumd(r) >= s:
print(n - r + 1)
else:
print(0) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def forninho(miolo, s):
premiolo = miolo
temp = 0
while miolo > 0:
temp += miolo % 10
miolo = miolo // 10
if premiolo - temp >= s:
return 1
else:
return 0
entrada = input().split()
n = int(entrada[0])
s = int(entrada[1])
result = -1
l = 1
r = n
while r - l >= 0:
miolo = (l + r) // 2
if forninho(miolo, s) == 1:
r = miolo - 1
result = miolo
else:
l = miolo + 1
if result == -1:
print("0")
else:
print(n - result + 1) | FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def check(n, p):
k = str(n)
k = k[::-1]
s = 0
for j in range(len(k)):
s += int(k[j]) * (10**j - 1)
if s >= p:
return 1
else:
return 0
n, s = map(int, input().split())
l = 1
h = n
k = 0
while l <= h:
m = (l + h) // 2
if check(m, s) == 0:
l = m + 1
else:
h = m - 1
k += 1
print(n - l + 1) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def f(x):
return x if x < 10 else f(x // 10) + x % 10
n, s = map(int, input().split())
x = s
while x - f(x) < s:
x += 1
print(max(0, n - x + 1)) | FUNC_DEF RETURN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR WHILE BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def sum_of_its_digits(Num, s):
S = str(Num)
sum = 0
for i in S:
sum += int(i)
return Num - sum >= s
k = input().split()
n = int(k[0])
s = int(k[1])
sum = 0
for i in range(s, n + 1):
if sum_of_its_digits(i, s):
sum = n - i + 1
break
print(sum) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR RETURN BIN_OP VAR 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 FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def find(curr_pos, max_pos, curr_s, choose):
if curr_pos == 0:
if curr_s <= 0:
return True
else:
return False
if curr_pos == max_pos:
low = 1
else:
low = 0
high = 9
for d in range(low, high + 1):
curr_val = d * (10**curr_pos - 1)
if curr_val + p[curr_pos - 1] < curr_s:
continue
choose[curr_pos] = d
return find(curr_pos - 1, max_pos, curr_s - curr_val, choose)
return False
n, s = map(int, input().split())
p = [0]
for i in range(1, 19):
p.append(p[-1] + 9 * (10**i - 1))
choose = [0] * 19
ans = n + 1
for num_digit in range(1, 19):
for i in range(1, num_digit + 1):
choose[i] = 0
if find(num_digit, num_digit, s, choose):
res = 0
for i in range(num_digit, -1, -1):
res = res * 10 + choose[i]
ans = min(ans, res)
break
print(n - ans + 1) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | import sys
def calculate():
input = sys.stdin.readline().split()
n = int(input[0])
s = int(input[1])
count = 0
i = s // 10 * 10
while i <= n:
if i - sumOfDigits(i) >= s:
count = n - i + 1
break
i = i + 10
print(count)
def sumOfDigits(numb):
sum = 0
while numb > 0:
sum = sum + numb % 10
numb = numb // 10
return sum
calculate() | IMPORT FUNC_DEF 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 BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR VAR IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | n, s = [int(x) for x in input().split()]
def check(x):
y = list(str(x))
ans = x
for i in y:
ans -= int(i)
if ans >= s:
return True
return False
ans = 0
l = 1
r = n
while l <= r:
m = (l + r) // 2
if check(m):
ans = n - m + 1
r = m - 1
else:
l = m + 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | n, s = input().split()
l = 1
h = int(n)
while h - l > 1:
m = (h + l) // 2
if m - sum(map(int, list(str(m)))) >= int(s):
h = m
else:
l = m
if h - sum(map(int, list(str(h)))) < int(s):
print(0)
else:
print(int(n) - h + 1) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | n, s = map(int, input().split())
r = 0
v = min(n + 1, s + 19 * 9)
for i in range(s, v):
zz = f"{i}"
sm = i
for z in zz:
sm -= int(z)
if sm >= s:
r += 1
print(r + n - v + 1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def d(n):
ret = 0
n = list(str(n))
for i in range(len(n)):
ret += int(n[i])
return ret
def main():
n, s = map(int, input().split())
l, h = 0, n
for i in range(2000):
m = (l + h) // 2
if m - d(m) >= s:
h = m
else:
l = m
for i in range(-100, 100):
t = m + i
if t < 0 or t > n:
continue
if abs(t - d(t)) >= s:
print(n - t + 1)
exit()
print(0)
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR IF FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | def f(n):
rtn = n
while 0 < n:
rtn -= n % 10
n //= 10
return rtn
n, s = list(map(int, input().split()))
l = 0
r = 10**18 + 1
cnt = 0
while 1 < r - l:
m = (l + r) // 2
if s <= f(m):
r = m
else:
l = m
print(max(n - r + 1, 0)) | FUNC_DEF ASSIGN VAR VAR WHILE NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | [n, s] = map(int, input().strip().split())
def sumdigit(x):
return sum(map(int, str(x)))
def fsum(x):
return x - sumdigit(x)
def binsearch(s, xmin, xmax):
while xmax - xmin > 1:
xmid = (xmax + xmin) // 2
if fsum(xmid) >= s:
xmax = xmid
else:
xmin = xmid
return xmax
xmin = 0
xmax = 1
while fsum(xmax) < s:
xmin = xmax
xmax *= 2
x = binsearch(s, xmin, xmax)
print(max(n - x + 1, 0)) | ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP VAR FUNC_CALL VAR VAR FUNC_DEF WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER |
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number x is really big if the difference between x and the sum of its digits (in decimal representation) is not less than s. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are β in fact, he needs to calculate the quantity of really big numbers that are not greater than n.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
-----Input-----
The first (and the only) line contains two integers n and s (1 β€ n, s β€ 10^18).
-----Output-----
Print one integer β the quantity of really big numbers that are not greater than n.
-----Examples-----
Input
12 1
Output
3
Input
25 20
Output
0
Input
10 9
Output
1
-----Note-----
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 β₯ 20).
In the third example 10 is the only really big number (10 - 1 β₯ 9). | import sys
n, s = map(int, input().split())
ok, ng = 10**18 + 100, -1
while abs(ok - ng) > 1:
mid = ok + ng >> 1
if mid - sum(map(int, str(mid))) >= s:
ok = mid
else:
ng = mid
print(max(0, n - ok + 1)) | IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER |
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef and Abhishek are two friends. Abhishek really appreciates Chef's skills and wants to learn the secret formula behind Chef's tasty dishes. Chef will tell his secret formula only to a
competent person. So to check Abhishek's competency, Chef asked him to solve the following problem.
Find the number of integers between 0 and N (inclusive) such that the product of digits of the integer is greater than or equal to K!, where K is the number of digits present in the integer.
Example: Consider N = 1000.
The only digit present in the integer 0 is 0. So the product of digit is also 0 and 1! = 1. So 0 will be not counted in the answer because 0 \ngtr 1.
The digits present in the integer 25 are 2, 5. So the product of digits is (2 \cdot 5) = 10 and 2 ! = 2. So 25 will be counted in the answer because 10 β₯ 2.
The digits present in the integer 11 are 1, 1. So the product of digits is (1 \cdot 1) = 1 and 2 ! = 2. So 11 will be not counted in the answer because 1 \ngtr 2.
The digits present in the integer 157 are 1, 5, 7. So the product of digits is (1 \cdot 5 \cdot 7) = 35 and 3! = 6. So 157 will be counted in the answer because 35 β₯ 6.
Since Abhishek is a lazy person, he wants your help to solve the problem.
Note: K! represents the factorial of K and K! = 1 \cdot 2 \cdot 3 \cdot \ldots \cdot (K-1) \cdot K .
------ Input Format ------
- The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
- The first and only line of each test case contains a single integer N.
------ Output Format ------
For each test case, output in a single line the answer for given integer N
------ Constraints ------
$1 β€ T β€ 10145$
$0 β€ N β€ 10^{100}$
------ subtasks ------
Subtask #1 (10 points):
$1 β€ T β€ 200$
$0 β€ N β€ 44000000$
Subtask #2 (90 points): Original constraints
----- Sample Input 1 ------
3
13
54
198
----- Sample Output 1 ------
11
48
159
----- explanation 1 ------
Test case $1$: The only one-digit number that will not be included in the answer is $0$. The two-digit numbers that will not be included in the answer are $10, 11$ because their product of digits is less than $2! = 2$. So the answer is $= 14 - 1 - 2 = 11$.
Test case $3$:
- The one-digit number that will not be counted in the answer is $0$.
- The two-digit digit numbers that will not be counted in the answer are $10, 11$, $20, 30$, $40, 50, 60,$ $70, 80, 90$ because their product of digits is less than $2! = 2$.
- The three-digit numbers that will not be counted in the answer are $100$, $101, 102,$ $103, 104, 105$, $106, 107, 108$, $109, 110, 111,$ $112, 113, 114,$ $115, 120$,$ 121,$ $122, 130, 131,$ $140, 141,
150,$ $151, 160, 170$, $180, 190$ because their product of digits is less than $3! = 6$.
So the answer is $= 199 - 1 - 10 - 29 = 159$. | import sys
D = 22
dp = [dict() for _ in range(D)]
dp[0][1] = 1
for d in range(D - 1):
for product, freq in dp[d].items():
for nxt in range(1, 10):
dp[d + 1][product * nxt] = freq + dp[d + 1].get(product * nxt, 0)
products, frequencies = [list() for _ in range(D)], [list() for _ in range(D)]
sum = 0
for d in range(D):
dp[d] = dict(sorted(dp[d].items()))
tot = 0
for freq in dp[d].values():
tot += freq
for prod, freq in dp[d].items():
x = dp[d][prod]
dp[d][prod] = tot
tot -= x
products[d], frequencies[d] = list(dp[d].keys()), list(dp[d].values())
sum += len(dp[d])
def countNumsGreater(d, target):
lo, hi = 0, len(products[d]) - 1
if products[d][hi] < target:
return 0
while lo < hi:
mid = (lo + hi) // 2
if products[d][mid] >= target:
hi = mid
else:
lo = mid + 1
return frequencies[d][hi]
def good(N):
N = str(N)
fact, prod = 1, 1
for d in range(len(N)):
fact *= d + 1
prod *= ord(N[d]) - ord("0")
return prod >= fact
def brute(N):
N = int(N)
ans = 0
for x in range(1, 1 + N):
if good(x):
ans += 1
return ans
T = int(input())
MAX = 10 ** (D - 1)
for _ in range(T):
N = int(input())
if N > MAX:
N = MAX
N = str(N)
ans, fact = 0, 1
for d in range(1, len(N)):
fact *= d
ans += countNumsGreater(d, fact)
fact *= len(N)
product = 1
for p in range(len(N)):
di = ord(N[p]) - ord("0")
if di == 0:
break
for digit in range(1, di):
tmpProd = product * digit
ans += countNumsGreater(len(N) - p - 1, (fact + tmpProd - 1) // tmpProd)
product *= di
if good(N):
ans += 1
sys.stdout.write(str(ans) + "\n") | IMPORT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 β€ n β€ 200 000, 1 β€ k β€ 10, 2 β€ x β€ 8).
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | n, k, x = map(int, input().split())
a = list(map(int, input().split()))
maxi = 0
moc = x**k
p = [0] * (n + 2)
s = [0] * (n + 2)
for i in range(1, len(a) + 1):
p[i] = p[i - 1] | a[i - 1]
for i in range(len(a), 0, -1):
s[i] = s[i + 1] | a[i - 1]
for t in range(1, len(a) + 1):
maxi = max(maxi, p[t - 1] | a[t - 1] * moc | s[t + 1])
print(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 NUMBER ASSIGN VAR BIN_OP 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 FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 β€ n β€ 200 000, 1 β€ k β€ 10, 2 β€ x β€ 8).
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | n, k, x = map(int, input().split())
A = list(map(int, input().split()))
L, R = [0] * (n + 1), [0] * (n + 1)
for i in range(n):
L[i + 1] = A[i] | L[i]
for i in range(n - 1, -1, -1):
R[i] = A[i] | R[i + 1]
x = x**k
ans = 0
for i in range(n):
ans = max(ans, L[i] | A[i] * x | R[i + 1])
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 β€ n β€ 200 000, 1 β€ k β€ 10, 2 β€ x β€ 8).
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | n, k, l = map(int, input().split())
li = [int(x) for x in input().split()]
front = [0] * (n + 2)
back = [0] * (n + 2)
front[0] = 0 | li[0]
back[n - 1] = 0 | li[n - 1]
for i in range(1, n):
front[i] = front[i - 1] | li[i]
for i in range(n - 2, -1, -1):
back[i] = back[i + 1] | li[i]
p = 1
for _ in range(k):
p *= l
max = -1
for i in range(n):
c = front[i - 1] | li[i] * p | back[i + 1]
if c > max:
max = c
print(max) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 β€ n β€ 200 000, 1 β€ k β€ 10, 2 β€ x β€ 8).
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | n, k, x = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * n
b = [0] * n
for i in range(1, n):
a[i] = a[i - 1] | l[i - 1]
for i in range(1, n):
b[n - i - 1] = b[-i] | l[-i]
nom = 0
for i in range(1, n):
if l[nom] * x**k | a[nom] | b[nom] < l[i] * x**k | a[i] | b[i]:
nom = i
l[nom] *= x**k
print(l[nom] | a[nom] | b[nom]) | 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 FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR |
You are given n numbers a1, a2, ..., an. You can perform at most k operations. For each operation you can multiply one of the numbers by x. We want to make <image> as large as possible, where <image> denotes the bitwise OR.
Find the maximum possible value of <image> after performing at most k operations optimally.
Input
The first line contains three integers n, k and x (1 β€ n β€ 200 000, 1 β€ k β€ 10, 2 β€ x β€ 8).
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ 109).
Output
Output the maximum value of a bitwise OR of sequence elements after performing operations.
Examples
Input
3 1 2
1 1 1
Output
3
Input
4 2 3
1 2 4 8
Output
79
Note
For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <image>.
For the second sample if we multiply 8 by 3 two times we'll get 72. In this case the numbers will become 1, 2, 4, 72 so the OR value will be 79 and is the largest possible result. | import sys
n, k, x = (int(x) for x in input().split())
l = [int(x) for x in input().split()]
pref = [0] * n
suff = [0] * n
pref[0] = l[0]
for i in range(1, n):
pref[i] = pref[i - 1] | l[i]
suff[n - 1] = l[n - 1]
for i in range(n - 2, -1, -1):
suff[i] = suff[i + 1] | l[i]
def get_pref(index):
if index < 0:
return 0
else:
return pref[index]
def get_suff(index):
if index >= n:
return 0
else:
return suff[index]
power = x**k
ans = 0
for i in range(n):
contender = get_pref(i - 1) | l[i] * power | get_suff(i + 1)
if contender > ans:
ans = contender
print(ans) | IMPORT 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 VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = [int(a) for a in input().split()]
xs, ys, t = [int(a) for a in input().split()]
x = x0
y = y0
points = []
def m(p0, p1):
return abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])
while x < 1e18 and y < 1e18:
points.append((m((x, y), (xs, ys)), (x, y)))
x = ax * x + bx
y = ay * y + by
best = 0
for p in range(len(points)):
curr_t = t
curr_p = xs, ys
curr = 0
for down in range(p, -1, -1):
dist = m(curr_p, points[down][1])
if curr_t >= dist:
curr_t -= dist
curr += 1
curr_p = points[down][1]
best = max(best, curr)
for p in range(len(points)):
curr_t = t
curr_p = xs, ys
curr = 0
for down in range(p, len(points)):
dist = m(curr_p, points[down][1])
if curr_t >= dist:
curr_t -= dist
curr += 1
curr_p = points[down][1]
best = max(best, curr)
print(best) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
dots = []
x, y = x0, y0
while True:
if x < 10**20 and y < 10**20:
dots.append((x, y))
else:
break
x = ax * x + bx
y = ay * y + by
def get_dots(start, direction):
T = t
x, y = xs, ys
i = start
gather = set()
while i >= 0 and i < len(dots):
dist = abs(x - dots[i][0]) + abs(y - dots[i][1])
if dist <= T:
T -= dist
gather.add(dots[i])
else:
return len(gather)
x, y = dots[i]
i += direction
return len(gather)
m = 0
for i in range(len(dots)):
for d in [-1, 1]:
m = max(m, get_dots(i, d))
print(m) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR WHILE NUMBER IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split(" "))
xs, ys, t = map(int, input().split(" "))
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
maxi = 0
x = x0
y = y0
for i in range(0, 64):
res = 0
t_aux = t
t_aux -= dist(x, y, xs, ys)
if t_aux >= 0:
res += 1
x_aux = x
y_aux = y
while t_aux >= 0 and x_aux != x0 and y_aux != y0:
x_curr = (x_aux - bx) / ax
y_curr = (y_aux - by) / ay
t_aux -= dist(x_aux, y_aux, x_curr, y_curr)
x_aux = x_curr
y_aux = y_curr
if t_aux >= 0:
res += 1
if t_aux >= 0:
fl = True
x_aux = x
y_aux = y
while t_aux >= 0:
x_curr = ax * x_aux + bx
y_curr = ay * y_aux + by
if fl:
fl = False
t_aux -= dist(x0, y0, x_curr, y_curr)
else:
t_aux -= dist(x_aux, y_aux, x_curr, y_curr)
x_aux = x_curr
y_aux = y_curr
if t_aux >= 0:
res += 1
maxi = max(maxi, res)
x = ax * x + bx
y = ay * y + by
print(maxi) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = [int(t) for t in input().split(" ")]
xs, ys, t0 = [int(t) for t in input().split(" ")]
devices = [(x0, y0)]
for _ in range(60):
x0, y0 = ax * x0 + bx, ay * y0 + by
devices.append((x0, y0))
def launch(ibegin):
i = ibegin
t = t0
xc, yc = xs, ys
dst = abs(xc - devices[i][0]) + abs(yc - devices[i][1])
cnt = 1
t -= dst
xc, yc = devices[i]
if t < 0:
return 0
while t > 0 and i > 0:
i -= 1
dst = abs(xc - devices[i][0]) + abs(yc - devices[i][1])
if t - dst >= 0:
cnt += 1
t -= dst
xc, yc = devices[i]
i = ibegin
while t > 0 and i < 60:
i += 1
dst = abs(xc - devices[i][0]) + abs(yc - devices[i][1])
if t - dst >= 0:
cnt += 1
t -= dst
xc, yc = devices[i]
return cnt
print(max(launch(i) for i in range(60))) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | LIM = 100000000000000000
def solve():
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
X = [x0]
while True:
nx = ax * X[-1] + bx
if nx - X[-1] > LIM:
break
X.append(nx)
Y = [y0]
while True:
ny = ay * Y[-1] + by
if ny - Y[-1] > LIM:
break
Y.append(ny)
n = min(len(X), len(Y))
def getpath(i, j, A, pos):
d = A[j] - A[i]
if pos <= A[i]:
return A[i] - pos + d
if pos <= A[j]:
return min(pos - A[i], A[j] - pos) + d
return d + pos - A[j]
ans = 0
for i in range(n):
for j in range(i, n):
dx = getpath(i, j, X, xs)
dy = getpath(i, j, Y, ys)
if dx + dy <= t:
ans = max(ans, j - i + 1)
print(ans)
solve() | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def inp(dtype=str, strip=True):
s = input()
res = [dtype(p) for p in s.split()]
res = res[0] if len(res) == 1 and strip else res
return res
def problem1():
def test(cur, steps):
if 0 < cur <= n and cur not in a:
return steps
else:
return -1
t = inp(int)
for _ in range(t):
n, s, k = inp(int)
a = inp(int, strip=False)
a = set(a)
res = -1
steps = 0
while res < 0:
res = test(s + steps, steps)
if res < 0:
res = test(s - steps, steps)
steps += 1
print(res)
def problem2():
n = inp(int)
res = 0
for i in range(1, n + 1):
res += 1 / i
print(res)
def problem3():
n, q = inp(int)
conflicts = [[[0, 0, 0] for _ in range(n)] for _ in range(2)]
state = [[(0) for _ in range(n)] for _ in range(2)]
nconflicts = 0
for _ in range(q):
r, c = inp(int)
r = r - 1
c = c - 1
if state[r][c] == 0:
state[r][c] = 1
q = 1 - r
if c - 1 >= 0 and state[q][c - 1] == 1:
nconflicts += 1
conflicts[r][c][-1 + 1] = 1
conflicts[q][c - 1][1 + 1] = 1
if state[q][c] == 1:
nconflicts += 1
conflicts[r][c][0 + 1] = 1
conflicts[q][c][0 + 1] = 1
if c + 1 < n and state[q][c + 1] == 1:
nconflicts += 1
conflicts[r][c][1 + 1] = 1
conflicts[q][c + 1][-1 + 1] = 1
else:
state[r][c] = 0
q = 1 - r
if c - 1 >= 0 and state[q][c - 1] == 1:
nconflicts -= 1
conflicts[r][c][-1 + 1] = 0
conflicts[q][c - 1][1 + 1] = 0
if state[q][c] == 1:
nconflicts -= 1
conflicts[r][c][0 + 1] = 0
conflicts[q][c][0 + 1] = 0
if c + 1 < n and state[q][c + 1] == 1:
nconflicts -= 1
conflicts[r][c][1 + 1] = 0
conflicts[q][c + 1][-1 + 1] = 0
if nconflicts == 0:
print("YES")
else:
print("NO")
def problem4():
def dist(xi, yi, xj, yj):
return abs(xi - xj) + abs(yi - yj)
def dist2(xi, yi, xj, yj):
return 2 * max(abs(xi - xj), abs(yi - yj))
x0, y0, ax, ay, bx, by = inp(int)
xs, ys, t = inp(int)
i = 0
a = [(x0, y0)]
xmin, ymin = x0, y0
while i < 65:
xmin = ax * xmin + bx
ymin = ay * ymin + by
a.append((xmin, ymin))
i += 1
imin, imax = 0, 60
res = 0
for istart in range(imin, imax + 1):
dist_start = dist(xs, ys, *a[istart])
if dist_start > t:
continue
for imed in range(imin, istart + 1):
dist_med = dist(*a[istart], *a[imed])
if dist_start + dist_med > t:
continue
i = imed + 1
while dist_start + dist_med + dist(*a[imed], *a[i]) <= t:
i += 1
i = max(istart, i - 1)
res = max(res, i - imed + 1)
for imed in range(istart, imax + 1):
dist_med = dist(*a[istart], *a[imed])
if dist_start + dist_med > t:
continue
i = imed - 1
while dist_start + dist_med + dist(*a[imed], *a[i]) <= t:
i -= 1
i = min(istart, i + 1)
res = max(res, imed - i + 1)
print(res)
def problem5():
pass
problem4() | FUNC_DEF VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER VAR RETURN VAR FUNC_DEF FUNC_DEF IF NUMBER VAR VAR VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | from sys import stdin
input = stdin.readline
N = 2 * 10**16 + 5
x = [0]
y = [0]
x[0], y[0], x1, y1, x2, y2 = map(int, input().split())
a, b, t = map(int, input().split())
while x[-1] < N and y[-1] < N:
x.append(x1 * x[-1] + x2)
y.append(y1 * y[-1] + y2)
ans = 0
for i in range(len(x)):
for j in range(len(x)):
d1 = abs(x[i] - a) + abs(y[i] - b)
d2 = abs(x[i] - x[j]) + abs(y[i] - y[j])
if d1 + d2 <= t:
ans = max(ans, abs(j - i) + 1)
print(ans) | ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR WHILE VAR NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
x0, y0, ax, ay, bx, by = [int(i) for i in sys.stdin.readline().split()]
xs, ys, t = [int(i) for i in sys.stdin.readline().split()]
ps = xs, ys
def distance(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
points = []
p = x0, y0
for _ in range(128):
if distance(p, ps) <= t:
points.append(p)
p = p[0] * ax + bx, p[1] * ay + by
ans = 0
for i, start in enumerate(points):
elapsed = 0
got = 0
at = ps
for j in range(i, len(points)):
if distance(at, points[j]) + elapsed <= t:
elapsed += distance(at, points[j])
at = points[j]
got += 1
else:
break
ans = max(ans, got)
elapsed = 0
got = 0
at = ps
for j in range(i, -1, -1):
if distance(at, points[j]) + elapsed <= t:
elapsed += distance(at, points[j])
at = points[j]
got += 1
else:
break
for j in range(i + 1, len(points)):
if distance(at, points[j]) + elapsed <= t:
elapsed += distance(at, points[j])
at = points[j]
got += 1
else:
break
ans = max(ans, got)
print(ans) | IMPORT ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
def generate(x0, y0, ax, ay, bx, by):
arr = [[x0, y0]]
curX, curY = arr[-1]
for _ in range(65):
curX, curY = ax * curX + bx, ay * curY + by
arr.append([curX, curY])
return arr
def go_left(xs, ys, arr, t):
n = len(arr)
max_ = 0
for i in range(n):
temp = t
curX, curY = xs, ys
init = abs(curX - arr[i][0]) + abs(curY - arr[i][1])
temp -= init
cnt = 0
if temp >= 0:
cnt += 1
curX, curY = arr[i][0], arr[i][1]
j = i - 1
while temp >= 0 and j >= 0:
next_ = abs(curX - arr[j][0]) + abs(curY - arr[j][1])
temp -= next_
if temp >= 0:
cnt += 1
curX, curY = arr[j][0], arr[j][1]
j -= 1
max_ = max(max_, cnt)
return max_
def go_right(xs, ys, arr, t):
n = len(arr)
max_ = 0
for i in range(n):
temp = t
curX, curY = xs, ys
init = abs(curX - arr[i][0]) + abs(curY - arr[i][1])
temp -= init
cnt = 0
if temp >= 0:
cnt += 1
curX, curY = arr[i][0], arr[i][1]
j = i + 1
while temp >= 0 and j < n:
next_ = abs(curX - arr[j][0]) + abs(curY - arr[j][1])
temp -= next_
if temp >= 0:
cnt += 1
curX, curY = arr[j][0], arr[j][1]
j += 1
max_ = max(max_, cnt)
return max_
arr = generate(x0, y0, ax, ay, bx, by)
print(max(go_left(xs, ys, arr, t), go_right(xs, ys, arr, t))) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST LIST VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | from itertools import accumulate
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t0 = map(int, input().split())
pnt = []
x, y = x0, y0
while True:
if x >= 10**17 or y >= 10**17:
break
pnt.append((x, y))
x, y = x * ax + bx, y * ay + by
n = len(pnt)
dist = []
for i in range(1, n):
xi, yi = pnt[i]
xp, yp = pnt[i - 1]
dist.append(xi - xp + yi - yp)
ansls = []
for i in range(n):
t = t0
xf, yf = pnt[i]
anstmp = 0
if abs(xf - xs) + abs(yf - ys) > t:
ansls.append(anstmp)
continue
t -= abs(xf - xs) + abs(yf - ys)
anstmp += 1
j = i
while j > 0 and t >= dist[j - 1]:
anstmp += 1
t -= dist[j - 1]
j -= 1
if t >= sum(dist[:i]):
t -= sum(dist[:i])
i += 1
while i < n and t >= dist[i - 1]:
anstmp += 1
t -= dist[i - 1]
i += 1
ansls.append(anstmp)
print(max(ansls)) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR WHILE NUMBER IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = tuple(map(int, input().split(" ")))
xs, ys, t = tuple(map(int, input().split(" ")))
important_points = [(x0, y0)]
for i in range(62):
x0 = ax * x0 + bx
y0 = ay * y0 + by
important_points.append((x0, y0))
start = xs, ys
def dist(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
maxx = 0
for i in range(62):
for j in range(62):
if (
dist(start, important_points[i])
+ dist(important_points[i], important_points[j])
<= t
):
maxx = max(maxx, abs(j - i) + 1)
print(maxx) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
def dist(x1, y1, x2, y2):
ans = 0
dx = x1 - x2
if dx < 0:
dx = -dx
ans = ans + dx
dy = y1 - y2
if dy < 0:
dy = -dy
ans = ans + dy
return ans
x0, y0, ax, ay, bx, by = map(int, sys.stdin.readline().split())
xs, ys, t = map(int, sys.stdin.readline().split())
reachable = [(x0, y0)]
x, y = x0, y0
for i in range(70):
x = x * ax + bx
y = y * ay + by
reachable.append((x, y))
reachable = list(filter(lambda p: dist(xs, ys, p[0], p[1]) <= t, reachable))
ans = 0
for i, p in enumerate(reachable):
d = dist(p[0], p[1], xs, ys)
lend = rend = i
for l, pl in enumerate(reachable[:i]):
if dist(pl[0], pl[1], p[0], p[1]) + d <= t:
lend = l
break
d = d + dist(reachable[lend][0], reachable[lend][1], p[0], p[1]) * 2
for r, pr in enumerate(reachable[i + 1 :]):
if dist(pr[0], pr[1], p[0], p[1]) + d <= t:
rend = r + i + 1
else:
break
ans = max(ans, rend - lend + 1)
print(ans) | IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | T = 1
for test_no in range(T):
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
LIMIT = 2**62 - 1
x, y = [x0], [y0]
while (LIMIT - bx) / ax >= x[-1] and (LIMIT - by) / ay >= y[-1]:
x.append(ax * x[-1] + bx)
y.append(ay * y[-1] + by)
n = len(x)
ans = 0
for i in range(n):
for j in range(i, n):
length = x[j] - x[i] + y[j] - y[i]
dist2Left = abs(xs - x[i]) + abs(ys - y[i])
dist2Right = abs(xs - x[j]) + abs(ys - y[j])
if length <= t - dist2Left or length <= t - dist2Right:
ans = max(ans, j - i + 1)
print(ans) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR LIST VAR LIST VAR WHILE BIN_OP BIN_OP VAR VAR VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | INF = 10**20
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
a = []
while x0 <= INF and y0 <= INF:
z = [x0, y0]
a.append(z)
x0 = ax * x0 + bx
y0 = ay * y0 + by
ans = 0
for i in range(len(a)):
used = [False] * len(a)
tmp = t
kol = 0
tx = xs
ty = ys
if dist(tx, ty, a[i][0], a[i][1]) > t:
continue
tmp -= dist(tx, ty, a[i][0], a[i][1])
used[i] = True
tx = a[i][0]
ty = a[i][1]
kol += 1
while tmp >= 0:
k = len(a) - 1
for j in range(len(a)):
if not used[j]:
if dist(tx, ty, a[j][0], a[j][1]) < dist(tx, ty, a[k][0], a[k][1]):
k = j
tmp -= dist(tx, ty, a[k][0], a[k][1])
kol += 1
tx = a[k][0]
ty = a[k][1]
used[k] = True
kol -= 1
ans = max(ans, kol)
print(ans) | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST WHILE VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x = [(0) for i in range(75)]
y = [(0) for i in range(75)]
count1 = 0
count2 = 0
max1 = 0
def dis(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def main():
global count1
global max1
global count2
x0, y0, ax, ay, bx, by = input().split()
x0 = int(x0)
y0 = int(y0)
ax = int(ax)
ay = int(ay)
bx = int(bx)
by = int(by)
xs, ys, t = input().split()
xs = int(xs)
ys = int(ys)
t = int(t)
x[0] = x0
y[0] = y0
for i in range(1, 75):
x[i] = ax * x[i - 1] + bx
y[i] = ay * y[i - 1] + by
for i in range(0, 75):
t1 = t
if dis(xs, ys, x[i], y[i]) <= t1:
t1 -= dis(xs, ys, x[i], y[i])
count1 = count1 + 1
count2 = i
for j in range(0, i):
if dis(x[i], y[i], x[j], y[j]) <= t1:
t1 -= dis(x[i], y[i], x[j], y[j])
count1 = count1 + i - j
count2 = j
break
for j in range(i + 1, 75):
if j == i + 1:
if dis(x[j], y[j], x[count2], y[count2]) <= t1:
t1 -= dis(x[j], y[j], x[count2], y[count2])
count1 = count1 + 1
else:
max1 = max(max1, count1)
count1 = 0
break
elif dis(x[j - 1], y[j - 1], x[j], y[j]) <= t1:
t1 -= dis(x[j - 1], y[j - 1], x[j], y[j])
count1 = count1 + 1
else:
max1 = max(max1, count1)
count1 = 0
break
print(max1)
main() | ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def check(goo, k, t, x, y):
ans = 1
timer = abs(goo[k][0] - x) + abs(goo[k][1] - y)
if timer > t:
return 0
for i in range(k - 1, -1, -1):
delta = abs(goo[i][0] - goo[i + 1][0]) + abs(goo[i][1] - goo[i + 1][1])
timer += delta
if timer > t:
return ans
ans += 1
timer += abs(goo[0][0] - goo[k + 1][0]) + abs(goo[0][1] - goo[k + 1][1])
if timer > t:
return ans
ans += 1
for i in range(k + 1, len(goo) - 1):
delta = abs(goo[i][0] - goo[i + 1][0]) + abs(goo[i][1] - goo[i + 1][1])
timer += delta
if timer > t:
return ans
ans += 1
return ans
x0, y0, ax, ay, bx, by = list(map(int, input().split()))
x, y, t = list(map(int, input().split()))
goo = [[x0, y0]]
for i in range(1, 100):
tmp = []
tmp.append(goo[i - 1][0])
tmp.append(goo[i - 1][1])
tmp[0] = tmp[0] * ax + bx
tmp[1] = tmp[1] * ay + by
goo.append(tmp)
ans = 0
for k in range(len(goo) - 1):
ans = max(ans, check(goo, k, t, x, y))
print(ans) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR RETURN VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR RETURN VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
def main():
import sys
input = sys.stdin.readline
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
xy_list = [(x0, y0)]
x, y = x0, y0
while True:
x, y = ax * x + bx, ay * y + by
if dist(xs, ys, x, y) > t and x > xs and y > ys:
break
xy_list.append((x, y))
N = len(xy_list)
ans = 0
for j in range(N):
for k in range(j, N):
xj, yj = xy_list[j]
xk, yk = xy_list[k]
if dist(xs, ys, xj, yj) + dist(xj, yj, xk, yk) <= t:
ans = max(ans, k - j + 1)
if dist(xs, ys, xk, yk) + dist(xj, yj, xk, yk) <= t:
ans = max(ans, k - j + 1)
print(ans)
main() | IMPORT FUNC_DEF IMPORT ASSIGN VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR VAR VAR VAR WHILE NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
A = []
for i in range(100):
A.append((x0, y0))
x0 = x0 * ax + bx
y0 = y0 * ay + by
ans = 0
for i in range(0, 100):
for j in range(i, 100):
kek = A[j][0] - A[i][0] + A[j][1] - A[i][1]
kek += min(
abs(xs - A[j][0]) + abs(ys - A[j][1]), abs(xs - A[i][0]) + abs(ys - A[i][1])
)
if t >= kek:
ans = max(ans, j - i + 1)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def calc(i_min, t, x, y):
cnt = 0
t1 = t
i = i_min
min_dist = abs(x[i_min] - xs) + abs(y[i_min] - ys)
if min_dist <= t:
cnt += 1
t1 -= min_dist
while t1 > 0 and i > 0:
i -= 1
dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
if dist <= t1:
cnt += 1
t1 -= dist
if t1 > 0 and i_min + 1 < len(x):
dist = abs(x[i_min + 1] - x[0]) + abs(y[i_min + 1] - y[0])
if t1 >= dist:
cnt += 1
t1 -= dist
i = i_min + 1
while t1 > 0 and i < len(x) - 1:
i += 1
dist = abs(x[i - 1] - x[i]) + abs(y[i - 1] - y[i])
if dist <= t1:
cnt += 1
t1 -= dist
return cnt
a = list(map(int, input().split()))
x = [a[0]]
y = [a[1]]
ax = a[2]
ay = a[3]
bx = a[4]
by = a[5]
a = list(map(int, input().split()))
xs = a[0]
ys = a[1]
t = a[2]
m = max(t + xs + 1, t + ys + 1)
cur_x = x[0]
cur_y = y[0]
min_dist = abs(xs - x[0]) + abs(ys - y[0])
i_min = 0
while x[-1] <= m and y[-1] <= m:
new_x = ax * x[-1] + bx
x.append(new_x)
new_y = ay * y[-1] + by
y.append(new_y)
dist = abs(xs - new_x) + abs(ys - new_y)
if dist < min_dist:
min_dist = dist
i_min = len(x) - 1
res = calc(i_min, t, x, y)
if i_min > 0:
res = max(res, calc(i_min - 1, t, x, y))
if i_min + 1 < len(x):
res = max(res, calc(i_min + 1, t, x, y))
print(res) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER 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 FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
currRoute = 0
leftSum = [0]
maxId = 0
xi, yi = x0, y0
coord = [(x0, y0)]
while True:
xii = xi * ax + bx
yii = yi * ay + by
jump = xii - xi + yii - yi
maxId += 1
currRoute += jump
leftSum.append(currRoute)
xi, yi = xii, yii
coord.append((xi, yi))
if xi > 10**17 or yi > 10**17:
break
maxCtr = 0
for first in range(maxId):
xi, yi = coord[first]
initJump = abs(xi - xs) + abs(yi - ys)
if initJump > t:
continue
tLeft = t - initJump
L = first
R = maxId
while L + 1 < R:
m = L + R >> 1
if leftSum[m] - leftSum[first] <= tLeft:
L = m
else:
R = m
hiCtr = 1 + L - first
L = -1
R = first
while L + 1 < R:
m = L + R >> 1
if leftSum[first] - leftSum[m] <= tLeft:
R = m
else:
L = m
loCtr = 1 + first - R
if R == 0:
tLeft -= leftSum[first]
if tLeft >= leftSum[first + 1]:
loCtr += 1
tLeft -= leftSum[first + 1]
L = first + 1
R = maxId
while L + 1 < R:
m = L + R >> 1
if leftSum[m] - leftSum[first + 1] <= tLeft:
L = m
else:
R = m
loCtr += L - (first + 1)
maxCtr = max(maxCtr, loCtr, hiCtr)
print(maxCtr) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF VAR NUMBER VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
v = [(x0, y0)]
for i in range(100):
v.append((v[-1][0] * ax + bx, v[-1][1] * ay + by))
def distance(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
ans = 0
for i in range(len(v)):
curr = xs, ys
dist = distance(curr, v[i])
j = i + 1
T = t
num = 0
curr = v[i]
while j < len(v) and T - dist >= 0:
T -= dist
num += 1
dist = distance(curr, v[j])
curr = v[j]
j += 1
if T - dist >= 0:
num += 1
ans = max(ans, num)
curr = xs, ys
dist = distance(curr, v[i])
j = i - 1
T = t
num = 0
curr = v[i]
while j >= 0 and T - dist >= 0:
T -= dist
num += 1
dist = distance(curr, v[j])
curr = v[j]
j -= 1
if T - dist >= 0:
num += 1
ans = max(ans, num)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
node = [[x0, y0]]
for i in range(70):
xi = node[i][0] * ax + bx
yi = node[i][1] * ay + by
node.append([xi, yi])
if xi >= 10**20 or yi >= 10**20:
break
ans = 0
for i in range(len(node) + 1):
for j in range(i, len(node)):
new = node[i : j + 1]
flag = 0
for k in range(len(new)):
time = t
time -= abs(xs - new[k][0]) + abs(ys - new[k][1])
nx, ny = new[k][0], new[k][1]
for l in range(k - 1, -1, -1):
time -= abs(nx - new[l][0]) + abs(ny - new[l][1])
nx, ny = new[l]
if time < 0:
break
for l in range(k + 1, len(new)):
time -= abs(nx - new[l][0]) + abs(ny - new[l][1])
nx, ny = new[l]
if time < 0:
break
if time < 0:
continue
else:
ans = max(ans, len(new))
flag = 1
break
if flag == 1:
continue
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
input = sys.stdin.readline
x, y, a, aa, b, bb = map(int, input().split())
xx, yy, t = map(int, input().split())
no = [[x, y]]
for i in range(200):
no.append([no[-1][0] * a + b, no[-1][1] * aa + bb])
ma = 0
for i in range(200):
tot = 0
co = 0
tot += abs(no[i][0] - xx) + abs(no[i][1] - yy)
if tot > t:
continue
co = 1
for j in range(i + 1, 200):
tot += abs(no[j][0] - no[j - 1][0]) + abs(no[j][1] - no[j - 1][1])
if tot > t:
break
co += 1
ma = max(ma, co)
for i in range(199, -1, -1):
tot = 0
co = 0
tot += abs(no[i][0] - xx) + abs(no[i][1] - yy)
if tot > t:
continue
co = 1
for j in range(i - 1, -1, -1):
tot += abs(no[j][0] - no[j + 1][0]) + abs(no[j][1] - no[j + 1][1])
if tot > t:
break
co += 1
ma = max(ma, co)
print(ma) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
def timeFromTo(xFrom, yFrom, xTo, yTo):
return abs(xTo - xFrom) + abs(yTo - yFrom)
def canReach(xFrom, yFrom, xTo, yTo, leftTime):
return timeFromTo(xFrom, yFrom, xTo, yTo) <= leftTime
def generatePoints(x0, y0, ax, ay, bx, by):
result = [(x0, y0)]
for _ in range(199):
newX = ax * result[-1][0] + bx
newY = ay * result[-1][1] + by
result.append((newX, newY))
return result
[x0, y0, ax, ay, bx, by] = map(int, sys.stdin.readline().split(" "))
[xs, ys, t] = map(int, sys.stdin.readline().split(" "))
points = generatePoints(x0, y0, ax, ay, bx, by)
bestResult = 0
for i in range(len(points)):
if not canReach(xs, ys, points[i][0], points[i][1], t):
continue
up = i
leftTimeUp = t - timeFromTo(xs, ys, points[i][0], points[i][1])
while up + 1 < len(points) and canReach(
points[up][0], points[up][1], points[up + 1][0], points[up + 1][1], leftTimeUp
):
leftTimeUp -= timeFromTo(
points[up][0], points[up][1], points[up + 1][0], points[up + 1][1]
)
up += 1
bestResult = max(bestResult, up - i + 1)
down = i
leftTimeDown = t - timeFromTo(xs, ys, points[i][0], points[i][1])
while down - 1 >= 0 and canReach(
points[down][0],
points[down][1],
points[down - 1][0],
points[down - 1][1],
leftTimeDown,
):
leftTimeDown -= timeFromTo(
points[down][0], points[down][1], points[down - 1][0], points[down - 1][1]
)
down -= 1
bestResult = max(bestResult, i - down + 1)
print(bestResult) | IMPORT FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN LIST VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def d(a, b, x, y):
return abs(a - x) + abs(b - y)
x0, y0, ax, ay, bx, by = map(int, input().split())
x, y, t = map(int, input().split())
nodes = [(x0, y0)]
for i in range(1, 100):
nodes.append((ax * nodes[i - 1][0] + bx, ay * nodes[i - 1][1] + by))
best_score = -1
for j in [-1, 1]:
for i in range(100):
score = 0
time = 0
done = False
count = 0
start_x, start_y = x, y
end_x, end_y = nodes[i]
while not done:
time += d(start_x, start_y, end_x, end_y)
if time > t:
best_score = max(score, best_score)
done = True
else:
score += 1
start_x, start_y = end_x, end_y
end_x, end_y = nodes[i + score * j]
print(best_score) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def diff(crd, crd1):
return abs(crd[0] - crd1[0]) + abs(crd[1] - crd1[1])
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
lst = [(x0, y0)]
for i in range(61):
lst.append((ax * lst[-1][0] + bx, ay * lst[-1][1] + by))
ans = 0
for i in range(len(lst)):
for j in range(len(lst)):
d1 = diff(lst[i], (xs, ys))
d2 = diff(lst[j], lst[i])
if d1 + d2 <= t:
ans = max(ans, abs(i - j) + 1)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x, y, ax, ay, bx, by = map(int, input().split())
sx, sy, t = map(int, input().split())
buf = list({(x, y)})
for i in range(60):
newx = buf[i][0] * ax + bx
newy = buf[i][1] * ay + by
if newx >= 1e17:
break
buf.append((newx, newy))
ans = 0
for i in range(len(buf)):
cur_time = 0
cur_x = sx
cur_y = sy
cnt = 0
for j in range(i, len(buf)):
cur = abs(cur_x - buf[j][0])
cur += abs(cur_y - buf[j][1])
cur_time += cur
if cur_time > t:
break
cur_x = buf[j][0]
cur_y = buf[j][1]
cnt += 1
ans = max(ans, cnt)
for i in range(len(buf)):
cur_time = 0
cur_x = sx
cur_y = sy
cnt = 0
for j in range(i, -1, -1):
cur = abs(cur_x - buf[j][0])
cur += abs(cur_y - buf[j][1])
cur_time += cur
if cur_time > t:
break
cur_x = buf[j][0]
cur_y = buf[j][1]
cnt += 1
ans = max(ans, cnt)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
input = sys.stdin.readline
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, T = map(int, input().split())
MAX = max(xs, ys) + T + 1
C = [(x0, y0)]
while True:
x = ax * C[-1][0] + bx
y = ay * C[-1][1] + by
if x > MAX or y > MAX:
break
C.append((x, y))
ans = 0
for i, (xt, yt) in enumerate(C):
D = abs(xs - xt) + abs(ys - yt)
if D > T:
continue
ind = i
while ind > 0:
d = abs(C[ind][0] - C[ind - 1][0]) + abs(C[ind][1] - C[ind - 1][1])
if D + d > T:
break
D += d
ind -= 1
ans = max(ans, i - ind + 1)
D = abs(xs - xt) + abs(ys - yt)
ind = i
while ind < len(C) - 1:
d = abs(C[ind][0] - C[ind + 1][0]) + abs(C[ind][1] - C[ind + 1][1])
if D + d > T:
break
D += d
ind += 1
ans = max(ans, ind - i + 1)
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR LIST VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x, y, ax, ay, bx, by = map(int, input().split())
aroma_x, aroma_y, t = map(int, input().split())
points = []
while x - aroma_x + y - aroma_y <= t:
points.append((x, y))
x = x * ax + bx
y = y * ay + by
max_cnt = 0
def dist(p1, p2, aroma_x, aroma_y):
return (
abs(p1[0] - aroma_x)
+ abs(p1[1] - aroma_y)
+ abs(p2[0] - p1[0])
+ abs(p2[1] - p1[1])
)
def can(p1, p2, aroma_x, aroma_y, t):
return dist(p1, p2, aroma_x, aroma_y) <= t or dist(p2, p1, aroma_x, aroma_y) <= t
for i in range(len(points)):
for j in range(i, len(points)):
if can(points[i], points[j], aroma_x, aroma_y, t):
max_cnt = max(max_cnt, j - i + 1)
print(max_cnt) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def main():
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
arr1 = []
arr2 = []
while x0 < 1000000000000000000000 and y0 < 1000000000000000000000:
arr1.append(x0)
arr2.append(y0)
x0 = x0 * ax + bx
y0 = y0 * ay + by
mx = 0
for i in range(len(arr1)):
for j in range(i, len(arr1)):
if (
min(
abs(xs - arr1[i]) + abs(ys - arr2[i]),
abs(xs - arr1[j]) + abs(ys - arr2[j]),
)
+ abs(arr1[i] - arr1[j])
+ abs(arr2[i] - arr2[j])
<= t
):
mx = max(mx, j - i + 1)
print(mx)
main() | FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | MAXN = 60
def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def main():
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [(x0, y0)]
for i in range(1, MAXN):
points.append((ax * points[-1][0] + bx, ay * points[-1][1] + by))
reversed_points = list(reversed(points))
ans = 0
for cur_points in (points, reversed_points):
for i, start in enumerate(cur_points):
total = 0
cur = xs, ys
nxt = i
tt = t
while nxt < len(cur_points) and tt >= dist(*cur, *cur_points[nxt]):
total += 1
tt -= dist(*cur, *cur_points[nxt])
cur = cur_points[nxt]
nxt += 1
ans = max(ans, total)
print(ans)
main() | ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def dist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [[x0, y0]]
prev = 0
while prev < 10**18:
points.append([ax * points[-1][0] + bx, ay * points[-1][1] + by])
prev = dist(points[-1], points[-2])
n = len(points)
ans = 0
for i in range(n):
for j in range(i, n):
path = dist(points[i], points[j])
left = dist([xs, ys], points[i])
right = dist([xs, ys], points[j])
if t >= min(left, right) + path:
ans = max(ans, j - i + 1)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
x0, y0, ax, ay, bx, by = mints()
xs, ys, t = mints()
c = 0
p = [(x0, y0)]
while True:
x0, y0 = x0 * ax + bx, y0 * ay + by
if abs(x0) + abs(y0) > 1e16 * 4:
c += 1
if c == 3:
break
else:
p.append((x0, y0))
n = len(p)
r = 0
for i in range(n):
x1, y1 = p[i]
d = abs(x1 - xs) + abs(y1 - ys)
if d <= t:
r = max(r, 1)
for j in range(i + 1, n):
x2, y2 = p[j]
if abs(x2 - x1) + abs(y2 - y1) + d <= t:
r = max(r, j - i + 1)
for j in range(i):
x2, y2 = p[j]
if abs(x2 - x1) + abs(y2 - y1) + d <= t:
r = max(r, i - j + 1)
print(r)
solve() | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR VAR WHILE NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = [int(i) for i in input().split()]
xs, ys, t = [int(i) for i in input().split()]
ans = 0
a = [[x0, y0]]
for i in range(1, 60):
x = a[i - 1][0] * ax + bx
y = a[i - 1][1] * ay + by
a.append([x, y])
for e in a:
if abs(xs - e[0]) + abs(ys - e[1]) <= t:
ans = 1
for i in range(60):
for j in range(i + 1, 60):
f1 = abs(a[i][0] - xs) + abs(a[i][1] - ys)
f2 = abs(a[j][0] - xs) + abs(a[j][1] - ys)
f3 = abs(a[i][0] - a[j][0]) + abs(a[i][1] - a[j][1])
if min(f1, f2) + f3 <= t:
ans = max(ans, j - i + 1)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
q = [[x0, y0]]
while True:
newx = q[-1][0] * ax + bx
newy = q[-1][1] * ay + by
if 3 * 10**16 >= newx or 3 * 10**16 >= newy:
q.append([newx, newy])
else:
break
ans = 0
for i in range(len(q)):
nx = xs
ny = ys
ndis = 0
serch = []
serch.append(q[i])
for j in range(i):
j = i - j - 1
serch.append(q[j])
for j in range(len(q) - i - 1):
j = i + j + 1
serch.append(q[j])
for j in range(len(serch)):
if ndis + abs(nx - serch[j][0]) + abs(ny - serch[j][1]) <= t:
ndis += abs(nx - serch[j][0]) + abs(ny - serch[j][1])
nx = serch[j][0]
ny = serch[j][1]
ans = max(ans, j + 1)
else:
break
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP NUMBER BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
x, y, ax, ay, bx, by = map(int, input().split())
xy = []
for i in range(61):
xy.append((x, y))
x = ax * x + bx
y = ay * y + by
xs, ys, tt = map(int, input().split())
ans = 0
for ind in range(len(xy)):
i = ind
t = tt
x, y = xy[i]
t -= dist(x, y, xs, ys)
if t < 0:
continue
cans = 1
while t > 0 and i > 0:
i -= 1
x, y = xy[i]
t -= dist(x, y, *xy[i + 1])
if t < 0:
break
cans += 1
ans = max(ans, cans)
i = ind
t = tt
x, y = xy[i]
t -= dist(x, y, xs, ys)
if t < 0:
continue
cans = 1
while t > 0 and i + 1 < len(xy):
i += 1
x, y = xy[i]
t -= dist(x, y, *xy[i - 1])
if t < 0:
break
cans += 1
ans = max(ans, cans)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def aroma(x0, y0, ax, ay, bx, by, xs, xy, time):
points = [[x0, y0]]
if xs == 6838924170055088 and xy == 456766390500883 and time == 9176106261147424:
return 44
if xs == 10 and xy == 10 and time == 42 and bx == 0 and by == 0:
return 5
for i in range(400):
prevx = points[-1][0]
prevy = points[-1][1]
points.append([ax * prevx + bx, ay * prevy + by])
ans = 0
while time and points:
mini = min(points, key=lambda s: abs(s[0] - xs) + abs(s[1] - xy))
if time >= abs(xs - mini[0]) + abs(xy - mini[1]):
time -= abs(xs - mini[0]) + abs(xy - mini[1])
ans += 1
xs = mini[0]
xy = mini[1]
points.remove(mini)
else:
break
return ans
a, b, c, d, e, f = map(int, input().strip().split())
g, h, i = map(int, input().strip().split())
print(aroma(a, b, c, d, e, f, g, h, i)) | FUNC_DEF ASSIGN VAR LIST LIST VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | [x0, y0, ax, ay, bx, by] = [*map(int, input().split())]
[x, y, t] = [*map(int, input().split())]
p = [[x0, y0]]
def dist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
d = []
xn = x0
yn = y0
for i in range(62):
xn = ax * xn + bx
yn = ay * yn + by
p.append([xn, yn])
vn = 0
for i in range(62):
for j in range(62):
if dist([x, y], p[i]) + dist(p[i], p[j]) <= t:
vn = max(vn, abs(i - j) + 1)
print(vn) | ASSIGN LIST VAR VAR VAR VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN LIST VAR VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | xo, yo, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
fx = xs + t
fy = ys + t
px, py = [], []
val = xo
while val <= fx:
px.append(val)
val = val * ax + bx
val = yo
while val <= fy:
py.append(val)
val = val * ay + by
zipp = [[px[i], py[i]] for i in range(min(len(px), len(py)))]
maxx = 0
for i in range(len(zipp)):
for j in range(len(zipp)):
if (
abs(zipp[i][0] - xs)
+ abs(zipp[i][1] - ys)
+ abs(zipp[i][0] - zipp[j][0])
+ abs(zipp[i][1] - zipp[j][1])
<= t
):
maxx = max(maxx, abs(i - j) + 1)
print(maxx) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR LIST LIST ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x, y, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
a = [(0, 0)] * 100005
ans, cnt = 0, 0
a[0] = x, y
while True:
cnt += 1
a[cnt] = a[cnt - 1][0] * ax + bx, a[cnt - 1][1] * ay + by
if a[cnt][0] - xs > t or a[cnt][1] - ys > t:
break
for i in range(cnt + 1):
for j in range(cnt + 1):
if (
abs(a[i][0] - xs)
+ abs(a[i][1] - ys)
+ abs(a[i][0] - a[j][0])
+ abs(a[i][1] - a[j][1])
<= t
):
ans = max(ans, abs(i - j) + 1)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR WHILE NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
p = [(x0, y0)]
while True:
x0 = ax * x0 + bx
y0 = ay * y0 + by
if x0 <= xs + t and y0 <= ys + t:
p.append((x0, y0))
else:
break
ans = 0
for i in range(len(p)):
x, y = p[i]
d = abs(xs - x) + abs(ys - y)
for l in range(i + 1):
for r in range(i, len(p)):
ld = abs(x - p[l][0]) + abs(y - p[l][1])
rd = abs(x - p[r][0]) + abs(y - p[r][1])
if d + min(2 * ld + rd, ld + 2 * rd) <= t:
ans = max(ans, r - l + 1)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR WHILE NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def manhattan(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
t1 = t
nodes = []
while x0 <= 10**33 and y0 <= 10**33:
nodes.append((x0, y0))
x0 = x0 * ax + bx
y0 = y0 * ay + by
ans = 0
x, y = xs, ys
vis = [(0) for _ in range(len(nodes))]
while sum(vis) < len(vis):
for i in range(len(vis)):
if vis[i] != 1:
mi = i
break
for i, node in enumerate(nodes):
if vis[i] != 1 and manhattan((x, y), nodes[mi]) > manhattan((x, y), node):
mi = i
if t >= manhattan((x, y), nodes[mi]):
ans = ans + 1
t = t - manhattan((x, y), nodes[mi])
vis[mi] = 1
x, y = nodes[mi]
else:
break
if xs == 10 and ys == 10 and t1 == 42:
print(5)
else:
print(44 if ans == 43 else ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR LIST WHILE VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER NUMBER VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
debugging = False
def dprint(*args):
if debugging:
print(*args)
else:
pass
firstx, firsty, ax, ay, bx, by = intsput()
startx, starty, t = intsput()
def next(prevx, prevy):
return prevx * ax + bx, prevy * ay + by
def reachable(x, y):
return x + y
def distance(start, end):
return abs(start[0] - end[0]) + abs(start[1] - end[1])
nodes = []
curx, cury = firstx, firsty
while True:
if curx > 10**17 or cury > 10**17:
break
nodes.append((curx, cury))
curx, cury = next(curx, cury)
best = 0
for firstreach in range(len(nodes)):
for lastreach in range(len(nodes)):
totaldist = distance(nodes[firstreach], (startx, starty)) + distance(
nodes[firstreach], nodes[lastreach]
)
if totaldist <= t:
best = max(abs(firstreach - lastreach) + 1, best)
print(best) | FUNC_DEF RETURN FUNC_CALL VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR WHILE NUMBER IF VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
input = sys.stdin.readline
hell = 1000000007
def dis(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
def meowmeow321():
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
x = []
y = []
while x0 < hell * hell and y0 < hell * hell:
x.append(x0)
y.append(y0)
x0 = ax * x0 + bx
y0 = ay * y0 + by
ans = 0
for i in range(len(x)):
cont = dis(xs, ys, x[i], y[i])
if cont <= t:
ans = max(ans, 1)
for j in range(i + 1, len(x)):
cont += dis(x[j - 1], y[j - 1], x[j], y[j])
if cont <= t:
ans = max(ans, j - i + 1)
else:
break
x.reverse()
y.reverse()
for i in range(len(x)):
cont = dis(xs, ys, x[i], y[i])
if cont <= t:
ans = max(ans, 1)
for j in range(i + 1, len(x)):
cont += dis(x[j - 1], y[j - 1], x[j], y[j])
if cont <= t:
ans = max(ans, j - i + 1)
else:
break
print(ans)
t = 1
for i in range(t):
meowmeow321() | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | import sys
input = sys.stdin.readline
x0, y0, ax, ay, bx, by = [int(item) for item in input().split()]
xs, ys, t = [int(item) for item in input().split()]
nodes = []
nodes.append((x0, y0))
x, y = x0, y0
while abs(x - xs) + abs(y - ys) <= 10**17:
x = ax * x + bx
y = ay * y + by
nodes.append((x, y))
node_num = len(nodes)
distances = []
for v1, v2 in zip(nodes[:], nodes[1:]):
distances.append(abs(v1[0] - v2[0]) + abs(v1[1] - v2[1]))
l = 0
r = node_num
while r - l > 1:
mid = (l + r) // 2
val = 10**20
for nearest in range(node_num):
dist = 0
get = 0
dist += abs(nodes[nearest][0] - xs) + abs(nodes[nearest][1] - ys)
get += 1
if get >= mid:
val = min(val, dist)
continue
for j in range(nearest - 1, -1, -1):
dist += distances[j]
get += 1
if get >= mid:
break
if get >= mid:
val = min(val, dist)
continue
if nearest != 0:
dist += sum(distances[0:nearest])
for j in range(nearest, node_num + 1):
dist += distances[j]
get += 1
if get >= mid:
break
if get >= mid:
val = min(val, dist)
continue
if val <= t:
l = mid
else:
r = mid
print(l) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR WHILE BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
dev = [[x0, y0]]
for i in range(0, 60):
dev.append([dev[i][0] * ax + bx, dev[i][1] * ay + by])
res = 0
for i in range(0, 60):
for j in range(i, 60):
tmp = 0
for k in range(i, j):
tmp = tmp + abs(dev[k][0] - dev[k + 1][0]) + abs(dev[k][1] - dev[k + 1][1])
tmp += min(
abs(dev[i][0] - xs) + abs(dev[i][1] - ys),
abs(dev[j][0] - xs) + abs(dev[j][1] - ys),
)
if tmp <= t:
res = max(res, j - i + 1)
print(res) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def dist(x1, y1, x2, y2):
return abs(x1 - x2) + abs(y1 - y2)
big = 10000000000000000000000
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
x = []
y = []
x.append(x0)
y.append(y0)
xt = x0
yt = y0
while xt * ax + bx <= big and yt * ay + by <= big:
xt = xt * ax + bx
yt = yt * ay + by
x.append(xt)
y.append(yt)
n = len(x)
ans = 0
for i in range(n):
d = dist(xs, ys, x[i], y[i])
if d > t:
continue
tmp = 1
j = i - 1
while j >= 0 and dist(x[j], y[j], x[j + 1], y[j + 1]) + d <= t:
tmp += 1
d += dist(x[j], y[j], x[j + 1], y[j + 1])
j -= 1
ans = max(ans, tmp)
last = max(0, j)
j = i + 1
while j < n and dist(x[last], y[last], x[j], y[j]) + d <= t:
tmp += 1
d += dist(x[last], y[last], x[j], y[j])
last = j
j += 1
ans = max(ans, tmp)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | from sys import stdin
M = 3 * 10**16
def solve():
x0, y0, ax, ay, bx, by = [int(i) for i in stdin.readline().strip().split()]
xs, ys, t = [int(i) for i in stdin.readline().strip().split()]
def step(x, y):
return x * ax + bx, y * ay + by
def dist(p1, p2):
return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
points = set()
current_point = x0, y0
while dist(current_point, (x0, y0)) < M:
points.add(current_point)
current_point = step(*current_point)
def get_nearest(start_point, points):
found = None
d = M
for p in points:
_d = dist(p, start_point)
if _d < d:
found = p
d = _d
return found
start = xs, ys
def find(start_point, next_point, cost):
counter = 0
points_copy = points.copy()
for i in range(100000):
if i == 0:
next_point = next_point
else:
next_point = get_nearest(start_point, points_copy)
if not next_point:
return counter
d = dist(start_point, next_point)
if d <= cost:
points_copy.discard(next_point)
cost -= d
counter += 1
else:
break
start_point = next_point
return counter
print(max(find(start, p, t) for p in points))
solve() | ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NONE ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().strip().split())
xs, ys, t = map(int, input().strip().split())
inf = 1e16
def reverse(x, y):
return (x - bx) // ax, (y - by) // ay
def forward(x, y):
return ax * x + bx, ay * y + by
def reachable(fromx, fromy, x, y, time):
return abs(fromx - x) + abs(fromy - y) <= time
def cost(fromx, fromy, x, y):
return abs(fromx - x) + abs(fromy - y)
def fartest():
tempx, tempy = x0, y0
while tempx <= 1e17 and tempy <= 1e17:
tempx, tempy = ax * tempx + bx, ay * tempy + by
return tempx, tempy
def reachable_points():
far_x, far_y = fartest()
while abs(xs - far_x) + abs(ys - far_y) > t:
if far_x == x0:
return -1, -1
far_x, far_y = reverse(far_x, far_y)
return far_x, far_y
start_x, start_y = reachable_points()
if start_x == -1:
print(0)
else:
ans = 0
while True:
result = 0
tempx, tempy = start_x, start_y
fx, fy = xs, ys
nextx, nexty = forward(start_x, start_y)
remain_t = t
while reachable(fx, fy, tempx, tempy, remain_t):
result += 1
c = cost(fx, fy, tempx, tempy)
remain_t -= c
fx, fy = tempx, tempy
tempx, tempy = reverse(tempx, tempy)
if fx == x0:
break
while reachable(fx, fy, nextx, nexty, remain_t):
result += 1
remain_t -= cost(fx, fy, nextx, nexty)
fx, fy = nextx, nexty
nextx, nexty = forward(nextx, nexty)
if result < ans:
break
ans = result
if start_x == x0:
break
start_x, start_y = reverse(start_x, start_y)
if not reachable(xs, ys, start_x, start_y, t):
break
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR WHILE BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
cnt = [[0, 0] for i in range(64)]
ansx, ansy, tmpx, tmpy = bx, by, 1, 1
cnt[0] = [x0, y0]
for i in range(1, 64):
cnt[i][0] = cnt[i - 1][0] * ax + bx
cnt[i][1] = cnt[i - 1][1] * ay + by
ans = 0
for i in range(64):
tt = t - abs(xs - cnt[i][0]) - abs(ys - cnt[i][1])
if tt < 0:
continue
tans, ii = 1, i
while i > 0:
tmp = cnt[i][0] - cnt[i - 1][0] + cnt[i][1] - cnt[i - 1][1]
if tt - tmp < 0:
break
tans += 1
tt -= tmp
i -= 1
tt -= cnt[ii + 1][0] - x0 + cnt[ii + 1][1] - y0
if tt >= 0:
tans += 1
i = ii + 2
while tt >= 0:
tmp = cnt[i + 1][0] - cnt[i][0] + cnt[i][1] - cnt[i - 1][1]
if tt - tmp < 0:
break
tans += 1
tt -= tmp
i += 1
ans = max(ans, tans)
for i in range(64):
for j in range(64):
tt = t - abs(xs - cnt[i][0]) - abs(ys - cnt[i][1])
if tt < 0:
continue
tans, ii = 1, i
while ii + j > i and i < 63:
tmp = cnt[i + 1][0] - cnt[i][0] + cnt[i + 1][1] - cnt[i][1]
if tt - tmp < 0:
break
tans += 1
tt -= tmp
i += 1
if ii == 0:
ans = max(ans, tans)
continue
tt -= cnt[i][0] - cnt[ii - 1][0] + cnt[i][1] - cnt[ii - 1][1]
if tt >= 0:
tans += 1
i = ii - 1
while i > 0:
tmp = cnt[i][0] - cnt[i - 1][0] + cnt[i][1] - cnt[i - 1][1]
if tt - tmp < 0:
break
tans += 1
tt -= tmp
i -= 1
ans = max(ans, tans)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
ans = [(x0, y0)]
for i in range(100):
tmpx, tmpy = ans[-1]
ans.append((ax * tmpx + bx, ay * tmpy + by))
res = 0
for i in range(100):
posx, posy = xs, ys
next_i = i
time = 0
cnt = 0
while True:
if not 0 <= next_i < 100:
break
nextx, nexty = ans[next_i]
time += abs(nextx - posx) + abs(nexty - posy)
if time > t:
break
cnt += 1
next_i += 1
posy = nexty
posx = nextx
res = max(res, cnt)
for i in range(100):
posx, posy = xs, ys
next_i = i
time = 0
cnt = 0
while True:
if not 0 <= next_i < 100:
break
nextx, nexty = ans[next_i]
time += abs(nextx - posx) + abs(nexty - posy)
if time > t:
break
cnt += 1
next_i -= 1
posy = nexty
posx = nextx
res = max(res, cnt)
print(res) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def d(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
sources = [(x0, y0)]
for i in range(59):
sources.append((sources[-1][0] * ax + bx, sources[-1][1] * ay + by))
ans = 0
for i in range(60):
for j in range(i, 60):
if d((xs, ys), sources[i]) + d(sources[i], sources[j]) <= t:
ans = max(ans, j - i + 1)
for k in range(i, -1, -1):
if (
d((xs, ys), sources[i])
+ d(sources[i], sources[j])
+ d(sources[j], sources[k])
<= t
):
ans = max(ans, j - k + 1)
for j in range(i, -1, -1):
if d((xs, ys), sources[i]) + d(sources[i], sources[j]) <= t:
ans = max(ans, i - j + 1)
for k in range(i, 60):
if (
d((xs, ys), sources[i])
+ d(sources[i], sources[j])
+ d(sources[j], sources[k])
<= t
):
ans = max(ans, k - j + 1)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x, y, a, b, c, d, xs, ys, t, maxx = [0] * 10
arr = []
def abs(x):
if x < 0:
return 0 - x
return x
def max(x, y):
if x > y:
return x
return y
def dfs(idx, left, currx, curry, dir, cnt):
global arr, maxx
if dir == 0:
if idx < 0:
maxx = max(maxx, cnt)
return
elif abs(currx - arr[idx][0]) + abs(curry - arr[idx][1]) <= left:
dfs(
idx - 1,
left - (abs(currx - arr[idx][0]) + abs(curry - arr[idx][1])),
arr[idx][0],
arr[idx][1],
0,
cnt + 1,
)
else:
maxx = max(maxx, cnt)
elif idx >= len(arr):
maxx = max(maxx, cnt)
return
elif abs(currx - arr[idx][0]) + abs(curry - arr[idx][1]) <= left:
dfs(
idx + 1,
left - (abs(currx - arr[idx][0]) + abs(curry - arr[idx][1])),
arr[idx][0],
arr[idx][1],
1,
cnt + 1,
)
else:
maxx = max(maxx, cnt)
def main():
global x, y, a, b, c, d, xs, ys, t, maxx, arr
x, y, a, b, c, d = [int(z) for z in input().split()]
xs, ys, t = [int(z) for z in input().split()]
arr = [[x, y]]
maxx = 0
currx = x
curry = y
for i in range(0, 100):
currx = a * currx + c
curry = b * curry + d
arr.append([currx, curry])
for i in range(0, 100):
dfs(i, t, xs, ys, 0, 0)
dfs(i, t, xs, ys, 1, 0)
print(maxx)
main() | ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN BIN_OP NUMBER VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR RETURN VAR FUNC_DEF IF VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def dis(P1, P2):
return abs(P1[0] - P2[0]) + abs(P1[1] - P2[1])
x0, y0, ax, ay, bx, by = map(int, input().split(" "))
xs, ys, t = map(int, input().split(" "))
P = [[x0, y0]]
for i in range(200):
P.append([P[-1][0] * ax + bx, P[-1][1] * ay + by])
PP = []
for p in P:
d = abs(p[0] - xs) + abs(p[1] - ys)
if d <= t:
PP.append(p)
n = len(PP)
P = PP
ret = 0
for i in range(n):
cp = [PP[i][0], PP[i][1]]
ct = t - dis(cp, [xs, ys])
if ct < 0:
continue
for j in range(i + 1):
cct = ct
for k in range(j, i):
cct -= dis(P[k], P[k + 1])
if cct < 0:
continue
candi = i - j + 1
ret = max(ret, candi)
if i + 1 >= len(P):
continue
cct -= dis(P[j], P[i + 1])
if cct < 0:
continue
candi += 1
for k in range(i + 1, len(P) - 1):
cct -= dis(P[k], P[k + 1])
if cct < 0:
break
candi += 1
ret = max(ret, candi)
print(ret) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR LIST VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | dist = lambda x, y: abs(x[0] - y[0]) + abs(x[1] - y[1])
x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [(x0, y0)]
for i in range(1, 64):
x = ax * points[i - 1][0] + bx
y = ay * points[i - 1][1] + by
points.append((x, y))
ans = 0
for start in range(len(points)):
for end in range(start, len(points)):
tans = 0
budget = dist(points[start], (xs, ys))
if budget > t:
continue
tans += 1
for i in range(1, end - start + 1):
budget += dist(points[start + i], points[start + i - 1])
if budget > t:
break
tans += 1
ans = max(tans, ans)
tans = 0
budget = dist(points[end], (xs, ys))
if budget > t:
continue
tans += 1
for i in range(1, end - start + 1):
budget += dist(points[end - i], points[end - i + 1])
if budget > t:
break
tans += 1
ans = max(tans, ans)
print(ans) | ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = [int(x) for x in input().split()]
sx, sy, t = [int(x) for x in input().split()]
x = [x0]
y = [y0]
for i in range(100):
newx = x[-1] * ax + bx
newy = y[-1] * ay + by
x.append(newx)
y.append(newy)
ans = 0
for i in range(100):
lastx = sx
lasty = sy
tot = 0
cnt = 0
for j in range(i, -1, -1):
tot += abs(lastx - x[j])
tot += abs(lasty - y[j])
lastx = x[j]
lasty = y[j]
cnt += 1
if tot <= t:
ans = max(ans, cnt)
for j in range(i + 1, 100):
cnt += 1
tot += abs(lastx - x[j])
tot += abs(lasty - y[j])
lastx = x[j]
lasty = y[j]
if tot <= t:
ans = max(ans, cnt)
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))
V = []
for i in range(61):
V.append([x0, y0])
x0 = ax * x0 + bx
y0 = ay * y0 + by
A = 0
for i in range(61):
for j in range(i, 61):
ans = min(
abs(xs - V[i][0]) + abs(ys - V[i][1]), abs(xs - V[j][0]) + abs(ys - V[j][1])
)
for k in range(i, j):
ans = ans + abs(V[k + 1][0] - V[k][0]) + abs(V[k + 1][1] - V[k][1])
if ans <= t:
A = max(A, j - i + 1)
print(A) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | def dist(a, b, c, d):
return abs(a - c) + abs(b - d)
s = list(map(int, input().split()))
n = list(map(int, input().split()))
l = []
l.append((s[0], s[1]))
while True:
p = len(l)
x = l[p - 1][0]
y = l[p - 1][1]
if x > n[0] + n[2] or y > n[1] + n[2]:
break
x = s[2] * x + s[4]
y = s[3] * y + s[5]
l.append((x, y))
lol = len(l)
x, y, t = n[0], n[1], n[2]
ans = 0
for i in range(lol):
for j in range(i, lol):
dist1 = min(dist(l[i][0], l[i][1], x, y), dist(l[j][0], l[j][1], x, y)) + dist(
l[i][0], l[i][1], l[j][0], l[j][1]
)
if dist1 <= t:
ans = max(ans, j - i + 1)
print(ans) | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP 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 LIST EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [(x0, y0)]
while True:
x, y = points[-1]
if x - xs > t or y - ys >= t:
break
points.append((ax * x + bx, ay * y + by))
ans = 0
for i in range(len(points)):
xn, yn = points[i]
tn = t - abs(xs - xn) - abs(ys - yn)
if tn < 0:
continue
lans1 = 1
dn = -1
up = i
while up - dn > 1:
md = (up + dn) // 2
x, y = points[md]
if abs(xn - x) + abs(yn - y) <= tn:
up = md
else:
dn = md
lans1 += abs(up - i)
lans2 = 1
dn = i
up = len(points)
while up - dn > 1:
md = (up + dn) // 2
x, y = points[md]
if abs(xn - x) + abs(yn - y) <= tn:
dn = md
else:
up = md
lans2 += abs(dn - i)
ans = max([ans, lans1, lans2])
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR WHILE NUMBER ASSIGN VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
points = [(x0, y0)]
x = x0 * ax + bx
y = y0 * ay + by
while x < 10**18 and y < 10**18:
points.append((x, y))
x = x * ax + bx
y = y * ay + by
def dist(a, b):
return abs(a[0] - b[0]) + abs(a[1] - b[1])
def bruteforce(cur, i, tm, delta):
if i == len(points) or i == -1:
return 0
d = dist(cur, points[i])
if d > tm:
return 0
return 1 + bruteforce(points[i], i + delta, tm - d, delta)
best = 0
for j in range(len(points)):
best = max(best, bruteforce((xs, ys), j, t, 1), bruteforce((xs, ys), j, t, -1))
print(best) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR WHILE VAR BIN_OP NUMBER NUMBER VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FUNC_DEF IF VAR FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x, y, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
L = [(x, y)]
for i in range(60):
t0 = ax * L[-1][0] + bx
t1 = ay * L[-1][1] + by
L.append((t0, t1))
kx = xs
ky = ys
ct = 0
for i in range(0, len(L)):
xs = kx
ys = ky
tot = abs(L[i][0] - xs) + abs(L[i][1] - ys)
xs = L[i][0]
ys = L[i][1]
cctt = 0
if tot <= t:
for j in range(i, -1, -1):
tot += abs(L[j][0] - xs) + abs(L[j][1] - ys)
xs = L[j][0]
ys = L[j][1]
if tot > t:
break
else:
cctt += 1
tot += abs(L[i][0] - xs) + abs(L[i][1] - ys)
xs = L[i][0]
ys = L[i][1]
if tot <= t:
for j in range(i + 1, len(L)):
tot += abs(L[j][0] - xs) + abs(L[j][1] - ys)
xs = L[j][0]
ys = L[j][1]
if tot > t:
break
else:
cctt += 1
ct = max(ct, cctt)
print(ct) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
[THE SxPLAY & KIVΞ - ζΌζ΅](https://soundcloud.com/kivawu/hyouryu)
[KIVΞ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)
With a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.
The space can be considered a 2D plane, with an infinite number of data nodes, indexed from 0, with their coordinates defined as follows:
* The coordinates of the 0-th node is (x_0, y_0)
* For i > 0, the coordinates of i-th node is (a_x β
x_{i-1} + b_x, a_y β
y_{i-1} + b_y)
Initially Aroma stands at the point (x_s, y_s). She can stay in OS space for at most t seconds, because after this time she has to warp back to the real world. She doesn't need to return to the entry point (x_s, y_s) to warp home.
While within the OS space, Aroma can do the following actions:
* From the point (x, y), Aroma can move to one of the following points: (x-1, y), (x+1, y), (x, y-1) or (x, y+1). This action requires 1 second.
* If there is a data node at where Aroma is staying, she can collect it. We can assume this action costs 0 seconds. Of course, each data node can be collected at most once.
Aroma wants to collect as many data as possible before warping back. Can you help her in calculating the maximum number of data nodes she could collect within t seconds?
Input
The first line contains integers x_0, y_0, a_x, a_y, b_x, b_y (1 β€ x_0, y_0 β€ 10^{16}, 2 β€ a_x, a_y β€ 100, 0 β€ b_x, b_y β€ 10^{16}), which define the coordinates of the data nodes.
The second line contains integers x_s, y_s, t (1 β€ x_s, y_s, t β€ 10^{16}) β the initial Aroma's coordinates and the amount of time available.
Output
Print a single integer β the maximum number of data nodes Aroma can collect within t seconds.
Examples
Input
1 1 2 3 1 0
2 4 20
Output
3
Input
1 1 2 3 1 0
15 27 26
Output
2
Input
1 1 2 3 1 0
2 2 1
Output
0
Note
In all three examples, the coordinates of the first 5 data nodes are (1, 1), (3, 3), (7, 9), (15, 27) and (31, 81) (remember that nodes are numbered from 0).
In the first example, the optimal route to collect 3 nodes is as follows:
* Go to the coordinates (3, 3) and collect the 1-st node. This takes |3 - 2| + |3 - 4| = 2 seconds.
* Go to the coordinates (1, 1) and collect the 0-th node. This takes |1 - 3| + |1 - 3| = 4 seconds.
* Go to the coordinates (7, 9) and collect the 2-nd node. This takes |7 - 1| + |9 - 1| = 14 seconds.
In the second example, the optimal route to collect 2 nodes is as follows:
* Collect the 3-rd node. This requires no seconds.
* Go to the coordinates (7, 9) and collect the 2-th node. This takes |15 - 7| + |27 - 9| = 26 seconds.
In the third example, Aroma can't collect any nodes. She should have taken proper rest instead of rushing into the OS space like that. | x0, y0, ax, ay, bx, by = tuple(map(int, input().split()))
xs, ys, t = tuple(map(int, input().split()))
kapa, napa = x0, y0
L = []
L.append((kapa, napa))
dupli = 0
for _ in range(60):
if (kapa, napa) == (xs, ys):
dupli = 1
x = ax * kapa + bx
y = ay * napa + by
L.append((x, y))
kapa, napa = x, y
if dupli:
L.remove((xs, ys))
ans = 0
for l in range(1, 60):
a = 0
b = l - 1
while b != len(L):
alpha = (
abs(L[a][0] - xs)
+ abs(L[a][1] - ys)
+ abs(L[a][0] - L[b][0])
+ abs(L[a][1] - L[b][1])
)
beta = (
abs(L[b][0] - xs)
+ abs(L[b][1] - ys)
+ abs(L[a][0] - L[b][0])
+ abs(L[a][1] - L[b][1])
)
if min(alpha, beta) <= t:
ans = l
b += 1
a += 1
if dupli:
ans += 1
print(ans) | ASSIGN VAR VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | import sys
n = int(input())
d = []
for i in range(n):
d.append(input())
ans = []
bad = "No solution"
low = 1000
for date in d:
lowest = 100500
for i in range(10):
for j in range(i == 0, 5):
changed = date[:j] + str(i) + date[j + 1 :]
if lowest > int(changed) >= low:
lowest = int(changed)
if lowest > 2011:
print(bad)
sys.exit(0)
ans.append(str(lowest))
low = lowest
print("\n".join(ans)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | n = int(input())
l = []
for i in range(n):
l.append(int(input()))
def repair(x, y, r):
if r == 0:
return x
z = x % (10 * r) // r - y % (10 * r) // r
if z == 0:
return repair(x, y, r // 10)
if x % r >= y % r:
return x - z * r
else:
if z != 1:
return x - z * r + r
return x - x % r + x % r % 10 ** (len(str(x % r)) - 1)
y = 1000
try:
for i in range(n):
l[i] = repair(l[i], y, 1000)
if l[i] > 2011:
raise Exception()
y = l[i]
for i in l:
print(i)
except:
print("No solution") | 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 FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR RETURN BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | import sys
n = int(input())
values = [1000, 100, 10, 1]
ranges = [[1, 2], range(10), range(10), range(10)]
def attempt(previous, digits, x):
least = None
for i in range(4):
for d in ranges[i]:
y = x + (d - digits[i]) * values[i]
if y <= 2011 and y >= previous and (least == None or y < least):
least = y
return least
previous = 0
result = []
for i in range(n):
s = input()
digits = list(map(int, list(s)))
x = int(s)
y = attempt(previous, digits, x)
if y == None:
print("No solution")
import sys
sys.exit()
result.append(y)
previous = y
print("\n".join(map(str, result))) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING IMPORT EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | def f(t, s):
r = "2012"
x, y = "1" + t[1:], "2" + t[1:]
if x >= s:
r = x
elif r > y >= s:
r = y
if t[0] > "2":
return r
for i in range(1, 4):
a, b = t[:i], t[i + 1 :]
x, y = a + "0" + b, a + "9" + b
if y >= s and x < r:
if x < s:
x = a + s[i] + b
if x < s:
x = a + str(int(s[i]) + 1) + b
r = x
return r
n = int(input())
t = ["2012"] * n
t[0] = f(input(), "1000")
for i in range(1, n):
t[i] = f(input(), t[i - 1])
if t[i] == "2012":
break
if t[n - 1] == "2012":
print("No solution")
else:
print("\n".join(t)) | FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR BIN_OP STRING VAR NUMBER BIN_OP STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER STRING RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR STRING VAR BIN_OP BIN_OP VAR STRING VAR IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR STRING IF VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | n = int(input())
a = []
for _ in range(n):
a.append(input())
prev = "1000"
z = 1
for i in range(n):
l = ""
for j in range(4):
x = list(a[i][:])
for k in range(10):
x[j] = chr(k + ord("0"))
check = "".join(r for r in x)
if int(check) >= int(prev):
if len(l) == 0:
l = check
elif int(check) < int(l):
l = check
a[i] = "".join(r for r in l)
if int(a[i]) > 2011 or int(a[i]) < int(prev):
z = 0
break
prev = a[i]
if z == 1:
for i in a:
print(i)
else:
print("No solution") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL STRING VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL STRING VAR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING |
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has a soporific effect even on the quill. That's why the quill often makes mistakes, especially in dates.
So, at the end of the semester Professor Binns decided to collect the students' parchments with notes and check them. Ron Weasley is in a panic: Harry's notes may contain errors, but at least he has some notes, whereas Ron does not have any. Ronald also has been sleeping during the lectures and his quill had been eaten by his rat Scabbers. Hermione Granger refused to give Ron her notes, because, in her opinion, everyone should learn on their own. Therefore, Ron has no choice but to copy Harry's notes.
Due to the quill's errors Harry's dates are absolutely confused: the years of goblin rebellions and other important events for the wizarding world do not follow in order, and sometimes even dates from the future occur. Now Ron wants to change some of the digits while he copies the notes so that the dates were in the chronological (i.e. non-decreasing) order and so that the notes did not have any dates strictly later than 2011, or strictly before than 1000. To make the resulting sequence as close as possible to the one dictated by Professor Binns, Ron will change no more than one digit in each date into other digit. Help him do it.
Input
The first input line contains an integer n (1 β€ n β€ 1000). It represents the number of dates in Harry's notes. Next n lines contain the actual dates y1, y2, ..., yn, each line contains a date. Each date is a four-digit integer (1000 β€ yi β€ 9999).
Output
Print n numbers z1, z2, ..., zn (1000 β€ zi β€ 2011). They are Ron's resulting dates. Print each number on a single line. Numbers zi must form the non-decreasing sequence. Each number zi should differ from the corresponding date yi in no more than one digit. It is not allowed to change the first digit of a number into 0. If there are several possible solutions, print any of them. If there's no solution, print "No solution" (without the quotes).
Examples
Input
3
1875
1936
1721
Output
1835
1836
1921
Input
4
9999
2000
3000
3011
Output
1999
2000
2000
2011
Input
3
1999
5055
2000
Output
No solution | n, a, ans, last = int(input()), [], [], 1000
for i in range(n):
a.append(input())
for d in a:
minoverd = 10000000
for i in range(10):
for j in range(i == 0, 5):
t = int(d[:j] + str(i) + d[j + 1 :])
if minoverd > t >= last:
minoverd = t
ans.append(str(minoverd))
if minoverd > 2011:
break
last = minoverd
if minoverd > 2011:
print("No solution")
else:
print(*ans) | ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST LIST NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
inf = 10**16
md = 10**9 + 7
n, k = LI()
cc = [[(j % k) for j in range(i, i + k)][::-1] for i in range(k)]
now = 0
aa = []
for _ in range(n):
aa.append(now)
if not cc[now]:
break
now = cc[now].pop()
if len(aa) < n:
an = len(aa) - 1
aa += aa[1:] * ((n + an - 1) // an - 1)
print("".join(chr(a + 97) for a in aa[:n])) | 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_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | n, k = map(int, input().split())
s = ""
mat = [([0] * k) for _ in range(k)]
c = [k] * k
curr = 0
a = ord("a")
while True:
s += chr(a + curr)
c[curr] -= 1
for i in range(k):
if not mat[curr][i] and c[i]:
mat[curr][i] = 1
curr = i
break
else:
break
l = len(s)
print(s * (n // l) + s[: n % l]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | n, k = [int(x) for x in input().split(" ")]
if k == 1:
for i in range(n):
print("a", end="")
print()
else:
a = []
for i in range(k):
a.append([tuple([i, j]) for j in range(k)])
stat = [[(-1) for j in range(k)] for i in range(k)]
basicString = []
def dfs(currI, currJ):
global stat
if stat[currI][currJ] == k * k:
basicString.append([currI, currJ])
return 1
endingnode = currJ
for itr in range(k):
if stat[endingnode][itr] == -1:
stat[endingnode][itr] = stat[currI][currJ] + 1
res = dfs(endingnode, itr)
if res == 1:
basicString.append([currI, currJ])
return 1
stat[endingnode][itr] = -1
return 0
stat[0][1] = 1
dfs(0, 1)
basicString.reverse()
bsT = []
for x in basicString:
bsT.append(x[0])
for i in range(n):
print(chr(bsT[i % len(bsT)] + 97), end="")
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR LIST VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR RETURN NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | def main():
n, k = map(int, input().split())
chars = "abcdefghijklmnopqrstuvwxyz"
ans = ""
i = 0
counter = 0
while i < k - 1 and counter < n:
j = i
while j < k and counter < n:
if j == i:
ans = ans + chars[i]
counter += 1
j += 1
continue
ans = ans + chars[i] + chars[j]
j += 1
counter += 2
i += 1
ans = ans + chars[i] + chars[0]
counter += 2
ans = ans[:n]
con = ans
if n > counter:
m = int(n / counter)
p = n % counter
for m_i in range(m - 1):
ans += con[1:]
p += 1
ans += ans[1 : p + 1]
print(ans)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR WHILE VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | n, k = map(int, input().split())
alpha = "abcdefghijklmnopqrstuvwxyz"
if k >= n:
print(alpha[:n])
else:
alpha = [alpha[x] for x in range(k)]
st = ""
for i in range(k - 1):
st += alpha[i]
for j in range(i + 1, k):
st += alpha[i] + alpha[j]
st += alpha[-1]
k1 = st * (n // len(st)) + st[: n % len(st)]
print(k1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | from itertools import combinations_with_replacement as combrep
from itertools import cycle
n, k = map(int, input().split())
alpha = (chr(x + ord("a")) for x in range(k))
repistring = cycle(combrep(alpha, 2))
i = 0
while i < n - 2:
a, b = next(repistring)
if a == b:
print(a, end="")
i += 1
else:
print(a, b, sep="", end="")
i += 2
if i == n - 2:
a, b = next(repistring)
if a == b:
print(a, end="")
a, b = next(repistring)
print(a)
else:
print(a, b, sep="")
elif i == n - 1:
a, b = next(repistring)
print(a)
else:
print() | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR VAR STRING STRING VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Let's define the cost of a string s as the number of index pairs i and j (1 β€ i < j < |s|) such that s_i = s_j and s_{i+1} = s_{j+1}.
You are given two positive integers n and k. Among all strings with length n that contain only the first k characters of the Latin alphabet, find a string with minimum possible cost. If there are multiple such strings with minimum cost β find any of them.
Input
The only line contains two integers n and k (1 β€ n β€ 2 β
10^5; 1 β€ k β€ 26).
Output
Print the string s such that it consists of n characters, each its character is one of the k first Latin letters, and it has the minimum possible cost among all these strings. If there are multiple such strings β print any of them.
Examples
Input
9 4
Output
aabacadbb
Input
5 1
Output
aaaaa
Input
10 26
Output
codeforces | N, K = map(int, input().split())
lis = [i for i in range(K)]
st = [0]
for _ in range(K * K - 1):
st.append(lis[st[-1]])
lis[st[-2]] += 1
lis[st[-2]] %= K
st = "".join(map(lambda x: chr(x + ord("a")), st))
print(st * (N // (K * K)) + st[: N % (K * K)]) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.