message stringlengths 2 44.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 276 109k | cluster float64 23 23 | __index_level_0__ int64 552 217k |
|---|---|---|---|---|---|
Provide a correct Python 3 solution for this coding contest problem.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No | instruction | 0 | 15,706 | 23 | 31,412 |
"Correct Solution:
```
mod = 1000000007
eps = 10**-9
def main():
import sys
input = sys.stdin.buffer.readline
from collections import deque
# compressed[v]: 縮約後のグラフで縮約前のvが属する頂点
# num: 縮約後のグラフの頂点数
# 縮約後のグラフの頂点番号はトポロジカル順
def SCC(adj, adj_rev):
N = len(adj) - 1
seen = [0] * (N + 1)
compressed = [0] * (N + 1)
order = []
for v0 in range(1, N + 1):
if seen[v0]:
continue
st = deque()
st.append(v0)
while st:
v = st.pop()
if v < 0:
order.append(-v)
else:
if seen[v]:
continue
seen[v] = 1
st.append(-v)
for u in adj[v]:
st.append(u)
seen = [0] * (N + 1)
num = 0
for v0 in reversed(order):
if seen[v0]:
continue
num += 1
st = deque()
st.append(v0)
seen[v0] = 1
compressed[v0] = num
while st:
v = st.pop()
for u in adj_rev[v]:
if seen[u]:
continue
seen[u] = 1
compressed[u] = num
st.append(u)
return num, compressed
# 縮約後のグラフを構築
# 先にSCC()を実行してnum, compressedを作っておく
def construct(adj, num, compressed):
N = len(adj) - 1
adj_compressed = [set() for _ in range(num + 1)]
for v in range(1, N + 1):
v_cmp = compressed[v]
for u in adj[v]:
u_cmp = compressed[u]
if v_cmp != u_cmp:
adj_compressed[v_cmp].add(u_cmp)
return adj_compressed
class TwoSat:
def __init__(self, N):
self.N = N
self.adj = [[] for _ in range(2 * N + 1)]
self.adj_rev = [[] for _ in range(2 * N + 1)]
self.compressed = None
# (a == a_bool) or (b = b_bool)というクローズを追加
# a, b は1-indexed
def add_clause(self, a, a_bool, b, b_bool):
if not a_bool:
a += self.N
if not b_bool:
b += self.N
if a <= self.N:
self.adj[a + self.N].append(b)
self.adj_rev[b].append(a + self.N)
else:
self.adj[a - self.N].append(b)
self.adj_rev[b].append(a - self.N)
if b <= self.N:
self.adj[b + self.N].append(a)
self.adj_rev[a].append(b + self.N)
else:
self.adj[b - self.N].append(a)
self.adj_rev[a].append(b - self.N)
def satisfiable(self):
_, self.compressed = SCC(self.adj, self.adj_rev)
for i in range(1, self.N + 1):
if self.compressed[i] == self.compressed[i + self.N]:
return False
return True
# 直前に読んだsatisfiableの割り当てを返す
# 長さN+1のbool値の配列を返す
def answer(self):
assert self.compressed is not None
ret = [True] * (self.N + 1)
for i in range(1, self.N + 1):
if self.compressed[i] < self.compressed[i + self.N]:
ret[i] = False
return ret
N, D = map(int, input().split())
X = []
Y = []
for _ in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
TS = TwoSat(N)
for i in range(N):
for j in range(i+1, N):
if abs(X[i] - X[j]) < D:
TS.add_clause(i+1, 0, j+1, 0)
if abs(X[i] - Y[j]) < D:
TS.add_clause(i+1, 0, j+1, 1)
if abs(Y[i] - X[j]) < D:
TS.add_clause(i+1, 1, j+1, 0)
if abs(Y[i] - Y[j]) < D:
TS.add_clause(i+1, 1, j+1, 1)
ok = TS.satisfiable()
if not ok:
print("No")
else:
print("Yes")
ans = TS.answer()
for i in range(N):
if ans[i+1]:
print(X[i])
else:
print(Y[i])
if __name__ == '__main__':
main()
``` | output | 1 | 15,706 | 23 | 31,413 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
class csr:
def __init__(self, n: int, edges: list):
self.start = [0] * (n + 1)
self.elist = [0] * len(edges)
for e in edges:
self.start[e[0] + 1] += 1
for i in range(1, n + 1):
self.start[i] += self.start[i - 1]
counter = self.start[::]
for e in edges:
self.elist[counter[e[0]]] = e[1]
counter[e[0]] += 1
class internal_scc_graph:
def __init__(self, n: int = 0):
self.__n = n
self.__edges = []
def num_vertices(self):
return self.__n
def add_edge(self, from_: int, to: int):
self.__edges.append([from_, to])
def scc_ids(self):
g = csr(self.__n, self.__edges)
now_ord = 0
group_num = 0
visited = []
low = [0] * self.__n
ord = [-1] * self.__n
ids = [0] * self.__n
parent = [-1] * self.__n
for root in range(self.__n):
if(ord[root] == -1):
stack = []
stack.extend([root] * 2)
while(stack):
v = stack.pop()
if(ord[v] == -1):
visited.append(v)
low[v] = now_ord
ord[v] = now_ord
now_ord += 1
for i in range(g.start[v], g.start[v + 1]):
to = g.elist[i]
if(ord[to] == -1):
stack.extend([to] * 2)
parent[to] = v
else:
low[v] = min(low[v], ord[to])
else:
if(low[v] == ord[v]):
while(True):
u = visited.pop()
ord[u] = self.__n
ids[u] = group_num
if(u == v):
break
group_num += 1
if(parent[v] != -1):
low[parent[v]] = min(low[parent[v]], low[v])
for i, x in enumerate(ids):
ids[i] = group_num - 1 - x
return [group_num, ids]
class two_sat:
def __init__(self, n: int = 0):
self.__n = n
self.__answer = [0] * n
self.__scc = internal_scc_graph(2 * n)
def add_clause(self, i: int, f: bool, j: int, g: bool):
assert (0 <= i) & (i < self.__n)
assert (0 <= j) & (j < self.__n)
self.__scc.add_edge(2 * i + (1 - f), 2 * j + g)
self.__scc.add_edge(2 * j + (1 - g), 2 * i + f)
def satisfiable(self):
id = self.__scc.scc_ids()[1]
for i in range(self.__n):
if(id[2 * i] == id[2 * i + 1]):
return False
self.__answer[i] = (id[2 * i] < id[2 * i + 1])
return True
def answer(self):
return self.__answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,d = map(int,readline().split())
xy = [list(map(int, i.split())) for i in readlines()]
ts = two_sat(n)
for i in range(n-1):
for j in range(i+1,n):
for ii,jj in zip([0,0,1,1],[0,1,0,1]):
if(abs(xy[i][ii] - xy[j][jj]) < d):
ts.add_clause(i, 1-ii, j, 1-jj)
if(ts.satisfiable()):
print('Yes')
else:
print('No')
exit()
ans = []
for i,tf in enumerate(ts.answer()):
ans.append(xy[i][tf])
print('\n'.join(map(str,ans)))
``` | instruction | 0 | 15,707 | 23 | 31,414 |
Yes | output | 1 | 15,707 | 23 | 31,415 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
import sys
sys.setrecursionlimit(10**7)
class SCC:
def __init__(self,N):
self.N = N
self.graph = [[] for _ in range(N)]
self.graph_rev = [[] for _ in range(N)]
self.flag = [False]*N
def add_edge(self,start,end):
if start == end:
return
self.graph[start].append(end)
self.graph_rev[end].append(start)
def dfs(self,node,graph):
self.flag[node] = True
for n in graph[node]:
if self.flag[n]:
continue
self.dfs(n,graph)
self.order.append(node)
def first_dfs(self):
self.flag = [False]*self.N
self.order = []
for i in range(self.N):
if self.flag[i] == False:
self.dfs(i,self.graph)
def second_dfs(self):
self.flag = [False]*self.N
self.ans = []
for n in reversed(self.order):
if self.flag[n]:
continue
self.flag[n] = True
self.order = []
self.dfs(n,self.graph_rev)
self.order.reverse()
self.ans.append(self.order)
def scc(self):
self.first_dfs()
self.second_dfs()
return self.ans
class Two_SAT():
def __init__(self,N):
self.N = N
self.e = [[] for _ in range(2*N)]
def add_condition(self,start,bool_start,end,bool_end): # start or end という条件を考える
self.e[start*2+(bool_start^1)].append(end*2+bool_end)
self.e[end*2+(bool_end^1)].append(start*2+bool_start)
def satisfiable(self):
scc = SCC(2*self.N)
for i in range(2*self.N):
for j in self.e[i]:
scc.add_edge(i,j)
C = scc.scc()
I = [0]*(2*self.N)
for i in range(len(C)):
for j in C[i]:
I[j] = i
res = [0]*(2*self.N)
for i in range(self.N):
if I[2*i] == I[2*i+1]:
return (False,res)
if I[2*i] < I[2*i+1]:
res[i] = 1
return (True,res)
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,D = MI()
TS = Two_SAT(N)
XY = [tuple(MI()) for _ in range(N)]
for i in range(N-1):
x1,y1 = XY[i]
for j in range(i+1,N):
x2,y2 = XY[j]
if abs(x1-x2) < D:
TS.add_condition(i,1,j,1)
if abs(x1-y2) < D:
TS.add_condition(i,1,j,0)
if abs(y1-x2) < D:
TS.add_condition(i,0,j,1)
if abs(y1-y2) < D:
TS.add_condition(i,0,j,0)
# 0:X,1:Y
bl,sa = TS.satisfiable()
if not bl:
print('No')
else:
print('Yes')
print(*[XY[i][sa[i]] for i in range(N)],sep='\n')
``` | instruction | 0 | 15,708 | 23 | 31,416 |
Yes | output | 1 | 15,708 | 23 | 31,417 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
N,D = map(int,input().split())
XY = [tuple(map(int,input().split())) for i in range(N)]
import sys
sys.setrecursionlimit(10**8)
class Scc:
def __init__(self,n):
self.n = n
self.edges = []
def add_edge(self,fr,to):
assert 0 <= fr < self.n
assert 0 <= to < self.n
self.edges.append((fr, to))
def scc(self):
csr_start = [0] * (self.n + 1)
csr_elist = [0] * len(self.edges)
for fr,to in self.edges:
csr_start[fr + 1] += 1
for i in range(1,self.n+1):
csr_start[i] += csr_start[i-1]
counter = csr_start[:]
for fr,to in self.edges:
csr_elist[counter[fr]] = to
counter[fr] += 1
self.now_ord = self.group_num = 0
self.visited = []
self.low = [0] * self.n
self.ord = [-1] * self.n
self.ids = [0] * self.n
def _dfs(v):
self.low[v] = self.ord[v] = self.now_ord
self.now_ord += 1
self.visited.append(v)
for i in range(csr_start[v], csr_start[v+1]):
to = csr_elist[i]
if self.ord[to] == -1:
_dfs(to)
self.low[v] = min(self.low[v], self.low[to])
else:
self.low[v] = min(self.low[v], self.ord[to])
if self.low[v] == self.ord[v]:
while 1:
u = self.visited.pop()
self.ord[u] = self.n
self.ids[u] = self.group_num
if u==v: break
self.group_num += 1
for i in range(self.n):
if self.ord[i] == -1: _dfs(i)
for i in range(self.n):
self.ids[i] = self.group_num - 1 - self.ids[i]
groups = [[] for _ in range(self.group_num)]
for i in range(self.n):
groups[self.ids[i]].append(i)
return groups
class TwoSat:
def __init__(self,n=0):
self.n = n
self.answer = []
self.scc = Scc(2*n)
def add_clause(self, i:int, f:bool, j:int, g:bool):
assert 0 <= i < self.n
assert 0 <= j < self.n
self.scc.add_edge(2*i + (not f), 2*j + g)
self.scc.add_edge(2*j + (not g), 2*i + f)
def satisfiable(self):
g = self.scc.scc()
for i in range(self.n):
if self.scc.ids[2*i] == self.scc.ids[2*i+1]: return False
self.answer.append(self.scc.ids[2*i] < self.scc.ids[2*i+1])
return True
def get_answer(self):
return self.answer
ts = TwoSat(N)
for i in range(N-1):
xi,yi = XY[i]
for j in range(i+1,N):
xj,yj = XY[j]
if abs(xi - xj) < D:
ts.add_clause(i, False, j, False)
if abs(xi - yj) < D:
ts.add_clause(i, False, j, True)
if abs(yi - xj) < D:
ts.add_clause(i, True, j, False)
if abs(yi - yj) < D:
ts.add_clause(i, True, j, True)
if not ts.satisfiable():
print('No')
exit()
print('Yes')
ans = []
for b,(x,y) in zip(ts.get_answer(), XY):
if b:
ans.append(x)
else:
ans.append(y)
print(*ans, sep='\n')
``` | instruction | 0 | 15,709 | 23 | 31,418 |
Yes | output | 1 | 15,709 | 23 | 31,419 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
import sys
input = sys.stdin.buffer.readline
class StronglyConnectedComponets:
def __init__(self, n: int) -> None:
self.n = n
self.edges = [[] for _ in range(n)]
self.rev_edeges = [[] for _ in range(n)]
self.vs = []
self.order = [0] * n
self.used = [False] * n
def add_edge(self, from_v: int, to_v: int) -> None:
self.edges[from_v].append(to_v)
self.rev_edeges[to_v].append(from_v)
def dfs(self, v: int) -> None:
self.used[v] = True
for child in self.edges[v]:
if not self.used[child]:
self.dfs(child)
self.vs.append(v)
def rdfs(self, v: int, k: int) -> None:
self.used[v] = True
self.order[v] = k
for child in self.rev_edeges[v]:
if not self.used[child]:
self.rdfs(child, k)
def run(self) -> int:
self.used = [False] * self.n
self.vs.clear()
for v in range(self.n):
if not self.used[v]:
self.dfs(v)
self.used = [False] * self.n
k = 0
for v in reversed(self.vs):
if not self.used[v]:
self.rdfs(v, k)
k += 1
return k
class TwoSat(StronglyConnectedComponets):
def __init__(self, num_var: int) -> None:
super().__init__(2 * num_var + 1)
self.num_var = num_var
self.ans = []
def add_constraint(self, a: int, b: int) -> None:
super().add_edge(self._neg(a), self._pos(b))
super().add_edge(self._neg(b), self._pos(a))
def _pos(self, v: int) -> int:
return v if v > 0 else self.num_var - v
def _neg(self, v: int) -> int:
return self.num_var + v if v > 0 else -v
def run(self) -> bool:
super().run()
self.ans.clear()
for i in range(self.num_var):
if self.order[i + 1] == self.order[i + self.num_var + 1]:
return False
self.ans.append(self.order[i + 1] > self.order[i + self.num_var + 1])
return True
def main() -> None:
N, D = map(int, input().split())
flags = [tuple(int(x) for x in input().split()) for _ in range(N)]
# (X_i, Y_i) -> (i, -i) (i=1, ..., N) と考える
sat = TwoSat(N)
# 節 a, b の距離が D 以下の場合,
# a -> -b つまり -a or -b が成立しなければならない
for i, (x_i, y_i) in enumerate(flags, 1):
for j, (x_j, y_j) in enumerate(flags[i:], i+1):
if abs(x_i - x_j) < D:
sat.add_constraint(-i, -j)
if abs(y_i - x_j) < D:
sat.add_constraint(i, -j)
if abs(x_i - y_j) < D:
sat.add_constraint(-i, j)
if abs(y_i - y_j) < D:
sat.add_constraint(i, j)
if sat.run():
print("Yes")
print(*[x_i if sat.ans[i] else y_i for i, (x_i, y_i) in enumerate(flags)], sep="\n")
else:
print("No")
if __name__ == "__main__":
main()
``` | instruction | 0 | 15,710 | 23 | 31,420 |
Yes | output | 1 | 15,710 | 23 | 31,421 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
import networkx as nx
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
N, D = [int(x) for x in input().split()]
XY = [[int(x) for x in input().split()] for i in range(N)]
graph = nx.DiGraph()
# a_i = 0 means choose x, a_i = 1 means choose y
# Store i for a_i==0 and i+N for a_i==1
for i, (x1, y1) in enumerate(XY):
for j in range(N):
if i != j:
x2, y2 = XY[j]
if abs(x1 - x2) < D:
# a_i==0 => a_j==1
graph.add_edge(i, j + N)
if abs(x1 - y2) < D:
# a_i==0 => a_j==0
graph.add_edge(i, j)
if abs(y1 - x2) < D:
# a_i==1 => a_j==1
graph.add_edge(i + N, j + N)
if abs(y1 - y2) < D:
# a_i==1 => a_j==0
graph.add_edge(i + N, j)
SCC = nx.algorithms.components.strongly_connected_components(graph)
assignment = {}
for comp in SCC:
for x in comp:
if (x < N and x + N in comp) or (x >= N and x - N in comp):
print("No")
exit()
if x not in assignment:
assignment[x] = True
assignment[(x + N) % (2 * N)] = False
print("Yes")
for i in range(N):
print(XY[i][0] if assignment[i] else XY[i][1])
``` | instruction | 0 | 15,711 | 23 | 31,422 |
No | output | 1 | 15,711 | 23 | 31,423 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Consider placing N flags on a line. Flags are numbered through 1 to N.
Flag i can be placed on the coordinate X_i or Y_i. For any two different flags, the distance between them should be at least D.
Decide whether it is possible to place all N flags. If it is possible, print such a configulation.
Constraints
* 1 \leq N \leq 1000
* 0 \leq D \leq 10^9
* 0 \leq X_i < Y_i \leq 10^9
* All values in Input are integer.
Input
Input is given from Standard Input in the following format:
N D
X_1 Y_1
X_2 Y_2
\vdots
X_N Y_N
Output
Print `No` if it is impossible to place N flags.
If it is possible, print `Yes` first. After that, print N lines. i-th line of them should contain the coodinate of flag i.
Examples
Input
3 2
1 4
2 5
0 6
Output
Yes
4
2
0
Input
3 3
1 4
2 5
0 6
Output
No
Submitted Solution:
```
from collections import deque
class Graph(): #directed
def __init__(self, n):
self.n = n
self.graph = [set() for _ in range(n)]
self.rev = [set() for _ in range(n)]
self.deg = [0 for _ in range(n)]
def add_edge(self, p, q):
self.graph[p].add(q)
self.rev[q].add(p)
self.deg[q] += 1
def topological_sort(self):
deg = self.deg[:]
res = [i for i in range(self.n) if deg[i] == 0]
queue = deque(res)
used = [False for _ in range(self.n)]
while queue:
node = queue.popleft()
for adj in self.graph[node]:
deg[adj] -= 1
if deg[adj] == 0:
queue.append(adj)
res.append(adj)
return res
def strongry_connected(self):
group = [None for _ in range(self.n)]
used = [0 for _ in range(self.n)]
order = []
for s in range(self.n):
if not used[s]:
stack = [s]
used[s] = 1
while stack:
node = stack.pop()
movable = False
for adj in self.graph[node]:
if not used[adj]:
movable = True
used[adj] = 1
stack.append(node)
stack.append(adj)
break
if not movable:
order.append(node)
used = [0 for _ in range(self.n)]
count = 0
for s in order[::-1]:
if not used[s]:
stack = [s]
group[s] = count
while stack:
node = stack.pop()
used[node] = 1
for adj in self.rev[node]:
if not used[adj]:
group[adj] = count
stack.append(adj)
count += 1
return group, count
import sys
input = sys.stdin.buffer.readline
N, D = map(int, input().split())
X = []
Y = []
g = Graph(2 * N)
for _ in range(N):
x, y = map(int, input().split())
X.append(x)
Y.append(y)
for i in range(N - 1):
for j in range(i + 1, N):
if abs(X[i] - X[j]) < D:
g.add_edge(i, ~j)
g.add_edge(j, ~i)
if abs(X[i] - Y[j]) < D:
g.add_edge(i, ~j)
g.add_edge(~j, i)
if abs(Y[i] - X[i]) < D:
g.add_edge(~i, j)
g.add_edge(j, ~i)
if abs(Y[i] - Y[j]) < D:
g.add_edge(~i, j)
g.add_edge(~j, i)
group, count = g.strongry_connected()
group_to_node = [[] for _ in range(count)]
for i in range(N):
if group[i] == group[~i]:
print('No')
break
group_to_node[group[i]].append(i)
group_to_node[group[~i]].append(~i)
else:
print('Yes')
comp = Graph(count)
for i in range(2 * N):
for j in g.graph[i]:
if group[i] == group[j]:
continue
comp.add_edge(group[i], group[j])
ts = comp.topological_sort()
res = [None for _ in range(N)]
for i in ts:
for node in group_to_node[i]:
if node >= 0:
if res[node] is None:
res[node] = Y[node]
else:
if res[~node] is None:
res[~node] = X[~node]
for i in range(N):
if res[i] is None:
res[i] = Y[node]
print('\n'.join(map(str, res)))
``` | instruction | 0 | 15,712 | 23 | 31,424 |
No | output | 1 | 15,712 | 23 | 31,425 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,732 | 23 | 31,464 |
"Correct Solution:
```
n=int(input())
if n%3==0:
for i in range(n//3):
print("a.."*(n//3))
print("a.."*(n//3))
print(".aa"*(n//3))
elif n%2==0 and n>=4:
x="aacd"+"."*(n-4)
y="bbcd"+"."*(n-4)
for i in range(n//2):
print(x)
print(y)
x=x[2:]+x[:2]
y=y[2:]+y[:2]
elif n>=13:
x="aacd"+"."*(n-13)
y="bbcd"+"."*(n-13)
for i in range((n-9)//2):
print(x+"."*9)
print(y+"."*9)
x=x[2:]+x[:2]
y=y[2:]+y[:2]
for i in range(3):
print("."*(n-9)+"a..a..a..")
print("."*(n-9)+"a..a..a..")
print("."*(n-9)+".aa.aa.aa")
elif n==5:
print("aabba")
print("bc..a")
print("bc..b")
print("a.ddb")
print("abbaa")
elif n==7:
print("aabbcc.")
print("dd.dd.a")
print("..e..ea")
print("..e..eb")
print("dd.dd.b")
print("..e..ec")
print("..e..ec")
elif n==11:
print("aabbcc.....")
print("dd.dd.a....")
print("..e..ea....")
print("..e..eb....")
print("dd.dd.b....")
print("..e..ec....")
print("..e..ec....")
print(".......aacd")
print(".......bbcd")
print(".......cdaa")
print(".......cdbb")
else:
print(-1)
``` | output | 1 | 15,732 | 23 | 31,465 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,733 | 23 | 31,466 |
"Correct Solution:
```
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
n = int(input())
pata = ["abb",
"a.c",
"ddc"]
patb = ["abcc",
"abdd",
"eefg",
"hhfg"]
patc = ["abbcc",
"ad..e",
"fd..e",
"f.ggh",
"iijjh"]
patd = [".aabbcc",
"a.ddee.",
"ad....d",
"bd....d",
"be....e",
"ce....e",
"c.ddee."]
pate = [".aabbcc....",
"a.ddee.....",
"ad....d....",
"bd....d....",
"be....e....",
"ce....e....",
"c.ddee.....",
".......abcc",
".......abdd",
".......ccab",
".......ddab"]
cnt = 0
def create_ab(w):
val = [["."] * w for _ in range(w)]
ok = False
for fives in range(200):
if (w - fives * 5) % 4 == 0:
fours = (w - fives * 5) // 4
if fours >= 0:
ok = True
break
if not ok:
return None
t = 0
for i in range(fives):
for i, line in enumerate(patc):
for j, ch in enumerate(line):
val[t+i][t+j] = ch
t += 5
for i in range(fours):
for i, line in enumerate(patb):
for j, ch in enumerate(line):
val[t+i][t+j] = ch
t += 4
ret = []
for line in val:
ret.append("".join([str(item) for item in line]))
return ret
def solve(n):
global cnt
if n % 3 == 0:
repeat = n // 3
for i in range(repeat):
for line in pata:
print(line * repeat)
elif n % 4 == 0:
repeat = n // 4
for i in range(repeat):
for line in patb:
print(line * repeat)
elif n % 5 == 0:
repeat = n // 5
for i in range(repeat):
for line in patc:
print(line * repeat)
elif n % 7 == 0:
repeat = n // 7
for i in range(repeat):
for line in patd:
print(line * repeat)
elif n % 11 == 0:
repeat = n // 11
for i in range(repeat):
for line in pate:
print(line * repeat)
else:
ret = create_ab(n)
if ret:
for line in ret:
print(line)
else:
cnt += 1
print(-1)
solve(n)
``` | output | 1 | 15,733 | 23 | 31,467 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,734 | 23 | 31,468 |
"Correct Solution:
```
n = int(input())
if n == 2:
print(-1)
if n == 3:
print("aa.")
print("..b")
print("..b")
if n == 4:
ans = ["aabc","ddbc","bcaa","bcdd"]
print(*ans,sep="\n")
if n == 5:
ans = ["aabbc","dde.c","..eab","a..ab","accdd"]
print(*ans,sep="\n")
if n == 6:
ans = ["aa.bbc","..de.c","..deff","aabcc.","d.b..a","dcc..a"]
print(*ans,sep="\n")
if n == 7:
ans = ["aab.cc.","..bd..e","ff.d..e","..g.hhi","..gj..i","kllj...","k..mmnn"]
print(*ans,sep="\n")
if n >= 8:
ans = [["." for i in range(n)] for j in range(n)]
ch = [list("aabc"),list("ddbc"),list("bcaa"),list("bcdd")]
x = n//4-1
y = n%4+4
for i in range(x):
for j in range(4):
for k in range(4):
ans[i*4+j][i*4+k] = ch[j][k]
if y == 4:
for j in range(4):
for k in range(4):
ans[x*4+j][x*4+k] = ch[j][k]
elif y == 5:
ch2 = ["aabbc","dde.c","..eab","a..ab","accdd"]
for j in range(5):
for k in range(5):
ans[x*4+j][x*4+k] = ch2[j][k]
elif y == 6:
ch2 = ["aa.bbc","..de.c","..deff","aabcc.","d.b..a","dcc..a"]
for j in range(6):
for k in range(6):
ans[x*4+j][x*4+k] = ch2[j][k]
elif y == 7:
ch2 = ["aab.cc.","..bd..e","ff.d..e","..g.hhi","..gj..i","kllj...","k..mmnn"]
for j in range(7):
for k in range(7):
ans[x*4+j][x*4+k] = ch2[j][k]
for row in ans:
print(*row,sep="")
``` | output | 1 | 15,734 | 23 | 31,469 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,735 | 23 | 31,470 |
"Correct Solution:
```
def GCD(x,y):
if y == 0:
return x
else:
return GCD(y,x%y)
N = int(input())
if N == 2:
print(-1)
exit()
if N == 7:
ans = [".aabbcc",
"c..ddee",
"c..ffgg",
"hij....",
"hij....",
"klm....",
"klm...."]
for i in ans:
print("".join(i))
exit()
if N == 3:
print(".aa")
print("a..")
print("a..")
exit()
four = ["aacd",
"bbcd",
"efgg",
"efhh"]
five = ["aabbc",
"h.iic",
"hj..d",
"gj..d",
"gffee"]
six = ["aacd..",
"bbcd..",
"ef..gg",
"ef..hh",
"..iikl",
"..jjkl"]
ans = [list("."*N) for i in range(N)]
a,b,c = [[0,N//5,0],[0,N//5-1,1],[0,N//5-2,2],[2,N//5-1,0],[1,N//5,0]][N%5]
p = 0
for i in range(a):
for x in range(4):
for y in range(4):
ans[p+x][p+y] = four[x][y]
p += 4
for i in range(b):
for x in range(5):
for y in range(5):
ans[p+x][p+y] = five[x][y]
p += 5
for i in range(c):
for x in range(6):
for y in range(6):
ans[p+x][p+y] = six[x][y]
p += 6
for i in ans:
print("".join(i))
``` | output | 1 | 15,735 | 23 | 31,471 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,736 | 23 | 31,472 |
"Correct Solution:
```
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())
#n, op = [i for i in readline().split()]
a21 = [["a","a"],["b","b"]]
a22 = [["c","d"],["c","d"]]
a3 = [["a","a","."],[".",".","b"],[".",".","b"]]
a4 = [["q","q","r","s"],["t","t","r","s"],["u","x","v","v"],["u","x","w","w"]]
a5 = [["c","c","d","d","l"],["e","f","f",".","l"],["e",".",".","h","g"],["i",".",".","h","g"],["i","j","j","k","k"]]
a7 = [["c","c","d","d",".",".","e"],[".","f","f",".",".","g","e"],[".",".","h","h",".","g","i"],["j",".",".",".","k",".","i"],["j","l",".",".","k",".","."],["m","l",".",".","n","n","."],["m",".",".","o","o","p","p"]]
if n == 2: print(-1)
else:
if n == 3:
ans = a3
elif n%2 == 0:
ans = [["."]*n for i in range(n)]
for i in range(n//2):
for j in range(2):
for k in range(2):
ans[2*i+j][2*i+k] = a21[j][k]
for i in range(n//2):
for j in range(2):
for k in range(2):
ans[2+2*i+j-n][2*i+k] = a22[j][k]
elif n%4==1:
ans = [["."]*n for i in range(n)]
for i in range(5):
for j in range(5):
ans[i][j] = a5[i][j]
for i in range((n-5)//2):
for j in range(2):
for k in range(2):
ans[5+2*i+j][5+2*i+k] = a21[j][k]
for i in range((n-5)//2):
for j in range(2):
for k in range(2):
c = 5+2+2*i+j
d = 5+2*i+k
if c >= n:
c = 5+j
ans[c][d] = a22[j][k]
elif n%4==3:
ans = [["."]*n for i in range(n)]
for i in range(7):
for j in range(7):
ans[i][j] = a7[i][j]
for i in range((n-7)//2):
for j in range(2):
for k in range(2):
ans[7+2*i+j][7+2*i+k] = a21[j][k]
for i in range((n-7)//2):
for j in range(2):
for k in range(2):
c = 7+2+2*i+j
d = 7+2*i+k
if c >= n:
c = 7+j
ans[c][d] = a22[j][k]
for i in ans:
print(*i,sep="")
``` | output | 1 | 15,736 | 23 | 31,473 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,737 | 23 | 31,474 |
"Correct Solution:
```
n = int(input())
if n % 3 == 0:
m = n // 3
for i in range(m):
print('.' * (3 * i) + 'abb' + '.' * (n - 3 - 3 * i))
print('.' * (3 * i) + 'a.a' + '.' * (n - 3 - 3 * i))
print('.' * (3 * i) + 'bba' + '.' * (n - 3 - 3 * i))
elif n % 4 == 0:
m = n // 4
for i in range(m):
print('.' * (4 * i) + 'abaa' + '.' * (n - 4 - 4 * i))
print('.' * (4 * i) + 'abcc' + '.' * (n - 4 - 4 * i))
print('.' * (4 * i) + 'ccba' + '.' * (n - 4 - 4 * i))
print('.' * (4 * i) + 'aaba' + '.' * (n - 4 - 4 * i))
else:
if n % 3 == 1:
if n >= 10:
print('abaa' + '.' * (n - 4))
print('abcc' + '.' * (n - 4))
print('ccba' + '.' * (n - 4))
print('aaba' + '.' * (n - 4))
m = (n - 4) // 3
for i in range(m):
if i == m - 1:
print('.' * 4 + 'dd.' + '.' * (n - 10) + 'abb')
print('.' * 4 + '..d' + '.' * (n - 10) + 'a.a')
print('.' * 4 + '..d' + '.' * (n - 10) + 'bba')
else:
print('.' * (4 + 3 * i) + 'abbdd.' + '.' * (n - 10 - 3 * i))
print('.' * (4 + 3 * i) + 'a.a..d' + '.' * (n - 10 - 3 * i))
print('.' * (4 + 3 * i) + 'bba..d' + '.' * (n - 10 - 3 * i))
elif n == 7:
print('a.aa..a')
print('ab....a')
print('.b..aab')
print('aabb..b')
print('.b.aacc')
print('aba....')
print('a.a.aa.')
else: # n == 4
print('abaa')
print('abcc')
print('ccba')
print('aaba')
elif n % 3 == 2:
if n >= 14:
m = (n - 8) // 3
print('abaa' + '.' * (n - 4))
print('abcc' + '.' * (n - 4))
print('ccba' + '.' * (n - 4))
print('aaba' + '.' * (n - 4))
print('....abaa' + '.' * (n - 8))
print('....abcc' + '.' * (n - 8))
print('....ccba' + '.' * (n - 8))
print('....aaba' + '.' * (n - 8))
m = (n - 8) // 3
for i in range(m):
if i == m - 1:
print('.' * 8 + 'dd.' + '.' * (n - 14) + 'abb')
print('.' * 8 + '..d' + '.' * (n - 14) + 'a.a')
print('.' * 8 + '..d' + '.' * (n - 14) + 'bba')
else:
print('.' * (8 + 3 * i) + 'abbdd.' + '.' * (n - 14 - 3 * i))
print('.' * (8 + 3 * i) + 'a.a..d' + '.' * (n - 14 - 3 * i))
print('.' * (8 + 3 * i) + 'bba..d' + '.' * (n - 14 - 3 * i))
elif n == 11:
print('a.aa..a' + '....')
print('ab....a' + '....')
print('.b..aab' + '....')
print('aabb..b' + '....')
print('.b.aacc' + '....')
print('aba....' + '....')
print('a.a.aa.' + '....')
print('.' * 7 + 'abaa')
print('.' * 7 + 'abcc')
print('.' * 7 + 'ccba')
print('.' * 7 + 'aaba')
elif n == 8:
print('abaa....')
print('abcc....')
print('ccba....')
print('aaba....')
print('....abaa')
print('....abcc')
print('....ccba')
print('....aaba')
elif n == 5:
print('abbaa')
print('a..bc')
print('bb.bc')
print('a.aab')
print('abb.b')
else:
print(-1)
``` | output | 1 | 15,737 | 23 | 31,475 |
Provide a correct Python 3 solution for this coding contest problem.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1 | instruction | 0 | 15,738 | 23 | 31,476 |
"Correct Solution:
```
def join(xs, N):
n = len(xs)
r = ""
s = 0
for i, x in enumerate(xs):
x = x.strip()
t = len(x.split())
S,E="."*s,"."*(N-t-s)
for l in x.split():
r+=S+l+E+"\n"
s += t
return r
s7="""
.bc.a..
.bc.a..
..aabba
aab...a
x.baa..
x..b.aa
aa.b.xx
"""
s6="""
..aabx
d...bx
dla...
.lab..
xx.bxx
ddaall"""
s5="""
aa.bx
d..bx
dee.a
i.rra
ijjxx
"""
s4="""
xyzz
xyrr
zzxy
rrxy"""
s3="""
jj.
..j
..j"""
s=[s4,s5,s6,s7]
N=int(input())
if N<3:
print(-1)
elif N==3:
print(s3.strip())
elif N<=7:
print(s[N-4].strip())
else:
print(join([s[0]]*(N//4-1)+[s[N%4]],N))
``` | output | 1 | 15,738 | 23 | 31,477 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
n = int(input())
s3=["abb","a.d","ccd"]
s = [["abcc", "abdd", "ddba", "ccba"],
["dccdd", "daa.c", "c..bc", "c..bd", "ddccd"],
["abbc..", "a.ac..", "bba.cc", "a..aab", "a..b.b", ".aabaa"],
["aba....","aba....","bab....","bab....","a..bbaa","a..aabb",".aabbaa"]]
if n == 2:
print(-1)
elif n == 3:
[print(x) for x in s3]
else:
d, m = divmod(n, 4)
d -= 1
m += 4
for i in range(d):
[print("." * 4 * i + x + "." * (4 * (d - i - 1) + m)) for x in s[0]]
[print("." * 4 * d + x) for x in s[m - 4]]
``` | instruction | 0 | 15,739 | 23 | 31,478 |
Yes | output | 1 | 15,739 | 23 | 31,479 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
import sys
n=int(input())
if n==2:
print(-1)
sys.exit()
if n==3:
print('aa.')
print('..a')
print('..a')
sys.exit()
x=(n//4)-1
y=(n%4)+4
l=[[['a','a','b','c'],['d','d','b','c'],['b','c','a','a'],['b','c','d','d']],[['a','a','b','b','a'],['b','c','c','.','a'],['b','.','.','c','b'],['a','.','.','c','b'],['a','b','b','a','a']],[['a','a','b','c','.','.'],['d','d','b','c','.','.'],['.','.','a','a','b','c'],['.','.','d','d','b','c'],['b','c','.','.','a','a'],['b','c','.','.','d','d']],[['a','a','b','b','c','c','.'],['d','d','.','d','d','.','a'],['.','.','d','.','.','d','a'],['.','.','d','.','.','d','b'],['d','d','.','d','d','.','b'],['.','.','d','.','.','d','c'],['.','.','d','.','.','d','c']]]
if n<8:
for i in range(n):
print(''.join(l[n-4][i]))
sys.exit()
ans=[]
for i in range(n):
ans1=['.']*n
ans.append(ans1)
for i in range(x):
for j in range(4):
for k in range(4):
ans[i*4+j][i*4+k]=l[0][j][k]
for j in range(y):
for k in range(y):
ans[x*4+j][x*4+k]=l[y-4][j][k]
for i in range(n):
print(''.join(ans[i]))
``` | instruction | 0 | 15,740 | 23 | 31,480 |
Yes | output | 1 | 15,740 | 23 | 31,481 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
n=int(input())
if n==2:
print(-1)
else:
x=[]
if n%3==0:
for i in range(n//3):
x.append("."*(3*i)+"a"+"."*(n-3*i-1))
x.append("."*(3*i)+"a"+"."*(n-3*i-1))
x.append("."*(3*i)+".aa"+"."*(n-3*i-3))
elif n%6==1:
for i in range(n//6-1):
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
x.append("."*(n-7)+".aab.c.")
x.append("."*(n-7)+"d..b.c.")
x.append("."*(n-7)+"d..eeff")
x.append("."*(n-7)+"g..mm.l")
x.append("."*(n-7)+"gnn...l")
x.append("."*(n-7)+"h...kkj")
x.append("."*(n-7)+"hii...j")
elif n%6==2:
for i in range(n//6-1):
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
x.append("."*(n-8)+".a.bb.cc")
x.append("."*(n-8)+".a...m.j")
x.append("."*(n-8)+"..pp.m.j")
x.append("."*(n-8)+"hh..i.o.")
x.append("."*(n-8)+"gg..i.o.")
x.append("."*(n-8)+"..n.ll.k")
x.append("."*(n-8)+"f.n....k")
x.append("."*(n-8)+"f.dd.ee.")
elif n%6==4:
for i in range(n//6):
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
x.append("."*(n-4)+"aacb")
x.append("."*(n-4)+"ffcb")
x.append("."*(n-4)+"hgdd")
x.append("."*(n-4)+"hgee")
else:
for i in range(n//6):
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+".a.b.c"+"."*(n-6*i-6))
x.append("."*(6*i)+"ddg.ll"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.g.kk"+"."*(n-6*i-6))
x.append("."*(6*i)+"e.hhj."+"."*(n-6*i-6))
x.append("."*(6*i)+"ffiij."+"."*(n-6*i-6))
x.append("."*(n-5)+"aabbc")
x.append("."*(n-5)+"g.h.c")
x.append("."*(n-5)+"gjh..")
x.append("."*(n-5)+"dj.ii")
x.append("."*(n-5)+"deeff")
for i in range(n):
print("".join(x[i]))
#また出力が違うやつをやりましたが
``` | instruction | 0 | 15,741 | 23 | 31,482 |
Yes | output | 1 | 15,741 | 23 | 31,483 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
n = int(input())
if n % 3 == 0:
m = n // 3
for i in range(m):
print('.' * (3 * i) + 'abb' + '.' * (n - 3 - 3 * i))
print('.' * (3 * i) + 'a.a' + '.' * (n - 3 - 3 * i))
print('.' * (3 * i) + 'bba' + '.' * (n - 3 - 3 * i))
else:
if n % 3 == 1:
if n >= 10:
print('abaa' + '.' * (n - 4))
print('abcc' + '.' * (n - 4))
print('ccba' + '.' * (n - 4))
print('aaba' + '.' * (n - 4))
m = (n - 4) // 3
for i in range(m):
if i == m - 1:
print('.' * 4 + 'dd.' + '.' * (n - 10) + 'abb')
print('.' * 4 + '..d' + '.' * (n - 10) + 'a.a')
print('.' * 4 + '..d' + '.' * (n - 10) + 'bba')
else:
print('.' * (4 + 3 * i) + 'abbdd.' + '.' * (n - 10 - 3 * i))
print('.' * (4 + 3 * i) + 'a.a..d' + '.' * (n - 10 - 3 * i))
print('.' * (4 + 3 * i) + 'bba..d' + '.' * (n - 10 - 3 * i))
elif n == 7:
print('a.aa..a')
print('ab....a')
print('.b..aab')
print('aabb..b')
print('.b.aacc')
print('aba....')
print('a.a.aa.')
else: # n == 4
print('abaa')
print('abcc')
print('ccba')
print('aaba')
elif n % 3 == 2:
if n >= 14:
m = (n - 8) // 3
print('abaa' + '.' * (n - 4))
print('abcc' + '.' * (n - 4))
print('ccba' + '.' * (n - 4))
print('aaba' + '.' * (n - 4))
print('....abaa' + '.' * (n - 8))
print('....abcc' + '.' * (n - 8))
print('....ccba' + '.' * (n - 8))
print('....aaba' + '.' * (n - 8))
m = (n - 8) // 3
for i in range(m):
if i == m - 1:
print('.' * 8 + 'dd.' + '.' * (n - 14) + 'abb')
print('.' * 8 + '..d' + '.' * (n - 14) + 'a.a')
print('.' * 8 + '..d' + '.' * (n - 14) + 'bba')
else:
print('.' * (8 + 3 * i) + 'abbdd.' + '.' * (n - 14 - 3 * i))
print('.' * (8 + 3 * i) + 'a.a..d' + '.' * (n - 14 - 3 * i))
print('.' * (8 + 3 * i) + 'bba..d' + '.' * (n - 14 - 3 * i))
elif n == 11:
print('a.aa..a' + '....')
print('ab....a' + '....')
print('.b..aab' + '....')
print('aabb..b' + '....')
print('.b.aacc' + '....')
print('aba....' + '....')
print('a.a.aa.' + '....')
print('.' * 7 + 'abaa')
print('.' * 7 + 'abcc')
print('.' * 7 + 'ccba')
print('.' * 7 + 'aaba')
elif n == 8:
print('abaa....')
print('abcc....')
print('ccba....')
print('aaba....')
print('....abaa')
print('....abcc')
print('....ccba')
print('....aaba')
elif n == 5:
print('abbaa')
print('a..bc')
print('bb.bc')
print('a.aab')
print('abb.b')
else:
print(-1)
``` | instruction | 0 | 15,742 | 23 | 31,484 |
Yes | output | 1 | 15,742 | 23 | 31,485 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
N=int(input())
if N%3==0:
a=["aa."]*(N//3)
b=["..b"]*(N//3)
for i in range(N//3):
print("".join(a))
print("".join(b))
print("".join(b))
else:
print(-1)
``` | instruction | 0 | 15,743 | 23 | 31,486 |
No | output | 1 | 15,743 | 23 | 31,487 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
N = int(input())
ans = [['.']*N for i in range(N)]
if N%3==0:
for i in range(N//3):
ans[i*3][i*3] = 'a'
ans[i*3][i*3+1] = 'a'
ans[i*3][i*3+2] = 'b'
ans[i*3+1][i*3+2] = 'b'
ans[i*3+2][i*3+2] = 'a'
ans[i*3+2][i*3+1] = 'a'
ans[i*3+2][i*3] = 'b'
ans[i*3+1][i*3] = 'b'
for row in ans:
print(''.join(row))
exit()
x = 0
while x <= N:
y = N-x
if y%2==0 and y != 2:
if (y//2)%2:
q = (y-2)//4*3
else:
q = y//4*3
if x==0 or (q%2==0 and q <= x*2//3):
break
x += 3
else:
print(-1)
exit()
if (y//2)%2 == 0:
for i in range(y//2):
for j in range(y//2):
if (i+j)%2==0:
ans[i*2][j*2] = 'a'
ans[i*2][j*2+1] = 'a'
ans[i*2+1][j*2] = 'b'
ans[i*2+1][j*2+1] = 'b'
else:
ans[i*2][j*2] = 'c'
ans[i*2][j*2+1] = 'd'
ans[i*2+1][j*2] = 'c'
ans[i*2+1][j*2+1] = 'd'
else:
for i in range(y//2):
for j in range(y//2):
if i==j: continue
if i<j:
if (i+j)%2==0:
ans[i*2][j*2] = 'a'
ans[i*2][j*2+1] = 'a'
ans[i*2+1][j*2] = 'b'
ans[i*2+1][j*2+1] = 'b'
else:
ans[i*2][j*2] = 'c'
ans[i*2][j*2+1] = 'd'
ans[i*2+1][j*2] = 'c'
ans[i*2+1][j*2+1] = 'd'
else:
if (i+j)%2==0:
ans[i*2][j*2] = 'c'
ans[i*2][j*2+1] = 'd'
ans[i*2+1][j*2] = 'c'
ans[i*2+1][j*2+1] = 'd'
else:
ans[i*2][j*2] = 'a'
ans[i*2][j*2+1] = 'a'
ans[i*2+1][j*2] = 'b'
ans[i*2+1][j*2+1] = 'b'
z = x//3
for i in range(z):
for j in range(i, i+q//2):
j %= z
ans[y+i*3][y+j*3] = 'a'
ans[y+i*3][y+j*3+1] = 'a'
ans[y+i*3][y+j*3+2] = 'b'
ans[y+i*3+1][y+j*3+2] = 'b'
ans[y+i*3+2][y+j*3+2] = 'a'
ans[y+i*3+2][y+j*3+1] = 'a'
ans[y+i*3+2][y+j*3] = 'b'
ans[y+i*3+1][y+j*3] = 'b'
for row in ans:
print(''.join(row))
``` | instruction | 0 | 15,744 | 23 | 31,488 |
No | output | 1 | 15,744 | 23 | 31,489 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
N = int(input())
if N % 3 != 0:
print(-1)
else:
for i in range(N // 3):
line = "aa." * (N // 3)
print(line)
line = "..b" * (N // 3)
print(line)
print(line)
``` | instruction | 0 | 15,745 | 23 | 31,490 |
No | output | 1 | 15,745 | 23 | 31,491 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Let us consider a grid of squares with N rows and N columns. You want to put some domino pieces on this grid. Each domino piece covers two squares that have a common side. Each square can be covered by at most one piece.
For each row of the grid, let's define its quality as the number of domino pieces that cover at least one square in this row. We define the quality of each column similarly.
Find a way to put at least one domino piece on the grid so that the quality of every row is equal to the quality of every column, or determine that such a placement doesn't exist.
Constraints
* 2 \le N \le 1000
Input
Input is given from Standard Input in the following format:
N
Output
If the required domino placement doesn't exist, print a single integer `-1`.
Otherwise, output your placement as N strings of N characters each. If a square is not covered, the corresponding character must be `.` (a dot). Otherwise, it must contain a lowercase English letter. Squares covered by the same domino piece must contain the same letter. If two squares have a common side but belong to different pieces, they must contain different letters.
Examples
Input
6
Output
aabb..
b..zz.
ba....
.a..aa
..a..b
..a..b
Input
2
Output
-1
Submitted Solution:
```
#
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A):
for a in A: print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
N=I()
if N%3!=0:
if N%4:
print(-1)
return
if N%4==0:
ans = [["."]*N for _ in range(N)]
for i in range(N):
base = (i//4)*4
if i%4==0:
ans[i][base]="a"
ans[i][base+1]="a"
ans[i][base+2]="c"
ans[i][base+3]="d"
elif i%4==1:
ans[i][base]="b"
ans[i][base+1]="b"
ans[i][base+2]="c"
ans[i][base+3]="d"
elif i%4==2:
ans[i][base]="c"
ans[i][base+1]="d"
ans[i][base+2]="a"
ans[i][base+3]="a"
else:
ans[i][base]="c"
ans[i][base+1]="d"
ans[i][base+2]="b"
ans[i][base+3]="b"
for a in ans:
print(*a,sep="")
return
ans = [["."]*N for _ in range(N)]
for i in range(N):
base = (i//3)*3
if i%3==0:
ans[i][base]="a"
elif i%3==1:
ans[i][base]="a"
else:
ans[i][base+1]="a"
ans[i][base+2]="a"
for a in ans:
print(*a,sep="")
if __name__ == '__main__':
main()
``` | instruction | 0 | 15,746 | 23 | 31,492 |
No | output | 1 | 15,746 | 23 | 31,493 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are several rectangular sheets placed on a flat surface. Create a program to find the area and perimeter of the part covered by these sheets.
However, when the plane is regarded as the coordinate plane, the arrangement of the sheets shall satisfy the following conditions (1) and (2).
(1) The x and y coordinates of the four vertices of the rectangle on each sheet are all integers from 0 to 10000, and each side of the rectangle is parallel to the x-axis or y-axis.
(2) The number of sheets is at most 10,000 or less.
The number n of rectangles and the integer r indicating the type of problem are separated by a space in the first line of the input data. In each line after the second line, the coordinates of the lower left vertex of each sheet (x1, y1) and The coordinates of the upper right vertex coordinates (x2, y2) are written in the order of x1, y1, x2, y2, separated by a blank.
The output outputs the area on the first line when r = 1, the area on the first line when r = 2, and the perimeter on the second line. In either case, insert a line break at the end.
In 40% of the test data, the coordinates of the vertices of the rectangle are 0 or more and 100 or less, and 1/2 of them is the problem of finding only the area. Furthermore, 1/2 of the whole is the problem of finding only the area.
Input Example 1 | Input Example 2 | Input Example 3 | Input Example 4
--- | --- | --- | ---
|
5 1 | 5 2 | 2 2 | 3 2
0 0 3 2 | 0 0 3 2 | 0 0 8 9 | 2 2 8 8
1 1 2 5 | 1 1 2 5 | 0 0 9 8 | 3 0 4 9
0 4 6 5 | 0 4 6 5 | | 5 0 7 9
3 3 5 6 | 3 3 5 6 | |
5 0 7 6 | 5 0 7 6 | |
Output example 1 | Output example 2 | Output example 3 | Output example 4
29 | 29 | 80 | 45
38 | 36 | 36
input
The input consists of multiple datasets. Input ends when both n and r are 0. The number of datasets does not exceed 10.
output
For each dataset, the area is output on the first line when r = 1, the area is output on the first line when r = 2, and the perimeter is output on the second line.
Example
Input
5 1
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
5 2
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
2 2
0 0 8 9
0 0 9 8
3 2
2 2 8 8
3 0 4 9
5 0 7 9
0 0
Output
29
29
38
80
36
45
36
Submitted Solution:
```
while True:
n, r = map(int, input().split())
if not n:
break
sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
table_c = [0] * 10001
table_r = [0] * 10001
table_e = [0] * 10001
for x1, y1, x2, y2 in sheets:
for y in range(y1, y2):
rx = table_r[y]
if rx < x1 or not rx:
table_c[y] += x2 - x1
table_r[y] = x2
table_e[y] += 2
elif rx < x2:
table_c[y] += x2 - rx
table_r[y] = x2
print(sum(table_c))
if r == 1:
continue
around = 0
prev_w = 0
for y, w in enumerate(table_c):
around += abs(w - prev_w) + (table_e[y] if w else 0)
prev_w = w
around += prev_w
print(around)
``` | instruction | 0 | 15,875 | 23 | 31,750 |
No | output | 1 | 15,875 | 23 | 31,751 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are several rectangular sheets placed on a flat surface. Create a program to find the area and perimeter of the part covered by these sheets.
However, when the plane is regarded as the coordinate plane, the arrangement of the sheets shall satisfy the following conditions (1) and (2).
(1) The x and y coordinates of the four vertices of the rectangle on each sheet are all integers from 0 to 10000, and each side of the rectangle is parallel to the x-axis or y-axis.
(2) The number of sheets is at most 10,000 or less.
The number n of rectangles and the integer r indicating the type of problem are separated by a space in the first line of the input data. In each line after the second line, the coordinates of the lower left vertex of each sheet (x1, y1) and The coordinates of the upper right vertex coordinates (x2, y2) are written in the order of x1, y1, x2, y2, separated by a blank.
The output outputs the area on the first line when r = 1, the area on the first line when r = 2, and the perimeter on the second line. In either case, insert a line break at the end.
In 40% of the test data, the coordinates of the vertices of the rectangle are 0 or more and 100 or less, and 1/2 of them is the problem of finding only the area. Furthermore, 1/2 of the whole is the problem of finding only the area.
Input Example 1 | Input Example 2 | Input Example 3 | Input Example 4
--- | --- | --- | ---
|
5 1 | 5 2 | 2 2 | 3 2
0 0 3 2 | 0 0 3 2 | 0 0 8 9 | 2 2 8 8
1 1 2 5 | 1 1 2 5 | 0 0 9 8 | 3 0 4 9
0 4 6 5 | 0 4 6 5 | | 5 0 7 9
3 3 5 6 | 3 3 5 6 | |
5 0 7 6 | 5 0 7 6 | |
Output example 1 | Output example 2 | Output example 3 | Output example 4
29 | 29 | 80 | 45
38 | 36 | 36
input
The input consists of multiple datasets. Input ends when both n and r are 0. The number of datasets does not exceed 10.
output
For each dataset, the area is output on the first line when r = 1, the area is output on the first line when r = 2, and the perimeter is output on the second line.
Example
Input
5 1
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
5 2
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
2 2
0 0 8 9
0 0 9 8
3 2
2 2 8 8
3 0 4 9
5 0 7 9
0 0
Output
29
29
38
80
36
45
36
Submitted Solution:
```
while True:
n, r = map(int, input().split())
if not n:
break
sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
table_c = [0] * 10001
table_r = [0] * 10001
table_e = [0] * 10001
for x1, y1, x2, y2 in sheets:
for y in range(y1, y2):
rx = table_r[y]
if not rx or rx < x1:
table_c[y] += x2 - x1
table_r[y] = x2
table_e[y] += 2
elif rx < x2:
table_c[y] += x2 - rx
table_r[y] = x2
print(sum(table_c))
if r == 1:
continue
around = 0
prev_w = 0
for y, w in enumerate(table_c):
around += abs(w - prev_w) + (table_e[y] if w else 0)
prev_w = w
around += prev_w
print(around)
``` | instruction | 0 | 15,876 | 23 | 31,752 |
No | output | 1 | 15,876 | 23 | 31,753 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are several rectangular sheets placed on a flat surface. Create a program to find the area and perimeter of the part covered by these sheets.
However, when the plane is regarded as the coordinate plane, the arrangement of the sheets shall satisfy the following conditions (1) and (2).
(1) The x and y coordinates of the four vertices of the rectangle on each sheet are all integers from 0 to 10000, and each side of the rectangle is parallel to the x-axis or y-axis.
(2) The number of sheets is at most 10,000 or less.
The number n of rectangles and the integer r indicating the type of problem are separated by a space in the first line of the input data. In each line after the second line, the coordinates of the lower left vertex of each sheet (x1, y1) and The coordinates of the upper right vertex coordinates (x2, y2) are written in the order of x1, y1, x2, y2, separated by a blank.
The output outputs the area on the first line when r = 1, the area on the first line when r = 2, and the perimeter on the second line. In either case, insert a line break at the end.
In 40% of the test data, the coordinates of the vertices of the rectangle are 0 or more and 100 or less, and 1/2 of them is the problem of finding only the area. Furthermore, 1/2 of the whole is the problem of finding only the area.
Input Example 1 | Input Example 2 | Input Example 3 | Input Example 4
--- | --- | --- | ---
|
5 1 | 5 2 | 2 2 | 3 2
0 0 3 2 | 0 0 3 2 | 0 0 8 9 | 2 2 8 8
1 1 2 5 | 1 1 2 5 | 0 0 9 8 | 3 0 4 9
0 4 6 5 | 0 4 6 5 | | 5 0 7 9
3 3 5 6 | 3 3 5 6 | |
5 0 7 6 | 5 0 7 6 | |
Output example 1 | Output example 2 | Output example 3 | Output example 4
29 | 29 | 80 | 45
38 | 36 | 36
input
The input consists of multiple datasets. Input ends when both n and r are 0. The number of datasets does not exceed 10.
output
For each dataset, the area is output on the first line when r = 1, the area is output on the first line when r = 2, and the perimeter is output on the second line.
Example
Input
5 1
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
5 2
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
2 2
0 0 8 9
0 0 9 8
3 2
2 2 8 8
3 0 4 9
5 0 7 9
0 0
Output
29
29
38
80
36
45
36
Submitted Solution:
```
from itertools import chain
max_size = 10002
while 1:
n, r = (int(i) for i in input().strip().split())
if n == r == 0:
break
flag = False if r == 2 else True
sheets = dict()
max_size = 0
for i in range(n):
points = tuple(int(i) + 1 for i in input().strip().split())
max_size = max(max_size, max(points))
sheets[points[0]] = tuple(chain(sheets.get(points[0], ()), ((points[1], 1), (points[3], -1))))
sheets[points[2]] = tuple(chain(sheets.get(points[2], ()), ((points[3], 1),( points[1], -1))))
max_size += 2
size, perimeter = 0, 0
# dp[0] is left, dp[1] is now vertical line
dp0, dp1 = dict(), dict()
for x in range(0, max_size):
# put value to each point
for i in range(0, len(sheets.get(x, ()))):
pos, val = sheets[x][i]
dp1[pos] = val + dp1.get(pos, 0)
# paint '1' to left line, and '-1' to right line
for y in range(1, max_size):
dp1[y] = dp1.get(y, 0) + dp1.get(y - 1, 0)
# merge `left' and `now'
for y in range(1, max_size):
dp1[y] = dp1.get(y, 0) + dp0.get(y, 0)
# check and add
for y in range(1, max_size):
# if `now' or `left' equal zero, and another more than zero.
up = (dp0.get(y, 0) == 0 and dp1.get(y, 0) > 0) \
or (dp0.get(y, 0) > 0 and dp1.get(y, 0) == 0)
# if `now' or `under' equal zero, and another more than zero.
left = (dp1.get(y - 1, 0) == 0 and dp1.get(y, 0) > 0) \
or (dp1.get(y - 1, 0) > 0 and dp1.get(y, 0) == 0)
# if `now' is more than zero.
flag = dp1.get(y, 0) > 0
perimeter += up + left
size += flag
dp0, dp1 = dp1, dict()
print(size)
if r == 2:
print(perimeter)
``` | instruction | 0 | 15,877 | 23 | 31,754 |
No | output | 1 | 15,877 | 23 | 31,755 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are several rectangular sheets placed on a flat surface. Create a program to find the area and perimeter of the part covered by these sheets.
However, when the plane is regarded as the coordinate plane, the arrangement of the sheets shall satisfy the following conditions (1) and (2).
(1) The x and y coordinates of the four vertices of the rectangle on each sheet are all integers from 0 to 10000, and each side of the rectangle is parallel to the x-axis or y-axis.
(2) The number of sheets is at most 10,000 or less.
The number n of rectangles and the integer r indicating the type of problem are separated by a space in the first line of the input data. In each line after the second line, the coordinates of the lower left vertex of each sheet (x1, y1) and The coordinates of the upper right vertex coordinates (x2, y2) are written in the order of x1, y1, x2, y2, separated by a blank.
The output outputs the area on the first line when r = 1, the area on the first line when r = 2, and the perimeter on the second line. In either case, insert a line break at the end.
In 40% of the test data, the coordinates of the vertices of the rectangle are 0 or more and 100 or less, and 1/2 of them is the problem of finding only the area. Furthermore, 1/2 of the whole is the problem of finding only the area.
Input Example 1 | Input Example 2 | Input Example 3 | Input Example 4
--- | --- | --- | ---
|
5 1 | 5 2 | 2 2 | 3 2
0 0 3 2 | 0 0 3 2 | 0 0 8 9 | 2 2 8 8
1 1 2 5 | 1 1 2 5 | 0 0 9 8 | 3 0 4 9
0 4 6 5 | 0 4 6 5 | | 5 0 7 9
3 3 5 6 | 3 3 5 6 | |
5 0 7 6 | 5 0 7 6 | |
Output example 1 | Output example 2 | Output example 3 | Output example 4
29 | 29 | 80 | 45
38 | 36 | 36
input
The input consists of multiple datasets. Input ends when both n and r are 0. The number of datasets does not exceed 10.
output
For each dataset, the area is output on the first line when r = 1, the area is output on the first line when r = 2, and the perimeter is output on the second line.
Example
Input
5 1
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
5 2
0 0 3 2
1 1 2 5
0 4 6 5
3 3 5 6
5 0 7 6
2 2
0 0 8 9
0 0 9 8
3 2
2 2 8 8
3 0 4 9
5 0 7 9
0 0
Output
29
29
38
80
36
45
36
Submitted Solution:
```
while True:
n, r = map(int, input().split())
if not n:
break
sheets = sorted(tuple(map(int, input().split())) for _ in range(n))
max_y = max(p[3] for p in sheets)
table_c = [0] * max_y
table_r = [0] * max_y
table_e = 0
for x1, y1, x2, y2 in sheets:
for y in range(y1, y2):
rx = table_r[y]
if rx < x1 or not rx:
table_c[y] += x2 - x1
table_r[y] = x2
table_e += 2
elif rx < x2:
table_c[y] += x2 - rx
table_r[y] = x2
print(sum(table_c))
if r == 1:
continue
around = table_e
prev_w = 0
for w in table_c:
around += abs(w - prev_w)
prev_w = w
around += prev_w
print(around)
``` | instruction | 0 | 15,878 | 23 | 31,756 |
No | output | 1 | 15,878 | 23 | 31,757 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,933 | 23 | 31,866 |
Tags: geometry, number theory
Correct Solution:
```
n, m, k = map(int, input().split())
s = n*m / k
def gcd(a,b):
if b == 0:
return a
else:
return gcd(b, a%b)
if 2*n*m % k == 0:
f = True
if(k % 2 == 0):
k //= 2
f = False
print("YES")
a = n / gcd(n, k)
b = m*gcd(n, k) / k
if(f):
if(a < n): a *= 2;
else: b *= 2;
print(0,0)
print(0,int(b))
print(int(a),0)
else:
print("NO")
``` | output | 1 | 15,933 | 23 | 31,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,934 | 23 | 31,868 |
Tags: geometry, number theory
Correct Solution:
```
import math
a,b,c=map(int,input().split())
ans1=2*a
ans2=b
v=math.gcd(ans1,c)
ans1//=v
c//=v
v=math.gcd(ans2,c)
ans2//=v
c//=v
if c!=1 :
print("NO")
exit()
if ans1>a :
ans1,ans2=int(ans1/2),ans2*2
print("YES")
print(0,0)
print(ans1,0)
print(0,ans2)
``` | output | 1 | 15,934 | 23 | 31,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,935 | 23 | 31,870 |
Tags: geometry, number theory
Correct Solution:
```
from sys import stdin, stdout
input = stdin.buffer.readline
#print = stdout.write
n, m, k = map(int, input().split())
if 2 * n * m % k == 0:
i = 2
t = k
N = n
while i * i <= k:
while t % i == 0 and (n % i == 0 or m % i == 0):
t //= i
if n % i == 0:
n //= i
else:
m //= i
i += 1
if t % 2:
if t > 1:
if n % t == 0:
n //= t
else:
m //= t
if n * 2 <= N:
n *= 2
else:
m *= 2
else:
t //= 2
if t > 1:
if n % t == 0:
n //= t
else:
m //= t
print('YES')
print(0, 0)
print(n, 0)
print(0, m)
else:
print('NO')
``` | output | 1 | 15,935 | 23 | 31,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,936 | 23 | 31,872 |
Tags: geometry, number theory
Correct Solution:
```
def nod(a, b):
if(a == 0 or b == 0):
return a + b
if(a > b):
return nod(b, a % b)
else:
return nod(a, b % a)
n, m, k = map(int, input().split())
n2 = n // nod(n, k)
k = k // nod(n, k)
m2 = m // nod(m, k)
k = k // nod(m, k)
if(k > 2):
print("NO")
else:
if(k == 1):
if(n2 < n):
n2 = n2 * 2
else:
m2 = m2 * 2
print("YES")
print(0, 0)
print(n2, 0)
print(n2, m2)
``` | output | 1 | 15,936 | 23 | 31,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,937 | 23 | 31,874 |
Tags: geometry, number theory
Correct Solution:
```
def gcd(a, b):
if a==0:
return b
elif b==0:
return a
else:
if a>b:
return gcd (a%b, b)
else:
return gcd (a, b%a)
n, m, k = map(int, input().split())
n1, m1, k1=n, m, k
f=0
if (2*m*n)%k!=0:
print ("NO")
else:
f=0
if k%2==0:
k=k//2
f=1
t=gcd(n, k)
while t!=1:
n=n//t
k=k//t
t=gcd(n, k)
t=gcd(m, k)
while t!=1:
m=m//t
k=k//t
t=gcd(m, k)
if f==0:
if m*2<=m1:
m*=2
print ("YES")
print ('0 0')
print (0, m)
print (n, 0)
else:
if n*2<=n1:
n*=2
print ("YES")
print ('0 0')
print (0, m)
print (n, 0)
else:
print ('NO')
else:
if n<=n1 and m<=m1:
print ("YES")
print ('0 0')
print (0, m)
print (n, 0)
else:
print ("NO")
``` | output | 1 | 15,937 | 23 | 31,875 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,938 | 23 | 31,876 |
Tags: geometry, number theory
Correct Solution:
```
n,m,k=map(int,input().split())
from math import gcd
if (n*m)/k-(n*m)//k!=0 and (n*m)/k-(n*m)//k!=0.5:
print("NO")
else:
a=2*n
b=2*m
g1=gcd(a,k)
g2=gcd(b,k)
x=a//g1
y=m//(k//g1)
c=b//g2
d=n//(k//g2)
if x<=n and y<=m:
print("YES")
print(0,0)
print(x,0)
print(0,y)
elif x<=m and y<=n:
print("YES")
print(0,0)
print(y,0)
print(0,x)
elif c<=n and d<=m:
print("YES")
print(0,0)
print(c,0)
print(0,d)
elif c<=m and d<=n:
print("YES")
print(0,0)
print(d,0)
print(0,c)
else:
print("NO")
``` | output | 1 | 15,938 | 23 | 31,877 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,939 | 23 | 31,878 |
Tags: geometry, number theory
Correct Solution:
```
import math
import time
from collections import defaultdict,deque,Counter
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
from queue import PriorityQueue
import sys
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
n,m,k=map(int,stdin.readline().split())
N=n
M=m
g=gcd(n,k)
n=n//g
k=k//g
g=gcd(m,k)
m=m//g
k=k//g
if(k>2):
print("NO")
elif(n*m)/k >N*m:
print("NO")
elif(k==2):
print("YES")
print(0,0)
print(n,0)
print(0,m)
else:
if(n+n<=N):
n+=n
else:
m+=m
print("YES")
print(0,0)
print(n,0)
print(0,m)
``` | output | 1 | 15,939 | 23 | 31,879 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,940 | 23 | 31,880 |
Tags: geometry, number theory
Correct Solution:
```
n, m, k = map(int, input().split())
if (n * m * 2) % k != 0:
print("NO")
exit()
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
div = 0
if k % 2 == 0:
k //= 2
div = 1
g = gcd(n, k)
a = n // g
b = (m * g) // k
if not div:
if 2 * a <= n:
a *= 2
else:
b *= 2
print("YES")
print(a, 0)
print(0, b)
print(0, 0)
``` | output | 1 | 15,940 | 23 | 31,881 |
Provide tags and a correct Python 2 solution for this coding contest problem.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7. | instruction | 0 | 15,941 | 23 | 31,882 |
Tags: geometry, number theory
Correct Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
from fractions import gcd
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().split())
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
n,m,k=li()
if (2*n*m)%k:
pr('NO')
exit()
f=0
pr('YES\n')
if k%2==0:
k/=2
f=1
g=gcd(k,n)
k1=k/g
a=n/g
b=m/k1
if not f:
if a*2<n:
a*=2
else:
b*=2
pa([0,0])
pa([a,0])
pa([0,b])
``` | output | 1 | 15,941 | 23 | 31,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
def gcd(a,b):
if(a==0):
return b
return gcd(b%a,a)
n,m,k = map(int,input().split())
flag = 1
if(k%2==0):
flag = k%2
k=k//2
if(n*m)%k!=0:
print("NO")
else:
s = gcd(n,k)
k = k//s
a = n//s
s = gcd(m,k)
k = k//s
b = m//s
if(flag == 1):
if(a<n):
a+=a
else:
b+=b
print("YES")
print("0 0")
print(a,"0")
print("0",b)
# PRIYANHSU KUMAR
# Miles to go before i sleep :->>
``` | instruction | 0 | 15,942 | 23 | 31,884 |
Yes | output | 1 | 15,942 | 23 | 31,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
inp = input()
n, m, k = [int(x) for x in inp.split()]
def gcd(x, y):
if y == 0:
return x
return gcd(y, x % y)
if 2 * n * m % k != 0:
print('NO')
else:
print('YES')
if n * m % k != 0:
k //= 2
need = False
else:
need = True
p = gcd(n, k)
q = k // p
x = n // p
y = m // q
if need:
if p > 1:
x *= 2
else:
y *= 2
print(0, 0)
print(x, 0)
print(0, y)
``` | instruction | 0 | 15,943 | 23 | 31,886 |
Yes | output | 1 | 15,943 | 23 | 31,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
#1030D
[n,m,k] = list(map(int,input().split()))
def gcd(a,b):
x = max(a,b)
y = min(a,b)
r = x%y
while r > 0:
x = y
y = r
r = x%y
return y
x = gcd(m,k)
y = gcd(n,k)
if x > y:
s = (m//x)*n
else:
s = m*(n//y)
if (2*s)%(k//max(x,y)) == 0:
print('YES')
s = s//(k//max(x,y))*2
if x > y:
print(0,0)
if x < k:
print(2*n//(k//x),0)
print(0,(m//x))
else:
print(n//(k//x),0)
print(0,(2*m//x))
else:
print(0,0)
if y < k:
print((n//y),0)
print(0,2*m//(k//y))
else:
print(2*n//y,0)
print(0,m//(k//y))
else:
print('NO')
``` | instruction | 0 | 15,944 | 23 | 31,888 |
Yes | output | 1 | 15,944 | 23 | 31,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
def gcd(a, b):
while b != 0:
a, b = b, a % b
return a
n, m, k = map(int, input().split())
if n * m * 2 % k != 0:
print('NO')
else:
#print('YES')
s2 = n * m * 2 // k
ans = [(0, 0)]
"""i = 1
while i * i <= s2:
if s2 % i == 0:
if i <= n and s2 // i <= m:
ans.append((i, 0))
ans.append((0, s2 // i))
break
if s2 // i <= n and i <= m:
ans.append((s2 // i, 0))
ans.append((0, i))
break
i += 1
if ans == [(0, 0)]:
print('NO')
else:
print('YES')
for i in ans:
print(i[0], i[1])"""
xx1 = n // gcd(n, k)
yy1 = s2 // xx1
yy2 = m // gcd(m, k)
xx2 = s2 // yy2
if s2 % n == 0:
print('YES')
print(0, 0)
print(n, 0)
print(0, s2 // n)
elif s2 % m == 0:
print('YES')
print(0, 0)
print(s2 // m, 0)
print(0, m)
elif xx1 <= n and yy1 <= m and xx1 * yy1 == n * m * 2 // k:
print('YES')
print(0, 0)
print(xx1, 0)
print(0, yy1)
elif xx2 <= n and yy2 <= m and xx2 * yy2 == n * m * 2 // k:
print('YES')
print(0, 0)
print(xx2, 0)
print(0, yy2)
else:
print('NO')
``` | instruction | 0 | 15,945 | 23 | 31,890 |
Yes | output | 1 | 15,945 | 23 | 31,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
from math import gcd
n,m,k=map(int,input().split())
tt,pp=n,m
xx=gcd(n,k)
k=k//xx
n=n//xx
xx=gcd(m,k)
k=k//xx
m=m//xx
if k>2:
print('NO')
else:
x=0
print('YES')
print(0,0)
if 2*n<=tt:
print(2*n,0)
x=1
else:
print(n,0)
if 2*m<=pp and not x:
print(0,2*m)
else:
print(0,m)
``` | instruction | 0 | 15,946 | 23 | 31,892 |
No | output | 1 | 15,946 | 23 | 31,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
import sys
# sys.stdin = open('inp', 'r')
n, m, k = map(int, input().split())
if (2 * n * m) % k != 0:
print('NO')
sys.exit()
pts = [(0, 0)]
if 2 % k == 0:
h, b = 2 // k, n * m
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if m % k == 0:
h, b = 2 * n, m // k
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if n % k == 0:
h, b = 2 * m, n // k
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if (2 * m) % k == 0:
h, b = n, (2 * m) // k
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if (2 * n) % k == 0:
h, b = m, (2 * n) // k
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if (n * m) % k == 0:
h, b = 2, (n * m) // k
if b <= n and h <= m:
pts.append((0, h)), pts.append((b, 0))
elif b <= m and h <= n:
pts.append((h, 0)), pts.append((0, b))
if len(pts) == 1:
print('NO')
sys.exit()
else:
print('YES')
for p in pts[:3]:
print(p[0], p[1])
``` | instruction | 0 | 15,947 | 23 | 31,894 |
No | output | 1 | 15,947 | 23 | 31,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
import math
import sys
lines = sys.stdin.readlines()
def read_three_nums(line):
[n1, n2, n3] = list(map(int, line.strip().split(" ")))
return n1, n2, n3
def get_divisors(num):
divisors = []
for i in range(1, int(math.sqrt(num)) + 1):
if num % i == 0:
divisors.append(i)
divisors.append(num / i)
return divisors
n, m, k = read_three_nums(lines[0])
target_area = n * m / k
if target_area % 0.5 != 0:
print("NO")
else:
m_divisors = get_divisors(m)
n_divisors = get_divisors(n)
for i in n_divisors:
for j in m_divisors:
if i * j / 2 == target_area:
print("YES")
print(f"0 0")
print(f"{int(i)} 0")
print(f"0 {int(j)}")
sys.exit()
print("NO")
``` | instruction | 0 | 15,948 | 23 | 31,896 |
No | output | 1 | 15,948 | 23 | 31,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
n, m, k = map(int, input().split())
if k == 2:
print("YES")
print(0, 0)
print(0, m)
print(n, 0)
exit(0)
a = n
b = k
while a > 0 and b > 0:
if a > b:
a %= b
else:
b %= a
a = a + b
k1 = k // a
if a == 1 or k1 == 1:
if k1 >= 2 and m % k1 == 0:
print("YES")
print(0, 0)
print(0, 2 * m // k1)
print(n // a, 0)
exit(0)
a = m
b = k
while a > 0 and b > 0:
if a > b:
a %= b
else:
b %= a
a = a + b
k1 = k // a
if n % k1 != 0:
print("NO")
exit(0)
if k1 >= 2:
print("YES")
print(0, 0)
print(0, m // a)
print(2 * n // k1, 0)
exit(0)
else:
if m % k1 != 0:
print("NO")
exit(0)
if k1 >= 2:
print("YES")
print(0, 0)
print(0, 2 * m // k1)
print(n // a, 0)
exit(0)
print("NO")
``` | instruction | 0 | 15,949 | 23 | 31,898 |
No | output | 1 | 15,949 | 23 | 31,899 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
Vasya has got three integers n, m and k. He'd like to find three integer points (x_1, y_1), (x_2, y_2), (x_3, y_3), such that 0 ≤ x_1, x_2, x_3 ≤ n, 0 ≤ y_1, y_2, y_3 ≤ m and the area of the triangle formed by these points is equal to nm/k.
Help Vasya! Find such points (if it's possible). If there are multiple solutions, print any of them.
Input
The single line contains three integers n, m, k (1≤ n, m ≤ 10^9, 2 ≤ k ≤ 10^9).
Output
If there are no such points, print "NO".
Otherwise print "YES" in the first line. The next three lines should contain integers x_i, y_i — coordinates of the points, one point per line. If there are multiple solutions, print any of them.
You can print each letter in any case (upper or lower).
Examples
Input
4 3 3
Output
YES
1 0
2 3
4 1
Input
4 4 7
Output
NO
Note
In the first example area of the triangle should be equal to nm/k = 4. The triangle mentioned in the output is pictured below:
<image>
In the second example there is no triangle with area nm/k = 16/7.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
from fractions import gcd
pr = stdout.write
mod=10**9+7
def ni():
return int(raw_input())
def li():
return map(int,raw_input().split())
def pn(n):
stdout.write(str(n)+'\n')
def pa(arr):
pr(' '.join(map(str,arr))+'\n')
# fast read function for total integer input
def inp():
# this function returns whole input of
# space/line seperated integers
# Use Ctrl+D to flush stdin.
return map(int,stdin.read().split())
range = xrange # not for python 3.0+
# main code
n,m,k=li()
if (2*n*m)%k:
pr('NO')
exit()
f=0
if k%2==0:
k/=2
f=1
g=gcd(k,n)
k1=k/g
a=n/g
b=m/k1
if not f:
if a*2<n:
a*=2
else:
b*=2
pa([0,0])
pa([a,0])
pa([0,b])
``` | instruction | 0 | 15,950 | 23 | 31,900 |
No | output | 1 | 15,950 | 23 | 31,901 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
from itertools import permutations, combinations
from sys import stdin, gettrace
INF = int(1E10)
if gettrace():
inputi = input
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def solve():
xy = []
for _ in range(4):
x, y = map(int, inputi().split())
xy.append((x, y))
res = INF
for p in combinations(range(4), 2):
mxx1 = 0
mnx1 = INF
mxx2 = 0
mnx2 = INF
q = [i for i in range(4) if i not in p]
mnx1 = min(xy[i][0] for i in p)
mxx1 = max(xy[i][0] for i in p)
mnx2 = min(xy[i][0] for i in q)
mxx2 = max(xy[i][0] for i in q)
mnxl = mnx2 - mxx1 if mxx1 < mnx2 else mnx1 - mxx2 if mnx1 > mxx2 else 0
mxxl = max(mxx2 - mnx1, mxx1 - mnx2)
xc = mxx1 - mnx1 + mxx2 - mnx2
mny1 = min(xy[p[0]][1], xy[q[0]][1])
mxy1 = max(xy[p[0]][1], xy[q[0]][1])
mny2 = min(xy[p[1]][1], xy[q[1]][1])
mxy2 = max(xy[p[1]][1], xy[q[1]][1])
mnyl = mny2 - mxy1 if mxy1 < mny2 else mny1 - mxy2 if mny1 > mxy2 else 0
mxyl = max(mxy2 - mny1, mxy1 - mny2)
yc = mxy1 - mny1 + mxy2 - mny2
c = xc + yc + 2*max(0, max(mnxl, mnyl) - min(mxxl, mxyl))
res = min(c, res)
mny1 = min(xy[p[0]][1], xy[q[1]][1])
mxy1 = max(xy[p[0]][1], xy[q[1]][1])
mny2 = min(xy[p[1]][1], xy[q[0]][1])
mxy2 = max(xy[p[1]][1], xy[q[0]][1])
mnyl = mny2 - mxy1 if mxy1 < mny2 else mny1 - mxy2 if mny1 > mxy2 else 0
mxyl = max(mxy2 - mny1, mxy1 - mny2)
yc = mxy1 - mny1 + mxy2 - mny2
c = xc + yc + 2*max(0, max(mnxl, mnyl) - min(mxxl, mxyl))
res = min(c, res)
print(res)
def main():
t = int(inputi())
for _ in range(t):
solve()
if __name__ == "__main__":
main()
``` | instruction | 0 | 16,186 | 23 | 32,372 |
Yes | output | 1 | 16,186 | 23 | 32,373 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools
def four_points(P):
min_cost = 4 * int(1e9)
for p in itertools.permutations(range(4)):
(ax, ay), (bx, by), (cx, cy), (dx, dy) = (P[i] for i in p)
x1 = min(ax, bx), max(ax, bx)
x2 = min(cx, dx), max(cx, dx)
cost = x1[1] - x1[0] + x2[1] - x2[0]
y1 = min(ay, cy), max(ay, cy)
y2 = min(by, dy), max(by, dy)
cost += y1[1] - y1[0] + y2[1] - y2[0]
x_seg = max(x1[0] - x2[1], x2[0] - x1[1]), max(x1[1] - x2[0], x2[1] - x1[0])
y_seg = max(y1[0] - y2[1], y2[0] - y1[1]), max(y1[1] - y2[0], y2[1] - y1[0])
cost += 2 * max(0, max(x_seg[0], y_seg[0]) - min(x_seg[1], y_seg[1]))
min_cost = min(min_cost, cost)
return min_cost
t = int(input())
for _ in range(t):
P = [[int(xy) for xy in input().split()] for _ in range(4)]
ans = four_points(P)
print(ans)
``` | instruction | 0 | 16,187 | 23 | 32,374 |
Yes | output | 1 | 16,187 | 23 | 32,375 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
import sys,os,io
input = sys.stdin.readline
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from random import *
T = int(input())
ans = [0]*T
for t in range(T):
X,Y = [0]*4,[0]*4
A = [0]*4
for i in range(4):
X[i],Y[i] = map(int, input().split())
# X[i], Y[i] = choices(range(1,11),k=2)
# print(X[i],Y[i])
A[i] = [X[i], Y[i]]
X.sort(); Y.sort(); A.sort()
cnt = 0
for i in range(2):
rank = 1
for j in range(4):
if A[i][1] < A[j][1]:
rank += 1
if rank<=2:
cnt += 1
if cnt!=1:
ans[t] += min(Y[2]-Y[1], X[2]-X[1])*2
x_min = X[2]-X[1]; x_max = X[3]-X[0]
y_min = Y[2]-Y[1]; y_max = Y[3]-Y[0]
if x_max<y_min:
ans[t] += (X[3]-X[2])+(X[1]-X[0])
ans[t] += (Y[3]-Y[2])+(Y[1]-Y[0])+2*(y_min-x_max)
elif y_max<x_min:
ans[t] += (X[3]-X[2])+(X[1]-X[0])+2*(x_min-y_max)
ans[t] += (Y[3]-Y[2])+(Y[1]-Y[0])
else:
ans[t] += (X[3]-X[2])+(X[1]-X[0])
ans[t] += (Y[3]-Y[2])+(Y[1]-Y[0])
# print(ans[t])
print(*ans, sep='\n')
``` | instruction | 0 | 16,188 | 23 | 32,376 |
Yes | output | 1 | 16,188 | 23 | 32,377 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
import sys
from itertools import permutations
rl=[]
def gen_sort(n,x):
if n==4:
rl.append(x[:])
for i in range(n,4):
x[i],x[n]=x[n],x[i]
gen_sort(n+ 1,x)
x[i],x[n]=x[n],x[i]
return
gen_sort(0,[0,1,2,3])
#rl= list(permutations([0,1, 2, 3]))
#print (rl)
max=lambda x,y:x if x>y else y
min=lambda x,y:x if x<y else y
abs=lambda x: x if x>0 else -x
xlr=[0,0]
xrr=[0,0]
dxr=[0,0]
y_up_r=[0,0]
y_down_r=[0,0]
dyr=[0,0]
if __name__=="__main__":
T=int(sys.stdin.readline().strip())
while (T>0):
T-=1
point=[]
for i in range(4):
a,b=sys.stdin.readline().strip().split(" ")
point.append([int(a),int(b)])
res=4000000000
for now in rl:
p=[]
for i in range(4):
p.append(point[now[i]])
#tmp=calc(p)
#xlr=[min(p[0][0],p[2][0]), max(p[0][0],p[2][0])]
#xrr=[min(p[1][0],p[3][0]), max(p[1][0],p[3][0])]
xlr[0]=min(p[0][0],p[2][0])
xlr[1]=max(p[0][0],p[2][0])
xrr[0]=min(p[1][0],p[3][0])
xrr[1]=max(p[1][0],p[3][0])
#dxr=[max(0, xrr[0]-xlr[1] ), max(0,xrr[1]-xlr[0] )]
#dxr=[abs( xrr[0]-xlr[1] ), abs(xrr[1]-xlr[0] )]
dxr[0]=abs( xrr[0]-xlr[1] )
dxr[1]=abs(xrr[1]-xlr[0] )
if dxr[0]>dxr[1]:
dxr[0],dxr[1]=dxr[1],dxr[0]
y_up_r =[min(p[0][1],p[1][1]), max(p[0][1],p[0][1])]
y_down_r=[min(p[2][1],p[3][1]), max(p[2][1],p[3][1])]
y_up_r[0]=min(p[0][1],p[1][1])
y_up_r[1]= max(p[0][1],p[0][1])
y_down_r[0]=min(p[2][1],p[3][1])
y_down_r[1]=max(p[2][1],p[3][1])
#dyr=[max(0, y_down_r[0]-y_up_r[1] ), max(0, y_down_r[1]-y_up_r[0])]
#dyr=[abs( y_down_r[0]-y_up_r[1] ), abs( y_down_r[1]-y_up_r[0])]
dyr[0]=abs( y_down_r[0]-y_up_r[1] )
dyr[1]= abs( y_down_r[1]-y_up_r[0])
if dyr[0]>dyr[1]:
dyr[1],dyr[0]=dyr[0],dyr[1]
#print (p)
ans=abs(p[2][0]-p[0][0]) +abs(p[1][0]-p[3][0]) +abs(p[1][1]-p[0][1]) +abs(p[2][1]-p[3][1])
#print (p,xlr, xrr, dxr,dyr)
if dxr[1]<dyr[0]:
ans+=(dyr[0]-dxr[1])*2
elif dyr[1]<dxr[0]:
ans+=(dxr[0]-dyr[1])*2
#return ans
res=min(res,ans)
print (res)
``` | instruction | 0 | 16,189 | 23 | 32,378 |
Yes | output | 1 | 16,189 | 23 | 32,379 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
from itertools import *
for t in range(int(input())):
a = []
for i in range(4):
a.append(list(map(int, input().split())))
ans = 1e18
for tp in range(2):
for X1 in range(4):
for X2 in range(4):
for Y1 in range(4):
for yf in range(2):
x1, x2, y1 = a[X1][0], a[X2][0], a[Y1][1]
if x1 > x2: continue
if yf: y2 = y1 + x2 - x1
else: y2 = y1 - x2 - x1
B = [[x1, y1], [x1, y2], [x2, y1], [x2, y2]]
for b in permutations(B):
res = 0
for i in range(4):
res += abs(a[i][0] - b[i][0]) + abs(a[i][1] - b[i][1])
ans = min(ans, res)
for i in range(4): a[i].reverse()
print(ans)
``` | instruction | 0 | 16,190 | 23 | 32,380 |
No | output | 1 | 16,190 | 23 | 32,381 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid.
In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it to (x, y + 1), (x, y - 1), (x + 1, y) or (x - 1, y).
Your goal to move points in such a way that they will form a square with sides parallel to OX and OY axes (a square with side 0 is allowed).
What is the minimum number of steps you need to make such a square?
Input
The first line contains a single integer t (1 ≤ t ≤ 10^4) — the number of test cases.
Each test case consists of four lines. Each line contains two integers x and y (0 ≤ x, y ≤ 10^9) — coordinates of one of the points p_i = (x, y).
All points are different in one test case.
Output
For each test case, print the single integer — the minimum number of steps to make a square.
Example
Input
3
0 2
4 2
2 0
2 4
1 0
2 0
4 0
6 0
1 6
2 2
2 5
4 1
Output
8
7
5
Note
In the first test case, one of the optimal solutions is shown below:
<image> Each point was moved two times, so the answer 2 + 2 + 2 + 2 = 8.
In the second test case, one of the optimal solutions is shown below:
<image> The answer is 3 + 1 + 0 + 3 = 7.
In the third test case, one of the optimal solutions is shown below:
<image> The answer is 1 + 1 + 2 + 1 = 5.
Submitted Solution:
```
f=int(input())
for i in range(f):
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())
if(a1==a2):
a1+=1
if(a4==a3):
a4+=1
if(b1==b2):
b1+=1
if(b4==b3):
b4+=1
x=(max(max(a1,a2),max(a3,a4))-min(max(a1,a2),max(a3,a4)))+(max(min(a1,a2),min(a3,a4))-min(min(a1,a2),min(a3,a4)))
y=(max(max(b1,b2),max(b3,b4))-min(max(b1,b2),max(b3,b4)))+(max(min(b1,b2),min(b3,b4))-min(min(b1,b2),min(b3,b4)))
print(x+y)
``` | instruction | 0 | 16,191 | 23 | 32,382 |
No | output | 1 | 16,191 | 23 | 32,383 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.