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 |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
import math
def koch(n, p1x, p1y, p2x, p2y):
if n == 0:
return
sx = (2*p1x + 1*p2x)/3
sy = (2*p1y + 1*p2y)/3
tx = (1*p1x + 2*p2x)/3
ty = (1*p1y + 2*p2y)/3
theta = math.pi/3
ux = math.cos(theta)*(tx-sx) - math.sin(theta)*(ty-sy) + sx
uy = math.sin(theta)*(tx-sx) + math.cos(theta)*(ty-sy) + sy
koch(n-1, p1x, p1y, sx, sy)
print("{:.5f} {:.5f}".format(sx, sy))
koch(n-1, sx, sy, ux, uy)
print("{:.5f} {:.5f}".format(ux, uy))
koch(n-1, ux, uy, tx, ty)
print("{:.5f} {:.5f}".format(tx, ty))
koch(n-1, tx, ty, p2x, p2y)
n = int(input())
p1x, p1y = 0.0, 0.0
p2x, p2y = 100.0, 0.0
print("{:.5f} {:.5f}".format(p1x, p1y))
koch(n, p1x, p1y, p2x, p2y)
print("{:.5f} {:.5f}".format(p2x, p2y))
``` | instruction | 0 | 47,913 | 23 | 95,826 |
Yes | output | 1 | 47,913 | 23 | 95,827 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
import math
n = int(input())
class Coordinate:
def __init__(self,x,y):
self.x = x
self.y = y
def Koch(n,p1,p2):
if n == 0:
return
else:
s = Coordinate(2/3 * p1.x + 1/3 * p2.x, 2/3 * p1.y + 1/3 * p2.y)
u = Coordinate(1/3 * p1.x + 2/3 * p2.x, 1/3 * p1.y + 2/3 * p2.y)
t = Coordinate(1/2*(u.x-s.x) - math.sqrt(3)/2*(u.y-s.y) + s.x, math.sqrt(3)/2*(u.x-s.x) + 1/2*(u.y-s.y) + s.y)
Koch(n-1,p1,s)
print(str(s.x) +" "+str(s.y))
Koch(n-1,s,t)
print(str(t.x) +" "+str(t.y))
Koch(n-1,t,u)
print(str(u.x) +" "+str(u.y))
Koch(n-1,u,p2)
p1 = Coordinate(0,0)
p2 = Coordinate(100,0)
print(str(p1.x) +" "+str(p1.y))
Koch(n,p1,p2)
print(str(p2.x) +" "+str(p2.y))
``` | instruction | 0 | 47,914 | 23 | 95,828 |
Yes | output | 1 | 47,914 | 23 | 95,829 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
import math
n=int(input())
#def koch(p1,p2,n):
def koch(d,p1,p2):
if d==0:
return
#3等分する
s=[(2*p1[0]+1*p2[0])/3,(2*p1[1]+1*p2[1])/3]
t=[(1*p1[0]+2*p2[0])/3,(1*p1[1]+2*p2[1])/3]
#正三角形の頂点のひとつである座標を求める
u=[
(t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0],
(t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1]
]
koch(d-1,p1,s)
print(*s)
koch(d-1,s,u)
print(*u)
koch(d-1,u,t)
print(*t)
koch(d-1,t,p2)
print('0 0')
koch(n,[0,0],[100,0])
print('100 0')
``` | instruction | 0 | 47,915 | 23 | 95,830 |
Yes | output | 1 | 47,915 | 23 | 95,831 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
# coding=utf-8
import math
def divide_segment(left, right):
"""divide segment
Args:
left: left edge coordinate
right: right edge coordinate
Returns:
divided points
"""
delta_x_quarter = (right[0] - left[0]) / 3.0
delta_y_quarter = (right[1] - left[1]) / 3.0
delta_x_quarter_rotated = (delta_x_quarter - math.sqrt(3) * delta_y_quarter) / 2.0
delta_y_quarter_rotated = (math.sqrt(3) * delta_x_quarter + delta_y_quarter) / 2.0
s = [left[0] + delta_x_quarter, left[1] + delta_y_quarter]
t = [left[0] + delta_x_quarter * 2.0, left[1] + delta_y_quarter * 2.0]
u = [s[0] + delta_x_quarter_rotated, s[1] + delta_y_quarter_rotated]
return s, t, u
def make_coch_curve(depth, left, right):
"""make coch curve with depth iteration_number between point left, right
each vertices positions are printed
Args:
depth: depth
left: left edge point
right: right edge point
Returns:
None
"""
print("{0:2.8f} {1:2.8f}".format(left[0], left[1]))
make_coch_curve_recursively(depth, left, right)
def make_coch_curve_recursively(depth, left, right):
"""recursion part of coch curve
Args:
depth: depth
left: left edge coordinate
right: right edge coordinate
Returns:
None
"""
# get coordinate of divided points
s, t, u = divide_segment(left, right)
if depth == 1:
print("{0:2.8f} {1:2.8f}".format(s[0], s[1]))
print("{0:2.8f} {1:2.8f}".format(u[0], u[1]))
print("{0:2.8f} {1:2.8f}".format(t[0], t[1]))
print("{0:2.8f} {1:2.8f}".format(right[0], right[1]))
else:
make_coch_curve_recursively(depth - 1, left, s)
make_coch_curve_recursively(depth - 1, s, u)
make_coch_curve_recursively(depth - 1, u, t)
make_coch_curve_recursively(depth - 1, t, right)
def main():
depth = int(input().strip())
make_coch_curve(depth, left=[0.0, 0.0], right=[100.0, 0.0])
if __name__ == '__main__':
main()
``` | instruction | 0 | 47,916 | 23 | 95,832 |
No | output | 1 | 47,916 | 23 | 95,833 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
import math
T = []
class Vect:
def __init__(self,x,y):
self.x = x
self.y = y
def hoge(p,q):
ax = q.x-p.x
ay = q.y-p.y
bx = ax/5 - ay*math.sqrt(3)/2
by = ax*math.sqrt(3)/2 + ay/2
nb = Vect(p.x+bx,p.y+by)
return nb
def koch(p,q,n):
if n == 0:
T.append(p)
else:
s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3)
t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3)
u = hoge(s,t)
koch(p,s,n-1)
koch(s,u,n-1)
koch(u,t,n-1)
koch(t,q,n-1)
n = int(input())
koch(Vect(0,0),Vect(100,0),n)
T.append(Vect(100,0))
for i in T:
print("%f %f"%(i.x,i.y))
``` | instruction | 0 | 47,917 | 23 | 95,834 |
No | output | 1 | 47,917 | 23 | 95,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
from math import sqrt
from numpy import array
def koch(n, start, end):
if n != 0:
vec = end - start
normal_vec = array([-vec[1], vec[0]])
a = start + vec/3
b = start + vec/2 + sqrt(3)*normal_vec/6
c = end - vec/3
koch(n-1, start, a)
print(a[0], a[1])
koch(n-1, a, b)
print(b[0], b[1])
koch(n-1, b, c)
print(c[0], c[1])
koch(n-1, c, end)
n = int(input())
start = array([0.0, 0.0])
end = array([100.0,0.0])
print(start[0], end[1])
koch(n, start, end)
print(start[0], end[1])
``` | instruction | 0 | 47,918 | 23 | 95,836 |
No | output | 1 | 47,918 | 23 | 95,837 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Write a program which reads an integer n and draws a Koch curve based on recursive calles of depth n.
The Koch curve is well known as a kind of fractals.
You can draw a Koch curve in the following algorithm:
* Divide a given segment (p1, p2) into three equal segments.
* Replace the middle segment by the two sides of an equilateral triangle (s, u, t) of the same length as the segment.
* Repeat this procedure recursively for new segments (p1, s), (s, u), (u, t), (t, p2).
<image>
You should start (0, 0), (100, 0) as the first segment.
Notes
Constraints
* 0 ≤ n ≤ 6
Input
An integer n is given.
Output
Print each point (x, y) of the Koch curve. Print a point in a line. You should start the point(0, 0), which is the endpoint of the first segment and end with the point (100, 0), the other endpoint so that you can draw the Koch curve as an unbroken line. Each solution should be given as a decimal with an arbitrary number of fractional digits, and with an absolute error of at most 10-4.
Examples
Input
1
Output
0.00000000 0.00000000
33.33333333 0.00000000
50.00000000 28.86751346
66.66666667 0.00000000
100.00000000 0.00000000
Input
2
Output
0.00000000 0.00000000
11.11111111 0.00000000
16.66666667 9.62250449
22.22222222 0.00000000
33.33333333 0.00000000
38.88888889 9.62250449
33.33333333 19.24500897
44.44444444 19.24500897
50.00000000 28.86751346
55.55555556 19.24500897
66.66666667 19.24500897
61.11111111 9.62250449
66.66666667 0.00000000
77.77777778 0.00000000
83.33333333 9.62250449
88.88888889 0.00000000
100.00000000 0.00000000
Submitted Solution:
```
# -*- coding: utf-8 -*-
# 宇都宮涼
# J5-170029
# Kannoudou
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0168
# 右中央
import math
import copy
def EqualParts(a,b):
li = []
s = [0,0]
t = [0,0]
s[0] = (2*a[0]+b[0])/3.0
s[1] = (2*a[1]+b[1])/3.0
t[0] = (a[0]+2*b[0])/3.0
t[1] = (a[1]+2*b[1])/3.0
li.append(s)
li.append(t)
return li
def triangle(a,b):
u = [0,0]
if a[1] == b[1]:
u[0] = (a[0]+b[0])/2.0
u[1] = (b[0]-a[0])/2.0*math.sqrt(3)
else:
li = EqualParts(a,b)
if a[0] < b[0]:
if a[1] > b[1]:
u[0] = b[0]+(b[0]-a[0])
u[1] = a[1]
else:
u[0] = a[0]-(b[0]-a[0])
u[1] = b[1]
else:
if a[1] > b[1]:
u[0] = a[0]-(b[0]-a[0])
u[1] = a[1]
else:
u[0] = b[0]+(b[0]-a[0])
u[1] = b[1]
return u
def koch(n):
if n == 0:
return ([[0.0,0.0],[100.0, 0.0]])
else:
li = koch(n-1)
answer = copy.copy(li)
for i in range(len(li)-1):
temp = EqualParts(li[i],li[i+1])
s = temp[0]
t = temp[1]
u = triangle(s,t)
answer.insert(3*i+1+i,s)
answer.insert(3*i+2+i,u)
answer.insert(3*i+3+i,t)
return answer
n = int(input())
answer = koch(n)
for j in range(len(answer)):
print(' '.join(map(str,answer[j])))
``` | instruction | 0 | 47,919 | 23 | 95,838 |
No | output | 1 | 47,919 | 23 | 95,839 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
n, m = [int(x) for x in input().split()]
arr = []
turn = []
for i in range(n):
turn.append([None] * m)
for i in range(m):
arr.append(list(input()))
for i in range(m):
for j in range(n):
turn[j][i] = arr[i][n - j - 1]
s = []
for i in range(n):
s.append(list(turn[i]))
#------------------------------------------
for i in range(m):
for j in range(n):
turn[j][i] = s[n - j - 1][i]
for i in range(n):
for k in range(2):
for j in range(m):
print(turn[i][j] * 2, end="")
print()
``` | instruction | 0 | 48,326 | 23 | 96,652 |
Yes | output | 1 | 48,326 | 23 | 96,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
def function():
size = input().split(' ')
w = int(size[0])
h = int(size[1])
if not (1 <= w <= 100) and not (1 <= h <= 100):
return None
matrix_result = [[None for j in range(0, 2*h)] for i in range(0, 2*w)]
for i in range(0, h):
arr = list(input())
for j in range(0, w):
matrix_result[2*j][2*i] = arr[j]
matrix_result[2*j + 1][2*i] = arr[j]
matrix_result[2*j][2*i + 1] = arr[j]
matrix_result[2*j + 1][2*i + 1] = arr[j]
for i in range(0, 2*w):
print(''.join(str(x) for x in matrix_result[i]))
function()
``` | instruction | 0 | 48,327 | 23 | 96,654 |
Yes | output | 1 | 48,327 | 23 | 96,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
w, h = map(int, input().split())
listGorizontal = []
listVertical = []
for i in range(h):
listGorizontal.append(input())
for i in range(h):
s = ""
k = w
for j in listGorizontal[i]:
s += j[w - k]*2
listVertical.append(s)
s = ""
k = h
for i in range(2*w):
for j in range(h):
s += 2 * listVertical[h - k][i]
k += -1
k = h
if i != 2*w :
s += "\n"
print(s)
``` | instruction | 0 | 48,328 | 23 | 96,656 |
Yes | output | 1 | 48,328 | 23 | 96,657 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
w, h = map(int, input().split())
image = [input() for i in range(h)]
for i in range(w):
image2 = ""
for j in range(h):
temp = image[j][i]
print(temp+temp,end="")
image2 += temp + temp
print()
print(image2)
``` | instruction | 0 | 48,329 | 23 | 96,658 |
Yes | output | 1 | 48,329 | 23 | 96,659 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
def povorot(a,b):
for i in range(m+1):
for j in range(n+1):
b[j][i] = a[i][j]
def otr(b,c):
for i in range(1,m+1):
for j in range(1,n+1):
c[j-1][i-1] = b[j][i]
def mashtab(c,d,e):
r = 0
for i in range(n):
tmp = ''.join(c[i])
for j in range(len(tmp)):
d[r][j] = tmp[j]
d[r+1][j] = tmp[j]
r = r + 2
r = 0
for i in range(m):
for j in range(2 * (n)):
e[j][r] = d[j][i]
e[j][r+1] = d[j][i]
r = r + 2
n,m = map(int,input().split())
a = [ [0] * (n+1) for i in range(m+1) ]
for i in range(1,m+1):
tmp = input()
tmp.rstrip()
for j in range(len(tmp)):
a[i][j+1] = tmp[j]
b = [ [0] * (m+1) for i in range(n+1) ]
povorot(a,b)
c = [ [0] * (m) for i in range(n) ]
otr(b,c)
d = [ [0] * (2 * (m)) for i in range(2 * (n)) ]
e = [ [0] * (2 * (m)) for i in range(2 * (n)) ]
mashtab(c,d,e)
for i in range(len(e)):
for j in range(len(e[i])):
print(e[i][j],end = ' ')
print()
``` | instruction | 0 | 48,330 | 23 | 96,660 |
No | output | 1 | 48,330 | 23 | 96,661 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
w, h = map(int, input().split())
a = []
res = [[0] * h for i in range(w)]
for i in range(h):
s = input()
for i2 in range(w):
res[i2][h - i - 1] = s[i2]
for elem in res:
print(elem)
print()
print()
for i in range(w):
res[i] = res[i][::-1]
for elem in res:
print(elem)
for elem in res:
for i in range(2):
for i2 in range(h):
print(elem[i2], end='')
print(elem[i2], end='')
print()
``` | instruction | 0 | 48,331 | 23 | 96,662 |
No | output | 1 | 48,331 | 23 | 96,663 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
#!/usr/bin/python3
w, h = map(int, input().split())
arr = [list(input()) for i in range(h)]
rotated_and_mirrored = [[arr[i][j] for i in range(h)] for j in range(w)]
ans = [["" for i in range(2 * h)] for j in range(2 * w)]
for i in range(w):
for j in range(h):
for dx in range(2):
for dy in range(2):
ans[2 * i][2 * j] = rotated_and_mirrored[i][j]
print("\n".join(map(lambda x : "".join(x), ans)))
``` | instruction | 0 | 48,332 | 23 | 96,664 |
No | output | 1 | 48,332 | 23 | 96,665 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three.
He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes).
Implement this feature to help Polycarp test his editor.
Input
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome.
Output
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
Examples
Input
3 2
.*.
.*.
Output
....
....
****
****
....
....
Input
9 20
**.......
****.....
******...
*******..
..******.
....****.
......***
*.....***
*********
*********
*********
*********
....**...
...****..
..******.
.********
****..***
***...***
**.....**
*.......*
Output
********......**********........********
********......**********........********
********........********......********..
********........********......********..
..********......********....********....
..********......********....********....
..********......********..********......
..********......********..********......
....********....****************........
....********....****************........
....********....****************........
....********....****************........
......******************..**********....
......******************..**********....
........****************....**********..
........****************....**********..
............************......**********
............************......**********
Submitted Solution:
```
w, h = map(int, input().split())
listGorizontal = []
listVertical = []
for i in range(h):
listGorizontal.append(input())
for i in range(h):
s = ""
for j in listGorizontal[i]:
s += j*2
listVertical.append(s)
s = ""
k = 1
for i in range(2*w):
for j in range(h):
s += 2 * listVertical[h - k][i]
k += 1
k = 1
if i != 2*w :
s += "\n"
print(s)
``` | instruction | 0 | 48,333 | 23 | 96,666 |
No | output | 1 | 48,333 | 23 | 96,667 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1 | instruction | 0 | 48,482 | 23 | 96,964 |
Tags: constructive algorithms
Correct Solution:
```
'''input
4 5
'''
n, k = map(int, input().split())
m = [["0"]*n for _ in range(n)]
for x in range(n):
for y in range(x, n):
if x == y and k >= 1:
m[x][y] = "1"
k -= 1
elif k >= 2:
m[x][y] = "1"
m[y][x] = "1"
k -= 2
if k > 0:
print(-1)
else:
print("\n".join([" ".join(i) for i in m]))
``` | output | 1 | 48,482 | 23 | 96,965 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1 | instruction | 0 | 48,485 | 23 | 96,970 |
Tags: constructive algorithms
Correct Solution:
```
import sys
n,k=map(int,input().split())
ans=[[0 for i in range(n)]for i in range(n)]
if k>n*n:
print(-1)
sys.exit()
cur=0
j=0
while(k>0):
if k==1:
inc=0
if j>cur:
inc=1
ans[cur+inc][cur+inc]=1
k-=1
else:
ans[cur][j]=1
ans[j][cur]=1
k-=2
if cur==j:
k+=1
while(ans[cur][j]==1):
j+=1
if j==n:
j=0
cur+=1
for i in range(n):
print(*ans[i],sep=" ")
``` | output | 1 | 48,485 | 23 | 96,971 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1 | instruction | 0 | 48,486 | 23 | 96,972 |
Tags: constructive algorithms
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#q.sort(key=lambda x:((x[1]-x[0]),-x[0]))
#from collections import Counter
#from fractions import Fraction
from bisect import bisect_left
from collections import Counter
#s=iter(input())
#from collections import deque
#ls=list(map(int,input().split()))
#for in range(m):
#for _ in range(int(input())):
#n=int(input())
# n,k=map(int,input().split())
# arr=list(map(int,input().split()))
#for i in range(int(input())):
#n=int(input())
#arr=sorted([(x,i) for i,x in enumerate(map(int,input().split()))])[::-1]
#print(arr)
#arr=sorted(list(map(int,input().split())))[::-1]
n,k=map(int,input().split())
if k>n**2:
print(-1)
else:
m=[[0]*n for i in range(n)]
for i in range(n):
if k<=0:
break
m[i][i]=1
k-=1
for j in range(i+1,n):
if k>=2:
m[i][j]=1
m[j][i]=1
k-=2
for i in m:
print(*i)
``` | output | 1 | 48,486 | 23 | 96,973 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1 | instruction | 0 | 48,487 | 23 | 96,974 |
Tags: constructive algorithms
Correct Solution:
```
n, k = map(int, input().split())
#n=2
#k=5
matrica=[ ['0' for i in range(n)] for i in range(n)]
# print("matrica: {0}x{0}\n k ir {1}\n".format(n, k))
if(n**2<k): print(-1)
else:
for i in range(n):
if(k>0):
matrica[i][i]='1'
k-=1
else: break
for j in range(i+1, n):
if(k>1):
matrica[i][j]='1'
matrica[j][i]='1'
k-=2
else: break
for i in range(n):
for j in range(n):
print(matrica[i][j]," ", end="")
print("")
# beidzas else
``` | output | 1 | 48,487 | 23 | 96,975 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1
Submitted Solution:
```
n,k=map(int,input().strip().split(' '))
mat=[]
for i in range(n):
mat.append([0]*n)
for i in range(n):
for j in range(i,n):
if k>1 and i!=j:
k-=2
mat[i][j],mat[j][i]=1,1
elif k>0 and i==j:
k-=1
mat[i][j]=1
if k==0:
for i in range(n):
for j in range(n-1):
print(mat[i][j],end=' ')
print(mat[i][n-1])
else:
print(-1)
``` | instruction | 0 | 48,493 | 23 | 96,986 |
Yes | output | 1 | 48,493 | 23 | 96,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.
If there exists no such matrix then output -1.
Input
The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
Output
If the answer exists then output resulting matrix. Otherwise output -1.
Examples
Input
2 1
Output
1 0
0 0
Input
3 2
Output
1 0 0
0 1 0
0 0 0
Input
2 5
Output
-1
Submitted Solution:
```
n,k=map(int,input().split())
if k>n and (k-n)%2==1:
print("-1")
elif k>n*n:
print("-1")
else:
t=0
mat=[]
a=[]
for i in range(n):
for i in range(n):
a.append(0)
mat.append(a)
a=[]
while t<k and t<n:
mat[t][t]=1
t+=1
#t-=1
i=n-1
l=0
j=l
while t<k:
for i in range(1,n):
for j in range(i):
mat[i][j]=1
mat[j][i]=1
t+=2
if t>=k:
break
if t>=k:
break
for i in range(n):
for j in range(n-1):
print("%d" % mat[i][j],end=" ")
print(mat[i][n-1])
``` | instruction | 0 | 48,496 | 23 | 96,992 |
No | output | 1 | 48,496 | 23 | 96,993 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1≦M≦N≦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,670 | 23 | 97,340 |
"Correct Solution:
```
N,M=map(int,input().split())
A=[input() for i in range(N)]
B=[input() for i in range(M)]
judge=any([line[j:j+M] for line in A[i:i+M]]==B for i in range(N-M+1) for j in range(N-M+1))
print("Yes" if judge else "No")
``` | output | 1 | 48,670 | 23 | 97,341 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1≦M≦N≦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,672 | 23 | 97,344 |
"Correct Solution:
```
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
ans="No"
for i in range(n-m+1):
for j in range(n-m+1):
if [line[j:j+m] for line in a[i:i+m]]==b:
ans="Yes"
break
if ans=="Yes":
break
print(ans)
``` | output | 1 | 48,672 | 23 | 97,345 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1≦M≦N≦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,673 | 23 | 97,346 |
"Correct Solution:
```
n,m=map(int,input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]
cnt=False
for i in range(n-m+1):
for j in range(n-m+1):
t=[k[j:j+m]for k in a[i:i+m]]
if t==b:
cnt=True
print("Yes" if cnt else "No")
``` | output | 1 | 48,673 | 23 | 97,347 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1≦M≦N≦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,674 | 23 | 97,348 |
"Correct Solution:
```
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
for j in range(n-m+1):
x=[]
for k in range(m):
x.append(a[i+k][j:j+m])
if x==b:
print("Yes")
exit()
print("No")
``` | output | 1 | 48,674 | 23 | 97,349 |
Provide a correct Python 3 solution for this coding contest problem.
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.
A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.
Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: `.` corresponds to a white pixel, and `#` corresponds to a black pixel.
The image A is given as N strings A_1,...,A_N.
The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).
Similarly, the template image B is given as M strings B_1,...,B_M.
The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.
Constraints
* 1≦M≦N≦50
* A_i is a string of length N consisting of `#` and `.`.
* B_i is a string of length M consisting of `#` and `.`.
Input
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M
Output
Print `Yes` if the template image B is contained in the image A. Print `No` otherwise.
Examples
Input
3 2
#.#
.#.
#.#
#.
.#
Output
Yes
Input
3 2
.#
.#.
.#
.
.#
Output
Yes
Input
4 1
....
....
....
....
Output
No | instruction | 0 | 48,677 | 23 | 97,354 |
"Correct Solution:
```
N, M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
cnt = 0
tmp = []
for a in A:
for b in B:
if(tmp != B):
if(b in a):
tmp.append(b)
else:
break
if(tmp == B):
print("Yes")
else:
print("No")
``` | output | 1 | 48,677 | 23 | 97,355 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,753 | 23 | 97,506 |
"Correct Solution:
```
import copy
def main():
while True:
n,m,t,p = map(int,input().split())
if not n and not m and not t and not p:
return
dlist,clist = [],[]
for _ in range(t):
d,c = map(int,input().split())
dlist.append(d)
clist.append(c)
coorlist = [tuple(map(int,input().split())) for _ in range(p)]
oldm = [[1 for _ in range(m)] for _ in range(n)]
for d,c in zip(dlist,clist):
if d == 1: # →
if 2*c <= n:
newm = [[0 for _ in range(m)] for _ in range(n-c)]
for i in range(c):
for j in range(m):
newm[i][j] = oldm[c+i][j] + oldm[c-1-i][j]
for i in range(c,n-c):
for j in range(m):
newm[i][j] = oldm[c+i][j]
n = n-c
else:
newm = [[0 for _ in range(m)] for _ in range(c)]
for i in range(n-c):
for j in range(m):
newm[i][j] = oldm[c+i][j] + oldm[c-1-i][j]
for i in range(n-c,c):
for j in range(m):
newm[i][j] = oldm[c-1-i][j]
n = c
else: # ↑
if 2*c <= m:
newm = [[0 for _ in range(m-c)] for _ in range(n)]
for i in range(n):
for j in range(c):
newm[i][j] = oldm[i][c+j] + oldm[i][c-1-j]
for i in range(n):
for j in range(c,m-c):
newm[i][j] = oldm[i][c+j]
m = m-c
else:
newm = [[0 for _ in range(c)] for _ in range(n)]
for i in range(n):
for j in range(m-c):
newm[i][j] = oldm[i][c+j] + oldm[i][c-1-j]
for i in range(n):
for j in range(m-c,c):
newm[i][j] = oldm[i][c-1-j]
m = c
oldm = newm
ans = 0
for c in coorlist:
print(oldm[c[0]][c[1]])
def visualize(mmap):
print("------------------")
for j in range(len(mmap[0])):
print('|', end="")
for i in range(len(mmap)):
print(mmap[i][len(mmap[0])-1-j], '|', end="")
print()
print("------------------")
if __name__ == '__main__':
main()
``` | output | 1 | 48,753 | 23 | 97,507 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,754 | 23 | 97,508 |
"Correct Solution:
```
class Paper:
def __init__(self, n, m):
self.n = n
self.m = m
self.table = [[1] * n for _ in range(m)]
def __str__(self):
return str(self.table)
def thickness(self, x, y):
return self.table[y][x]
def fold(self, d, c):
if d == 1:
return self.foldl(c)
else:
return self.foldb(c)
def foldl(self, c):
nn = max(c, self.n - c)
tbl = [[0] * nn for _ in range(self.m)]
for y in range(self.m):
for x in range(c):
tbl[y][x] += self.table[y][c - x - 1]
for x in range(self.n - c):
tbl[y][x] += self.table[y][c + x]
self.n = nn
self.table = tbl
def foldb(self, c):
mm = max(c, self.m - c)
tbl = [[0] * self.n for _ in range(mm)]
for x in range(self.n):
for y in range(c):
tbl[y][x] += self.table[c - y - 1][x]
for y in range(self.m - c):
tbl[y][x] += self.table[c + y][x]
self.m = mm
self.table = tbl
while True:
n, m, t, p = map(int, input().split())
if n == m == t == p == 0:
break
paper = Paper(n, m)
for i in range(t):
d, c = map(int, input().split())
paper.fold(d, c)
for i in range(p):
x, y = map(int, input().split())
print(paper.thickness(x, y))
``` | output | 1 | 48,754 | 23 | 97,509 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,755 | 23 | 97,510 |
"Correct Solution:
```
import sys
from inspect import currentframe
def pri(*args):
names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
# print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))
def solve(n, m, t, p, d, c, x, y):
a = [[1 for _ in range(m)] for _ in range(n)]
pri(a)
for i in range(t):
if d[i] == 1:
m = max(m - c[i], c[i])
a_new = [[0 for _ in range(m)] for _ in range(n)]
pri(a_new)
for n_i in range(len(a)):
for m_i in range(len(a[0])):
if m_i >= c[i]:
a_new[n_i][m_i - c[i]] += a[n_i][m_i]
else:
a_new[n_i][c[i] - m_i - 1] += a[n_i][m_i]
pri(a_new)
a = a_new
else:
n = max(n - c[i], c[i])
a_new = [[0 for _ in range(m)] for _ in range(n)]
pri(a_new)
for n_i in range(len(a)):
for m_i in range(len(a[0])):
if n_i >= c[i]:
a_new[n_i - c[i]][m_i] += a[n_i][m_i]
else:
a_new[c[i] - n_i - 1][m_i] += a[n_i][m_i]
pri(a_new)
a = a_new
for j in range(p):
print(a[y[j]][x[j]])
return
if __name__ == '__main__':
while True:
n_imput, m_imput, t_imput, p_imput = map(int, input().split())
if p_imput == m_imput == n_imput == t_imput == 0:
break
d_imput = [0 for _ in range(t_imput)]
c_imput = [0 for _ in range(t_imput)]
x_imput = [0 for _ in range(p_imput)]
y_imput = [0 for _ in range(p_imput)]
for i in range(t_imput):
d_imput[i], c_imput[i] = map(int, input().split())
for i in range(p_imput):
x_imput[i], y_imput[i] = map(int, input().split())
solve(m_imput, n_imput, t_imput, p_imput, d_imput, c_imput, x_imput, y_imput)
``` | output | 1 | 48,755 | 23 | 97,511 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,756 | 23 | 97,512 |
"Correct Solution:
```
import sys
input = sys.stdin.readline
def main():
while True:
n,m,t,p = map(int,input().split())
if [n,m,t,p] == [0,0,0,0]:
exit()
dp = [[0]*(m*m+1) for i in range(n*n+1)]
sx = 0
sy = 0
ex = n
ey = m
for i in range(n):
for j in range(m):
dp[sx+i][sy+j] = 1
for i in range(t):
d,c = map(int,input().split())
if d == 1:
for k in range(c):
for j in range(sy,ey):
dp[sx+c+k][j] += dp[sx+c-k-1][j]
sx += c
ex = max(ex,sx+c)
else:
for k in range(c):
for j in range(sx,ex):
dp[j][sy+c+k] += dp[j][sy+c-k-1]
sy += c
ey = max(ey,sy+c)
res = 0
for i in range(p):
x,y = map(int,input().split())
res = dp[sx+x][sy+y]
print(res)
main()
``` | output | 1 | 48,756 | 23 | 97,513 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,757 | 23 | 97,514 |
"Correct Solution:
```
def main():
import sys
input = sys.stdin.buffer.readline
N,M,T,P = (int(i) for i in input().split())
answer = []
while not(N == M == T == P == 0):
DC = [[int(i) for i in input().split()] for _ in range(T)]
XY = [[int(i) for i in input().split()] for _ in range(P)]
rec = [[0]*(32**2+1) for _ in range(32**2+1)]
for y in range(M):
for x in range(N):
rec[y][x] += 1
ori_x,ori_y = 0,0
for d,c in DC:
if d == 1:
ori_x += c
for y in range(ori_y,32**2+1):
for x in range(ori_x,ori_x+c):
# print(M,y,ori_x*2-x-1, ori_x,x)
rec[y][x] += rec[y][ori_x*2-x-1]
else:
ori_y += c
for y in range(ori_y,ori_y+c):
for x in range(ori_x,32**2+1):
rec[y][x] += rec[ori_y*2-y-1][x]
for px,py in XY:
answer.append(rec[ori_y+py][ori_x+px])
N,M,T,P = (int(i) for i in input().split())
for a in answer:
print(a)
if __name__ == "__main__":
main()
``` | output | 1 | 48,757 | 23 | 97,515 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,758 | 23 | 97,516 |
"Correct Solution:
```
while True:
n, m, t, p = list(map(int, input().split()))
if n==0:
break
gx, gy = 500, 500
paper = [[0 for i in range(1000)] for i in range(1000)]
for i in range(n):
for j in range(m):
paper[500+i][500+j] = 1
for _ in range(t):
d, c = list(map(int, input().split()))
if d==1:
gx = gx+c
for i in range(c):
for j in range(1000):
paper[gx+i][j] += paper[gx-i-1][j]
paper[gx-i-1][j] = 0
if d==2:
gy = gy+c
for i in range(1000):
for j in range(c):
paper[i][gy+j] += paper[i][gy-j-1]
paper[i][gy-j-1] = 0
for i in range(p):
x, y = list(map(int, input().split()))
print(paper[gx+x][gy+y])
``` | output | 1 | 48,758 | 23 | 97,517 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,759 | 23 | 97,518 |
"Correct Solution:
```
# origami
import sys
input = sys.stdin.readline
def f(a, n):
a = [list(e) for e in a]
for j in range(len(a)):
for i in range(n):
if n + i >= len(a[j]):
a[j].append(a[j][n-1-i])
else:
a[j][n+i] += a[j][n-1-i]
a[j] = a[j][n:]
return a
def g(a, n):
return list(zip(*f(list(zip(*a)),n)))
while True:
n, m, t, p = map(int, input().split())
a = [[1]*n for _ in range(m)]
if n == 0: break
for _ in range(t):
d, c = map(int, input().split())
a = (f if d == 1 else g)(a, c)
for _ in range(p):
x, y= map(int, input().split())
print(a[y][x])
``` | output | 1 | 48,759 | 23 | 97,519 |
Provide a correct Python 3 solution for this coding contest problem.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6 | instruction | 0 | 48,760 | 23 | 97,520 |
"Correct Solution:
```
def main(n, m, t, p):
dpn = [1] * n
dpm = [1] * m
ldpn = n
ldpm = m
for _ in range(t):
d, c = map(int, input().split())
if d == 1:
if ldpn // 2 < c:
for i in range(ldpn - c):
dpn[c - i - 1] += dpn[c + i]
dpn = dpn[c - 1::-1]
ldpn = c
else:
for i in range(c):
dpn[c + i] += dpn[c - 1 - i]
dpn = dpn[c:]
ldpn -= c
else:
if ldpm // 2 < c:
for i in range(ldpm - c):
dpm[c - i - 1] += dpm[c + i]
dpm = dpm[c - 1::-1]
ldpm = c
else:
for i in range(c):
dpm[c + i] += dpm[c - 1 - i]
dpm = dpm[c:]
ldpm -= c
ans = []
for _ in range(p):
x, y = map(int, input().split())
ans.append(str(dpn[x] * dpm[y]))
print("\n".join(ans))
while 1:
n, m, t, p = map(int, input().split())
if n == m == t == p == 0:
break
main(n, m, t, p)
``` | output | 1 | 48,760 | 23 | 97,521 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def MAP(): return map(int, input().split())
def remove_left(M, c):
for i in range(len(M)):
M[i] = M[i][c:]
return M
def remove_bottom(M, c):
M = M[:len(M)-c]
return M
def reverse_tate(M):
for i in range(len(M)//2):
for j in range(len(M[0])):
M[i][j], M[-1-i][j] = M[-1-i][j], M[i][j]
return M
def reverse_yoko(M):
for i in range(len(M)):
M[i] = M[i][::-1]
return M
def turn_left(M, c):
if c > len(M[0])/2:
M = reverse_yoko(M)
c = len(M[0]) - c
for i in range(len(M)):
for j in range(c):
M[i][c+j] += M[i][c-1-j]
M = remove_left(M, c)
return M
def turn_bottom(M, c):
if c > len(M)/2:
M = reverse_tate(M)
c = len(M) - c
for i in range(len(M[0])):
for j in range(c):
M[len(M)-c-1-j][i] += M[len(M)-c+j][i]
M = remove_bottom(M, c)
return M
ans = []
while 1:
n, m, t, p = MAP()
if (n, m, t, p) == (0, 0, 0, 0):
break
dc = [LIST() for _ in range(t)]
xy = [LIST() for _ in range(p)]
M = [[1]*n for _ in range(m)]
for d, c in dc:
if d == 1: # 左->右
M = turn_left(M, c)
else: # 下->上
M = turn_bottom(M, c)
for x, y in xy:
ans.append(M[-1-y][0+x])
for i in ans:
print(i)
``` | instruction | 0 | 48,761 | 23 | 97,522 |
Yes | output | 1 | 48,761 | 23 | 97,523 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
#!/usr/bin/python3
import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys
def main():
while True:
N, M, T, P = read_ints()
if (N, M, T, P) == (0, 0, 0, 0):
break
F = [read_ints() for _ in range(T)]
H = [read_ints() for _ in range(P)]
print(*solve(N, M, T, P, F, H), sep='\n')
def solve(N, M, T, P, F, H):
w = N
h = M
paper = [[1] * w for _ in range(h)]
for d, c in F:
if d == 1:
w1 = max(c, w - c)
npaper = [[0] * w1 for _ in range(h)]
for y in range(h):
for dx in range(c):
npaper[y][c - 1 - dx] += paper[y][dx]
for dx in range(c, w):
npaper[y][dx - c] += paper[y][dx]
w = w1
paper = npaper
continue
h1 = max(c, h - c)
npaper = [[0] * w for _ in range(h1)]
for x in range(w):
for dy in range(c):
npaper[c - 1 - dy][x] += paper[dy][x]
for dy in range(c, h):
npaper[dy - c][x] += paper[dy][x]
h = h1
paper = npaper
return [paper[y][x] for x, y in H]
###############################################################################
# AUXILIARY FUNCTIONS
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def read_int():
return int(inp())
def read_ints():
return [int(e) for e in inp().split()]
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
if __name__ == '__main__':
main()
``` | instruction | 0 | 48,762 | 23 | 97,524 |
Yes | output | 1 | 48,762 | 23 | 97,525 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
def solve():
grid_wid, grid_hei, t, p = map(int, input().split())
if grid_wid == 0:
exit()
grid = [[1]*grid_wid for _ in range(grid_hei)]
fold = [list(map(int, input().split())) for _ in range(t)]
pin = [list(map(int, input().split())) for _ in range(p)]
# 区間の左端と右端[L,R)
L = 0
R = grid_wid
# 区間の下端と上端[B,H)
B = 0
H = grid_hei
for ope, axis in fold:
if ope == 1:
# 横におる
current_width = R-L
if axis > current_width/2: # kaiten
alter_axis = current_width-axis
for i in range(alter_axis):
for j in range(grid_hei):
grid[j][axis-i-1+L] += grid[j][axis+i+L]
grid[j][axis+i+L] = 0
# 回転させる
for j in range(grid_hei):
grid[j] = list(reversed(grid[j]))
# 区間の更新
L, R = grid_wid-R+alter_axis, grid_wid-L
else:
for i in range(axis):
for j in range(grid_hei):
grid[j][axis+i+L] += grid[j][axis-i-1+L]
grid[j][axis-i-1+L] = 0
L += axis
if ope == 2:
# 縦におる
current_hei = H-B
if axis > current_hei/2: # kaiten
alter_axis = current_hei-axis
for i in range(alter_axis):
for j in range(grid_wid):
grid[axis-i-1+B][j] += grid[axis+B+i][j]
grid[axis+i+B][j] = 0
# 回転させる
grid = list(reversed(grid))
# 区間の更新
B, H = grid_hei-H+alter_axis, grid_hei-B
else:
for i in range(axis):
for j in range(grid_wid):
grid[axis+i+B][j] += grid[axis-i-1+B][j]
grid[axis-i-1+B][j] = 0
B += axis
for px, py in pin:
ans = grid[B+py][L+px]
print(ans)
while True:
solve()
``` | instruction | 0 | 48,763 | 23 | 97,526 |
Yes | output | 1 | 48,763 | 23 | 97,527 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
from operator import add
def fold_right(v, length):
global white_right
for i in range(white_right, len(v[0])):
if not any(list(zip(*v))[i]):
white_right += 1
continue
for j in range(length - 1, -1, -1):
for yoko in range(len(v)):
v[yoko][i + j + length] += v[yoko][i + (length - 1 - j)]
v[yoko][i + (length - 1 - j)] = 0
return v
def fold_up(v, length):
global white_up
for i in range(white_up, -1, -1):
if not any(v[i]):
white_up -= 1
continue
for j in range(length - 1, -1, -1):
# print(
# "i: {} j: {} length: {} i-j: {} i-j-length: {}".format(
# i, j, length, i - (length - 1 - j), i - j - length
# )
# )
v[i - j - length] = list(
map(add, v[i - j - length], v[i - (length - 1 - j)])
)
v[i - (length - 1 - j)] = [0] * len(v[i - j])
return v
def cut_cut_cut(v):
global white_right
global white_up
for i in range(len(v) - 1, -1, -1):
if not any(v[i]):
continue
white_up = i
break
for i in range(len(v[0])):
if not any(list(zip(*v))[i]):
continue
white_right = i
break
while True:
n, m, t, p = map(int, input().split())
if n == 0 and m == 0 and t == 0 and p == 0:
break
origami = [[0] * 500 for _ in range(500)]
for i in range(m):
for j in range(n):
origami[len(origami) - 1 - i][j] = 1
white_right = 0
white_up = len(origami) - 1
# print(*origami, sep="\n")
for i in range(t):
d, c = map(int, input().split())
if d == 1:
origami = fold_right(origami, c)
else:
origami = fold_up(origami, c)
# print(d, c)
# print(*origami, sep="\n")
cut_cut_cut(origami)
for i in range(p):
x, y = map(int, input().split())
print(origami[white_up - y][white_right + x])
``` | instruction | 0 | 48,764 | 23 | 97,528 |
Yes | output | 1 | 48,764 | 23 | 97,529 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
from operator import add
def fold_right(v, length):
for i in range(len(v[0])):
if not any(list(zip(*v))[i]):
continue
for j in range(length):
for yoko in range(len(v)):
v[yoko][i + j + length] += v[yoko][i + j]
v[yoko][i + j] = 0
return v
def fold_up(v, length):
for i in range(len(v) - 1, -1, -1):
if not any(v[i]):
continue
for j in range(length):
v[i - j - length] = list(map(add, v[i - j - length], v[i - j]))
v[i - j] = [0] * len(v[i - j])
return v
def cut_cut_cut(v, x, y):
for i in range(len(v) - 1, -1, -1):
if not any(v[i]):
continue
y = i - y
break
for i in range(len(v[0])):
if not any(list(zip(*v))[i]):
continue
x = i + x
break
return v[y][x]
while True:
n, m, t, p = map(int, input().split())
if n == 0 and m == 0 and t == 0 and p == 0:
break
origami = [[0] * 63 for _ in range(63)]
for i in range(m):
for j in range(n):
origami[len(origami) - 1 - i][j] = 1
for i in range(t):
d, c = map(int, input().split())
if d == 1:
origami = fold_right(origami, c)
else:
origami = fold_up(origami, c)
# print(*origami, sep="\n")
# print()
for i in range(p):
x, y = map(int, input().split())
print(cut_cut_cut(origami, x, y))
``` | instruction | 0 | 48,765 | 23 | 97,530 |
No | output | 1 | 48,765 | 23 | 97,531 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
def patam1(field, c):
length = len(field[0]) // 2
for row in field:
for i, v in zip(range(c, min(c * 2, len(row))), row[:c]):
row[i] += v
for i in reversed(range(c * 2 - len(row))):
row.append(row[i])
del row[:c]
def patam2(field, c):
length = len(field) // 2
for i, row in zip(range(c, min(c * 2, len(field))), field[:c]):
for target, cell in enumerate(row):
field[i][target] += cell
for i in reversed(range(c * 2 - len(field))):
field.append(field[i])
del field[:c]
def solve():
n, m, t, p = map(int, input().split())
if n == m == t == p == 0:
return True
field = [[1 for x in range(n)] for y in range(m)]
for i in range(t):
d, c = map(int, input().split())
globals()["patam" + str(d)](field, c)
for i in range(p):
x, y = map(int, input().split())
print(field[y][x])
while not solve(): pass
``` | instruction | 0 | 48,766 | 23 | 97,532 |
No | output | 1 | 48,766 | 23 | 97,533 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
#!/usr/bin/python3
# coding: utf-8
MAX_V = 70
# デバッグ用の関数
def show(origami):
for i in range(MAX_V):
for j in range(MAX_V):
print(origami[i][j], end = " ")
print()
print("--------------------------------------")
# 右に c だけ折り返す処理
def fold_a(origami, c):
t = c
for i in range(c):
for j in range(MAX_V):
origami[j][t+i] += origami[j][t-i-1]
origami[j][t-i-1] = 0
copy = [x[:] for x in origami]
for i in range(MAX_V):
for j in range(MAX_V):
if j-c < 0 or MAX_V-1 < j-c:
continue
origami[i][j-c] = copy[i][j]
# 上に c だけ折り返す処理
def fold_b(origami, c):
t = MAX_V - c -1
for i in range(MAX_V):
for j in range(c):
origami[t-j][i] += origami[t+j+1][i]
origami[t+j+1][i] = 0
copy = [x[:] for x in origami]
for i in range(MAX_V):
for j in range(MAX_V):
if i+c < 0 or MAX_V-1 < i+c:
continue
origami[i+c][j] = copy[i][j]
def main():
while True:
n, m, t, p = map(int, input().split())
origami = [[0 for i in range(MAX_V)] for _ in range(MAX_V)]
for i in range(n):
for j in range(m):
origami[-1-j][i] = 1
if n == 0 and m == 0 and t == 0 and p == 0:
break
for _ in range(t):
d, c = map(int, input().split())
if d == 1:
fold_a(origami, c)
if d == 2:
fold_b(origami, c)
for _ in range(p):
x, y = map(int, input().split())
print(origami[MAX_V-y-1][x])
return 0
main()
``` | instruction | 0 | 48,767 | 23 | 97,534 |
No | output | 1 | 48,767 | 23 | 97,535 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Origami, or the art of folding paper
Master Grus is a famous origami (paper folding) artist, who is enthusiastic about exploring the possibility of origami art. For future creation, he is now planning fundamental experiments to establish the general theory of origami.
One rectangular piece of paper is used in each of his experiments. He folds it horizontally and/or vertically several times and then punches through holes in the folded paper.
The following figure illustrates the folding process of a simple experiment, which corresponds to the third dataset of the Sample Input below. Folding the 10 × 8 rectangular piece of paper shown at top left three times results in the 6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate the locations to fold the paper and round arrows indicate the directions of folding. Grid lines are shown as solid lines to tell the sizes of rectangular shapes and the exact locations of folding. Color densities represent the numbers of overlapping layers. Punching through holes at A and B in the folded paper makes nine holes in the paper, eight at A and another at B.
<image>
Your mission in this problem is to write a computer program to count the number of holes in the paper, given the information on a rectangular piece of paper and folding and punching instructions.
Input
The input consists of at most 1000 datasets, each in the following format.
> n m t p
> d1 c1
> ...
> dt ct
> x1 y1
> ...
> xp yp
>
n and m are the width and the height, respectively, of a rectangular piece of paper. They are positive integers at most 32. t and p are the numbers of folding and punching instructions, respectively. They are positive integers at most 20. The pair of di and ci gives the i-th folding instruction as follows:
* di is either 1 or 2.
* ci is a positive integer.
* If di is 1, the left-hand side of the vertical folding line that passes at ci right to the left boundary is folded onto the right-hand side.
* If di is 2, the lower side of the horizontal folding line that passes at ci above the lower boundary is folded onto the upper side.
After performing the first i−1 folding instructions, if di is 1, the width of the shape is greater than ci. Otherwise the height is greater than ci. (xi + 1/2, yi + 1/2) gives the coordinates of the point where the i-th punching instruction is performed. The origin (0, 0) is at the bottom left of the finally obtained shape. xi and yi are both non-negative integers and they are less than the width and the height, respectively, of the shape. You can assume that no two punching instructions punch holes at the same location.
The end of the input is indicated by a line containing four zeros.
Output
For each dataset, output p lines, the i-th of which contains the number of holes punched in the paper by the i-th punching instruction.
Sample Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output for the Sample Input
2
3
8
1
3
6
Example
Input
2 1 1 1
1 1
0 0
1 3 2 1
2 1
2 1
0 0
10 8 3 2
2 2
1 3
1 1
0 1
3 4
3 3 3 2
1 2
2 1
1 1
0 1
0 0
0 0 0 0
Output
2
3
8
1
3
6
Submitted Solution:
```
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())
def rev_w(MAP,H,W):
nextMAP = [[] for y in range(H)]
for y in range(H):
nextMAP[y] = MAP[y][::-1]
return nextMAP
def rev_h(MAP,H,W):
nextMAP = [[] for y in range(H)]
for y in range(H):
for x in range(W):
nextMAP[y][x] = MAP[H-y-1][x]
return nextMAP
while True:
W,H,t,p = inpl()
if W == 0:
break
else:
MAP = [[1]*W for y in range(H)]
for _ in range(t):
d,c = inpl()
if d == 1:
if W//2 >= c:
hanten = False
else:
hanten = True
if hanten:
MAP = rev_w(MAP,H,W)
c = W - c
nextW = W - c
nextH = H
nextMAP = [[1]*nextW for y in range(H)]
for y in range(H):
for x in range(c):
nextMAP[y][x] = MAP[y][x+c] + MAP[y][(c-1)-x]
for x in range(c,nextW):
nextMAP[y][x] = MAP[y][x+c]
if hanten:
nextMAP = rev_w(nextMAP,H,nextW)
elif d == 2:
if H//2 >= c:
hanten = False
else:
hanten = True
if hanten:
MAP = rev_h(MAP,H,W)
c = H - c
nextW = W
nextH = H - c
nextMAP = [[1]*W for y in range(nextH)]
for x in range(W):
for y in range(c):
nextMAP[y][x] = MAP[y+c][x] + MAP[(c-1)-y][x]
for y in range(c,nextH):
nextMAP[y][x] = MAP[y+c][x]
if hanten:
nextMAP = rev_h(nextMAP,H,nextW)
MAP = nextMAP[:]
H,W = nextH,nextW
#for m in nextMAP:
# print(m)
for _ in range(p):
x,y = inpl()
print(MAP[y][x])
``` | instruction | 0 | 48,768 | 23 | 97,536 |
No | output | 1 | 48,768 | 23 | 97,537 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that <image>). You are given two integers n and k and n closed intervals [li, ri] on OX axis and you have to find:
<image>
In other words, you should find the sum of the number of integer points in the intersection of any k of the segments.
As the answer may be very large, output it modulo 1000000007 (109 + 7).
Mike can't solve this problem so he needs your help. You will help him, won't you?
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively.
Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.
Output
Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.
Examples
Input
3 2
1 2
1 3
2 3
Output
5
Input
3 3
1 3
1 3
1 3
Output
3
Input
3 1
1 2
2 3
3 4
Output
6
Note
In the first example:
<image>;
<image>;
<image>.
So the answer is 2 + 1 + 2 = 5. | instruction | 0 | 49,300 | 23 | 98,600 |
Tags: combinatorics, data structures, dp, geometry, implementation
Correct Solution:
```
MOD = 10**9 + 7
from sys import stderr
def readints():
return [int(fld) for fld in input().strip().split()]
def combk(n, k, MOD=MOD, tbl=[]):
if len(tbl) < k:
tbl += [0] * k + [1]
while n >= len(tbl):
tbl.append(tbl[-1] * len(tbl) * pow(len(tbl) - k, MOD-2, MOD) % MOD)
return tbl[n]
def main():
n, k = readints()
pairs = [readints() for _ in range(n)]
oplist = [p for l, r in pairs for p in (2*l, 2*r+1)]
oplist.sort()
count = total = 0
pos = oplist[0] // 2
for op in oplist:
if op & 1:
i, delta = (op+1)//2, -1
else:
i, delta = op//2, 1
total = (total + combk(count, k) * (i - pos)) % MOD
pos = i
count += delta
print(total)
main()
``` | output | 1 | 49,300 | 23 | 98,601 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that <image>). You are given two integers n and k and n closed intervals [li, ri] on OX axis and you have to find:
<image>
In other words, you should find the sum of the number of integer points in the intersection of any k of the segments.
As the answer may be very large, output it modulo 1000000007 (109 + 7).
Mike can't solve this problem so he needs your help. You will help him, won't you?
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively.
Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.
Output
Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.
Examples
Input
3 2
1 2
1 3
2 3
Output
5
Input
3 3
1 3
1 3
1 3
Output
3
Input
3 1
1 2
2 3
3 4
Output
6
Note
In the first example:
<image>;
<image>;
<image>.
So the answer is 2 + 1 + 2 = 5.
Submitted Solution:
```
N, K = map(int,input().split())
L = [list(map(int,input().split())) for x in range(N)]
a = [L[x][0] for x in range(N)]
b = [L[x][1] for x in range(N)]
s = 0
a.sort()
b.sort()
a = a[K-1:] + [a[-1]]*(K-1)
b = [b[0]]*(K-1) + b[:K-1]
print(sum(a)+sum(b))
``` | instruction | 0 | 49,301 | 23 | 98,602 |
No | output | 1 | 49,301 | 23 | 98,603 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,537 | 23 | 99,074 |
"Correct Solution:
```
N = int(input())
l = []
s = set()
for i in range(N):
a,b,c = map(int,input().split(' '))
l.append(a)
l.append(b)
l.append(c)
l.sort()
d = str(l[0])
e = str(l[1])
f = str(l[2])
g = d + e + f
s.add(g)
l = []
print(N - len(s))
``` | output | 1 | 49,537 | 23 | 99,075 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,538 | 23 | 99,076 |
"Correct Solution:
```
N = int(input())
id = set()
for l in range(N):
a = [int(i) for i in input().split()]
a.sort()
id.add(a[0]*1000000 + a[1]*1000 + a[2])
print(N-len(id))
``` | output | 1 | 49,538 | 23 | 99,077 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,539 | 23 | 99,078 |
"Correct Solution:
```
n=int(input())
a={tuple(sorted(list(map(int,input().split())))) for _ in range(n)}
print(n-len(a))
``` | output | 1 | 49,539 | 23 | 99,079 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,540 | 23 | 99,080 |
"Correct Solution:
```
n = int(input())
m = set()
c = 0
for _ in range(n):
s = sorted(list(map(int, input().split())))
s = tuple(s)
if s in m:c += 1
else:m.add(s)
print(c)
``` | output | 1 | 49,540 | 23 | 99,081 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,541 | 23 | 99,082 |
"Correct Solution:
```
n = int(input())
save = set()
for _ in range(n):
t = tuple(sorted(list(input().split())))
save.add(t)
print(n - len(save))
``` | output | 1 | 49,541 | 23 | 99,083 |
Provide a correct Python 3 solution for this coding contest problem.
Computer graphics uses polygon models as a way to represent three-dimensional shapes. A polygon model is a model that creates a surface by giving the coordinates of vertices and how to connect those vertices.
A general polygon model can handle any polygon, but this time we will consider a polygon model consisting of triangles. Any polygon model can be represented as a collection of surface information that represents a triangle.
One surface information represents three vertices side by side. However, if the same 3 points are arranged only in different arrangements, the same surface information will be represented. For example, in the tetrahedron shown below, the faces formed by connecting vertices 1, 2, and 3 can be represented as vertices 2, 3, 1, and vertices 3, 2, 1. In this way, if there are multiple pieces of the same surface information, it will be useless, so it is better to combine them into one.
<image>
Given the surface information, write a program to find the number of surface information that must be erased to eliminate duplicate surfaces.
Input
The input is given in the following format.
N
p11 p12 p13
p21 p22 p23
::
pN1 pN2 pN3
The number N (1 ≤ N ≤ 1000) of the surface information of the polygon model is given in the first line. The next N lines are given the number of vertices pij (1 ≤ pij ≤ 1000) used to create the i-th face. However, the same vertex is never used more than once for one face (pi1 ≠ pi2 and pi2 ≠ pi3 and pi1 ≠ pi3).
Output
Output the number of surface information that must be erased in order to eliminate duplicate surfaces on one line.
Examples
Input
4
1 3 2
1 2 4
1 4 3
2 3 4
Output
0
Input
6
1 3 2
1 2 4
1 4 3
2 3 4
3 2 1
2 3 1
Output
2 | instruction | 0 | 49,542 | 23 | 99,084 |
"Correct Solution:
```
n = int(input())
points = []
tmp = (list(map(int, input().split())))
tmp.sort()
points.append(tmp)
for i in range(n-1):
new = list(map(int, input().split()))
new.sort()
flag = True
for arr in points:
if(arr[0] == new[0] and arr[1] == new[1] and arr[2] == new[2]):
flag = False
if(flag):
points.append(new)
print(n - len(points))
``` | output | 1 | 49,542 | 23 | 99,085 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.