1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
from queue import Queue
from random import randint
def find_a(b, c):
return b - c - b
def find_b(a, c):
return a + (c - a) // 2
def find_c(a, b):
return b + b - a
square = []
for i in range(3):
square.append(input().split())
for row in square:
for i in range(len(row)):
if row[i].isdigit():
row[i] = int(row[i])
def fill_unknown(square):
for row in square:
a, b, c = row
known = list(map(type, row)).count(int)
if known == 2:
if isinstance(a, str):
a = find_a(b, c)
row[0] = a
elif isinstance(b, str):
b = find_b(a, c)
row[1] = b
elif isinstance(c, str):
c = find_c(a, b)
row[2] = c
for i in range(3):
a, b, c = square[0][i], square[1][i], square[2][i]
known = list(map(type, [a, b, c])).count(int)
if known == 2:
if isinstance(a, str):
a = find_a(b, c)
square[0][i] = a
elif isinstance(b, str):
b = find_b(a, c)
square[1][i] = b
elif isinstance(c, str):
c = find_c(a, b)
square[2][i] = c
return square
def is_good(square):
for row in square:
a, b, c = row
if (b - a) * 2 + a != c:
return False
for i in range(3):
a, b, c = square[0][i], square[1][i], square[2][i]
if (b - a) * 2 + a != c:
return False
return True
def deepcopy(square):
return [row[:] for row in square]
def fill_random(square):
for i in range(3):
for j in range(3):
if isinstance(square[i][j], str):
square[i][j] = randint(-1000000000, 1000000000)
square = fill_unknown(square)
return square
square = fill_unknown(square)
while True:
s = deepcopy(square)
s = fill_random(s)
if is_good(s):
for row in s:
print(*row)
break
# q = Queue()
# q.put(square)
#
# while not q.empty():
# current = q.get()
# if is_good(current):
# print(current)
# break
#
# row = current[0]
# a, b, c = row
# known = list(map(type, row)).count(int)
#
# if known == 1:
# if isinstance(a, int):
# s, e = -1000000000, 1000000000
# s = max(s, current[0][0])
# e = min(e, current[1][[1]])
# x = deepcopy(current)
# x[0][0] = randint(s, e)
# x[0][2] = find_c(x[0][0], x[0][1])
# q.put(x)
#
# s, e = -1000000000, 1000000000
# s = max(s, current[0][0])
# e = min(e, current[1][[2]])
# x = deepcopy(current)
# x[0][2] = randint(s, e)
# x[0][1] = find_b(x[0][0], x[0][2])
# q.put(x)
# elif isinstance(b, int):
# s, e = -1000000000, 1000000000
# e = min(e, current[0][1])
# x = deepcopy(current)
# x[0][0] = randint(s, e)
# x[0][2] = find_c(x[0][0], x[0][1])
# q.put(x)
#
# s, e = -1000000000, 1000000000
# s = max(s, current[0][1])
# e = min(e, current[1][[2]])
# x = deepcopy(current)
# x[0][2] = randint(s, e)
# x[0][0] = find_a(x[0][1], x[0][2])
# q.put(x)
# elif isinstance(c, int):
# s, e = -1000000000, 1000000000
# e = min(e, current[0][2])
# x = deepcopy(current)
# x[0][1] = randint(s, e)
# x[0][0] = find_a(x[0][1], x[0][2])
# q.put(x)
#
# s, e = -1000000000, 1000000000
# e = min(e, current[1][[1]])
# x = deepcopy(current)
# x[0][1] = randint(s, e)
#
# q.put(x)
#
# elif known == 0:
# pass
|