import sys
C1, M1 = [int(x) for x in sys.stdin.readline().rstrip().split()]
C2, M2 = [int(x) for x in sys.stdin.readline().rstrip().split()]
C3, M3 = [int(x) for x in sys.stdin.readline().rstrip().split()]
rlt = [M1, M2, M3]
max_limit = [C1, C2, C3]
count = 0
for i in range(0, 100):
temp = (rlt[i%3]+rlt[(i+1) % 3])
if temp >= max_limit[(i+1) % 3]:
rlt[i%3] = temp - max_limit[(i+1) % 3]
rlt[(i+1) % 3] = max_limit[(i+1) % 3]
else:
rlt[(i+1)%3] += rlt[i%3]
rlt[i%3] = 0
# print(i, rlt)
# print(rlt)
for i in rlt:
print(i)
C, M = list(), list()
for i in range(3):
a, b = map(int, input().split())
C.append(a)
M.append(b)
for i in range(100):
idx = i % 3
nxt = (idx + 1) % 3
# print(M)
## 동시에 바꾸는 것이 포인트!!!
## 따로 따로 실행하면 다른 결과가 나오니 주의!
M[idx], M[nxt] = max(M[idx] - (C[nxt]-M[nxt]), 0), min(C[nxt], M[nxt] + M[idx])
for i in M:
print(i)