Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.

As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters. 

Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2·d, ..., n·d meters.


-----Input-----

The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 10^5), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink.

The second line contains integer n (1 ≤ n ≤ 10^5) showing that Valera needs an extra drink n times.


-----Output-----

Print n lines, each line should contain two real numbers x_{i} and y_{i}, separated by a space. Numbers x_{i} and y_{i} in the i-th line mean that Valera is at point with coordinates (x_{i}, y_{i}) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10^{ - 4}.

Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.


-----Examples-----
Input
2 5
2

Output
1.0000000000 2.0000000000
2.0000000000 0.0000000000

Input
4.147 2.8819
6

Output
2.8819000000 0.0000000000
4.1470000000 1.6168000000
3.7953000000 4.1470000000
0.9134000000 4.1470000000
0.0000000000 2.1785000000
0.7034000000 0.0000000000

Difficulty: MEDIUM
Tags: Mathematics

Implementation

Starter code:

Solutions:
import sys

def main():
	(a, d) = map(lambda x: float(x) * 10000, input().split(' '))
	ans = []
	for i in range(1, int(input()) + 1):
		t = d * i % (a * 4)
		if t <= a:
			y = 0
			x = t / 10000
		elif t <= a * 2:
			x = a / 10000
			y = (t - a) / 10000
		elif t <= a * 3:
			y = a / 10000
			x = (a - (t - a * 2)) / 10000
		elif t < a * 4:
			x = 0
			y = (a - (t - a * 3)) / 10000
		ans.append('{} {}'.format(x, y))
	print('\n'.join(ans))
sys.exit(main())


def setPoint(point, a):
	p = point
	x = 0
	y = 0
	if p <= a:
		x = p
		y = 0
	elif p <= a * 2:
		x = a
		y = p - a
	elif p <= a * 3:
		x = a * 3 - p
		y = a
	else:
		x = 0
		y = a * 4 - p
	x = int(x * 100000) / 100000
	y = int(y * 100000) / 100000
	return str(x) + ' ' + str(y)
(a, d) = map(float, input().split())
n = int(input())
curP = 0
for l in range(0, n):
	curP += d
	curP = curP % (a * 4)
	print(setPoint(curP, a))


(a, d) = map(float, input().split())
n = int(input())

def pt(k):
	l = d * k
	c = int(l / a)
	l -= a * c
	c %= 4
	if c == 0:
		return (l, 0)
	elif c == 1:
		return (a, l)
	elif c == 2:
		return (a - l, a)
	else:
		return (0, a - l)
print('\n'.join((str(t[0]) + ' ' + str(t[1]) for t in map(pt, range(1, n + 1)))))


([a, d], n, tmp) = (map(float, input().split()), int(input()), 0)
for i in range(n):
	tmp = (tmp + d) % (4 * a)
	if tmp <= a:
		print(tmp, 0)
	elif tmp <= 2 * a:
		print(a, tmp - a)
	elif tmp <= 3 * a:
		print(3 * a - tmp, a)
	else:
		print(0, 4 * a - tmp)


(a, l) = map(float, input().split())
(b, c, d) = (2 * a, 3 * a, 4 * a)
(s, l) = (0, l % d)
u = str(a) + ' '
v = ' ' + str(a)

def f():
	global s
	s = (s + l) % d
	if s < a:
		return str(s) + ' 0'
	if s < b:
		return u + str(s - a)
	if s < c:
		return str(c - s) + v
	return '0 ' + str(d - s)
print('\n'.join((f() for i in range(int(input())))))


import sys

def main():
	(a, d) = [int(float(x) * 10000 + 1e-06) for x in input().split(' ')]
	ans = []
	for i in range(1, int(input()) + 1):
		cur_round_pos = d * i % (a * 4)
		if cur_round_pos <= a:
			y = 0
			x = cur_round_pos / 10000
		elif cur_round_pos <= a * 2:
			x = a / 10000
			y = (cur_round_pos - a) / 10000
		elif cur_round_pos <= a * 3:
			y = a / 10000
			x = (a * 3 - cur_round_pos) / 10000
		elif cur_round_pos < a * 4:
			x = 0
			y = (a * 4 - cur_round_pos) / 10000
		ans.append('{} {}'.format(x, y))
	print('\n'.join(ans))

def __starting_point():
	return main()
__starting_point()


(a, d) = map(float, input().split())
n = int(input())

def f(p):
	p %= 4 * a
	if p <= a:
		return (p, 0)
	elif p <= 2 * a:
		return (a, p - a)
	elif p <= 3 * a:
		return (3 * a - p, a)
	return (0, 4 * a - p)
print('\n'.join((' '.join(map(str, f(p))) for p in (i * d for i in range(1, n + 1)))))


def main():
	(a, d) = map(float, input().split())
	(ai, di) = (int(_ * 10000.0 + 0.1) for _ in (a, d))
	(a2, a3, a4) = (ai * _ for _ in (2, 3, 4))
	(n, sa) = (int(input()), '%.10f' % a)
	for t in range(di, n * di + 5001, di):
		t %= a4
		if t <= a2:
			if t <= ai:
				print('%.10f 0.0000000000' % (t * 0.0001))
			else:
				print(sa, '%.10f' % ((t - ai) * 0.0001))
		elif t <= a3:
			print('%.10f' % (-t % ai * 0.0001), sa)
		else:
			print('0.0000000000 %.10f' % (-t % ai * 0.0001))
main()


(a, d) = [float(i) for i in input().split()]
n = int(input())
d %= 4 * a
start = 0
seg = 0
for i in range(n):
	start += d
	lengths = int(start / a)
	start = start % a
	seg = (seg + lengths) % 4
	if seg == 0:
		print(start, 0)
	elif seg == 1:
		print(a, start)
	elif seg == 2:
		print(a - start, a)
	else:
		print(0, a - start)


from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

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

def main():
	(a, d) = map(float, input().split())
	n = ii()
	for i in range(1, n + 1):
		cul = d * i % (4 * a)
		if cul <= a:
			print(cul, 0)
		elif cul <= 2 * a:
			print(a, cul - a)
		elif cul <= 3 * a:
			print(3 * a - cul, a)
		else:
			print(0, 4 * a - cul)
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()


inputs = input().split(' ')
a = float(inputs[0])
d = float(inputs[1])
n = int(input())
x = 0
y = 0
direction = 'r'
for i in range(n):
	travel = d % (4 * a)
	while travel > 0.0:
		if direction == 'r':
			if travel > a - x:
				travel -= a - x
				x = a
				direction = 'u'
			else:
				x += travel
				travel = 0.0
		elif direction == 'u':
			if travel > a - y:
				travel -= a - y
				y = a
				direction = 'l'
			else:
				y += travel
				travel = 0.0
		elif direction == 'l':
			if travel > x:
				travel -= x
				x = 0.0
				direction = 'd'
			else:
				x -= travel
				travel = 0.0
		elif travel > y:
			travel -= y
			y = 0.0
			direction = 'r'
		else:
			y -= travel
			travel = 0.0
	print('{0} {1}'.format(x, y))


(a, d) = map(float, input().split())
n = int(input())
for i in range(n):
	k = (i + 1) * d // a % 4
	p = (i + 1) * d % a
	if k < 1:
		print(p, 0)
	elif k < 2:
		print(a, p)
	elif k < 3:
		print(a - p, a)
	else:
		print(0, a - p)


(a, d) = map(float, input().split())
n = int(input())
for i in range(1, n + 1):
	c = i * d // (4 * a)
	l = i * d - c * 4 * a
	if 2 * a <= l and l <= 3 * a:
		print(3 * a - l, a)
	elif a <= l and l <= 2 * a:
		print(a, l - a)
	elif 3 * a <= l:
		print(0, 4 * a - l)
	else:
		print(l, 0)


from math import ceil
(a, d) = map(float, input().split())
n = int(input())
s = a * 4
for i in range(1, n + 1):
	yy = d * i // s
	yy = d * i - yy * s
	tmp = s / 4
	if 0 <= yy <= tmp:
		print(yy, 0)
	elif tmp < yy <= tmp * 2:
		print(a, yy - a)
	elif tmp * 2 < yy <= tmp * 3:
		print(a - (yy - 2 * a), a)
	else:
		print(0, a - (yy - a * 3))


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')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from math import ceil
for _ in range(int(input()) if not True else 1):
	(a, d) = map(float, input().split())
	n = int(input())
	for i in range(1, n + 1):
		edges = int(i * d / a) % 4
		dist = i * d - a * int(i * d / a)
		if edges == 0:
			print(dist, 0)
		if edges == 1:
			print(a, dist)
		if edges == 2:
			print(a - dist, a)
		if edges == 3:
			print(0, a - dist)


from collections import *
import os, sys
from io import BytesIO, IOBase
from math import fmod

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')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
rfloats = lambda : [float(x) for x in input().split()]
ceil1 = lambda a, b: (a + b - 1) // b
(a, d) = rfloats()
(n, dist) = (rint(), 0)
for i in range(n):
	dist += d
	dist = fmod(dist, 4 * a)
	if dist < a:
		print(f'{dist:.10f} 0.0000000000')
	elif dist < a * 2:
		print(f'{a:.10f} {dist - a:.10f}')
	elif dist < 3 * a:
		print(f'{3 * a - dist:.10f} {a:.10f}')
	else:
		print(f'0.0000000000 {4 * a - dist:.10f}')


(a, d) = map(float, input().split())
n = int(input())
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
sx = [0, a, a, 0]
sy = [0, 0, a, a]
for i in range(1, n + 1):
	x = int(i * d / a)
	y = i * d - x * a
	x %= 4
	print(sx[x] + dx[x] * y, sy[x] + dy[x] * y)


from decimal import Decimal
(a, d) = map(Decimal, input().split())
n = int(input())
tot = Decimal(0.0)
x = Decimal()
y = Decimal()
for i in range(n):
	tot += d
	tot %= 4 * a
	if tot < a:
		x = tot
		y = 0.0
	elif tot < 2 * a:
		x = a
		y = tot - a
	elif tot < 3 * a:
		x = 3 * a - tot
		y = a
	else:
		x = 0.0
		y = 4 * a - tot
	print(x, end=' ')
	print(y)


class CodeforcesTask404BSolution:

	def __init__(self):
		self.result = ''
		self.a_d = []
		self.n = 0

	def read_input(self):
		self.a_d = [float(x) for x in input().split(' ')]
		self.n = int(input())

	def process_task(self):
		for x in range(1, self.n + 1):
			lpos = x * self.a_d[1] % (4 * self.a_d[0])
			pos = [0, 0]
			if lpos <= self.a_d[0]:
				pos[0] = lpos
			elif lpos <= self.a_d[0] * 2:
				pos[0] = self.a_d[0]
				pos[1] = lpos - self.a_d[0]
			elif lpos <= self.a_d[0] * 3:
				pos[0] = self.a_d[0] - (lpos - self.a_d[0] * 2)
				pos[1] = self.a_d[0]
			else:
				pos[1] = self.a_d[0] - (lpos - self.a_d[0] * 3)
			print('{0} {1}'.format(*pos))

	def get_result(self):
		return self.result
Solution = CodeforcesTask404BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


def pos(a, d):
	d %= 4 * a
	if d < a:
		return (d, 0)
	elif d < 2 * a:
		return (a, d - a)
	elif d < 3 * a:
		return (a - d % a, a)
	else:
		return (0, a - d % a)
(a, d) = map(float, input().split())
n = int(input())
for i in range(1, n + 1):
	p = pos(a, i * d)
	print('%.10f %.10f' % (p[0], p[1]))


def main():
	(a, d) = map(float, input().split())
	n = int(input())
	vertices = ((0, 0), (a, 0), (a, a), (0, a))
	units = ((1, 0), (0, 1), (-1, 0), (0, -1))
	outs = []
	side = 0
	offset = 0
	for i in range(n):
		(next_side, offset) = divmod(offset + d, a)
		side = (int(next_side) + side) % 4
		vertex = vertices[side]
		unit = units[side]
		shift = lambda x: '{:.10f}'.format(x[0] + offset * x[1])
		next_coord = tuple(map(shift, zip(vertex, unit)))
		outs.append(' '.join(next_coord))
	print('\n'.join(outs))
main()


import math
import sys
inp = sys.stdin
(a, d) = [float(x) for x in inp.readline().split()]
n = int(inp.readline())
result = ''
print(result)
for i in range(1, n + 1):
	abschnitt = math.floor(d * i / a)
	rest = d * i - abschnitt * a
	start = abschnitt % 4
	if start == 0:
		result += str(rest) + ' ' + str(0.0) + '\n'
	elif start == 1:
		result += str(a) + ' ' + str(rest) + '\n'
	elif start == 2:
		result += str(a - rest) + ' ' + str(a) + '\n'
	else:
		result += str(0.0) + ' ' + str(a - rest) + '\n'
print(result)


__author__ = 'Adela'

def main():
	(a, d) = (float(k) for k in input().split())
	n = int(input())
	remaining = d
	dir = 0
	while n:
		if remaining > a:
			laps = int(remaining / a)
			remaining -= laps * a
			dir += laps
			dir %= 4
		else:
			if dir == 0:
				print(remaining, 0.0)
			elif dir == 1:
				print(a, remaining)
			elif dir == 2:
				print(a - remaining, a)
			else:
				print(0.0, a - remaining)
			remaining += d
			n -= 1
main()


(a, d) = list(map(float, input().split()))
n = int(input())

def coordinates(s):
	if s <= a:
		return (s, 0)
	elif s <= 2 * a:
		return (a, s - a)
	elif s <= 3 * a:
		return (3 * a - s, a)
	else:
		return (0, 4 * a - s)
for i in range(1, n + 1):
	print('%f %f' % coordinates(i * d % (4 * a)))


(a, m) = map(float, input().split())
n = int(input())
x = 4 * a
l = []
l.append(m % x)
for i in range(1, n):
	l.append((l[-1] + m) % x)
for i in range(n):
	if l[i] <= a:
		print('{0:.5f}'.format(l[i]), 0)
	elif l[i] <= 2 * a:
		print('{0:.5f}'.format(a), '{0:.5f}'.format(l[i] - a))
	elif l[i] <= 3 * a:
		print('{0:.5f}'.format(3 * a - l[i]), '{0:.5f}'.format(a))
	else:
		print(0, '{0:.5f}'.format(4 * a - l[i]))


from math import floor
(a, d) = map(float, input().split())
n = int(input())
res = []
for i in range(n):
	rec = i * d + d
	tra = floor(rec / a) % 4
	seg = rec - floor(rec / a) * a
	if tra == 0:
		res.append('%.8f %.8f' % (seg, 0.0))
	elif tra == 1:
		res.append('%.8f %.8f' % (a, seg))
	elif tra == 2:
		res.append('%.8f %.8f' % (a - seg, a))
	elif tra == 3:
		res.append('%.8f %.8f' % (0.0, a - seg))
print('\n'.join(res))


(a, b) = [float(x) for x in input().split()]
n = int(input())
for i in range(1, n + 1):
	rem = i * b % (4 * a)
	print(*[(rem, 0), (a, rem - a), (3 * a - rem, a), (0, 4 * a - rem)][int(rem // a)])


(a, d) = map(float, input().split())
n = int(input())
t = 0
for i in range(n):
	t = (t + d) % (4 * a)
	if t < a:
		print(t, 0)
		continue
	if t < 2 * a:
		print(a, t - a)
		continue
	if t < 3 * a:
		print(3 * a - t, a)
		continue
	if t < 4 * a:
		print(0, 4 * a - t)


import math
(a, d) = map(float, input().split())
n = int(input())
for p in (math.fmod(i * d, 4 * a) for i in range(1, n + 1)):
	if p <= a:
		(x, y) = (p, 0)
	elif p <= 2 * a:
		(x, y) = (a, p - a)
	elif p <= 3 * a:
		(x, y) = (3 * a - p, a)
	else:
		(x, y) = (0, 4 * a - p)
	print('{:.10f} {:.10f}'.format(x, y))


(a, d) = map(float, input().split())
n = int(input())
s = 0
for i in range(1, n + 1):
	s += d
	s %= 4 * a
	t = s // a
	if t % 4 == 0:
		print(s % a, 0)
	elif t % 4 == 1:
		print(a, s % a)
	elif t % 4 == 2:
		print(a - s % a, a)
	elif t % 4 == 3:
		print(0, a - s % a)


(a, d) = [float(el) for el in input().split()]
n = int(input())
for i in range(1, n + 1):
	k = i * d % (4 * a)
	m = k // a
	if m == 0:
		(x, y) = (k % a, 0)
	elif m == 1:
		(x, y) = (a, k % a)
	elif m == 2:
		(x, y) = (a - k % a, a)
	elif m == 3:
		(x, y) = (0, a - k % a)
	print('%s %s' % (x, y))