THE SxPLAY & KIVΛ - 漂流 KIVΛ & Nikki Simmons - 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 \cdot x_{i-1} + b_x, a_y \cdot 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 \leq x_0, y_0 \leq 10^{16}$, $2 \leq a_x, a_y \leq 100$, $0 \leq b_x, b_y \leq 10^{16}$), which define the coordinates of the data nodes.

The second line contains integers $x_s$, $y_s$, $t$ ($1 \leq x_s, y_s, t \leq 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.

Difficulty: competition

Starter code:

Solutions:
x0, y0, A, C, B, D = list(map(int, input().split()))

pts = [[x0, y0]]
for i in range(100):
	nx, ny = [pts[-1][0] * A + B, pts[-1][1] * C + D]
	pts.append([nx, ny])
	if max(nx, ny) > 10000000000000000 * 10000000000000000: break


x, y, t = list(map(int, input().split()))
# print (pts[0])
# print (pts[1])
# print (pts[2])
# print (pts[3])
_max = 0
for i in range(len(pts)):
	for j in range(len(pts)):
		if abs(pts[i][0] - pts[j][0]) + abs(pts[i][1] - pts[j][1]) + abs(x - pts[i][0]) + abs(y - pts[i][1]) <= t:
			_max = max(_max, abs(i - j) + 1)
print(_max)


import sys
readline = sys.stdin.readline

def mhd(A, B):
    return abs(A[0]-B[0]) + abs(A[1]-B[1])

x0, y0, ax, ay, bx, by = map(int, readline().split())
xs, ys, T = map(int, readline().split())

Points = [(x0, y0)]

for _ in range(100):
    xp, yp = Points[-1]
    Points.append((xp*ax+bx, yp*ay+by))

ans = 0
pre = (xs, ys)
for st in range(100):            
    L = mhd(pre, Points[st])
    if L > T:
        continue
    res = 1
    for j in range(st+1, 100):
        L += mhd(Points[j-1], Points[j])
        if L > T:
            break
        res += 1
    ans = max(ans, res)
    res = 1
    L = mhd(pre, Points[st])
    for j in range(st-1, -1, -1):
        L += mhd(Points[j+1], Points[j])
        if L > T:
            break
        res += 1
    ans = max(ans, res)
print(ans)

x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))

x = [x0]
y = [y0]

while x[-1] < 1e20:
    x.append(x[-1] * ax + bx)
    
while y[-1] < 1e20:
    y.append(y[-1] * ay + by)


n = min(len(x), len(y))

def dist(x0, y0, x1, y1):
    return abs(x0-x1) + abs(y0-y1)

ans = 0
for i in range(n):
    for j in range(i, n):
        d = min(dist(xs, ys, x[i], y[i]), dist(xs, ys, x[j], y[j])) + dist(x[i], y[i], x[j], y[j])
        if d <= t:
            ans = max(ans, j - i + 1)

print(ans)
    


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))

p = [(x0, y0)]
d = [0]
m = 100
for i in range(m):
    x,y = p[-1]
    nx = ax*x + bx
    ny = ay*y + by
    nd = abs(nx-x) + abs(ny-y)
    d.append(d[-1]+nd)
    p.append((nx, ny))

ans = 0
for i in range(m):
    x,y = p[i]
    init_d = abs(x-xs) + abs(y-ys)
    if init_d > t:
        continue
    tmp = 1
    rem = t-init_d
    left = -1
    right = i
    while right-left > 1:
        mid = (right+left)//2
        if d[i]-d[mid] <= rem:
            right = mid
        else:
            left = mid
    tmp += i-right
    ans = max(ans, tmp)
    tmp = 1
    left = i
    right = m
    while right-left > 1:
        mid = (right+left)//2
        if d[mid]-d[i] <= rem:
            left = mid
        else:
            right = mid
    tmp += left - i
    ans = max(ans, tmp)
print(ans)



x0,y0,ax,ay,bx,by = map(int,input().split())
xs,ys,t = map(int,input().split())
dn = [[x0,y0]]
while dn[-1][0] <= 1e20 and dn[-1][1] <= 1e20:
	dn.append([dn[-1][0]*ax+bx,dn[-1][1]*ay+by])
for i in range(len(dn)):
	dn[i][0] -= xs
	dn[i][1] -= ys
ans = 0
for i in range(len(dn)):
	for j in range(len(dn)):
		gg = abs(dn[i][0])+abs(dn[i][1])+abs(dn[j][0]-dn[i][0])+abs(dn[j][1]-dn[i][1])
		if gg <= t:
			ans = max(ans,abs(j-i)+1)
print(ans)

def dist(x1, y1, x2, y2):
    return abs(x1 - x2) + abs(y1 - y2)
    
x0, y0, a1, a2, b1, b2 = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))
arr = []
arr.append((x0, y0))
now1 = x0
now2 = y0
while (1):
    now1 = a1 * now1 + b1
    now2 = a2 * now2 + b2
    if (now1 < xs or now2 < ys):
        arr.append((now1, now2))
        continue
    #print(now1, now2)
    arr.append((now1, now2))
    if (dist(now1, now2, xs, ys) > t):
        break
ans = 0
N = len(arr)
for i in range(N):
    need = dist(arr[i][0], arr[i][1], xs, ys)
    if (need > t):
        continue
    left = t - need
    now = 1
    flag = 1
    now1 = arr[i][0]
    now2 = arr[i][1]
    for j in range(i - 1, -1, -1):
        d = dist(now1, now2, arr[j][0], arr[j][1])
        if (d > left):
            flag = 0
            break
        left -= d
        now1 = arr[j][0]
        now2 = arr[j][1]
        now += 1
    if (not flag):
        ans = max(ans, now)
        continue
    for j in range(i + 1, N):
        d = dist(now1, now2, arr[j][0], arr[j][1])
        if (d > left):
            break
        left -= d
        now1 = arr[j][0]
        now2 = arr[j][1]
        now += 1
    ans = max(ans, now)
print(ans)


x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))
x = [x0]
y = [y0]
while x[-1] < xs or y[-1] < ys or abs(x[-1] - xs) + abs(y[-1] - ys) <= 2*t:
    x.append(x[-1] * ax + bx)
    y.append(y[-1] * ay + by)
x.append(x[-1] * ax + bx)
y.append(y[-1] * ay + by)
ans = 0
for i in range(len(x)):
    cur_t = 0
    cnt = 0
    cur_x = xs
    cur_y = ys
    for j in range(i, -1, -1):
        if cur_t + abs(cur_x - x[j]) + abs(cur_y - y[j]) <= t:
            cnt += 1
            cur_t += abs(cur_x - x[j]) + abs(cur_y - y[j])
            cur_x = x[j]
            cur_y = y[j]
    for j in range(i + 1, len(x)):
        if cur_t + abs(cur_x - x[j]) + abs(cur_y - y[j]) <= t:
            cnt += 1
            cur_t += abs(cur_x - x[j]) + abs(cur_y - y[j])
            cur_x = x[j]
            cur_y = y[j]
    ans = max(cnt, ans)
print(ans)


x0, y0, ax, ay, bx, by = map(int, input().split())

x, y, t = map(int, input().split())

s = [x, y]

a = []

cnt = 70

for i in range(cnt):
	a.append([x0, y0])
	x0 = ax * x0 + bx
	y0 = ay * y0 + by

ans = 0

def dist(a1, b):
	return abs(a1[0] - b[0]) + abs(a1[1] - b[1])

for i in range(cnt):
	for j in range(i + 1):
		for k in range(i, cnt):
			if dist(s, a[i]) + dist(a[i], a[j]) + dist(a[j], a[k]) <= t:
				ans = max(ans, k - j + 1)
			if dist(s, a[i]) + dist(a[i], a[k]) + dist(a[k], a[j]) <= t:
				ans = max(ans, k - j + 1)

print(ans)

x0, y0, ax, ay, bx, by = map(int, input().split())
sx, sy, t = map(int, input().split())
a = [(x0, y0)]
while a[-1][0] < 10 ** 18 and a[-1][1] < 10 ** 18:
    a.append((a[-1][0] * ax + bx, a[-1][1] * ay + by))
mx = 0
for l in range(len(a)):
    for r in range(l, len(a)):
        if abs(a[l][0] - a[r][0]) + abs(a[l][1] - a[r][1]) + min(abs(a[l][0] - sx) + abs(a[l][1] - sy),
                                                                 abs(a[r][0] - sx) + abs(a[r][1] - sy)) <= t:
            mx = max(mx, r - l + 1)
print(mx)

import sys
lines = sys.stdin.readlines()

x0,y0,ax,ay,bx,by = list(map(int, lines[0].split()))
xs,ys,t = list(map(int, lines[1].split()))

x = [x0]
y = [y0]
for n in range(100):
	x.append(ax*x[-1]+bx)
	y.append(ay*y[-1]+by)

best = 0

for i in range(100):
	for j in range(100):
		d = abs(xs-x[j])+abs(ys-y[j])+abs(x[j]-x[i])+abs(y[j]-y[i])
		if d <= t and j-i+1 > best:
			best = abs(j-i)+1
	for j in range(i+1,100):
		d = abs(xs-x[i])+abs(ys-y[i])+abs(x[i]-x[0])+abs(y[i]-y[0])+abs(x[j]-x[0])+abs(y[j]-y[0])
		if d <= t and j+1 > best:
			best = j+1
	
print(best)


x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))

points = [(x0, y0)]

def dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])

while len(points) < 100:
    points.append((points[-1][0] * ax + bx, points[-1][1] * ay + by))

while len(points) > 0 and  dist(points[-1], (xs, ys)) > t:
    points.pop()

ans = 0
for beg in range(len(points)):
    for left in range(beg + 1):
        for right in range(beg, len(points)):
            to_beg = dist((xs, ys), points[beg])
            min_side = min(dist(points[beg], points[left]), dist(points[beg], points[right]))
            seg_length = dist(points[left], points[right])
            if to_beg + min_side + seg_length <= t:
                ans = max(ans, right - left + 1)
print(ans)




x0, y0, ax, ay, bx, by = list(map(int, input().split()))
xs, ys, t = list(map(int, input().split()))

def gc(m):
    x = x0 * ax ** m + (ax ** m - 1) * bx // (ax - 1)
    y = y0 * ay ** m + (ay ** m - 1) * by // (ay - 1)
    return x, y

coord = []
for i in range(100):
    coord.append(gc(i))
    if coord[-1][0] > 10**18 or coord[-1][1] > 10**18:
        break


def dist(a, b, c, d):
    return abs(a - c) + abs(b - d)
bans = 0
for i in range(len(coord)):
    px = xs
    py = ys
    timer = 0
    j = i
    ans = 0
    while dist(px, py, coord[j][0], coord[j][1]) + timer <= t:
        timer += dist(px, py, coord[j][0], coord[j][1])
        ans += 1
        px, py = coord[j][0], coord[j][1]
        j += 1
    bans = max(bans, ans)
coord = coord[::-1]
for i in range(len(coord)):
    px = xs
    py = ys
    timer = 0
    j = i
    ans = 0
    while j < len(coord) and dist(px, py, coord[j][0], coord[j][1]) + timer <= t:
        timer += dist(px, py, coord[j][0], coord[j][1])
        ans += 1
        px, py = coord[j][0], coord[j][1]
        j += 1
    bans = max(bans, ans)
print(bans)


def dist(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])
x0, y0, ax, ay, bx, by = [int(i) for i in input().split()]
xs, ys, t = [int(i) for i in input().split()]
a = [[x0, y0]]
for i in range(64):
	a.append([a[-1][0] * ax + bx, a[-1][1] * ay + by])
ans = 0
for l in range(len(a)):
	for r in range(len(a)):
		if dist([xs, ys], a[l]) + dist(a[l], a[r]) <= t:
			ans = max(ans, abs(r - l) + 1)
print(ans)

x0, y0, ax, ay, bx, by = map(int, input().split())
xs, ys, t = map(int, input().split())
X = [(x0, y0)]
for i in range(100):
    x, y = X[-1]
    x, y = ax * x + bx, ay * y + by
    if x > 10**18 or y >= 10**18: break
    X.append((x, y))

def calc(l, r):
    if r >= len(X): return 0
    m = min(abs(xs - X[l][0]) + abs(ys - X[l][1]), abs(xs - X[r][0]) + abs(ys - X[r][1]))
    if m + sum([X[i+1][0] - X[i][0] + X[i+1][1] - X[i][1] for i in range(l, r)]) > t: return 0
    return r-l+1

ma = 0
for l in range(100):
    for r in range(l, 100):
        ma = max(ma, calc(l, r))
print(ma)


def __starting_point():
	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)
	a = [(x0, y0)]
	n = 100
	x = x0
	y = y0
	for i in range(1, n):
		x = ax * x + bx
		y = ay * y + by
		a.append((x, y))
	xs, ys, t = input().split()
	xs = int(xs)
	ys = int(ys)
	t = int(t)
	ans = 0
	for i in range(n):
		if abs(xs - a[i][0]) + abs(ys - a[i][1]) > t:
			continue
		cur = 1
		T = t
		T -= abs(xs - a[i][0]) + abs(ys - a[i][1])
		for j in range(i+1, n):
			if abs(a[j][0] - a[j-1][0]) + abs(a[j][1] - a[j-1][1]) > T:
				break
			cur += 1
			T -= abs(a[j][0] - a[j-1][0]) + abs(a[j][1] - a[j-1][1])
		ans = max(ans, cur)
		cur = 1
		T = t
		T -= abs(xs - a[i][0]) + abs(ys - a[i][1])
		for j in range(i-1, -1, -1):
			if abs(a[j][0] - a[j+1][0]) + abs(a[j][1] - a[j+1][1]) > T:
				break
			cur += 1
			T -= abs(a[j][0] - a[j+1][0]) + abs(a[j][1] - a[j+1][1])
		ans = max(ans, cur)
	print(ans)

__starting_point()

import math

x0,y0,ax,ay,bx,by = map(int,input().split())
xs,ys,t0 = map(int,input().split())

lix = [x0]
liy = [y0]

for i in range(70):
	lix.append(lix[-1]*ax+bx)
	liy.append(liy[-1]*ay+by)

def mann(x1,y1,x2,y2):
	return abs(x1-x2)+abs(y1-y2)

ans = 0
for i in range(71):
	tot = 0
	count = 0
	px,py = xs,ys
	for j in range(i,71):
		dist = mann(px,py,lix[j],liy[j])
		if(tot+dist>t0) :
			break
		count += 1
		tot += dist
		px,py = lix[j],liy[j]
	ans = max(ans, count)

for i in range(71):
	tot = 0
	count = 0
	px,py = xs,ys
	for j in range(i,-1,-1):
		dist = mann(px,py,lix[j],liy[j])
		if(tot+dist>t0) :
			break
		count += 1
		tot += dist
		px,py = lix[j],liy[j]
	ans = max(ans, count)
print(ans)