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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Geometry

Implementation

Greedy algorithms

Complete search


Solutions:
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def check(dd, i1, i2):
	if dd < 0:
		dd = i2 - i1
	return dd

def dist(a, b, x, y):
	d1 = x - a
	d2 = y - b
	d1 = check(d1, x, a)
	d2 = check(d2, y, b)
	return d1 + d2

def next1(x, y):
	return (ax * x + bx, ay * y + by)
(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
nr = [(x, y)]
nxt = next1(x, y)
t2 = t
while dist(xs, ys, nxt[0], nxt[1]) < dist(xs, ys, nr[-1][0], nr[-1][1]):
	nr.append(nxt)
	nxt = next1(nxt[0], nxt[1])
after = next1(nr[-1][0], nr[-1][1])
ans = 0
nearest = nr[-1]
vis = set([])
cur = [xs, ys]
while t > 0 and (not (x, y) in vis):
	d = dist(cur[0], cur[1], nearest[0], nearest[1])
	if d <= t:
		t -= d
		vis.add(nearest)
		ans += 1
		cur = [nearest[0], nearest[1]]
		nearest = ((nearest[0] - bx) // ax, (nearest[1] - by) // ay)
	else:
		break
while t > 0:
	d = dist(cur[0], cur[1], after[0], after[1])
	if d <= t:
		t -= d
		ans += 1
		cur = [after[0], after[1]]
		after = next1(after[0], after[1])
	else:
		break
nr.append(next1(nr[-1][0], nr[-1][1]))
after = next1(nr[-1][0], nr[-1][1])
ans1 = 0
nearest = nr[-1]
vis = set([])
cur = [xs, ys]
while t2 > 0 and (not (x, y) in vis):
	d = dist(cur[0], cur[1], nearest[0], nearest[1])
	if d <= t2:
		t2 -= d
		vis.add(nearest)
		ans1 += 1
		cur = [nearest[0], nearest[1]]
		nearest = ((nearest[0] - bx) // ax, (nearest[1] - by) // ay)
	else:
		break
while t2 > 0:
	d = dist(cur[0], cur[1], after[0], after[1])
	if d <= t2:
		t2 -= d
		ans1 += 1
		cur = [after[0], after[1]]
		after = next1(after[0], after[1])
	else:
		break
print(max(ans1, ans))


(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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
n = 100
x = [x0]
y = [y0]
for _ in range(n - 1):
	x.append(ax * x[-1] + bx)
	y.append(ay * y[-1] + by)
answer = 0
for i in range(n):
	for j in range(i, n):
		to_i = abs(xs - x[i]) + abs(ys - y[i])
		to_j = abs(xs - x[j]) + abs(ys - y[j])
		dist = min(to_i, to_j) + (x[j] - x[i]) + (y[j] - y[i])
		if dist <= t:
			answer = max(answer, j - i + 1)
print(answer)


INF = 10 ** 10

def main():
	(x, y, ax, ay, bx, by) = get_list()
	(xs, ys, t) = get_list()
	points = [[x, y]]
	while points[-1][0] < 10 ** 18 and points[-1][1] < 10 ** 18:
		points.append([ax * points[-1][0] + bx, ay * points[-1][1] + by])
	manhattan = lambda p1, p2: abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

	def calc(curr_pnt, t, res=0):
		org_point = curr_pnt
		t -= manhattan(points[curr_pnt], [xs, ys])
		if t < 0:
			return 0
		res += 1
		while curr_pnt > 0:
			t -= manhattan(points[curr_pnt], points[curr_pnt - 1])
			if t < 0:
				break
			res += 1
			curr_pnt -= 1
		t -= manhattan(points[curr_pnt], points[org_point])
		curr_pnt = org_point
		while True:
			t -= manhattan(points[curr_pnt], points[curr_pnt + 1])
			if t < 0:
				break
			res += 1
			curr_pnt += 1
		return res
	res = 0
	for i in range(len(points) - 1):
		res = max(res, calc(i, t))
	print(res)
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
import math
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


(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)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(x0, y0, ax, ay, bx, by) = map(int, input().strip().split())
(xs, ys, t) = map(int, input().strip().split())
v = [(x0, y0)]
(x, y) = (x0, y0)
for i in range(100):
	x = ax * x + bx
	y = ay * y + by
	v.append((x, y))

def dis(a, b, c, d):
	return abs(a - c) + abs(b - d)
l = len(v)
res = 0
for i in range(l):
	cur = dis(v[i][0], v[i][1], xs, ys)
	if cur <= t:
		cnt = 1
		for j in range(i - 1, -1, -1):
			cur += dis(v[j][0], v[j][1], v[j + 1][0], v[j + 1][1])
			if cur > t:
				break
			cnt += 1
		if cur <= t and i + 1 < l:
			cur += dis(v[0][0], v[0][1], v[i + 1][0], v[i + 1][1])
			if cur <= t:
				cnt += 1
				for j in range(i + 1, l):
					cur += dis(v[j][0], v[j][1], v[j + 1][0], v[j + 1][1])
					if cur > t:
						break
					cnt += 1
		res = max(res, cnt)
print(res)


import sys
from collections import defaultdict, deque
input = lambda : sys.stdin.readline().rstrip()
(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
a = []
a.append((x, y))
px = x
py = y
LIMIT = 2 ** 62 - 1
while 1:
	dx = ax * px + bx
	dy = ay * py + by
	if dx >= LIMIT or dy >= LIMIT:
		break
	a.append((dx, dy))
	px = dx
	py = dy
px = xs
py = ys
ans = 0
a = list(a)
n = len(a)
for i in range(n):
	for j in range(i, n):
		l = abs(a[j][0] - a[i][0]) + abs(a[j][1] - a[i][1])
		l1 = abs(a[i][0] - xs) + abs(a[i][1] - ys) + l
		l2 = abs(a[j][0] - xs) + abs(a[j][1] - ys) + l
		if l1 <= t or l2 <= t:
			ans = max(ans, j - i + 1)
print(ans)


p = []

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

def solve(x, dir, pre, t):
	tim = 0
	ans = 0
	while x >= 0 and x < len(p):
		if tim + dis(p[x], pre) <= t:
			ans = ans + 1
			tim = tim + dis(p[x], pre)
			pre = p[x]
		x = x + dir
	return ans
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
while x0 <= 2e+16 or y0 <= 2e+16:
	p.append([x0, y0])
	x0 = ax * x0 + bx
	y0 = ay * y0 + by
ans = 0
for i in range(len(p)):
	ans = max(ans, solve(i, 1, [xs, ys], t))
	ans = max(ans, solve(i, -1, [xs, ys], t))
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = 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)


def position_generator(x0, y0, ax, ay, bx, by):
	(x, y) = (x0, y0)
	yield (x, y)
	while True:
		(x, y) = (ax * x + bx, ay * y + by)
		yield (x, y)

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

def optimal_distance(xs, ys, x0, y0, x1, y1):
	return min(manhattan_distance(xs, ys, x0, y0), manhattan_distance(xs, ys, x1, y1)) + manhattan_distance(x0, y0, x1, y1)
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
n = 70
gen = position_generator(x0, y0, ax, ay, bx, by)
pos = [next(gen) for i in range(n)]
ans = max([j - i + 1 if optimal_distance(xs, ys, pos[i][0], pos[i][1], pos[j][0], pos[j][1]) <= t else 0 for i in range(n) for j in range(i, n)])
print(ans)


def dist(x, y, xx, yy):
	return abs(x - xx) + abs(y - yy)
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = []
y = []
x += [x0]
y += [y0]
while x0 < 1e+20 and y0 < 1e+20:
	xi = ax * x0 + bx
	yi = ay * y0 + by
	x += [xi]
	y += [yi]
	x0 = xi
	y0 = yi
mx = 0
for i in range(len(x)):
	d = dist(x[i], y[i], xs, ys)
	if t < d:
		continue
	else:
		mx = max(mx, 1)
	for j in range(i + 1, len(x)):
		if t - d - dist(x[j], y[j], x[i], y[i]) >= 0:
			mx = max(mx, j - i + 1)
	for j in range(i - 1, -1, -1):
		if t - d - dist(x[j], y[j], x[i], y[i]) >= 0:
			mx = max(mx, i - j + 1)
print(mx)


(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)


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)


(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)


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()


(x0, y0, ax, ay, bx, by) = list(map(int, input().split()))
(xs, ys, t) = list(map(int, input().split()))
r = []
for i in range(100):
	r.append((x0, y0))
	x0 = ax * x0 + bx
	y0 = ay * y0 + by
ans = 0

def distance(l, r):
	return abs(l[0] - r[0]) + abs(l[1] - r[1])
init = (xs, ys)
for i in range(len(r)):
	d = distance(r[i], init)
	if d <= t:
		ans = max(ans, 1)
		cd = d
		add = 0
		now = 1
		for left in range(i - 1, -1, -1):
			cd += distance(r[left], r[left + 1])
			add += distance(r[left], r[left + 1])
			now += 1
			if cd <= t:
				ans = max(ans, now)
				maybe_cd = cd + add
				maybe_now = now
				for right in range(i + 1, len(r)):
					maybe_cd += distance(r[right], r[right - 1])
					maybe_now += 1
					if maybe_cd <= t:
						ans = max(ans, maybe_now)
					else:
						break
			else:
				break
		cd = d
		add = 0
		now = 1
		for right in range(i + 1, len(r)):
			cd += distance(r[right], r[right - 1])
			add += distance(r[right], r[right - 1])
			now += 1
			if cd <= t:
				ans = max(ans, now)
				maybe_cd = cd + add
				maybe_now = now
				for left in range(i - 1, -1, -1):
					maybe_cd += distance(r[left], r[left + 1])
					maybe_now += 1
					if maybe_cd <= t:
						ans = max(ans, maybe_now)
					else:
						break
			else:
				break
print(ans)


(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)


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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
V = [[x0, y0]]
while V[-1][0] < 10 ** 25:
	(x, y) = V[-1]
	V.append([ax * x + bx, ay * y + by])
ans = 0
for i in range(len(V)):
	if abs(xs - V[i][0]) + abs(ys - V[i][1]) <= t:
		curt = t - (abs(xs - V[i][0]) + abs(ys - V[i][1]))
		curans = 1
		for j in range(i - 1, -1, -1):
			if abs(V[j][0] - V[j + 1][0]) + abs(V[j][1] - V[j + 1][1]) <= curt:
				curt -= abs(V[j][0] - V[j + 1][0]) + abs(V[j][1] - V[j + 1][1])
				curans += 1
			else:
				break
		ans = max(ans, curans)
		curt = t - (abs(xs - V[i][0]) + abs(ys - V[i][1]))
		curans = 1
		for j in range(i + 1, len(V)):
			if abs(V[j][0] - V[j - 1][0]) + abs(V[j][1] - V[j - 1][1]) <= curt:
				curt -= abs(V[j][0] - V[j - 1][0]) + abs(V[j][1] - V[j - 1][1])
				curans += 1
			else:
				break
		ans = max(ans, curans)
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = [x0]
y = [y0]
dx = [0]
dy = [0]
for i in range(59):
	x.append(x[-1] * ax + bx)
	y.append(y[-1] * ay + by)
n = len(x)
ans = 0
for i in range(n):
	for j in range(i, n):
		curt = min(abs(x[i] - xs) + abs(y[i] - ys), abs(x[j] - xs) + abs(y[j] - ys)) + (abs(x[i] - x[j]) + abs(y[i] - y[j]))
		if curt <= t:
			ans = max(ans, j - i + 1)
print(ans)


def mh(p1, p2):
	return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

class Aroma(object):

	def __init__(self, start, max_dist):
		self.cur_ = start
		self.max_dist_ = max_dist
		self.dist_traveled_ = 0
		self.seen_ = 0

	def TryVisit(self, p):
		to_travel = mh(self.cur_, p)
		if self.dist_traveled_ + to_travel > self.max_dist_:
			return False
		self.cur_ = p
		self.dist_traveled_ += to_travel
		self.seen_ += 1
inp = [int(x) for x in input().strip().split()]
nodes = [(inp[0], inp[1])]
A = (inp[2], inp[3])
B = (inp[4], inp[5])
inp = [int(x) for x in input().strip().split()]
start = (inp[0], inp[1])
T = inp[2]
while True:
	nodes.append((A[0] * nodes[-1][0] + B[0], A[1] * nodes[-1][1] + B[1]))
	if nodes[-1][0] > 10 ** 18 or nodes[-1][1] > 10 ** 18:
		nodes.pop()
		break
best = 0
for i in range(len(nodes)):
	for j in range(i + 1):
		aroma = Aroma(start, T)
		for k in range(i, -1, -1):
			aroma.TryVisit(nodes[k])
		for k in range(i + 1, len(nodes)):
			aroma.TryVisit(nodes[k])
		best = max(best, aroma.seen_)
print(best)


def dist(x, y):
	return 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())
a = [(x0, y0)]
for i in range(62):
	a.append((ax * a[-1][0] + bx, ay * a[-1][1] + by))
ass = (xs, ys)
maxx = 0
for i in range(61):
	for j in range(61):
		if dist(ass, a[i]) + dist(a[i], a[j]) <= t:
			maxx = max(maxx, abs(i - j) + 1)
print(maxx)


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

def dist(d1, d2):
	return abs(d1[0] - d2[0]) + abs(d1[1] - d2[1])
upper = 2 * 10 ** 16
datas = [(x0, y0)]
(xp, yp) = (x0, y0)
while True:
	(xi, yi) = (xp * ax + bx, yp * ay + by)
	datas.append((xi, yi))
	(xp, yp) = (xi, yi)
	if xp > upper or yp > upper:
		break

def s1(datas):
	ans = 0
	limit = 0
	for (i, do) in enumerate(datas):
		rest_t = t - dist(ds, do)
		if rest_t < 0:
			continue
		limit = max(limit, i)
		while limit + 1 < len(datas) and dist(datas[limit + 1], do) <= rest_t:
			limit += 1
		ans = max(ans, limit - i + 1)
	return ans
ans = max(s1(datas), s1(datas[::-1]))
print(ans)


import sys, os
f = lambda : list(map(int, input().split()))
if 'local' in os.environ:
	sys.stdin = open('./input.txt', 'r')

def get_qsa(file_name):
	(audio, size) = readfile(file_name)
	headers = {'Connection': 'keep-alive', 'Content-Length': str(size)}
	parameter = {'request_id': int(time.time() * 100), 'th': 1, 'tht': 'qf492_100fps', 'the': 1.0, 'thst': 'neural'}
	res = requests.post(f"http://{config['ip']}:{config['port']}", timeout=120, data=audio, headers=headers, params=parameter)
	res_json = res.json()
	if res_json['retmsg'] != 'success':
		raise Exception
	bin_str = res_json['th'][0]['feat']
	bin_data = base64.b64decode(bin_str)
	bin2qsa_siren(bin_data, file_name)

def dis(pt1, pt2):
	return abs(pt1[0] - pt2[0]) + abs(pt1[1] - pt2[1])

def solve():
	(x0, y0, ax, ay, bx, by) = f()
	(xs, ys, t) = f()
	start = (xs, ys)
	pts = []
	pts.append((-1e+17, -1e+17))
	pts.append((x0, y0))
	while 1:
		x = ax * pts[-1][0] + bx
		y = ay * pts[-1][1] + by
		if x < 1e+17 and y < 1e+17:
			pts.append((x, y))
		else:
			break
	pts.append((1e+17, 1e+17))
	n = len(pts)
	ans = 0
	for i in range(n):
		if dis(start, pts[i]) <= t:
			tt = t
			tt -= dis(start, pts[i])
			j = i
			a1 = 1
			while 1:
				if tt >= dis(pts[j], pts[j + 1]):
					tt -= dis(pts[j], pts[j + 1])
					j += 1
					a1 += 1
				else:
					break
			tt = t
			tt -= dis(start, pts[i])
			j = i
			a2 = 1
			while 1:
				if tt >= dis(pts[j], pts[j - 1]):
					tt -= dis(pts[j], pts[j - 1])
					j -= 1
					a2 += 1
				else:
					break
			ans = max(ans, a1, a2)
	print(ans)
solve()


(x, y, ax, ay, bx, by) = map(int, input().split())
(sx, sy, t) = map(int, input().split())
data = [(x, y)]
while data[-1][0] <= 10 ** 16 and data[-1][1] <= 10 ** 16:
	new = (data[-1][0] * ax + bx, data[-1][1] * ay + by)
	data.append(new)
ans = 0
for ind in range(len(data)):
	prev = (sx, sy)
	count = 0
	time = 0
	for i in range(ind, -1, -1):
		time += abs(data[i][0] - prev[0]) + abs(data[i][1] - prev[1])
		if time <= t:
			count += 1
			prev = data[i]
		else:
			break
	for i in range(ind + 1, len(data)):
		time += abs(data[i][0] - prev[0]) + abs(data[i][1] - prev[1])
		if time <= t:
			count += 1
			prev = data[i]
		else:
			break
	ans = max(ans, count)
print(ans)


(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))
v = v[::-1]

def solve(x):
	t = T
	tmpx = xs
	tmpy = ys
	ret = 0
	ans = 0
	for i in range(x, len(v)):
		t -= abs(tmpx - v[i][0]) + abs(tmpy - v[i][1])
		if t < 0:
			break
		tmpx = v[i][0]
		tmpy = v[i][1]
		ret += 1
		nt = t
		ntmpx = tmpx
		ntmpy = tmpy
		nret = 0
		for j in range(i - 1, 0, -1):
			nt -= abs(ntmpx - v[j][0]) + abs(ntmpy - v[j][1])
			if nt < 0:
				break
			if j < x:
				nret += 1
			ntmpx = v[j][0]
			ntmpy = v[j][1]
		ans = max(ans, ret + nret)
	return ans
sol = 0
for i in range(len(v)):
	sol = max(sol, solve(i))
print(sol)


(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)


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)


dist = []

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

def bs(ind, t):
	if t < 0:
		return ind + 1
	if t == 0:
		return ind
	l = 0
	r = ind + 1
	while r - l > 1:
		o = (r + l) // 2
		if dist[ind] - dist[o] < t:
			r = o
		else:
			l = o
	if dist[ind] - dist[l] <= t:
		return l
	else:
		return r
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = ax * x0 + bx
y = ay * y0 + by
prevx = 0
prevy = 0
cords = [[x0, y0]]
while get_dist(x, y, xs, ys) > t:
	prevx = x
	prevy = y
	x = ax * x + bx
	y = ay * y + by
	if x < prevx or y < prevy:
		break
	if get_dist(x, y, xs, ys) > get_dist(x0, y0, xs, ys):
		break
if x > prevx and y > prevy:
	prevx = x
	prevy = y
while x >= prevx and y >= prevy and (get_dist(x, y, xs, ys) <= t):
	cords.append([x, y])
	x = ax * x + bx
	y = ay * y + by
dist = [0] * len(cords)
dist[0] = 0
for i in range(1, len(cords)):
	dist[i] = dist[i - 1] + get_dist(cords[i][0], cords[i][1], cords[i - 1][0], cords[i - 1][1])
ma = 0
tmp = get_dist(x0, y0, xs, ys)
for i in range(len(dist)):
	if t - tmp - dist[i] >= 0:
		ma = max(ma, i + 1)
	ma = max(ma, 1 + i - bs(i, t - get_dist(cords[i][0], cords[i][1], xs, ys)))
print(ma)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = [x0]
y = [y0]
for i in range(99):
	x.append(x[-1] * ax + bx)
	y.append(y[-1] * ay + by)
ans = 0
for i in range(100):
	for j in range(100):
		temp = min(abs(xs - x[i]) + abs(ys - y[i]), abs(xs - x[j]) + abs(ys - y[j])) + x[j] + y[j] - x[i] - y[i]
		if temp <= t:
			ans = max(ans, j - i + 1)
print(ans)


(x0, y0, ax, ay, bx, by) = [int(x) for x in input().strip().split()]
(xs, ys, t) = [int(x) for x in input().strip().split()]
lis = [(x0, y0)]

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

def getdisp(p1, p2):
	(x1, y1) = p1
	(x2, y2) = p2
	return abs(x1 - x2) + abs(y1 - y2)
for i in range(1, 100):
	(xx, yy) = lis[i - 1]
	lis.append((ax * xx + bx, ay * yy + by))
ans = 0
sp = (xs, ys)
for i in range(100):
	if getdisp(sp, lis[i]) > t:
		continue
	tt = t - getdisp(sp, lis[i])
	res = 1
	res_b = 0
	tmp = tt
	for j in range(i - 1, -1, -1):
		if getdisp(lis[j], lis[j + 1]) > tmp:
			break
		tmp -= getdisp(lis[j], lis[j + 1])
		res_b += 1
	res_f = 0
	tmp = tt
	for j in range(i + 1, 100):
		if getdisp(lis[j], lis[j - 1]) > tmp:
			break
		tmp -= getdisp(lis[j], lis[j - 1])
		res_f += 1
	ans = max(ans, res + max(res_b, res_f))
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
from math import sqrt
x = [0] * 65
y = [0] * 65
x[0] = x0
y[0] = y0
for i in range(1, 65):
	x[i] = ax * x[i - 1] + bx
	y[i] = ay * y[i - 1] + by
ans = 0
for i in range(65):
	tans = 0
	if abs(x[i] - xs) + abs(y[i] - ys) > t:
		continue
	tp = t - (abs(x[i] - xs) + abs(y[i] - ys))
	ntp = tp
	tans = 1
	for j in range(i, 0, -1):
		req = abs(x[j - 1] - x[j]) + abs(y[j - 1] - y[j])
		tp -= req
		if tp < 0:
			break
		tans += 1
	ans = max(ans, tans)
	tp = ntp
	tans = 1
	for j in range(i, 65):
		req = abs(x[j + 1] - x[j]) + abs(y[j + 1] - y[j])
		tp -= req
		if tp < 0:
			break
		tans += 1
	ans = max(ans, tans)
print(ans)


import sys
input = sys.stdin.readline
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = x0
y = y0
A = []
B = []
MAX = 66
for i in range(MAX):
	A.append(x)
	B.append(y)
	x = x * ax + bx
	y = y * ay + by
ans = 0

def dis(x, y):
	return abs(A[x] - A[y]) + abs(B[x] - B[y])
for i in range(MAX):
	for j in range(MAX):
		distance = 0
		distance = abs(xs - A[i]) + abs(ys - B[i])
		distance += dis(i, j)
		if distance <= t:
			ans = max(ans, abs(i - j) + 1)
print(ans)


from math import *

def d(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
(x0, y0, ax, ay, bx, by) = list(map(int, input().split()))
(xs, ys, t) = list(map(int, input().split()))
v = []
v.append([x0, y0])
for i in range(64):
	(x1, y1) = (ax * x0 + bx, ay * y0 + by)
	v.append([x1, y1])
	(x0, y0) = (x1, y1)
n = len(v)
v.sort()
ans = 0
for i in range(n):
	for j in range(i, n):
		(v1, v2) = (0, 0)
		(px, py) = (xs, ys)
		for p in range(i, j + 1):
			v2 += d(px, py, v[p][0], v[p][1])
			(px, py) = (v[p][0], v[p][1])
		(px, py) = (xs, ys)
		p = j
		while p >= i:
			v1 += d(px, py, v[p][0], v[p][1])
			(px, py) = (v[p][0], v[p][1])
			p -= 1
		if min(v1, v2) <= t:
			ans = max(ans, j - i + 1)
print(ans)


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)


def solve(x0, y0, ax, ay, bx, by, xs, ys, t):
	x = x0
	y = y0
	pts = []
	for i in range(100):
		if abs(x - xs) + abs(y - ys) <= t:
			pts += [(x, y)]
		x = x * ax + bx
		y = y * ay + by
	res = 0
	n = len(pts)
	for i in range(n):
		for j in range(n):
			if j <= i:
				r = range(i, j - 1, -1)
			else:
				r = range(i, j + 1)
			r = list(map(lambda idx: pts[idx], r))
			c = 0
			c += abs(xs - r[0][0]) + abs(ys - r[0][1])
			for q in range(len(r) - 1):
				c += abs(r[q + 1][0] - r[q][0]) + abs(r[q + 1][1] - r[q][1])
			if c <= t:
				res = max(res, len(r))
	return res
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
print(solve(x0, y0, ax, ay, bx, by, xs, ys, t))


(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)


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)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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

def solve():
	(x0, y0, a1, a2, b1, b2) = sep()
	(xs, ys, t) = sep()
	points = []
	f = False
	if dist(xs, ys, x0, y0) <= t:
		points.append([x0, y0])
	while True:
		x = a1 * x0 + b1
		y = a2 * y0 + b2
		if dist(xs, ys, x, y) <= t:
			points.append([x, y])
		elif x > xs and y > ys:
			break
		(x0, y0) = (x, y)
	if len(points) == 0:
		print(0)
		return
	left = []
	right = []
	d = []
	for i in range(len(points)):
		d.append(dist(xs, ys, points[i][0], points[i][1]))
	ind = d.index(min(d))
	ans = 1
	for i in range(0, ind + 1):
		for j in range(ind + 1, len(d)):
			if d[i] + dist(points[i][0], points[i][1], points[j][0], points[j][1]) <= t:
				ans = max(ans, ind - i + 1 + (j - ind))
			else:
				break
	for i in range(ind, len(d)):
		for j in range(0, ind):
			if d[i] + dist(points[i][0], points[i][1], points[j][0], points[j][1]) <= t:
				ans = max(ans, i - ind + 1 + (ind - j))
	print(ans)
testcase(1)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
node = [[x0, y0]]
x = x0
y = y0
while x <= 10 ** 16 and y <= 10 ** 16:
	x = x * ax + bx
	y = y * ay + by
	node.append([x, y])
n = len(node)
d = []
d_s = []
for i in range(n - 1):
	d.append(sum(node[i + 1]) - sum(node[i]))
for i in range(n):
	d_s.append(abs(node[i][0] - xs) + abs(node[i][1] - ys))
dd = [0]
for i in range(n - 1):
	dd.append(dd[-1] + d[i])
ans = 0
for i in range(n):
	for j in range(i, n):
		i_j = dd[j] - dd[i]
		if min(i_j + d_s[i], i_j + d_s[j]) <= t:
			ans = max(ans, j - i + 1)
print(ans)


import sys
lines = sys.stdin.readlines()
(x0, y0, ax, ay, bx, by) = map(int, lines[0].split())
(xs, ys, t) = 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)


def main():

	def tt(x0, y0, x1, y1):
		return abs(x1 - x0) + abs(y1 - y0)
	(x0, y0, ax, ay, bx, by) = map(int, input().split())
	(xs, ys, t) = map(int, input().split())
	points = [[x0, y0]]
	(x1, y1) = (x0, y0)
	n = 63
	while n > 0:
		x1 = ax * x1 + bx
		y1 = ay * y1 + by
		points.append([x1, y1])
		n -= 1
	ans = 0
	for i in range(len(points)):
		for j in range(i, len(points)):
			cur_t = tt(*points[i], *points[j]) + min(tt(xs, ys, *points[i]), tt(xs, ys, *points[j]))
			if cur_t <= t:
				ans = max(ans, j - i + 1)
	print(ans)
main()


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)


import sys, math
import io, os

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
INF = float('inf')
mod = int(1000000000.0) + 7
(x0, y0, ax, ay, bx, by) = mdata()
(xs, ys, t) = mdata()
l = [(x0, y0)]
s = [abs(xs - x0) + abs(ys - y0)]
ind = 0
ans = 0
while ax * l[-1][0] + bx - xs + ay * l[-1][1] + by - ys <= t:
	s.append(abs(ax * l[-1][0] + bx - xs) + abs(ay * l[-1][1] + by - ys))
	l.append((ax * l[-1][0] + bx, ay * l[-1][1] + by))
s1 = [0]
for i in range(1, len(l)):
	s1.append(sum(l[i]) - sum(l[i - 1]))
for i in range(len(s)):
	for j in range(i, len(s)):
		for k in range(j, len(s)):
			sum1 = sum(s1[i + 1:k + 1]) + s[j]
			if i != j and k != j:
				sum1 += max(sum(s1[j + 1:i + 1]), sum(s1[i + 1:k + 1]))
			if sum1 <= t:
				ans = max(ans, k - i + 1)
out(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(sx, sy, t) = map(int, input().split())
LIMIT = 2 ** 62 - 1
x = [x0]
y = [y0]
while x[-1] * ax + bx < LIMIT and y[-1] * ay + by < LIMIT:
	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):
		dis1 = abs(sx - x[i]) + abs(sy - y[i]) + abs(x[i] - x[j]) + abs(y[i] - y[j])
		dis2 = abs(sx - x[j]) + abs(sy - y[j]) + abs(x[i] - x[j]) + abs(y[i] - y[j])
		if dis1 <= t or dis2 <= t:
			ans = max(ans, j - i + 1)
print(ans)


import math
a = input().split()
x0 = int(a[0])
y0 = int(a[1])
ax = int(a[2])
ay = int(a[3])
bx = int(a[4])
by = int(a[5])
a = input().split()
xs = int(a[0])
ys = int(a[1])
t = int(a[2])
a.clear()
a.append([x0, y0])
for i in range(1, 60):
	a.append([a[i - 1][0] * ax + bx, a[i - 1][1] * ay + by])
ans = 0
for i in range(60):
	for j in range(i, 60):
		len = a[j][0] - a[i][0] + a[j][1] - a[i][1]
		dist1 = abs(int(a[i][0]) - xs) + abs(int(a[i][1]) - ys)
		dist2 = abs(int(a[j][0]) - xs) + abs(int(a[j][1]) - ys)
		if t >= dist1 + len or t >= dist2 + len:
			ans = max(ans, j - i + 1)
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
points = []
cx = x0
cy = y0
while True:
	points.append((cx, cy))
	cx = ax * cx + bx
	cy = ay * cy + by
	if cx > xs and cy > ys and (abs(cx - xs) + abs(cy - ys) > t):
		break
n = len(points)
res = 0
for i in range(n):
	for j in range(i, n):
		start = min(abs(xs - points[i][0]) + abs(ys - points[i][1]), abs(xs - points[j][0]) + abs(ys - points[j][1]))
		final = start + abs(points[j][0] - points[i][0]) + abs(points[j][1] - points[i][1])
		if final <= t:
			res = max(res, j - i + 1)
print(res)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
(xo, yo, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = [xo]
y = [yo]
dx = [0]
dy = [0]
for i in range(59):
	x.append(x[-1] * ax + bx)
	y.append(y[-1] * ay + by)
n = len(x)
ans = 0
for i in range(n):
	for j in range(i, n):
		time = min(abs(x[i] - xs) + abs(y[i] - ys), abs(x[j] - xs) + abs(y[j] - ys)) + abs(x[i] - x[j]) + abs(y[i] - y[j])
		if time <= t:
			ans = max(ans, j - i + 1)
print(ans)


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)


import sys

def main():
	(x0, y0, ax, ay, bx, by) = get_ints()
	points = []
	points.append((x0, y0))
	(xs, ys, t) = get_ints()
	x = x0
	y = y0

	def manhattan(x1, y1, x2, y2):
		return abs(x1 - x2) + abs(y1 - y2)
	for i in range(1, 100):
		x = ax * x + bx
		y = ay * y + by
		points.append((x, y))
	(ans, curr) = (0, 0)
	for i in range(len(points)):
		T = t
		XS = xs
		YS = ys
		curr = 0
		f = 1
		for j in range(i, len(points)):
			x = points[j][0]
			y = points[j][1]
			dist = manhattan(XS, YS, x, y)
			T -= dist
			XS = x
			YS = y
			curr += 1
			if T < 0:
				ans = max(ans, curr - 1)
				f = 0
				break
		if f:
			ans = max(ans, curr)
	points.reverse()
	for i in range(len(points)):
		T = t
		XS = xs
		YS = ys
		curr = 0
		f = 1
		for j in range(i, len(points)):
			x = points[j][0]
			y = points[j][1]
			dist = manhattan(XS, YS, x, y)
			T -= dist
			curr += 1
			XS = x
			YS = y
			if T < 0:
				ans = max(ans, curr - 1)
				f = 0
				break
		if f:
			ans = max(ans, curr)
	print(ans)
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


(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)


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()


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
dn = [[x0, y0]]
while dn[-1][0] <= 1e+20 and dn[-1][1] <= 1e+20:
	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)


(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] < 1e+20:
	x.append(x[-1] * ax + bx)
while y[-1] < 1e+20:
	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)


(x0, y0, ax, ay, bx, by) = map(int, input().split(' '))
(x, y, t) = map(int, input().split(' '))
v = []
v.append([x0, y0])
for i in range(0, 100):
	x0 = x0 * ax + bx
	y0 = y0 * ay + by
	v.append([x0, y0])
maxkol = 0
for i in range(0, len(v)):
	r = abs(x - v[i][0]) + abs(y - v[i][1])
	kol = 0
	if r <= t:
		kol += 1
	cx = v[i][0]
	cy = v[i][1]
	for j in range(i - 1, -1, -1):
		r += abs(cx - v[j][0]) + abs(cy - v[j][1])
		cx = v[j][0]
		cy = v[j][1]
		if r <= t:
			kol += 1
	maxkol = max(maxkol, kol)
for i in range(0, len(v)):
	r = abs(x - v[i][0]) + abs(y - v[i][1])
	kol = 0
	if r <= t:
		kol += 1
	cx = v[i][0]
	cy = v[i][1]
	for j in range(i + 1, len(v)):
		r += abs(cx - v[j][0]) + abs(cy - v[j][1])
		cx = v[j][0]
		cy = v[j][1]
		if r <= t:
			kol += 1
	maxkol = max(maxkol, kol)
print(maxkol)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi, ceil, log, inf, gcd, floor
from itertools import permutations
from copy import deepcopy
from heapq import *

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	(x0, y0, ax, ay, bx, by) = map(int, input().split())
	(xs, ys, t) = map(int, input().split())
	a = [[x0, y0]]
	while 1:
		a.append([a[-1][0] * ax + bx, a[-1][1] * ay + by])
		if abs(a[-1][0] - a[-2][0]) + abs(a[-1][1] - a[-1][1]) >= 10000000000000000:
			break
	ma = 0
	n = len(a)
	for i in range(n):
		su = 0
		(xi, yi) = (xs, ys)
		x = 0
		for j in range(i, -1, -1):
			z = abs(xi - a[j][0]) + abs(yi - a[j][1])
			su += z
			if su > t:
				break
			x += 1
			(xi, yi) = (a[j][0], a[j][1])
			ma = max(ma, x)
		(xi, yi) = (xs, ys)
		su = 0
		x = 0
		for j in range(i, n):
			z = abs(xi - a[j][0]) + abs(yi - a[j][1])
			su += z
			if su > t:
				break
			x += 1
			(xi, yi) = (a[j][0], a[j][1])
			ma = max(ma, x)
	print(ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = 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)


x = [None] * 100
y = [None] * 100
ax = [None] * 100
ay = [None] * 100
(x[0], y[0], ax[0], ay[0], bx, by) = (int(i) for i in input().split())
(xs, ys, t) = (int(i) for i in input().split())
pts = [(xs, ys)] * 100
maxi = 0
for i in range(1, 75):
	ax[i] = ax[i - 1] * ax[0]
	ay[i] = ay[i - 1] * ay[0]
	x[i] = x[0] * ax[i - 1] + bx * (ax[i - 1] - 1) // (ax[0] - 1)
	y[i] = y[0] * ay[i - 1] + by * (ay[i - 1] - 1) // (ay[0] - 1)
	if x[i] > pow(10, 20) or y[i] > pow(10, 20):
		maxi = i
		break
ans = 0
for i in range(maxi):
	curt = t
	curans = 0
	cost = abs(xs - x[i]) + abs(ys - y[i])
	if curt - cost < 0:
		continue
	else:
		curt -= cost
	turun = i
	xprev = x[i]
	yprev = y[i]
	while turun >= 0:
		cost = abs(xprev - x[turun]) + abs(yprev - y[turun])
		if curt - cost >= 0:
			curt -= cost
			curans += 1
			xprev = x[turun]
			yprev = y[turun]
		else:
			break
		turun -= 1
	naik = i + 1
	while naik < maxi:
		cost = abs(xprev - x[naik]) + abs(yprev - y[naik])
		if curt - cost >= 0:
			curt -= cost
			curans += 1
			xprev = x[naik]
			yprev = y[naik]
		else:
			break
		naik += 1
	ans = max(ans, curans)
print(ans)


(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)


(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()))
_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)


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)


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 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)


(x0, y0, ax, ay, bx, by) = list(map(int, input().split()))
(xs, ys, t) = list(map(int, input().split()))
x = []
y = []
x.append(x0)
y.append(y0)
LIMIT = 10 ** 19
while True:
	if x[-1] > LIMIT and y[-1] > LIMIT:
		break
	x.append(x[-1] * ax + bx)
	y.append(y[-1] * ay + by)
n = len(x)
ans = 0
for i in range(n):
	for j in range(i, n):
		l1 = x[j] - x[i] + y[j] - y[i]
		dl = abs(xs - x[i]) + abs(ys - y[i])
		dr = abs(xs - x[j]) + abs(ys - y[j])
		if l1 <= t - dl or l1 <= t - dr:
			ans = max(ans, j - i + 1)
print(ans)


(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)


import bisect
import math
(x0, y0, ax, ay, bx, by) = [int(_) for _ in input().strip().split()]
(xs, ys, t) = [int(_) for _ in input().strip().split()]
limi = 2 * 10 ** 16
x = x0
y = y0
nodes = []
dist = []
while x <= limi and y <= limi:
	nodes.append((x, y))
	x = ax * x + bx
	y = ay * y + by
prev = None
for node in nodes:
	dist.append(node[0] - nodes[0][0] + node[1] - nodes[0][1])
t_max = 0
for (ind, node) in enumerate(nodes):
	tmpt = t - (abs(xs - node[0]) + abs(ys - node[1]))
	if tmpt >= 0:
		t_max = max(t_max, 1)
		tmp_ind = ind - 1
		while tmp_ind >= 0:
			tmpt_t = tmpt - abs(node[0] - nodes[tmp_ind][0]) - abs(node[1] - nodes[tmp_ind][1])
			if tmpt_t >= 0:
				t_max = max(t_max, abs(ind - tmp_ind) + 1)
				ins = bisect.bisect(dist, tmpt_t + dist[tmp_ind], tmp_ind)
				t_max = max(t_max, ins - tmp_ind)
			else:
				break
			tmp_ind -= 1
		tmp_ind = ind + 1
		while tmp_ind < len(nodes):
			tmpt_t = tmpt - abs(node[0] - nodes[tmp_ind][0]) - abs(node[1] - nodes[tmp_ind][1])
			if tmpt_t >= 0:
				t_max = max(t_max, abs(ind - tmp_ind) + 1)
				ins = bisect.bisect_left(dist, dist[tmp_ind] - tmpt_t, 0, tmp_ind)
				t_max = max(t_max, abs(ins - tmp_ind))
			else:
				break
			tmp_ind += 1
print(t_max)


from sys import stdin
(x0, y0, ax, ay, bx, by) = map(int, stdin.readline().split())
(xs, ys, t) = map(int, stdin.readline().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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = 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(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
(x0, y0, a1, a2, b1, b2) = map(int, input().split())
(xs, ys, t) = 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
	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)


s = input().split(' ')
[x0, y0, ax, ay, bx, by] = [int(p) for p in s]
s = input().split(' ')
[xs, ys, t] = [int(p) for p in s]
posb = []
find = 0
cnt = 0
while 1:
	now = abs(xs - x0) + abs(ys - y0)
	cnt += 1
	if now <= t:
		posb.append((x0, y0))
		find = 1
	else:
		if find == 1:
			break
		if cnt > 70:
			break
	(x0, y0) = (ax * x0 + bx, ay * y0 + by)
l = len(posb)
ans = 0
for i in range(0, l):
	for j in range(i, l):
		length = posb[j][0] + posb[j][1] - posb[i][0] - posb[i][1] + min(abs(xs - posb[j][0]) + abs(ys - posb[j][1]), abs(xs - posb[i][0]) + abs(ys - posb[i][1]))
		if length <= t:
			ans = max(ans, j - i + 1)
print(ans)


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


import sys
(x0, y0, ax, ay, bx, by) = (int(v) for v in sys.stdin.readline().split())
(xs, ys, t) = (int(v) for v in sys.stdin.readline().split())

def points_gen():
	(px, py) = (x0, y0)
	while True:
		yield (px, py)
		px = ax * px + bx
		py = ay * py + by

def mdist(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
pgen = points_gen()
points = [next(pgen) for i in range(60)]

def count_startat_i(i):
	d = mdist(xs, ys, *points[i])
	if d > t:
		return 0
	p = i
	c = 1
	while p > 0:
		d += mdist(*points[p], *points[p - 1])
		if d > t:
			return c
		c += 1
		p -= 1
	if i == len(points) - 1:
		return c
	d += mdist(*points[0], *points[i + 1])
	if d > t:
		return c
	p = i + 1
	c += 1
	while p < len(points) - 1:
		d += mdist(*points[p], *points[p + 1])
		if d > t:
			return c
		c += 1
		p += 1
print(max((count_startat_i(i) for i in range(len(points)))))


(x0, y0, ax, ay, bx, by) = map(int, input().split(' '))
ps = [(x0, y0)]
tam = 100
for i in range(1, tam):
	ps.append((ps[i - 1][0] * ax + bx, ps[i - 1][1] * ay + by))

def Caso(xs, ys, t, i, j):
	rec = 0
	global ps
	mind = min(abs(ps[j][0] - xs) + abs(ps[j][1] - ys), abs(ps[i][0] - xs) + abs(ps[i][1] - ys))
	t = t - mind
	if t < 0:
		return 0
	for k in range(i + 1, j + 1):
		t = t - abs(ps[k][0] - ps[k - 1][0]) - abs(ps[k][1] - ps[k - 1][1])
		if t < 0:
			return 0
		rec = rec + 1
		xs = ps[j][0]
		ys = ps[j][1]
	return j - i + 1
(xs, ys, t) = map(int, input().split(' '))
res = 0
for i in range(tam):
	for j in range(i, tam):
		res = max(res, int(Caso(xs, ys, t, i, j)))
print(res)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
LIM = 60
arr_xs = [x0]
for i in range(LIM * 2):
	arr_xs.append(arr_xs[i] * ax + bx)
arr_ys = [y0]
for i in range(LIM * 2):
	arr_ys.append(arr_ys[i] * ay + by)

def dst(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
ans = 0
for start in range(len(arr_ys)):
	cur_d = dst(arr_xs[start], arr_ys[start], xs, ys)
	pt = start
	if cur_d > t:
		continue
	cnt = 1
	while pt < len(arr_xs):
		cur_d += dst(arr_xs[pt], arr_ys[pt], arr_xs[pt + 1], arr_ys[pt + 1])
		if cur_d > t:
			break
		cnt += 1
		pt += 1
	ans = max(ans, cnt)
for start in range(len(arr_xs)):
	cur_d = dst(arr_xs[start], arr_ys[start], xs, ys)
	pt = start
	if cur_d > t:
		continue
	cnt = 1
	while pt > 0:
		cur_d += dst(arr_xs[pt], arr_ys[pt], arr_xs[pt - 1], arr_ys[pt - 1])
		if cur_d > t:
			break
		cnt += 1
		pt -= 1
	ans = max(ans, cnt)
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_max(mn, mx, func):
	ok = mn
	ng = mx
	while ok + 1 < ng:
		mid = (ok + ng) // 2
		if func(mid):
			ok = mid
		else:
			ng = mid
	return ok
(x0, y0, ax, ay, bx, by) = MAP()
(sx, sy, T) = MAP()
A = [(x0, y0)]
while A[-1][0] < INF and A[-1][1] < INF:
	(xi, yi) = A[-1]
	A.append((ax * xi + bx, ay * yi + by))
N = len(A)
dist = [0] * (N - 1)
for i in range(N - 1):
	(x1, y1) = A[i]
	(x2, y2) = A[i + 1]
	dist[i] = abs(x2 - x1) + abs(y2 - y1)

def check(m):
	res = INF
	for i in range(N):
		init = abs(A[i][0] - sx) + abs(A[i][1] - sy)
		if init > T:
			continue
		for l in range(m):
			r = m - l - 1
			if i - l < 0 or i + r > N:
				continue
			add = min(sum(dist[i - l:i]) * 2 + sum(dist[i:i + r]), sum(dist[i - l:i]) + sum(dist[i:i + r] * 2))
			res = min(res, init + add)
	return res <= T
res = bisearch_max(0, N + 1, check)
print(res)


import sys

def input():
	return sys.stdin.readline().rstrip()
BOUND = int(2 * 1e+16)

def slv():
	(x0, y0, ax, ay, bx, by) = map(int, input().split())
	(xs, ys, T) = map(int, input().split())

	def next_point(X, Y):
		return (ax * X + bx, ay * Y + by)
	(X, Y) = (x0, y0)
	DOT = []
	for i in range(100):
		if abs(xs - X) + abs(ys - Y) <= BOUND:
			DOT.append((X, Y))
			(X, Y) = next_point(X, Y)
	ans = 0
	if not DOT:
		print(0)
		return
	for (idx, v) in enumerate(DOT):
		time = T - abs(xs - v[0]) - abs(ys - v[1])
		stack = DOT[:idx][::-1] + DOT[idx + 1:]
		if time >= 0:
			tmpmax = 1
			ans = max(ans, tmpmax)
			(pX, pY) = v
			for (nX, nY) in stack:
				req_time = abs(pX - nX) + abs(pY - nY)
				if time >= req_time:
					tmpmax += 1
					time -= req_time
					(pX, pY) = (nX, nY)
					ans = max(ans, tmpmax)
				else:
					ans = max(ans, tmpmax)
					break
	print(ans)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


(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(61):
	for j in range(61):
		if dist(start, important_points[i]) + dist(important_points[i], important_points[j]) <= t:
			maxx = max(maxx, abs(j - i) + 1)
print(maxx)


(xo, yo, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
d1 = 0
d2 = d0 = abs(xo - xs) + abs(yo - ys)
c = 0
while d0 > t:
	(xo, yo) = (ax * xo + bx, ay * yo + by)
	_d0 = abs(xo - xs) + abs(yo - ys)
	if _d0 > d0:
		break
	d2 = d0 = _d0
(x, y) = (xo, yo)
while d1 + d2 <= t or d0 + d1 <= t:
	(x, y) = (ax * x + bx, ay * y + by)
	d1 = x - xo + y - yo
	d2 = abs(x - xs) + abs(y - ys)
	c += 1
print(c)


def dist(x, y):
	return abs(x[0] - y[0]) + abs(x[1] - y[1])
(x, y, ax, ay, bx, by) = list(map(int, input().split()))
(xs, ys, coins) = list(map(int, input().split()))
arr = [(x, y)]
for i in range(60):
	x = ax * x + bx
	y = ay * y + by
	arr.append((x, y))
cur = (xs, ys)
ans = 0
for i in range(60):
	for j in range(60):
		t = dist(cur, arr[i]) + dist(arr[i], arr[j])
		if t <= coins:
			ans = max(ans, abs(i - j) + 1)
print(ans)


(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()


(x, y, ax, ay, bx, by) = map(int, input().split())
(nx, ny, t) = map(int, input().split())
cx = []
cy = []
while True:
	if abs(x - nx) + abs(y - ny) <= t:
		cx.append(x)
		cy.append(y)
	elif len(cx) or x >= 2e+16 or y >= 2e+16:
		break
	x = x * ax + bx
	y = y * ay + by
ans = 0
for i in range(len(cx)):
	tmp = t
	cnt = 0
	px = nx
	py = ny
	j = i
	while True:
		if j < len(cx) and abs(px - cx[j]) + abs(py - cy[j]) <= tmp:
			cnt = cnt + 1
			tmp = tmp - (abs(px - cx[j]) + abs(py - cy[j]))
			px = cx[j]
			py = cy[j]
		else:
			break
		if j > i:
			j = j + 1
		else:
			j = j - 1
		if j == -1:
			j = i + 1
	ans = max(ans, cnt)
print(ans)


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


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))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	(x, y, ax, ay, bx, by) = cin()
	s = [(x, y)]
	for i in range(100):
		if math.log10(ax) + math.log10(x) > 18 or math.log10(ay) + math.log10(y) > 18:
			break
		xx = ax * x + bx
		yy = ay * y + by
		x = xx
		y = yy
		s.append((x, y))
	(x, y, t) = cin()
	n = len(s)
	p = 0
	if (x, y) in s:
		p = 1
		s.remove((x, y))
	n = len(s)
	an = p
	for i in range(n):
		f = 0
		ans = p
		xx = x
		yy = y
		for j in range(i, n):
			f += abs(s[j][0] - xx) + abs(s[j][1] - yy)
			xx = s[j][0]
			yy = s[j][1]
			if f > t:
				break
			ans += 1
		an = max(an, ans)
	s = s[::-1]
	for i in range(n):
		f = 0
		ans = p
		xx = x
		yy = y
		for j in range(i, n):
			f += abs(s[j][0] - xx) + abs(s[j][1] - yy)
			xx = s[j][0]
			yy = s[j][1]
			if f > t:
				break
			ans += 1
		an = max(an, ans)
	print(an)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import math

def dist(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
(x0, y0, ax, ay, bx, by) = map(int, input().split(' '))
(xs, ys, t) = map(int, input().split(' '))
nodes = [(x0, y0)]
(x, y) = (x0, y0)
for i in range(54):
	x = ax * x + bx
	y = ay * y + by
	nodes.append((x, y))

def max_nodes(i):
	res = 0
	d = 0
	(x, y) = (xs, ys)
	for j in range(i, -1, -1):
		d += dist(x, y, nodes[j][0], nodes[j][1])
		if d > t:
			return res
		(x, y) = nodes[j]
		res += 1
	for j in range(i + 1, 55):
		d += dist(x, y, nodes[j][0], nodes[j][1])
		if d > t:
			return res
		(x, y) = nodes[j]
		res += 1
	return res
res = 0
for i in range(54):
	res = max(res, max_nodes(i))
print(res)


def find_time(x, y, i, j):
	return abs(x[i] - x[j]) + abs(y[i] - y[j])

def find_after_backward(backward, x, y, forward, M, t):
	time = find_time(x, y, forward, backward)
	ans = 0
	if time <= t:
		ans += forward - backward
	return ans

def find_after_forward(forward, x, y, start, M, t):
	ans = 0
	time = find_time(x, y, start, forward)
	if time <= t:
		ans += forward - start
		cur = 0
		for backward in range(0, M + 1):
			if backward >= start:
				continue
			cur = max(cur, find_after_backward(backward, x, y, start, M, t - 2 * time))
		ans += cur
	return ans

def gogo(i, x, y, xs, ys, M, t):
	ans = 0
	for start in range(0, M + 1):
		cur = 0
		time = abs(x[start] - xs) + abs(y[start] - ys)
		if time <= t:
			cur += 1
		else:
			continue
		for forward in range(start, M + 1):
			ans = max(cur + find_after_forward(forward, x, y, start, M, t - time), ans)
	return ans

def solve():
	(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)
	M = 64
	for i in range(1, M + 1):
		x.append(ax * x[i - 1] + bx)
		y.append(ay * y[i - 1] + by)
	ans = 0
	for i in range(0, M + 1):
		ans = max(ans, gogo(i, x, y, xs, ys, M, t))
	print(ans)
solve()


import math
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, xy, t) = map(int, input().split())

def getX(n):
	if n == 0:
		return x0
	tmp = ax ** n
	return x0 * tmp + (tmp - 1) * bx // (ax - 1)

def getY(n):
	if n == 0:
		return y0
	tmp = ay ** n
	return y0 * tmp + (tmp - 1) * by // (ay - 1)

def getlen(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
INF = 10 ** 18
(l, r) = (int(0), int(min(math.log10(INF) / math.log10(ax), math.log10(INF) / math.log10(ay))))
(sta, end) = (int(-1), int(-1))
list = []
(L, R) = (l, r)
while L <= R:
	mid = L + R >> 1
	if getX(mid) >= xs - t and getY(mid) >= xy - t:
		sta = mid
		R = mid - 1
	else:
		L = mid + 1
(L, R) = (l, r)
while L <= R:
	mid = L + R >> 1
	if getX(mid) <= xs + t and getY(mid) <= xy + t:
		end = mid
		L = mid + 1
	else:
		R = mid - 1
ans = int(0)
if sta == -1 or end == -1:
	ans = 0
else:
	for i in range(sta, end + 1):
		list.append((getX(i), getY(i)))
	for i in range(len(list)):
		tmp = getlen(xs, xy, list[i][0], list[i][1])
		if tmp > t:
			continue
		for j in range(0, i + 1):
			for k in range(i, len(list)):
				one = getlen(list[i][0], list[i][1], list[j][0], list[j][1])
				two = getlen(list[i][0], list[i][1], list[k][0], list[k][1])
				if one * 2 + two + tmp <= t:
					ans = max(ans, k - j + 1)
				elif two * 2 + one + tmp <= t:
					ans = max(ans, k - j + 1)
print(ans)


def getNext(xy):
	(x, y) = xy
	return (ax * x + bx, ay * y + by)

def getDist(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
(x0, y0, ax, ay, bx, by) = [int(x) for x in input().split()]
(xs, ys, t) = [int(x) for x in input().split()]
(x, y) = (x0, y0)
nodes = []
while True:
	nodes.append([x, y])
	(x, y) = getNext((x, y))
	if x > xs and getDist(x, y, xs, ys) > t:
		break
ans = 0
l = 0
(xl, yl) = nodes[l]
for r in range(len(nodes)):
	(xr, yr) = nodes[r]
	if getDist(xr, yr, xs, ys) > t:
		continue
	t2 = t - getDist(xr, yr, xs, ys)
	while getDist(xl, yl, xr, yr) > t2:
		l += 1
		(xl, yl) = nodes[l]
	ans = max(ans, r - l + 1)
r = len(nodes) - 1
(xr, yr) = nodes[r]
for l in range(len(nodes) - 1, -1, -1):
	(xl, yl) = nodes[l]
	if getDist(xl, yl, xs, ys) > t:
		continue
	t2 = t - getDist(xl, yl, xs, ys)
	while getDist(xl, yl, xr, yr) > t2:
		r -= 1
		(xr, yr) = nodes[r]
	ans = max(ans, r - l + 1)
print(ans)


(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)


from sys import stdin, stdout
import sys
fa = list(map(int, stdin.readline().split()))
x0 = fa[0]
y0 = fa[1]
ax = fa[2]
ay = fa[3]
bx = fa[4]
by = fa[5]
sa = list(map(int, stdin.readline().split()))
xs = sa[0]
ys = sa[1]
t = sa[2]
dis = []
cx = x0
cy = y0
px = x0
py = y0
disSum = 0
for i in range(60):
	disSum += abs(cx - px) + abs(cy - py)
	la = [cx, cy, disSum]
	dis.append(la)
	nx = ax * cx + bx
	ny = ay * cy + by
	px = cx
	py = cy
	cx = nx
	cy = ny
res = 0
for i in range(60):
	for j in range(i, 60):
		for k in range(i, j + 1):
			op1 = 2 * (dis[k][2] - dis[i][2]) + (dis[j][2] - dis[k][2])
			op2 = dis[k][2] - dis[i][2] + 2 * (dis[j][2] - dis[k][2])
			ttldis = abs(xs - dis[k][0]) + abs(ys - dis[k][1]) + min(op1, op2)
			if t >= ttldis:
				res = max(res, j - i + 1)
print(str(res))


(x0, y0, ax, ay, bx, by) = map(int, input().strip().split())
(xs, ys, t) = map(int, input().strip().split())
v = [(x0, y0)]
(x, y) = (x0, y0)
for i in range(100):
	x = ax * x + bx
	y = ay * y + by
	v.append((x, y))

def dis(a, b, c, d):
	return abs(a - c) + abs(b - d)
l = len(v)
res = 0
for i in range(l):
	cur = dis(v[i][0], v[i][1], xs, ys)
	if cur <= t:
		cnt = 1
		for j in range(i - 1, -1, -1):
			cur += dis(v[j][0], v[j][1], v[j + 1][0], v[j + 1][1])
			if cur > t:
				break
			cnt += 1
		if cur <= t and i + 1 < l:
			cur += dis(v[0][0], v[0][1], v[i + 1][0], v[i + 1][1])
			if cur <= t:
				cnt += 1
				for j in range(i + 1, l):
					cur += dis(v[j][0], v[j][1], v[j + 1][0], v[j + 1][1])
					if cur > t:
						break
					cnt += 1
		res = max(res, cnt)
print(res)


import math
from collections import deque
x = []
y = []
s = input().split(' ')
x.append(int(s[0]))
y.append(int(s[1]))
ax = int(s[2])
ay = int(s[3])
bx = int(s[4])
by = int(s[5])
for i in range(1, 100):
	x.append(ax * x[i - 1] + bx)
	y.append(ay * y[i - 1] + by)
	if x[i] > 1e+18 or y[i] > 1e+18:
		break
s = input().split(' ')
xs = int(s[0])
ys = int(s[1])
t = int(s[2])
ans = 0
l = len(x)
for i in range(l):
	xn = xs
	yn = ys
	tot = 0
	for j in range(i, l):
		tot += abs(x[j] - xn) + abs(y[j] - yn)
		if tot > t:
			break
		ans = max(ans, j - i + 1)
		xn = x[j]
		yn = y[j]
for i in range(l - 1, -1, -1):
	xn = xs
	yn = ys
	tot = 0
	for j in range(i, -1, -1):
		tot += abs(x[j] - xn) + abs(y[j] - yn)
		if tot > t:
			break
		ans = max(ans, i - j + 1)
		xn = x[j]
		yn = y[j]
print(ans)


(x0, y0, ax, ay, bx, by) = list(map(int, input().split()))
(xs, ys, t) = list(map(int, input().split()))
nodes = [(x0, y0)]
(x, y) = (x0, y0)
for i in range(99):
	x = x * ax + bx
	y = y * ay + by
	nodes.append((x, y))
best = 0
for i in range(100):
	ti = t
	(x, y) = (xs, ys)
	cnt = 0
	for j in range(i, 100):
		(xj, yj) = nodes[j]
		ti -= abs(xj - x) + abs(yj - y)
		if ti < 0:
			break
		cnt += 1
		(x, y) = (xj, yj)
	best = max(best, cnt)
	ti = t
	(x, y) = (xs, ys)
	cnt = 0
	for j in range(i, -1, -1):
		(xj, yj) = nodes[j]
		ti -= abs(xj - x) + abs(yj - y)
		if ti < 0:
			break
		cnt += 1
		(x, y) = (xj, yj)
	best = max(best, cnt)
print(best)


(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)


[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)


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))


(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
xp = [x]
pre = x
yp = [y]
i = int(0)
while True:
	if ax * pre + bx >= 1e+20:
		break
	xp.append(ax * pre + bx)
	pre = ax * pre + bx
	i = i + 1
i = int(0)
pre = y
while True:
	if ay * pre + by >= 1e+20:
		break
	yp.append(ay * pre + by)
	i = i + 1
	pre = ay * pre + by
ans = int(0)
for i in range(0, min(len(xp), len(yp))):
	xpos = xp[i]
	ypos = yp[i]
	sax = abs(xs - xpos)
	say = abs(ys - ypos)
	tmp = t - sax - say
	if tmp < 0:
		continue
	ct1 = 1
	ct2 = 1
	for j in range(i + 1, min(len(xp), len(yp))):
		nx = xp[j]
		ny = yp[j]
		sax = abs(xpos - nx)
		say = abs(ny - ypos)
		tmp -= sax + say
		xpos = nx
		ypos = ny
		if tmp < 0:
			break
		ct1 = ct1 + 1
	xpos = xp[i]
	ypos = yp[i]
	sax = abs(xs - xpos)
	say = abs(ys - ypos)
	tmp = t - sax - say
	for j in range(0, i)[::-1]:
		nx = xp[j]
		ny = yp[j]
		sax = abs(xpos - nx)
		say = abs(ny - ypos)
		tmp -= sax + say
		xpos = nx
		ypos = ny
		if tmp < 0:
			break
		ct2 = ct2 + 1
	ans = max(ans, max(ct1, ct2))
print(ans)


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)


(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 < 1e+18 and y < 1e+18:
	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)


(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)


(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
a = [[x, y]]
for i in range(1, 70):
	a.append([a[i - 1][0] * ax + bx, a[i - 1][1] * ay + by])

def getCnt(mid):
	st = abs(a[mid][0] - xs) + abs(a[mid][1] - ys)
	if st > t:
		return -1e+20
	maxAns = 1
	ostT = t - st
	for i in range(mid - 1, -1, -1):
		d = abs(a[mid][0] - a[i][0]) + abs(a[mid][1] - a[i][1])
		if d <= ostT:
			maxAns = max(maxAns, mid - i + 1)
	for i in range(mid + 1, len(a)):
		d = abs(a[mid][0] - a[i][0]) + abs(a[mid][1] - a[i][1])
		if d <= ostT:
			maxAns = max(maxAns, i - mid + 1)
	return maxAns
res = 0
for i in range(len(a)):
	res = max(res, getCnt(i))
print(res)


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(x, y, ax, ay, bx, by) = I()
(xs, ys, t) = I()
pts = [(x, y)]

def dist(a, b, x, y):
	return abs(a - x) + abs(b - y)
p = (x, y)
ans = 0
d = dist(x, y, xs, ys)
if d <= t:
	ans = 1
for i in range(1, 60):
	(x, y) = (ax * x + bx, ay * y + by)
	d = dist(x, y, xs, ys)
	pts.append((x, y))
n = len(pts)
for i in range(n):
	r = t - dist(pts[i][0], pts[i][1], xs, ys)
	for j in range(i + 1):
		k = dist(pts[i][0], pts[i][1], pts[j][0], pts[j][1])
		ok = r - k
		if ok < 0:
			continue
		ans = max(ans, i - j + 1)
		ok -= k
		if ok < 0:
			continue
		m = i
		for k in range(i + 1, n):
			if dist(pts[i][0], pts[i][1], pts[k][0], pts[k][1]) <= ok:
				m = k
		ans = max(ans, m - j + 1)
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
cand = [[x0, y0]]
while True:
	cand.append([ax * cand[-1][0] + bx, ay * cand[-1][1] + by])
	if abs(ax * cand[-1][0] + bx - xs) + abs(ay * cand[-1][1] + by - ys) > 10 ** 30:
		break
inf = 10 ** 30
l = len(cand)

def check(j):
	ret = 0
	s = t
	i = j
	s -= abs(xs - cand[i][0]) + abs(ys - cand[i][1])
	if s < 0:
		return ret
	ret += 1
	while i != 0:
		i -= 1
		s -= cand[i + 1][0] - cand[i][0] + (cand[i + 1][1] - cand[i][1])
		if s < 0:
			return ret
		ret += 1
	i = j + 1
	s -= cand[i][0] - cand[0][0] + (cand[i][1] - cand[0][1])
	if s < 0:
		return ret
	ret += 1
	while True:
		s -= cand[i + 1][0] - cand[i][0] + (cand[i + 1][1] - cand[i][1])
		if s < 0:
			return ret
		i += 1
		ret += 1
print(max([check(i) for i in range(l)]))


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)


MAX = 70
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
p = [(x0, y0)]
for i in range(1, MAX):
	(x, y) = p[i - 1]
	x = ax * x + bx
	y = ay * y + by
	p.append((x, y))

def dist(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])
res = 0
for st in range(0, MAX):
	for ed in range(st, MAX):
		d = dist(p[st], p[ed])
		d += min(dist((xs, ys), p[st]), dist((xs, ys), p[ed]))
		if d <= t:
			res = max(res, ed - st + 1)
print(res)


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


def dis(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())
v = [(x0, y0)]
while v[-1][0] <= 1e+16 and v[-1][1] <= 1e+16:
	v.append((v[-1][0] * ax + bx, v[-1][1] * ay + by))
ans = 0
for i in range(len(v)):
	for j in range(len(v)):
		l = dis((xs, ys), v[i]) + dis(v[i], v[j])
		if l <= t:
			ans = max(ans, abs(i - j) + 1)
print(ans)


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()


(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)


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)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():

	def rec(l, r):
		pos = bisect.bisect(a, (a[r] + a[l]) // 2, l, r + 1)
		if l == r:
			d[prefsum[r + 1] - prefsum[l]] = 1
		elif l < r:
			if pos <= r:
				rec(l, pos - 1)
				rec(pos, r)
			d[prefsum[r + 1] - prefsum[l]] = 1
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(x0, y0, ax, ay, bx, by) = ria()
		(xs, ys, t) = ria()
		x = x0
		y = y0
		z = [[x, y]]
		while x - xs < t or y - ys < t:
			x = ax * x + bx
			y = ay * y + by
			z.append([x, y])
		dist = []
		for i in range(len(z)):
			xi = z[i][0]
			yi = z[i][1]
			for j in range(i, len(z)):
				xj = z[j][0]
				yj = z[j][1]
				dn = abs(xi - xj) + abs(yi - yj)
				if dn <= t:
					dist.append([dn, [i, j]])
		ans = 0
		for i in dist:
			l = i[1][0]
			r = i[1][1]
			(xl, yl) = z[l]
			(xr, yr) = z[r]
			dl = abs(xl - xs) + abs(yl - ys)
			dr = abs(xr - xs) + abs(yr - ys)
			if dl + i[0] <= t or dr + i[0] <= t:
				ans = max(ans, abs(l - r) + 1)
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

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

def startingpoint(ind, allpoints, lefttime):
	tot = 1
	currloc = allpoints[ind]
	i = ind
	while i:
		if lefttime >= dist(allpoints[i], allpoints[i - 1]):
			tot += 1
			lefttime -= dist(allpoints[i], allpoints[i - 1])
		else:
			return tot
		i -= 1
	if lefttime >= dist(currloc, allpoints[0]):
		lefttime -= dist(currloc, allpoints[0])
	i = ind
	while lefttime >= dist(allpoints[i], allpoints[i + 1]):
		lefttime -= dist(allpoints[i], allpoints[i + 1])
		tot += 1
		i += 1
	return tot
(x0, y0, a1, a2, b1, b2) = li()
(x, y, t) = li()
allpoints = [[x0, y0]]
while len(allpoints) < 60:
	allpoints.append([allpoints[-1][0] * a1 + b1, allpoints[-1][1] * a2 + b2])
dp = [0]
for i in range(1, len(allpoints)):
	dp.append(dp[-1] + dist(allpoints[i], allpoints[i - 1]))
ans = 0
for (ind, i) in enumerate(allpoints):
	if dist([x, y], i) <= t:
		ans = max(ans, startingpoint(ind, allpoints, t - dist([x, y], i)))
print(ans)


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) > 1e+16 * 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()


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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, ts) = map(int, input().split())
points = [[x0, y0]]
x = 0
y = 0
while len(points) < 100 and x < 10 ** 16 and (y < 10 ** 16):
	x = ax * points[-1][0] + bx
	y = ay * points[-1][1] + by
	points.append([x, y])
distance = []
for i in range(len(points)):
	for ii in range(i, len(points)):
		dist = abs(xs - points[i][0]) + abs(ys - points[i][1])
		dist += abs(points[ii][0] - points[i][0])
		dist += abs(points[ii][1] - points[i][1])
		if dist <= ts:
			distance.append([ii - i + 1, dist])
for i in range(len(points) - 1, -1, -1):
	for ii in range(i, -1, -1):
		dist = abs(xs - points[i][0]) + abs(ys - points[i][1])
		dist += abs(points[ii][0] - points[i][0])
		dist += abs(points[ii][1] - points[i][1])
		if dist <= ts:
			distance.append([i - ii + 1, dist])
distance.sort()
if len(distance) == 0:
	print(0)
else:
	print(distance[-1][0])


import string
MAX = 2e+18
x = []
y = []
s = input().split(' ')
x.append(int(s[0]))
y.append(int(s[1]))
ax = int(s[2])
ay = int(s[3])
bx = int(s[4])
by = int(s[5])
ans = 0
while x[len(x) - 1] <= MAX and y[len(y) - 1] <= MAX:
	x.append(ax * x[len(x) - 1] + bx)
	y.append(ay * y[len(y) - 1] + by)
s = input().split(' ')
sx = int(s[0])
sy = int(s[1])
t = int(s[2])
for i in range(0, len(x)):
	for j in range(i, len(y)):
		tmp = min(abs(sx - x[i]) + abs(sy - y[i]), abs(sx - x[j]) + abs(sy - y[j])) + abs(x[j] - x[i]) + abs(y[j] - y[i])
		if tmp <= t:
			ans = max(ans, j - i + 1)
print(ans)


import math
(xo, yo, ax, ay, bx, by) = map(int, input().split())
(orx, ory) = (xo, yo)
(xs, ys, t) = map(int, input().split())
cur = abs(xo - xs) + abs(yo - ys)
sort = [cur]
while True:
	(x, y) = (xo, yo)
	(xo, yo) = (ax * xo + bx, ay * yo + by)
	cur = abs(xo - xs) + abs(yo - ys)
	if cur > sort[-1]:
		break
	else:
		sort.append(cur)
dpoint = 0
(copyx, copyy) = (x, y)
mina = abs(x - xs) + abs(y - ys)
if mina <= t:
	dpoint += 1
time = 0
copy = time
while time < t and (x, y) != (orx, ory):
	(a, b) = (x, y)
	(x, y) = ((x - bx) // ax, (y - by) // ay)
	time += abs(x - a) + abs(y - b)
	if time + min(mina, abs(x - xs) + abs(y - ys)) <= t:
		dpoint += 1
if time + min(mina, abs(x - xs) + abs(y - ys)) < t:
	mina = abs(x - xs) + abs(y - ys)
	while time < t:
		(a, b) = (ax * copyx + bx, ay * copyy + by)
		time += abs(a - copyx) + abs(b - copyy)
		(copyx, copyy) = (a, b)
		(x, y) = (a, b)
		if time + min(mina, abs(a - xs) + (b - ys)) <= t:
			dpoint += 1
print(dpoint)


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)


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)


liStr = input().split()
x0 = int(liStr[0])
y0 = int(liStr[1])
ax = int(liStr[2])
ay = int(liStr[3])
bx = int(liStr[4])
by = int(liStr[5])
liStr = input().split()
xs = int(liStr[0])
ys = int(liStr[1])
t = int(liStr[2])
impX = []
impY = []
xCur = x0
yCur = y0
L = 1000000000000000000
while xCur < L and yCur < L:
	impX.append(xCur)
	impY.append(yCur)
	xCur = ax * xCur + bx
	yCur = ay * yCur + by
max = 0
i = 0
while i < len(impX):
	j = i
	while j < len(impY):
		td = abs(xs - impX[i]) + abs(ys - impY[i])
		ans = 0
		td += abs(impX[i] - impX[j]) + abs(impY[i] - impY[j])
		ans += abs(j - i) + 1
		if td <= t and ans > max:
			max = ans
		j += 1
	i += 1
i = len(impX) - 1
while i >= 0:
	j = i
	while j >= 0:
		td = abs(xs - impX[i]) + abs(ys - impY[i])
		ans = 0
		td += abs(impX[i] - impX[j]) + abs(impY[i] - impY[j])
		ans += abs(j - i) + 1
		if td <= t and ans > max:
			max = ans
		j -= 1
	i -= 1
print(max)


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)


lst = list(map(int, input().split()))
(x0, y0, ax, ay, bx, by) = (lst[0], lst[1], lst[2], lst[3], lst[4], lst[5])
lst = list(map(int, input().split()))
(xs, ys, t) = (lst[0], lst[1], lst[2])

def at(k):
	if k == 0:
		return (x0, y0)
	x = (ax ** k - 1) // (ax - 1) * bx + ax ** k * x0
	y = (ay ** k - 1) // (ay - 1) * by + ay ** k * y0
	return (x, y)

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

def next_dist(k):
	(xk, yk) = at(k)
	(xkp1, ykp1) = at(k + 1)
	return dist(xk, yk, xkp1, ykp1)
dmax = 0
for k0 in range(0, 200):
	(k0x, k0y) = at(k0)
	d1 = dist(k0x, k0y, xs, ys)
	if t < d1:
		continue
	cur_t1 = t - d1
	k1 = k0
	could_do1 = 1
	while next_dist(k1) <= cur_t1:
		cur_t1 -= next_dist(k1)
		k1 += 1
		could_do1 += 1
	if could_do1 > dmax:
		dmax = could_do1
	cur_t2 = t - d1
	k2 = k0
	could_do2 = 1
	while k2 > 0 and next_dist(k2 - 1) <= cur_t2:
		cur_t2 -= next_dist(k2 - 1)
		k2 -= 1
		could_do2 += 1
	if could_do2 > dmax:
		dmax = could_do2
print(dmax)


(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)))


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)


(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

class Point:

	def __init__(self, x=0, y=0):
		(self.x, self.y) = (x, y)

	def next(self, mata, matb):
		return Point(self.x * mata.x + matb.x, self.y * mata.y + matb.y)

	def dist(self, rhs):
		return abs(self.x - rhs.x) + abs(self.y - rhs.y)

	def __str__(self):
		return '(%d, %d)' % (self.x, self.y)

def left(a, post, dist):
	foo = 0
	(key, bar, wht) = (0, 0, 0)
	while bar < len(a):
		bar += 1
		if bar == 1:
			wht += post.dist(a[key + bar - 1])
		elif key + bar - 1 < len(a):
			wht += a[key + bar - 2].dist(a[key + bar - 1])
		else:
			wht += post.dist(a[key - 1]) - post.dist(a[key]) + a[key - 1].dist(a[key])
			key -= 1
		while key > 0:
			det = post.dist(a[key - 1]) - post.dist(a[key]) + a[key - 1].dist(a[key]) - a[key + bar - 2].dist(a[key + bar - 1])
			if det <= 0:
				wht += det
				key -= 1
			else:
				break
		while key + bar < len(a):
			det = post.dist(a[key + 1]) - post.dist(a[key]) + a[key + bar - 1].dist(a[key + bar]) - a[key].dist(a[key + 1])
			if det <= 0:
				wht += det
				key += 1
			else:
				break
		if wht <= dist:
			foo = max(bar, foo)
		else:
			break
	return foo

def solution(zero, mata, matb, post, dist):
	a = [None for i in range(128)]
	a[0] = zero
	for i in range(1, 128):
		a[i] = a[i - 1].next(mata, matb)
		if a[i].x > post.x + dist or a[i].y > post.y + dist:
			break
	a = [x for x in a if x is not None]
	return max(left(a, post, dist), left(a[::-1], post, dist))

def main():
	while True:
		try:
			(x0, y0, ax, ay, bx, by) = [int(i) for i in input().strip().split()]
			zero = Point(x0, y0)
			mata = Point(ax, ay)
			matb = Point(bx, by)
			(x, y, d) = [int(i) for i in input().strip().split()]
			post = Point(x, y)
			sys.stdout.write('%d\n' % solution(zero, mata, matb, post, d))
		except ValueError:
			continue
		except EOFError:
			break
main()


pt = []

def goright(i, time, lstx, lsty, n):
	cnt = 0
	for j in range(i + 1, n, 1):
		(X, Y) = pt[j]
		tmp = abs(X - lstx) + abs(Y - lsty)
		if tmp + time > t:
			break
		time += tmp
		cnt += 1
		lstx = X
		lsty = Y
	return cnt

def goleft(i, time, lstx, lsty, n):
	cnt = 0
	for j in range(i - 1, -1, -1):
		(X, Y) = pt[j]
		tmp = abs(X - lstx) + abs(Y - lsty)
		if tmp + time > t:
			break
		time += tmp
		cnt += 1
		lstx = X
		lsty = Y
	return cnt
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
pt.append((x0, y0))
cx = x0
cy = y0
while max(cx, cy) <= 10 ** 25:
	cx = ax * cx + bx
	cy = ay * cy + by
	pt.append((cx, cy))
n = len(pt)
res = 0
for i in range(n):
	(Xi, Yi) = pt[i]
	time = abs(xs - Xi) + abs(ys - Yi)
	if time > t:
		continue
	lstx = Xi
	lsty = Yi
	cnt = 1
	res = max(res, cnt + goright(i, time, lstx, lsty, n))
	res = max(res, cnt + goleft(i, time, lstx, lsty, n))
	for j in range(i - 1, -1, -1):
		(X, Y) = pt[j]
		tmp = abs(X - lstx) + abs(Y - lsty)
		if tmp + time > t:
			break
		time += tmp
		cnt += 1
		lstx = X
		lsty = Y
		res = max(res, cnt + goright(i, time, lstx, lsty, n))
	time = abs(xs - Xi) + abs(ys - Yi)
	lstx = Xi
	lsty = Yi
	cnt = 1
	for j in range(i + 1, n, 1):
		(X, Y) = pt[j]
		tmp = abs(X - lstx) + abs(Y - lsty)
		if tmp + time > t:
			break
		time += tmp
		cnt += 1
		lstx = X
		lsty = Y
		res = max(res, cnt + goleft(i, time, lstx, lsty, n))
print(res)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(sx, sy, t) = map(int, input().split())
x = []
y = []
x.append(x0)
y.append(y0)
for i in range(147):
	x.append(x[-1] * ax + bx)
	y.append(y[-1] * ay + by)
ans = 0
for i in range(len(x)):
	for zliva in range(0, i + 1):
		for sprava in range(i, len(x)):
			c = abs(sx - x[i]) + abs(sy - y[i])
			if c <= t:
				ans = max(ans, 1)
				d = abs(x[i] - x[zliva]) + abs(y[i] - y[zliva])
				if c + d <= t:
					ans = max(ans, i - zliva + 1)
					e = abs(x[zliva] - x[sprava]) + abs(y[zliva] - y[sprava])
					if c + d + e <= t:
						ans = max(ans, sprava - zliva + 1)
				d = abs(x[i] - x[sprava]) + abs(y[i] - y[sprava])
				if c + d <= t:
					ans = max(ans, sprava - i + 1)
					e = abs(x[zliva] - x[sprava]) + abs(y[zliva] - y[sprava])
					if c + d + e <= t:
						ans = max(ans, sprava - zliva + 1)
print(ans)


(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)


sp = lambda : list(map(int, input().split()))
si = lambda : int(input())

def dist(x1, y1, x2, y2):
	return abs(x2 - x1) + abs(y2 - y1)
(x0, y0, ax, ay, bx, by) = sp()
(xs, ys, t) = sp()
nodesx = [x0]
nodesy = [y0]
while dist(nodesx[-1], nodesy[-1], xs, ys) <= 10 ** 17:
	nodesx.append(ax * nodesx[-1] + bx)
	nodesy.append(ay * nodesy[-1] + by)
maxnodes = 0
distTraveled = 0
(lastX, lastY) = (xs, ys)
while True:
	distTraveled += dist(lastX, lastY, nodesx[maxnodes], nodesy[maxnodes])
	if distTraveled > t:
		break
	lastX = nodesx[maxnodes]
	lastY = nodesy[maxnodes]
	maxnodes += 1
for i in range(len(nodesx)):
	nodesTraveled = 0
	distTraveled = 0
	(lastX, lastY) = (xs, ys)
	for (nx, ny) in list(zip(nodesx, nodesy))[i::-1]:
		distTraveled += dist(lastX, lastY, nx, ny)
		if distTraveled > t:
			break
		lastX = nx
		lastY = ny
		nodesTraveled += 1
	maxnodes = max(maxnodes, nodesTraveled)
print(maxnodes)


(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)


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)


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 sys
input = sys.stdin.readline
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
STAR = [(x0, y0)]
for i in range(100):
	(x, y) = STAR[-1]
	STAR.append((ax * x + bx, ay * y + by))
DIS = [0]
for i in range(1, 100):
	DIS.append(abs(STAR[i][0] - STAR[i - 1][0]) + abs(STAR[i][1] - STAR[i - 1][1]))
from itertools import accumulate
S = list(accumulate(DIS))
import bisect
ANS = 0
for i in range(100):
	REST = t
	REST -= abs(xs - STAR[i][0]) + abs(ys - STAR[i][1])
	if REST < 0:
		continue
	if S[i] <= REST:
		ANS = max(ANS, i + 1)
	else:
		x = bisect.bisect_left(S, S[i] - REST)
		ANS = max(ANS, i - x + 1)
	y = bisect.bisect_right(S, S[i] + REST)
	ANS = max(ANS, y - i)
print(ANS)


from math import *
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
INF = int(1e+16 + 233)
x = [x0]
y = [y0]
while x[-1] < INF and y[-1] < INF:
	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):
		dist = abs(x[i] - x[j]) + abs(y[i] - y[j])
		fix1 = abs(x[i] - xs) + abs(y[i] - ys)
		fix2 = abs(x[j] - xs) + abs(y[j] - ys)
		if dist + fix1 <= t or dist + fix2 <= t:
			ans = max(ans, j - i + 1)
print(ans)


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
S = lambda : list(map(str, input().split()))

def solve(ax, bx, prev):
	return ax * prev + bx
(x0, y0, ax, ay, bx, by) = I()
(xs, ys, t) = I()
x = [x0]
y = [y0]
prevx = x0
prevy = y0
for i in range(101):
	x.append(int(solve(ax, bx, prevx)))
	prevx = x[-1]
	y.append(int(solve(ay, by, prevy)))
	prevy = y[-1]
max_val2 = 0
for i1 in range(100):
	min_val = abs(x[i1] - xs) + abs(y[i1] - ys)
	min_idx = i1
	if min_val > t:
		continue
	else:
		count = 1
		t1 = t - min_val
		curx = x[min_idx]
		cury = y[min_idx]
		dpup = []
		dpdown = []
		max_val = 0
		for i in range(min_idx, 100):
			dpup.append(abs(x[i] - curx) + abs(y[i] - cury))
		for i in range(min_idx, -1, -1):
			dpdown.append(abs(x[i] - curx) + abs(y[i] - cury))
		for i in range(len(dpup)):
			for j in range(len(dpdown)):
				if 2 * dpup[i] + dpdown[j] <= t1:
					max_val = max(i + j, max_val)
				if dpup[i] + 2 * dpdown[j] <= t1:
					max_val = max(i + j, max_val)
				if dpdown[j] <= t1:
					max_val = max(j, max_val)
				if dpup[i] <= t1:
					max_val = max(i, max_val)
		max_val2 = max(max_val2, max_val + count)
print(max_val2)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
points = [(x0, y0)] if abs(x0 - xs) + abs(y0 - ys) <= t else []
(x, y) = (x0, y0)
while True:
	(x, y) = (x * ax + bx, y * ay + by)
	if x > xs and y > ys and (abs(x - xs) + abs(y - ys) > t):
		break
	if abs(x - xs) + abs(y - ys) <= t:
		points.append((x, y))

def calc(i, j):
	return abs(points[i][0] - points[j][0]) + abs(points[i][1] - points[j][1])
ans = 0
n = len(points)
for i in range(n):
	lim = lim_ = t - abs(xs - points[i][0]) - abs(ys - points[i][1])
	count = 1
	for j in range(i - 1, -1, -1):
		lim -= calc(j, j + 1)
		if lim < 0:
			break
		count += 1
		if i == n - 1 or calc(j, i + 1) > lim:
			continue
		(_c, _lim) = (1, lim - calc(j, i + 1))
		for k in range(i + 2, n):
			_lim -= calc(k - 1, k)
			if _lim < 0:
				break
			_c += 1
		ans = max(ans, count + _c)
	ans = max(ans, count)
	lim = lim_
	count = 1
	for j in range(i + 1, n):
		lim -= calc(j, j - 1)
		if lim < 0:
			break
		count += 1
		if i == 0 or calc(j, i - 1) > lim:
			continue
		(_c, _lim) = (1, lim - calc(j, i - 1))
		for k in range(i - 2, -1, -1):
			_lim -= calc(k, k + 1)
			if _lim < 0:
				break
			_c += 1
		ans = max(ans, count + _c)
	ans = max(ans, count)
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)


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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
imp = [[x0, y0]]
for i in range(64):
	imp.append([imp[-1][0] * ax + bx, imp[-1][1] * ay + by])
l = len(imp)
pro = 0
for i in range(l):
	for j in range(l):
		if abs(xs - imp[i][0]) + abs(ys - imp[i][1]) + abs(imp[j][0] - imp[i][0]) + abs(imp[j][1] - imp[i][1]) <= t:
			pro = max(pro, abs(i - j) + 1)
print(pro)


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)


L = 60
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
s = (xs, ys)
ar = [(x0, y0)]
for _ in range(L - 1):
	ar.append((ax * ar[-1][0] + bx, ay * ar[-1][1] + by))
	if ar[-1][0] > 2e+17 or ar[-1][1] > 2e+17:
		break
L = len(ar)

def dist(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])
best = 0
for i in range(L):
	for j in range(i + 1, L + 1):
		d = min(dist(ar[i], s), dist(ar[j - 1], s)) + dist(ar[i], ar[j - 1])
		if d <= t:
			best = max(best, j - i)
print(best)


(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)


(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
xx = []
xx.append(x)
x1 = ax * x + bx
while len(xx) < 1000:
	xx.append(x1)
	x1 = ax * x1 + bx
yy = []
yy.append(y)
y1 = ay * y + by
while len(yy) < 1000:
	yy.append(y1)
	y1 = ay * y1 + by
n = 1000
ans = 0
for i in range(n):
	r1 = abs(xx[i] - xs) + abs(yy[i] - ys)
	if r1 > t:
		continue
	cnt = 1
	for j1 in range(1, i + 1):
		j = i - j1
		r1 += abs(xx[j] - xx[j + 1]) + abs(yy[j] - yy[j + 1])
		if r1 > t:
			break
		cnt += 1
	ans = max(ans, cnt)
	if i + 1 < 1000:
		r1 += abs(xx[i + 1] - xx[0]) + abs(yy[i + 1] - yy[0])
		if r1 > t:
			continue
		cnt += 1
		for j in range(i + 2, n):
			r1 += abs(xx[j] - xx[j - 1]) + abs(yy[j] - yy[j - 1])
			if r1 > t:
				break
			cnt += 1
		ans = max(ans, cnt)
print(ans)


edge = []
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
maxn = 10 ** 22
while x0 < maxn and y0 < maxn:
	edge.append((x0, y0))
	x0 *= ax
	x0 += bx
	y0 *= ay
	y0 += by
mx = 0
for _ in range(2):
	for i in range(len(edge)):
		(u, v) = edge[i]
		c = 1
		T = t - abs(xs - u) - abs(ys - v)
		for j in range(i + 1, len(edge)):
			if T < 0:
				break
			c += 1
			(lt, rt) = edge[j]
			(lx, rx) = edge[j - 1]
			T -= abs(lt - lx)
			T -= abs(rt - rx)
		if T < 0:
			c -= 1
		mx = max(mx, c)
	edge = edge[-1::-1]
print(mx)


import sys
import math
from collections import defaultdict, Counter
import bisect
(x1, y1, a1, a2, b1, b2) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
l = [[x1, y1]]
for j in range(1, 61):
	x = a1 * l[j - 1][0] + b1
	y = a2 * l[j - 1][1] + b2
	if len(str(x)) > 32 or len(str(y)) > 32:
		break
	l.append([x, y])
ansf = 0
t2 = t
for i in range(len(l)):
	start = i
	mi = abs(xs - l[start][0]) + abs(ys - l[start][1])
	ans = 0
	if mi <= t:
		t -= mi
		ans += 1
		for j in range(start, 0, -1):
			curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
			t -= curr
			if t < 0:
				break
			ans += 1
	else:
		continue
	if t > 0 and start + 1 != len(l):
		t1 = t
		ans1 = 0
		ans2 = 0
		for j in range(start + 1, 33):
			t += mi
			mi = abs(xs - l[j][0]) + abs(ys - l[j][1])
			t -= mi
			curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
			t -= curr
			if t < 0:
				break
			ans1 += 1
		mi = abs(l[start + 1][0] - l[0][0]) + abs(l[start + 1][1] - l[0][1])
		t = t1
		t -= mi
		if t >= 0:
			ans2 += 1
			for j in range(start + 2, len(l)):
				curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
				t -= curr
				if t < 0:
					break
				ans2 += 1
		ans += max(ans1, ans2)
	ansf = max(ansf, ans)
	t = t2
print(ansf)


(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))))


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

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

def getpoints(x0, y0, ax, ay, bx, by, xs, ys, t):
	s = [(x0, y0)]
	(x, y) = (x0, y0)
	while True:
		x = ax * x + bx
		y = ay * y + by
		if x > xs + t or y > ys + t:
			break
		s.append((x, y))
	return s

def solve(x0, y0, ax, ay, bx, by, xs, ys, totaltime):
	points = getpoints(x0, y0, ax, ay, bx, by, xs, ys, totaltime)
	ans = 0
	for start in range(len(points)):
		(x, y) = points[start]
		d = dist(x, y, xs, ys)
		t = totaltime
		if d > t:
			continue
		t -= d
		count = 1
		for i in range(start - 1, -1, -1):
			(nx, ny) = points[i]
			d = dist(x, y, nx, ny)
			if d > t:
				break
			count += 1
			t -= d
			(x, y) = (nx, ny)
		ans = max(ans, count)
		count = 1
		for i in range(start + 1, len(points)):
			(nx, ny) = points[i]
			d = dist(x, y, nx, ny)
			if d > t:
				break
			count += 1
			t -= d
			(x, y) = (nx, ny)
		ans = max(ans, count)
	return ans
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
print(solve(x0, y0, ax, ay, bx, by, xs, ys, t))


import io
import os
from collections import Counter, defaultdict, deque

def solve(x0, y0, ax, ay, bx, by, xs, ys, t):
	nodes = [(x0, y0)]
	for i in range(60):
		(xi, yi) = nodes[-1]
		nodes.append((ax * xi + bx, ay * yi + by))
	best = 0
	N = len(nodes)
	for i in range(N):
		j = i
		(xi, yi) = nodes[j]
		d = abs(xi - xs) + abs(yi - ys)
		count = 1
		while d <= t:
			best = max(best, count)
			j += 1
			if j == N:
				break
			d += abs(nodes[j][0] - xi) + abs(nodes[j][1] - yi)
			(xi, yi) = nodes[j]
			count += 1
	for i in range(N):
		j = i
		(xi, yi) = nodes[j]
		d = abs(xi - xs) + abs(yi - ys)
		count = 1
		while d <= t:
			best = max(best, count)
			j -= 1
			if j < 0:
				break
			d += abs(nodes[j][0] - xi) + abs(nodes[j][1] - yi)
			(xi, yi) = nodes[j]
			count += 1
	return best
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(x0, y0, ax, ay, bx, by) = [int(x) for x in input().split()]
(xs, ys, t) = [int(x) for x in input().split()]
ans = solve(x0, y0, ax, ay, bx, by, xs, ys, t)
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input().strip().split())
(xs, ys, t) = map(int, input().strip().split())
inf = 1e+16

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 <= 1e+17 and tempy <= 1e+17:
		(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)


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)


import sys
import math
from collections import defaultdict, Counter
import bisect
(x1, y1, a1, a2, b1, b2) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
l = [[x1, y1]]
mi = abs(xs - x1) + abs(ys - y1)
start = 0
for j in range(1, 61):
	x = a1 * l[j - 1][0] + b1
	y = a2 * l[j - 1][1] + b2
	l.append([x, y])
	curr = abs(xs - x) + abs(ys - y)
	if curr < mi:
		mi = curr
		start = j
ans = 0
if mi <= t:
	t -= mi
	ans += 1
	for j in range(start, 0, -1):
		curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
		t -= curr
		if t < 0:
			break
		ans += 1
if t > 0 and start + 1 != 61:
	t1 = t
	ans1 = 0
	ans2 = 0
	for j in range(start + 1, 61):
		t += mi
		mi = abs(xs - l[j][0]) + abs(ys - l[j][1])
		t -= mi
		curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
		t -= curr
		if t < 0:
			break
		ans1 += 1
	mi = abs(l[start + 1][0] - l[0][0]) + abs(l[start + 1][1] - l[0][1])
	t = t1
	t -= mi
	if t >= 0:
		ans2 += 1
		for j in range(start + 2, 61):
			curr = abs(l[j][0] - l[j - 1][0]) + abs(l[j][1] - l[j - 1][1])
			t -= curr
			if t < 0:
				break
			ans2 += 1
	ans += max(ans1, ans2)
print(ans)


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()


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
d0 = d2 = abs(x0 - xs) + abs(y0 - ys)
ans = 0
tmp = 0
while d0 > t:
	(x0, y0) = (x0 * ax + bx, y0 * ay + by)
	tmp = abs(x0 - xs) + abs(y0 - ys)
	if tmp > d0:
		break
	d0 = d2 = tmp
while tmp <= t:
	(x, y) = (x0, y0)
	if tmp > 0:
		d0 = d2 = tmp
	d1 = 0
	r = 0
	while d0 + d1 <= t or d2 + d1 <= t:
		(x, y) = (x * ax + bx, y * ay + by)
		d1 = x - x0 + y - y0
		d2 = abs(x - xs) + abs(y - ys)
		r += 1
	ans = max(ans, r)
	(x0, y0) = (x0 * ax + bx, y0 * ay + by)
	tmp = abs(x0 - xs) + abs(y0 - ys)
print(ans)


(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)


def dis(a, b):
	return abs(a[0] - b[0]) + abs(a[1] - b[1])
(x0, y0, a1, a2, b1, b2) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
l = [(x0, y0)]
ans = 0
ma = 4 * 10 ** 16
while l[-1][0] + l[-1][1] <= ma:
	l.append((l[-1][0] * a1 + b1, l[-1][1] * a2 + b2))
le = len(l)
for i in range(le):
	p = xs
	q = ys
	cnt = 0
	tt = t
	for j in range(i, -1, -1):
		if dis((p, q), l[j]) <= tt:
			cnt += 1
			tt -= dis((p, q), l[j])
			(p, q) = l[j]
		else:
			break
	else:
		for j in range(i + 1, le):
			if dis((p, q), l[j]) <= tt:
				cnt += 1
				tt -= dis((p, q), l[j])
				(p, q) = l[j]
			else:
				break
	ans = max(ans, cnt)
	p = xs
	q = ys
	cnt = 0
	tt = t
	for j in range(i, le):
		if dis((p, q), l[j]) <= tt:
			cnt += 1
			tt -= dis((p, q), l[j])
			(p, q) = l[j]
		else:
			break
	ans = max(ans, cnt)
print(ans)


(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)


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())
num = []
num.append([x0, y0])
for i in range(200):
	kek = num[-1]
	lol = [kek[0] * ax + bx, kek[1] * ay + by]
	num.append(lol)
	if lol[0] > 10 ** 30 and lol[1] > 10 ** 30:
		break
ans = 0
for i in range(len(num)):
	x = 0
	y = 0
	x += xs
	y += ys
	res = dist(x, y, num[i][0], num[i][1])
	nxt = i + 1
	x = num[i][0]
	y = num[i][1]
	kek = 0
	while res <= t and nxt < len(num):
		kek += 1
		res += dist(x, y, num[nxt][0], num[nxt][1])
		x = num[nxt][0]
		y = num[nxt][1]
		nxt += 1
	if res <= t:
		kek += 1
	x = 0
	y = 0
	x += xs
	y += ys
	ans = max(ans, kek)
	nxt = i - 1
	res = dist(x, y, num[i][0], num[i][1])
	x = num[i][0]
	y = num[i][1]
	kek = 0
	while res <= t and nxt >= 0:
		kek += 1
		res += dist(x, y, num[nxt][0], num[nxt][1])
		x = num[nxt][0]
		y = num[nxt][1]
		nxt -= 1
	if res <= t:
		kek += 1
	ans = max(ans, kek)
print(ans)


(x, y, ax, ay, bx, by) = map(int, input().split())
(x0, y0, t) = map(int, input().split())
p_0 = (x0, y0)
device = []
x_cur = x
y_cur = y
F_x = lambda x: x * ax + bx
F_y = lambda y: y * ay + by
dist = lambda p1, p2: abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
for i in range(100):
	if abs(x_cur - x0) + abs(y_cur - y0) <= t:
		device.append((x_cur, y_cur))
	x_cur = F_x(x_cur)
	y_cur = F_y(y_cur)
if len(device) != 0:
	ans = [1] * len(device)
	way = dist(p_0, device[0])
	while ans[0] < len(device) and way + dist(device[0], device[ans[0]]) <= t:
		ans[0] += 1
	for i in range(1, len(device)):
		way = dist(p_0, device[i])
		while ans[i] <= i and way + dist(device[i], device[i - ans[i]]) <= t:
			ans[i] += 1
	print(max(ans))
else:
	print(0)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x = list({x0})
y = list({y0})
tt = 70
while tt > 0:
	x.append(x[len(x) - 1] * ax + bx)
	y.append(y[len(y) - 1] * ay + by)
	tt -= 1
best = 0
for i in range(len(x)):
	total = abs(x[i] - xs) + abs(y[i] - ys)
	if total <= t and best < 1:
		best = 1
	for j in range(i + 1, len(x) - 1):
		total += abs(x[j] - x[j - 1]) + abs(y[j] - y[j - 1])
		if total > t:
			break
		if best < j - i + 1:
			best = j - i + 1
	total = abs(x[i] - xs) + abs(y[i] - ys)
	for j in range(i - 1, -1, -1):
		total += abs(x[j + 1] - x[j]) + abs(y[j + 1] - y[j])
		if total > t:
			break
		if best < i - j + 1:
			best = i - j + 1
print(best)


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)


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)


(x, y, a1, a2, b1, b2) = map(int, input().split())
(xs, ys, t) = map(int, input().split())

def calc(x, y, x1, y1):
	return abs(x1 - x) + abs(y - y1)
xx = [0] * 600
yy = [0] * 600
xx[0] = x
yy[0] = y
l = 0
r = 600
INF = 10 ** 19
for i in range(1, 600):
	xx[i] = xx[i - 1] * a1 + b1
	yy[i] = yy[i - 1] * a2 + b2
while r - l - 1 > 0:
	m = (l + r) // 2
	mm = INF
	for i in range(0, 600 - m + 1):
		dist = 0
		fromstart = min(calc(xs, ys, xx[i], yy[i]), calc(xs, ys, xx[i + m - 1], yy[i + m - 1]))
		for j in range(i + 1, i + m):
			dist += calc(xx[j], yy[j], xx[j - 1], yy[j - 1])
		mm = min(mm, dist + fromstart)
	if mm <= t:
		l = m
	else:
		r = m
print(l)


(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)


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()


(x, y, ax, ay, bx, by) = map(int, input().split(' '))
(xs, ys, t) = map(int, input().split(' '))
ans = 0
points = []
(tx, ty) = (x, y)
while tx <= 10 ** 22 and ty <= 10 ** 22:
	points.append((tx, ty))
	tx = tx * ax + bx
	ty = ty * ay + by
res = []
for i in range(len(points)):
	ind = i
	start = i + 1
	cx = xs
	cy = ys
	lol = 0
	ans = 0
	while lol + abs(cx - points[ind][0]) + abs(cy - points[ind][1]) <= t and ind >= 0:
		lol += abs(cx - points[ind][0]) + abs(cy - points[ind][1])
		cx = points[ind][0]
		cy = points[ind][1]
		ans += 1
		ind -= 1
	foo = 0
	while start < len(points) and lol + abs(cx - points[start][0]) + abs(cy - points[start][1]) <= t:
		lol += abs(cx - points[start][0]) + abs(cy - points[start][1])
		foo += 1
		cx = points[start][0]
		cy = points[start][1]
		start += 1
	ans += foo
	res.append(ans)
print(max(res))


import math

def f(n, a, b, p0):
	an = int(math.pow(a, n))
	return int(an * p0) + int((an - 1) * b / (a - 1))

def diff(a, b):
	if a == b:
		return 0
	if a > b:
		return int(a - b)
	else:
		return int(b - a)

def F(N, ax, ay, bx, by, x0, y0, xs, ys, t):
	c = 0
	i = N
	while i >= 0:
		fx = f(i, ax, bx, x0)
		fy = f(i, ay, by, y0)
		ct = diff(fx, xs)
		ct += diff(fy, ys)
		if t < ct:
			break
		t -= ct
		c += 1
		xs = fx
		ys = fy
		i -= 1
	i = N + 1
	while True:
		fx = f(i, ax, bx, x0)
		fy = f(i, ay, by, y0)
		ct = diff(fx, xs)
		ct += diff(fy, ys)
		if t < ct:
			break
		t -= ct
		c += 1
		xs = fx
		ys = fy
		i += 1
	return c
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
Nx = (math.log(ax * xs + bx - xs) - math.log(ax * x0 + bx - x0)) / math.log(ax)
Ny = (math.log(ay * ys + by - ys) - math.log(ay * y0 + by - y0)) / math.log(ay)
if Nx < 0:
	Nx = 0
if Ny < 0:
	Ny = 0
minN = Nx
maxN = Nx
if minN > Ny:
	minN = Ny
if maxN < Ny:
	maxN = Ny
minN = math.floor(minN)
maxN = math.ceil(maxN)
maxC = 0
while minN <= maxN:
	c = F(minN, ax, ay, bx, by, x0, y0, xs, ys, t)
	if c > maxC:
		maxC = c
	minN += 1
print(maxC)


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()


from math import ceil, log, floor, sqrt
import math
k = 1

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def min_subs(n, binary):
	(a, b) = (1, 1)
	mx = 0
	prev = not int(binary[0])
	res = [0] * n
	for i in range(n):
		if int(binary[i]) == 1:
			if int(binary[i]) == prev:
				a += 1
				b = a
			res[i] = a
		else:
			if int(binary[i]) == prev:
				b += 1
				a = b
			res[i] = b
		prev = int(binary[i])
		mx = max(mx, max(a, b))
	print(mx)
	print(*res, sep=' ')

def steps(n):
	return n // 2 + 1

def find_order(n):
	if n % 2 == 0:
		print(*[x for x in range(n, 0, -1)], sep=' ')
	else:
		print(-1)

def max_find(n, k, z, a):
	res = 0
	s = 0
	mx = 0
	for t in range(z + 1):
		pos = k - 2 * t
		if pos < 0:
			continue
		mx = 0
		s = 0
		for i in range(pos + 1):
			if i < n - 1:
				mx = max(mx, a[i] + a[i + 1])
			s += a[i]
		res = max(res, s + mx * t)
	return res
t = 1
while t:
	t = t - 1
	(x0, y0, ax, ay, bx, by) = map(int, input().split())
	(xs, ys, T) = map(int, input().split())
	MAX = 2 ** 62 - 1
	(x, y) = ([x0], [y0])
	while (MAX - bx) / ax >= x[-1] and (MAX - by) / ay >= y[-1]:
		x.append(ax * x[-1] + bx)
		y.append(ay * y[-1] + by)
	n = len(x)
	res = 0
	for i in range(n):
		for j in range(i, n):
			length = x[j] - x[i] + y[j] - y[i]
			l = abs(xs - x[i]) + abs(ys - y[i])
			r = abs(xs - x[j]) + abs(ys - y[j])
			if length <= T - l or length <= T - r:
				res = max(res, j - i + 1)
	print(res)


inf = (1 << 63) - 1
(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
pt = [(x0, y0)]
while 1:
	last = pt[-1]
	cur = (last[0] * ax + bx, ay * last[1] + by)
	if cur[0] > inf or cur[1] > inf:
		break
	pt.append(cur)
ans = 0
for i in range(0, len(pt)):
	for j in range(i, len(pt)):
		f = abs(pt[i][0] - pt[j][0]) + abs(pt[i][1] - pt[j][1])
		if f + abs(xs - pt[i][0]) + abs(ys - pt[i][1]) <= t or f + abs(xs - pt[j][0]) + abs(ys - pt[j][1]) <= t:
			ans = max(ans, j - i + 1)
print(ans)


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


import os, sys
from io import BytesIO, IOBase

def main():
	(x0, y0, ax, ay, bx, by) = map(int, input().split())
	(xs, ys, t1) = map(int, input().split())
	points = [(x0, y0)]
	while max(points[-1]) < 10 ** 17:
		(a, b) = points[-1]
		points.append((a * ax + bx, b * ay + by))
	ans = 0
	for i in range(len(points)):
		(x, y, curr, t) = (xs, ys, 0, t1)
		for j in range(i, -1, -1):
			t -= abs(points[j][0] - x) + abs(points[j][1] - y)
			if t >= 0:
				curr += 1
			else:
				break
			(x, y) = points[j]
		ans = max(ans, curr)
		(x, y, curr, t) = (xs, ys, 0, t1)
		for j in range(i, len(points)):
			t -= abs(points[j][0] - x) + abs(points[j][1] - y)
			if t >= 0:
				curr += 1
			else:
				break
			(x, y) = points[j]
		ans = max(ans, curr)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
nodes = []
(x, y) = (x0, y0)
while x - x0 + y - y0 <= 10 ** 17:
	nodes.append((x, y))
	x = ax * x + bx
	y = ay * y + by
maxNodes = 0
for (i, (x1, y1)) in enumerate(nodes):
	for (j, (x2, y2)) in enumerate(nodes):
		if abs(xs - x1) + abs(ys - y1) + abs(x2 - x1) + abs(y2 - y1) <= t:
			nodeCollected = abs(j - i) + 1
			maxNodes = max(maxNodes, nodeCollected)
print(maxNodes)


def dist(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
(x, y, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
x0 = x
y0 = y
X = []
Y = []
while dist(xs, ys, x, y) <= 10 ** 18:
	X.append(x)
	Y.append(y)
	x = x * ax + bx
	y = y * ay + by
ans = 0
for i in range(len(X)):
	for j in range(len(X)):
		if t >= min(dist(X[i], Y[i], xs, ys), dist(X[j], Y[j], xs, ys)) + dist(X[i], Y[i], X[j], Y[j]):
			ans = max(ans, abs(i - j) + 1)
print(ans)


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 os
import sys
from atexit import register
from io import StringIO
sys.stdout = StringIO()
register(lambda : os.write(1, sys.stdout.getvalue().encode()))
input = sys.stdin.readline
import math
nodes = []
(x0, y0, ax, ay, bx, by) = [int(k) for k in input().split()]
(xs, ys, t) = [int(k) for k in input().split()]
nodes.append((x0, y0))
x = x0
y = y0
d = 0
for i in range(100):
	_x = ax * x + bx
	_y = ay * y + by
	if xs <= _x:
		d += _x - x + _y - y
	nodes.append((_x, _y))
	x = _x
	y = _y
	if d >= 2 * t:
		break
ret = 0
for i in range(len(nodes)):
	x = xs
	y = ys
	s = t
	c = 0
	for j in range(i, -1, -1):
		s -= abs(x - nodes[j][0]) + abs(y - nodes[j][1])
		if s < 0:
			break
		x = nodes[j][0]
		y = nodes[j][1]
		c += 1
	s -= abs(x - nodes[i][0]) + abs(y - nodes[i][1])
	x = nodes[i][0]
	y = nodes[i][1]
	if s < 0:
		ret = max(ret, c)
		continue
	for j in range(i + 1, len(nodes)):
		s -= abs(x - nodes[j][0]) + abs(y - nodes[j][1])
		if s < 0:
			break
		x = nodes[j][0]
		y = nodes[j][1]
		c += 1
	ret = max(ret, c)
print(ret)


(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 >= 1e+17:
		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)


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)


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()


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
from collections import Counter
(x_0, y_0, a, c, b, d) = Input()
(x_s, y_s, t) = Input()
lis = [[0, 0], [abs(x_s - x_0) + abs(y_s - y_0), 0]]
(x, y) = (x_0, y_0)
(x_n, y_n) = (x_0 * a + b, y_0 * c + d)
for i in range(300):
	lis.append([abs(x_s - x_n) + abs(y_s - y_n), abs(x_n - x) + abs(y_n - y) + lis[-1][1]])
	(x, y) = (x_n, y_n)
	(x_n, y_n) = (x_n * a + b, y_n * c + d)
m = len(lis)
ans = 0
for i in range(1, m):
	if lis[i][0] <= t:
		ans += 1
		break
for i in range(2, m):
	for j in range(1, i):
		MIN = min(lis[i][0], lis[j][0])
		if MIN + lis[i][1] - lis[j][1] <= t:
			ans = max(ans, i - j + 1)
print(ans)


(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)


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)


(x0, y0, ax, ay, bx, by) = map(int, input().split())
(xs, ys, t) = map(int, input().split())
P = [(x0, y0)]
for i in range(70):
	(x, y) = P[-1]
	x = ax * x + bx
	y = ay * y + by
	P.append((x, y))

def dist(A, B):
	return abs(A[0] - B[0]) + abs(A[1] - B[1])
ans = 0
for i in range(len(P)):
	d = 0
	for j in range(i, len(P)):
		if j > i:
			d += dist(P[j], P[j - 1])
		w = min(dist((xs, ys), P[i]), dist((xs, ys), P[j])) + d
		if w <= t:
			ans = max(ans, j - i + 1)
print(ans)


R = lambda : map(int, input().split())
LIMIT = 10 ** 17
dist = lambda a, b: abs(a[0] - b[0]) + abs(a[1] - b[1])
(x0, y0, ax, ay, bx, by) = R()
(xs, ys, t) = R()
data = [(x0, y0)]
for i in range(60):
	_x = data[-1][0] * ax + bx
	_y = data[-1][1] * ay + by
	if _x > LIMIT or _y > LIMIT:
		break
	data.append((_x, _y))
(ans, start, n) = (0, (xs, ys), len(data))
for i in range(n):
	for j in range(n):
		if dist(start, data[i]) + dist(data[i], data[j]) <= t:
			ans = max(ans, abs(i - j) + 1)
print(ans)


(x0, y0, ax, ay, bx, by) = map(int, input('').split(' '))
(xs, ys, t) = map(int, input('').split(' '))
LIMIT = 1e+18
pts = []
while True:
	x = 0
	y = 0
	if len(pts) == 0:
		x = x0
		y = y0
	else:
		x = ax * pts[len(pts) - 1][0] + bx
		y = ay * pts[len(pts) - 1][1] + by
	if x > LIMIT or y > LIMIT:
		break
	pts.append([x, y])
ans = 0
for l in range(len(pts)):
	for r in range(l, len(pts)):
		ways = []
		res = 0
		if xs >= pts[r][0]:
			res = xs - pts[l][0] + abs(ys - pts[r][1])
			res += pts[r][1] - pts[l][1]
			ways.append(res)
		elif xs <= pts[l][0]:
			res = pts[r][0] - xs + abs(ys - pts[l][1])
			res += pts[r][1] - pts[l][1]
			ways.append(res)
		else:
			res = pts[r][1] - pts[l][1] + pts[r][0] - pts[l][0]
			tmp1 = res + pts[r][0] - xs + abs(pts[r][1] - ys)
			tmp2 = res + xs - pts[l][0] + abs(pts[l][1] - ys)
			ways += [tmp1, tmp2]
		final = min(ways)
		if final <= t:
			ans = max(ans, r - l + 1)
print(ans)


(x0, y0, ax, ay, bx, by) = [int(k) for k in input().strip().split(' ')]
(xs, ys, t) = [int(k) for k in input().strip().split(' ')]
cx = bx / (ax - 1)
cy = by / (ay - 1)
x0p = x0
y0p = y0
xsp = xs
ysp = ys
xip = x0p
yip = y0p
res = 0

def md(x, y, xp, yp):
	return abs(x - xp) + abs(y - yp)
totdto0 = 0
pvs = []
for i in range(200):
	tt = t
	maxres = 0
	tt -= md(xsp, ysp, xip, yip)
	if tt >= 0:
		myres = 1
		if tt >= 2 * totdto0:
			mr = i + 1
			ttt = tt - 2 * totdto0
			oxip = xip
			oyip = yip
			while ttt >= 0:
				nxip = ax * oxip + bx
				nyip = ay * oyip + by
				ttt -= md(nxip, nyip, oxip, oyip)
				if ttt >= 0:
					mr += 1
				oyip = nyip
				oxip = nxip
			maxres = max(maxres, mr)
		if tt >= totdto0:
			mr = i + 1
			maxres = max(maxres, mr)
		else:
			oxip = xip
			oyip = yip
			ttt = tt
			kk = -1
			mr = 1
			while ttt >= 0 and -kk <= len(pvs):
				nxip = pvs[kk][0]
				nyip = pvs[kk][1]
				ttt -= md(nxip, nyip, oxip, oyip)
				if ttt >= 0:
					mr += 1
				kk -= 1
				oyip = nyip
				oxip = nxip
			maxres = max(maxres, mr)
		mr = 1
		ttt = tt
		oxip = xip
		oyip = yip
		while ttt >= 0:
			nxip = ax * oxip + bx
			nyip = ay * oyip + by
			ttt -= md(nxip, nyip, oxip, oyip)
			if ttt >= 0:
				mr += 1
			oyip = nyip
			oxip = nxip
	res = max(res, maxres)
	oxip = xip
	oyip = yip
	pvs += [(oxip, oyip)]
	xip *= ax
	xip += bx
	yip *= ay
	yip += by
	totdto0 += md(xip, yip, oxip, oyip)
	if xip > xsp and yip > ysp and (xip + yip - xsp - ysp > t):
		break
print(res)


from math import factorial
from collections import Counter
from sys import stdin

def RL():
	return map(int, stdin.readline().rstrip().split())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
(x, y, ax, ay, bx, by) = RL()
(xx, yy, t) = RL()
score = [(x, y)]
res = 0
while True:
	(lx, ly) = (score[-1][0], score[-1][1])
	if lx > 10 ** 16 or ly > 10 ** 16:
		break
	score.append((ax * lx + bx, ay * ly + by))
for i in range(len(score)):
	for j in range(i, len(score)):
		dis = mdis(score[i][0], score[i][1], score[j][0], score[j][1])
		d1 = mdis(xx, yy, score[i][0], score[i][1])
		d2 = mdis(xx, yy, score[j][0], score[j][1])
		if d1 + dis <= t or d2 + dis <= t:
			res = max(res, j - i + 1)
print(res)