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.
Kiwon's favorite video game is now holding a new year event to motivate the users! The game is about building and defending a castle, which led Kiwon to think about the following puzzle.
In a 2-dimension plane, you have a set s = \{(x_1, y_1), (x_2, y_2), β¦, (x_n, y_n)\} consisting of n distinct points. In the set s, no three distinct points lie on a single line. For a point p β s, we can protect this point by building a castle. A castle is a simple quadrilateral (polygon with 4 vertices) that strictly encloses the point p (i.e. the point p is strictly inside a quadrilateral).
Kiwon is interested in the number of 4-point subsets of s that can be used to build a castle protecting p. Note that, if a single subset can be connected in more than one way to enclose a point, it is counted only once.
Let f(p) be the number of 4-point subsets that can enclose the point p. Please compute the sum of f(p) for all points p β s.
Input
The first line contains a single integer n (5 β€ n β€ 2 500).
In the next n lines, two integers x_i and y_i (-10^9 β€ x_i, y_i β€ 10^9) denoting the position of points are given.
It is guaranteed that all points are distinct, and there are no three collinear points.
Output
Print the sum of f(p) for all points p β s.
Examples
Input
5
-1 0
1 0
-10 -1
10 -1
0 3
Output
2
Input
8
0 1
1 2
2 2
1 3
0 -1
-1 -2
-2 -2
-1 -3
Output
40
Input
10
588634631 265299215
-257682751 342279997
527377039 82412729
145077145 702473706
276067232 912883502
822614418 -514698233
280281434 -41461635
65985059 -827653144
188538640 592896147
-857422304 -529223472
Output
213
Submitted Solution:
```
import sys
input = sys.stdin.readline
from math import atan2
pi=3.14159265358979323846264338327950288419716939937510582097494459230
n=int(input())
P=[tuple(map(int,input().split())) for i in range(n)]
sc=(n-1)*(n-2)*(n-3)*(n-4)//24
ANS=0
def calc3(x):
return x*(x-1)*(x-2)//6
for i in range(n):
x,y=P[i]
score=0
Q=[]
for z,w in P[:i]:
Q.append(atan2(w-y,z-x))
for z,w in P[i+1:]:
Q.append(atan2(w-y,z-x))
Q.sort()
Q=Q+[q+2*pi for q in Q]+[100]
#print(Q)
ind=0
for j in range(n-1):
now=Q[j]
while Q[ind]-Q[j]<pi:
ind+=1
if ind-j>=4:
#print(j,ind)
score+=calc3(ind-j-1)
ANS+=sc-score
print(ANS)
``` | instruction | 0 | 34,417 | 23 | 68,834 |
No | output | 1 | 34,417 | 23 | 68,835 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem H without modification queries.
Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.
The component is built on top of a breadboard β a grid-like base for a microchip. The breadboard has n rows and m columns, and each row-column intersection contains a node. Also, on each side of the breadboard there are ports that can be attached to adjacent nodes. Left and right side have n ports each, and top and bottom side have m ports each. Each of the ports is connected on the outside to one of the parts bridged by the breadboard, and is colored red or blue respectively.
<image>
Ports can be connected by wires going inside the breadboard. However, there are a few rules to follow:
* Each wire should connect a red port with a blue port, and each port should be connected to at most one wire.
* Each part of the wire should be horizontal or vertical, and turns are only possible at one of the nodes.
* To avoid interference, wires can not have common parts of non-zero length (but may have common nodes). Also, a wire can not cover the same segment of non-zero length twice.
The capacity of the breadboard is the largest number of red-blue wire connections that can be made subject to the rules above. For example, the breadboard above has capacity 7, and one way to make seven connections is pictured below.
<image>
Up to this point statements of both versions are identical. Differences follow below.
Given the current breadboard configuration, help Lester and Delbert find its capacity efficiently.
Input
The first line contains three integers n, m, q (1 β€ n, m β€ 10^5, \pmb{q = 0}). n and m are the number of rows and columns of the breadboard respectively. In this version q is always zero, and is only present for consistency with the harder version.
The next four lines describe initial coloring of the ports. Each character in these lines is either R or B, depending on the coloring of the respective port. The first two of these lines contain n characters each, and describe ports on the left and right sides respectively from top to bottom. The last two lines contain m characters each, and describe ports on the top and bottom sides respectively from left to right.
Output
Print a single integer β the given breadboard capacity.
Example
Input
4 5 0
BBRR
RBBR
BBBBB
RRRRR
Output
7
Submitted Solution:
```
print('kto')
``` | instruction | 0 | 34,454 | 23 | 68,908 |
No | output | 1 | 34,454 | 23 | 68,909 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem H without modification queries.
Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.
The component is built on top of a breadboard β a grid-like base for a microchip. The breadboard has n rows and m columns, and each row-column intersection contains a node. Also, on each side of the breadboard there are ports that can be attached to adjacent nodes. Left and right side have n ports each, and top and bottom side have m ports each. Each of the ports is connected on the outside to one of the parts bridged by the breadboard, and is colored red or blue respectively.
<image>
Ports can be connected by wires going inside the breadboard. However, there are a few rules to follow:
* Each wire should connect a red port with a blue port, and each port should be connected to at most one wire.
* Each part of the wire should be horizontal or vertical, and turns are only possible at one of the nodes.
* To avoid interference, wires can not have common parts of non-zero length (but may have common nodes). Also, a wire can not cover the same segment of non-zero length twice.
The capacity of the breadboard is the largest number of red-blue wire connections that can be made subject to the rules above. For example, the breadboard above has capacity 7, and one way to make seven connections is pictured below.
<image>
Up to this point statements of both versions are identical. Differences follow below.
Given the current breadboard configuration, help Lester and Delbert find its capacity efficiently.
Input
The first line contains three integers n, m, q (1 β€ n, m β€ 10^5, \pmb{q = 0}). n and m are the number of rows and columns of the breadboard respectively. In this version q is always zero, and is only present for consistency with the harder version.
The next four lines describe initial coloring of the ports. Each character in these lines is either R or B, depending on the coloring of the respective port. The first two of these lines contain n characters each, and describe ports on the left and right sides respectively from top to bottom. The last two lines contain m characters each, and describe ports on the top and bottom sides respectively from left to right.
Output
Print a single integer β the given breadboard capacity.
Example
Input
4 5 0
BBRR
RBBR
BBBBB
RRRRR
Output
7
Submitted Solution:
```
(n, m, _) = (int(i) for i in input().split())
res = 0
s1 = input()
s2 = input()
s3 = input()
s4 = input()
for i in range(n):
if s1[i] != s2[i]:
res += 1
for i in range(m):
if s3[i] != s4[i]:
res += 1
print(res)
``` | instruction | 0 | 34,455 | 23 | 68,910 |
No | output | 1 | 34,455 | 23 | 68,911 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
This is an easier version of the problem H without modification queries.
Lester and Delbert work at an electronics company. They are currently working on a microchip component serving to connect two independent parts of a large supercomputer.
The component is built on top of a breadboard β a grid-like base for a microchip. The breadboard has n rows and m columns, and each row-column intersection contains a node. Also, on each side of the breadboard there are ports that can be attached to adjacent nodes. Left and right side have n ports each, and top and bottom side have m ports each. Each of the ports is connected on the outside to one of the parts bridged by the breadboard, and is colored red or blue respectively.
<image>
Ports can be connected by wires going inside the breadboard. However, there are a few rules to follow:
* Each wire should connect a red port with a blue port, and each port should be connected to at most one wire.
* Each part of the wire should be horizontal or vertical, and turns are only possible at one of the nodes.
* To avoid interference, wires can not have common parts of non-zero length (but may have common nodes). Also, a wire can not cover the same segment of non-zero length twice.
The capacity of the breadboard is the largest number of red-blue wire connections that can be made subject to the rules above. For example, the breadboard above has capacity 7, and one way to make seven connections is pictured below.
<image>
Up to this point statements of both versions are identical. Differences follow below.
Given the current breadboard configuration, help Lester and Delbert find its capacity efficiently.
Input
The first line contains three integers n, m, q (1 β€ n, m β€ 10^5, \pmb{q = 0}). n and m are the number of rows and columns of the breadboard respectively. In this version q is always zero, and is only present for consistency with the harder version.
The next four lines describe initial coloring of the ports. Each character in these lines is either R or B, depending on the coloring of the respective port. The first two of these lines contain n characters each, and describe ports on the left and right sides respectively from top to bottom. The last two lines contain m characters each, and describe ports on the top and bottom sides respectively from left to right.
Output
Print a single integer β the given breadboard capacity.
Example
Input
4 5 0
BBRR
RBBR
BBBBB
RRRRR
Output
7
Submitted Solution:
```
word = input()
x = word[0]
y = str(len(word)-2)
z = word[-1]
if len(word) > 10:
print(x+y+z)
else:
print(word)
``` | instruction | 0 | 34,456 | 23 | 68,912 |
No | output | 1 | 34,456 | 23 | 68,913 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,632 | 23 | 69,264 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
n, m, k = map(int, input().split())
c = k
dir = "right"
start_x = 1
start_y = 1
ans = []
while c > 0:
if c == 1:
r = m*n-2*(k-1)
s = str(r)+' '
pos = []
while r > 0:
pos.append((start_y, start_x))
move = 1 if dir == "right" else -1
start_x += move
if start_x == m+1:
start_x = m
start_y += 1
dir = "left"
if start_x == 0:
start_x = 1
start_y += 1
dir = "right"
r -= 1
s += ' '.join(["{} {}".format(x[0],x[1]) for x in pos])
ans.append(s)
else:
move = 2 if dir == "right" else -2
if dir == "right":
if start_x + move > m+1:
ans.append("2 {} {} {} {}".format(start_y, start_x, start_y+1, start_x))
start_x = m
start_y += 1
move -= 1
dir = "left"
start_x -= 1
else:
ans.append("2 {} {} {} {}".format(start_y, start_x, start_y, start_x+1))
start_x += 2
if start_x > m:
start_y += 1
start_x = m
dir = "left"
else:
if start_x + move < 0:
ans.append("2 {} {} {} {}".format(start_y, start_x, start_y+1, start_x))
start_x = 1
start_y += 1
move -= 1
dir = "right"
start_x += 1
else:
ans.append("2 {} {} {} {}".format(start_y, start_x, start_y, start_x-1))
start_x -= 2
if start_x < 1:
start_y += 1
start_x = 1
dir = "right"
c -= 1
print(*ans, sep='\n')
``` | output | 1 | 34,632 | 23 | 69,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,633 | 23 | 69,266 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
from itertools import chain
r, c, n = map(int, input().split())
ans = []
for i in range(1, r + 1):
x, y, z = (1, c + 1, 1) if i % 2 == 1 else (c, 0, -1)
for j in range(x, y, z):
ans.append((i, j))
l = r * c // n
sans = [ans[i : i + l] for i in range(0, (n - 1) * l, l)]
sans.append(ans[l * len(sans) :])
print("\n".join(map(lambda x: " ".join(map(str, [len(x)] + list(chain(*x)))), sans)))
``` | output | 1 | 34,633 | 23 | 69,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,634 | 23 | 69,268 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
import time,math,bisect,sys
from sys import stdin,stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi=3.14159265358979323846264338327950
def II(): # to take integer input
return int(stdin.readline())
def IO(): # to take string input
return stdin.readline()
def IP(): # to take tuple as input
return map(int,stdin.readline().split())
def L(): # to take list as input
return list(map(int,stdin.readline().split()))
def P(x): # to print integer,list,string etc..
return stdout.write(str(x))
def PI(x,y): # to print tuple separatedly
return stdout.write(str(x)+" "+str(y)+"\n")
def lcm(a,b): # to calculate lcm
return (a*b)//gcd(a,b)
def gcd(a,b): # to calculate gcd
if a==0:
return b
elif b==0:
return a
if a>b:
return gcd(a%b,b)
else:
return gcd(a,b%a)
def readTree(): # to read tree
v=int(input())
adj=[set() for i in range(v+1)]
for i in range(v-1):
u1,u2=In()
adj[u1].add(u2)
adj[u2].add(u1)
return adj,v
def bfs(adj,v): # a schema of bfs
visited=[False]*(v+1)
q=deque()
while q:
pass
def sieve():
li=[True]*1000001
li[0],li[1]=False,False
for i in range(2,len(li),1):
if li[i]==True:
for j in range(i*i,len(li),i):
li[j]=False
prime=[]
for i in range(1000001):
if li[i]==True:
prime.append(i)
return prime
def setBit(n):
count=0
while n!=0:
n=n&(n-1)
count+=1
return count
#####################################################################################
def solve():
n,m,k=IP()
li=[]
for i in range(n):
if i%2==0:
for j in range(m):
li.append(i+1)
li.append(j+1)
else:
for j in range(m-1,-1,-1):
li.append(i+1)
li.append(j+1)
last=-1
n=len(li)
for i in range(k):
if i==(k-1):
print((n-last)//2,end=" ")
for j in range(last+1,n):
print(li[j],end=" ")
else:
print(2,end=" ")
for j in range(last+1,last+5):
print(li[j],end=" ")
last=last+4
print()
solve()
#######
#
#
####### # # # #### # # #
# # # # # # # # # # #
# #### # # #### #### # #
###### # # #### # # # # #
``` | output | 1 | 34,634 | 23 | 69,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,635 | 23 | 69,270 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
n,m,k = map(int,input().split())
ans=[]
i=1
j=1
gg = (n*m)//2
for g in range(gg):
if i%2!=0:
if j!=m:
ans.append([i,j,i,j+1])
j+=2
if j==m+1:
j=m
i+=1
else:
ans.append([i,j,i+1,m])
i+=1
j=m-1
else:
if j!=0:
ans.append([i,j,i,j-1])
j-=2
if j==0:
j=1
i+=1
else:
ans.append([i,j,i+1,1])
j=2
i+=1
x,y,z,q =ans[-1]
if n%2!=0 and q!=m:
ans[-1]+=[n,m]
elif n%2==0 and q!=1:
ans+=[n,1]
aa=[]
c=1
for i in ans[:k-1]:
print(len(i)//2,end=' ')
print(*i)
for i in ans[k-1:]:
aa+=i
print(len(aa)//2,end=' ')
print(*aa)
``` | output | 1 | 34,635 | 23 | 69,271 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,636 | 23 | 69,272 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
import sys, math, itertools, random, bisect
from collections import defaultdict
# sys.setrecursionlimit(999999999)
INF = 10**18
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
mod = 10**9 + 7
# MAX = 100001
# def sieve():
# isPrime = [True]*(MAX)
# isPrime[0] = False
# isPrime[1] = False
# for i in range(2,MAX):
# if isPrime[i]:
# for j in range(i*i, MAX, i):
# isPrime[j] = False
# primes = [2]
# for i in range(3,MAX,2):
# if isPrime[i]: primes.append(i)
# return primes
test = 1
# test = int(input())
for _ in range(test):
n,m,k = get_ints()
# a = get_array()
row = 1
col = 1
right = True
for i in range(k-1):
if right:
if col==m:
print(2, row, col, row+1, col)
col -= 1
row += 1
right = False
elif col>m:
row += 1
col -= 1
print(2, row, col, row, col-1)
col -= 2
right = False
else:
print(2, row, col, row, col+1)
col += 2
else:
if col==1:
print(2, row, col, row+1, col)
row += 1
col += 1
right = True
elif col<1:
row += 1
col += 1
print(2,row,col,row,col+1)
col += 2
right = True
else:
print(2, row, col, row, col-1)
col -= 2
rem = n*m - 2*(k-1)
ans = [rem]
if col==m+1 or col==0:
row += 1
col = 1
right = True
for i in range(rem):
if right:
if col==m:
ans.append(row)
ans.append(col)
row += 1
right = False
else:
ans.append(row)
ans.append(col)
col += 1
else:
if col==1:
ans.append(row)
ans.append(col)
row += 1
right = True
else:
ans.append(row)
ans.append(col)
col -= 1
print(*ans)
``` | output | 1 | 34,636 | 23 | 69,273 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,637 | 23 | 69,274 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
n, m, k = [int(c) for c in input().split()]
x, y = [1, 1]
def next_cell(x, y):
if x % 2 == 1 and y < m:
return [x, y + 1]
elif x % 2 == 0 and y > 1:
return [x, y - 1]
else:
return [x + 1, y]
for i in range(1, k):
x2, y2 = next_cell(x, y)
print(2, x, y, x2, y2)
x, y = next_cell(x2, y2)
last = [x, y]
req_len = n*m - (k-1)*2
while len(last) < req_len * 2:
x, y = next_cell(x, y)
last.append(x)
last.append(y)
print(len(last) // 2, ' '.join(map(str,last)))
``` | output | 1 | 34,637 | 23 | 69,275 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,638 | 23 | 69,276 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
#===========Template===============
from io import BytesIO, IOBase
from math import sqrt
import sys,os
from os import path
inpl=lambda:list(map(int,input().split()))
inpm=lambda:map(int,input().split())
inpi=lambda:int(input())
inp=lambda:input()
rev,ra,l=reversed,range,len
P=print
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)
def input(): return sys.stdin.readline().rstrip("\r\n")
def B(n):
return bin(n).replace("0b","")
def factors(n):
arr=[]
for i in ra(2,int(sqrt(n))+1):
if n%i==0:
arr.append(i)
if i*i!=n:
arr.append(int(n/i))
return arr
def dfs(arr,n):
pairs=[[i+1] for i in ra(n)]
vis=[0]*(n+1)
for i in ra(l(arr)):
pairs[arr[i][0]-1].append(arr[i][1])
pairs[arr[i][1]-1].append(arr[i][0])
comp=[]
for i in ra(n):
stack=[pairs[i]]
temp=[]
if vis[stack[-1][0]]==0:
while len(stack)>0:
if vis[stack[-1][0]]==0:
temp.append(stack[-1][0])
vis[stack[-1][0]]=1
s=stack.pop()
for j in s[1:]:
if vis[j]==0:
stack.append(pairs[j-1])
else:
stack.pop()
comp.append(temp)
return comp
#=========I/p O/p ========================================#
from bisect import bisect_left as bl
from bisect import bisect_right as br
import sys,operator,math,operator
from collections import Counter
if(path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
import random
#==============To chaliye shuru krte he ====================#
n,m,k=inpm()
fi=(n*m)-((k-1)*2)
arr=[[0 for i in ra(m)] for j in ra(n)]
row,col=0,0
P(fi,end=" ")
turn=True
for i in ra(fi):
if turn:
P(row+1,(col)%m+1,end=" ")
col+=1
if col%m==0:
turn=False
row+=1
col=m
else:
P(row+1,col,end=" ")
col-=1
if col==0:
turn=True
row+=1
col=0
c=0
for i in ra((n*m)-fi):
if c%2==0:
P()
P(2,end=" ")
if turn:
P(row+1,(col)%m+1,end=" ")
col+=1
if col%m==0:
turn=False
row+=1
col=m
else:
P(row+1,col,end=" ")
col-=1
if col==0:
turn=True
row+=1
col=0
c+=1
``` | output | 1 | 34,638 | 23 | 69,277 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image> | instruction | 0 | 34,639 | 23 | 69,278 |
Tags: constructive algorithms, dfs and similar, implementation
Correct Solution:
```
n, m, k = [int(i) for i in input().split()]
arr = []
start = 0
end = m
cont = 1
for i in range(n):
for j in range(start, end, cont):
arr.append(i+1)
arr.append(j+1)
if start == 0:
start = m-1
end = -1
cont = -1
else:
start = 0
end = m
cont = 1
start = 0
for i in range(k-1):
print(*([2]+arr[start:(start+4)]))
start += 4
print(*([n*m-((k-1)*2)]+arr[start:]))
``` | output | 1 | 34,639 | 23 | 69,279 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
(n, m, k) = map(int, input().split())
a = []
for i in range(1,n+1):
if i% 2 == 1:
for j in range(1,m+1):
a.append([i,j])
else:
for j in range(m,0,-1):
a.append([i,j])
x = 1
i = 0
while x < k:
print(2, end=' ')
for j in range(i,i+2):
print(*a[j], end=' ')
i += 2
x += 1
print()
print(len(a)-i, end=' ')
for j in a[i:]:
print(*j,end=' ')
``` | instruction | 0 | 34,640 | 23 | 69,280 |
Yes | output | 1 | 34,640 | 23 | 69,281 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
n,m,k=map(int,input().split())
l=[]
for i in range(n):
for j in range(m)[::[1,-1][i%2]]:
l+=[str(i+1),str(j+1)]
p=m*n//k
for i in range(k-1):print(p,' '.join(l[2*p*i:2*p*(i+1)]))
print(m*n-p*(k-1),' '.join(l[2*p*(k-1):]))
``` | instruction | 0 | 34,641 | 23 | 69,282 |
Yes | output | 1 | 34,641 | 23 | 69,283 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))
def new_point_generator(n, m):
i, j = 0, 0
yield f"{i + 1} {j + 1}"
while True:
if j + 1 < m and i % 2 == 0:
j += 1
elif j - 1 >= 0 and i % 2 == 1:
j -= 1
yield f"{i + 1} {j + 1}"
if j == m - 1 or j == 0:
i += 1
yield f"{i + 1} {j + 1}"
def solve():
n, m, k = read_tuple(int)
cells = n * m
cells_for_pipe = [cells // k for _ in range(k)]
cells_for_pipe[0] += cells % k
cells_for_pipe = iter(cells_for_pipe)
filled = 0
point_generator = new_point_generator(n, m)
while filled < cells:
_len = next(cells_for_pipe)
print(_len, end=' ')
for _ in range(_len):
print(next(point_generator), end=' ')
filled += _len
print()
if __name__ == '__main__':
solve()
``` | instruction | 0 | 34,642 | 23 | 69,284 |
Yes | output | 1 | 34,642 | 23 | 69,285 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
def next(x, y, xx):
if x == n and xx == 1:
y += 1
xx *= -1
elif x == 1 and xx == -1:
y += 1
xx *= -1
else:
x += xx
return x, y, xx
n, m, num = map(int, input().split(" "))
x = 1
xx = -1
y = 0
for i in range(num - 1):
j = 0
s = "2 "
while j < 2:
x, y, xx = next(x, y, xx)
s += "{} {} ".format(str(x), str(y))
j += 1
print(s)
s = str(n * m - 2 * (num - 1)) + " "
for i in range(n * m - 2 * (num - 1)):
x, y, xx = next(x, y, xx)
s += "{} {} ".format(str(x), str(y))
print(s)
``` | instruction | 0 | 34,643 | 23 | 69,286 |
Yes | output | 1 | 34,643 | 23 | 69,287 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify ,_heapify_max,_heappop_max,nsmallest,nlargest
sys.setrecursionlimit(111111)
INF=99999999999999999999999999999999
def main():
mod=1000000007
# InverseofNumber(mod)
# InverseofFactorial(mod)
# factorial(mod)
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
###CODE
tc = 1
for _ in range(tc):
n,m,k=ria()
matrix=[[0]*m for i in range(n)]
c=1
for i in range(n):
for j in range(0,m,2):
if j+1<m:
matrix[i][j]=c
matrix[i][j+1]=c
if c+1>k:
c=k
else:
c+=1
d={}
for i in range(n):
for j in range(m):
if matrix[i][j]==0:
matrix[i][j]=k
if matrix[i][j] not in d:
d[matrix[i][j]]=[[i+1,j+1]]
else:
d[matrix[i][j]].append([i+1,j+1])
# for i in matrix:
# print(i)
for i in range(1,k+1):
ans=[len(d[i])]
for x,y in d[i]:
ans.append(x)
ans.append(y)
wia(ans)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
``` | instruction | 0 | 34,644 | 23 | 69,288 |
No | output | 1 | 34,644 | 23 | 69,289 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
def valera_and_tube(n, m, k):
snake = []
x = 0
for y in range(1, m + 1):
if x == 0:
start = 1
stop = n + 1
step = 1
else:
start = n
stop = 0
step = -1
for x in range(start, stop, step):
snake.append((x, y))
for i in range(k - 1):
print(2, *snake[i * 2], *snake[i * 2 + 1])
i = 2 * i + 2
print(len(snake) - i, *[' '.join(map(str, x)) for x in snake[i:]])
n, m, k = map(int, input().strip().split())
valera_and_tube(n, m, k)
``` | instruction | 0 | 34,645 | 23 | 69,290 |
No | output | 1 | 34,645 | 23 | 69,291 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
# import sys
# sys.stdin = open("F:\\Scripts\\input","r")
# sys.stdout = open("F:\\Scripts\\output","w")
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
def pr(x,ys,ye):
for i in range(ys , ye + 1):
print(x,i,end = ' ')
print("")
n, m, k = I()
x = 1
y = 1
for i in range(1,k):
print(1,x,y)
y += 1
if y > m:
x += 1
y = 1
print((n - x)*m + m - y + 1,end = ' ')
while y <= m:
print(x,y,end=' ')
y += 1
for i in range(x+1,n+1):
for k in range(1 , m + 1):
print(i,k,end = ' ')
``` | instruction | 0 | 34,646 | 23 | 69,292 |
No | output | 1 | 34,646 | 23 | 69,293 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Valera has got a rectangle table consisting of n rows and m columns. Valera numbered the table rows starting from one, from top to bottom and the columns β starting from one, from left to right. We will represent cell that is on the intersection of row x and column y by a pair of integers (x, y).
Valera wants to place exactly k tubes on his rectangle table. A tube is such sequence of table cells (x1, y1), (x2, y2), ..., (xr, yr), that:
* r β₯ 2;
* for any integer i (1 β€ i β€ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;
* each table cell, which belongs to the tube, must occur exactly once in the sequence.
Valera thinks that the tubes are arranged in a fancy manner if the following conditions are fulfilled:
* no pair of tubes has common cells;
* each cell of the table belongs to some tube.
Help Valera to arrange k tubes on his rectangle table in a fancy manner.
Input
The first line contains three space-separated integers n, m, k (2 β€ n, m β€ 300; 2 β€ 2k β€ nΒ·m) β the number of rows, the number of columns and the number of tubes, correspondingly.
Output
Print k lines. In the i-th line print the description of the i-th tube: first print integer ri (the number of tube cells), then print 2ri integers xi1, yi1, xi2, yi2, ..., xiri, yiri (the sequence of table cells).
If there are multiple solutions, you can print any of them. It is guaranteed that at least one solution exists.
Examples
Input
3 3 3
Output
3 1 1 1 2 1 3
3 2 1 2 2 2 3
3 3 1 3 2 3 3
Input
2 3 1
Output
6 1 1 1 2 1 3 2 3 2 2 2 1
Note
Picture for the first sample:
<image>
Picture for the second sample:
<image>
Submitted Solution:
```
import sys
read = lambda: sys.stdin.readline().strip()
readi = lambda: map(int, read().split())
from collections import *
from math import *
n, m, k = readi()
totalTubes = ceil((n*m) / k)
step = 1
cellCount = 0
for i in range(1, n+1):
if step == 1:
for j in range(1, m+1):
if cellCount % totalTubes == 0:
if cellCount !=0: print()
print(totalTubes, end=" ")
print(i, j, end=" ")
cellCount += 1
step *= -1
else:
for j in range(m, 0, -1):
if cellCount % totalTubes == 0:
if cellCount !=0: print()
print(totalTubes, end=" ")
print(i, j, end=" ")
cellCount += 1
step *= -1
``` | instruction | 0 | 34,647 | 23 | 69,294 |
No | output | 1 | 34,647 | 23 | 69,295 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix of size n Γ m. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual!
Input
The first line contains two numbers n and m (1 β€ n β€ 212, 4 β€ m β€ 214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4.
Then the representation of matrix follows. Each of n next lines contains <image> one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Output
Print the number of connected components consisting of 1's.
Examples
Input
3 4
1
A
8
Output
3
Input
2 8
5F
E3
Output
2
Input
1 4
0
Output
0
Note
In the first example the matrix is:
0001
1010
1000
It is clear that it has three components.
The second example:
01011111
11100011
It is clear that the number of components is 2.
There are no 1's in the third example, so the answer is 0.
Submitted Solution:
```
n, m = map(int, input().split())
k = 0
ps = input()
ps = bin(int(ps, 16))
ps = ps[2:]
ps = '0' * (m - len(ps)) + ps
for i in range(m):
if ps[i] == '1':
if i == 0:
k += 1
elif ps[i - 1] != '1':
k += 1
for i in range(n - 1):
ns = input()
ns = bin(int(ns, 16))
ns = ns[2:]
ns = '0' * (m - len(ns)) + ns
for j in range(m):
if ns[j] == '1':
if j == 0:
if ns[j + 1] != '1' and ps[j] != '1':
k+= 1
elif j == m - 1:
if ns[j - 1] != '1' and ps[j] != '1':
k += 1
else:
if ns[j - 1] != '1' and ps[j] != '1' and ns[j + 1] != '1':
k += 1
ps = ns
print(k)
``` | instruction | 0 | 34,856 | 23 | 69,712 |
No | output | 1 | 34,856 | 23 | 69,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix of size n Γ m. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual!
Input
The first line contains two numbers n and m (1 β€ n β€ 212, 4 β€ m β€ 214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4.
Then the representation of matrix follows. Each of n next lines contains <image> one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Output
Print the number of connected components consisting of 1's.
Examples
Input
3 4
1
A
8
Output
3
Input
2 8
5F
E3
Output
2
Input
1 4
0
Output
0
Note
In the first example the matrix is:
0001
1010
1000
It is clear that it has three components.
The second example:
01011111
11100011
It is clear that the number of components is 2.
There are no 1's in the third example, so the answer is 0.
Submitted Solution:
```
#http://codeforces.com/contest/884/problem/E
#dsu
import sys
sys.setrecursionlimit(2000)
def init():
for i in range(m):
parent[i]=parent[m+i]
if parent[i]>=m:
parent[i]-=m
parent[m:]=[-1]*m
def find(i):
if parent[i] == i:
return i
parent[i]=find(parent[i])
return parent[i]
def union(i,j):
if parent[i]==-1 or parent[j]==-1:
return False
i=find(i)
j=find(j)
if i==j:
return False
if i > j:
parent[j]=i
else:
parent[i]=j
return True
n,m=map(int,sys.stdin.readline().split())
parent=[-1]*(2*m)
ans=0
for i in range(n):
st='F'*(m//4)
for l in range(len(st)):
if st[l]>='A':
num=10+ord(st[l])-65
else:
num=int(st[l])
j=l*4
for k in range(4):
if (num &(1<<(3-k)))==0: continue
parent[m+j+k]=m+j+k
ans+=1
if j+k > 0 and union(m+j+k,m+j+k-1):
ans-=1
if union(m+j+k,j+k):
ans-=1
init()
print(ans)
``` | instruction | 0 | 34,857 | 23 | 69,714 |
No | output | 1 | 34,857 | 23 | 69,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix of size n Γ m. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual!
Input
The first line contains two numbers n and m (1 β€ n β€ 212, 4 β€ m β€ 214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4.
Then the representation of matrix follows. Each of n next lines contains <image> one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Output
Print the number of connected components consisting of 1's.
Examples
Input
3 4
1
A
8
Output
3
Input
2 8
5F
E3
Output
2
Input
1 4
0
Output
0
Note
In the first example the matrix is:
0001
1010
1000
It is clear that it has three components.
The second example:
01011111
11100011
It is clear that the number of components is 2.
There are no 1's in the third example, so the answer is 0.
Submitted Solution:
```
n, m = map(int, input().split())
k = 0
ps = input()
ps = bin(int(ps, 16))
ps = ps[2:]
ps = '0' * (m - len(ps)) + ps
for i in range(m):
if ps[i] == '1':
if i == 0:
k += 1
elif ps[i - 1] != '1':
k += 1
for i in range(n - 1):
ns = input()
ns = bin(int(ns, 16))
ns = ns[2:]
ns = '0' * (m - len(ns)) + ns
ts = ns
for j in range(m):
if ts[j] == '1' and ps[j] == '1':
ts = ts[:j] +'0' + ts[j + 1:]
if j > 0:
ts = ts[:j - 1] +'0' + ts[j:]
if j < m - 1 :
ts = ts[:j + 1] +'0' + ts[j + 2:]
k += sum(list(map(int, ts)))
# for j in range(m):
# if ns[j] == '1':
# if j == 0:
# if ns[j + 1] != '1' and ps[j] != '1':
# k += 1
# elif j == m - 1:
# if ns[j - 1] != '1' and ps[j] != '1':
# k += 1
# else:
# if ns[j - 1] != '1' and ps[j] != '1' and ns[j + 1] != '1':
# k += 1
ps = ns
print(k)
``` | instruction | 0 | 34,858 | 23 | 69,716 |
No | output | 1 | 34,858 | 23 | 69,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a matrix of size n Γ m. Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual!
Input
The first line contains two numbers n and m (1 β€ n β€ 212, 4 β€ m β€ 214) β the number of rows and columns, respectively. It is guaranteed that m is divisible by 4.
Then the representation of matrix follows. Each of n next lines contains <image> one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Output
Print the number of connected components consisting of 1's.
Examples
Input
3 4
1
A
8
Output
3
Input
2 8
5F
E3
Output
2
Input
1 4
0
Output
0
Note
In the first example the matrix is:
0001
1010
1000
It is clear that it has three components.
The second example:
01011111
11100011
It is clear that the number of components is 2.
There are no 1's in the third example, so the answer is 0.
Submitted Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
"""
created by shhuan at 2017/11/8 09:50
"""
M, N = map(int, input().split())
A = []
for i in range(M):
A.append(list(input()))
def tob(valChar):
v = int(valChar, 16)
v = bin(v)
v = list(v[2:])
v = ['0'] * (4-len(v)) + v
return v
def one_index(a, r):
ones = [0] * N
for c in range(N // 4):
v = tob(a[r][c])
for i in range(4):
if v[i] == '1':
ones[c*4+i] = 1
groups = set()
if ones[0] != 0:
groups.add(1)
for i in range(1, N):
if ones[i] == 1:
if ones[i-1] != 0:
ones[i] = ones[i-1]
else:
ones[i] = i + 1
groups.add(i + 1)
return ones, groups
def one_index2(a, r):
ones = []
for c in range(N // 4):
v = tob(a[r][c])
t = []
for i in range(4):
if v[i] == '1':
j = c * 4 + i
if t and t[-1][1] == j - 1:
u = t.pop()
t.append((u[0], j))
else:
t.append((j, j))
if t:
if ones and ones[-1][1] == t[0][0] - 1:
u = ones.pop()
ones.append((u[0], t[0][1]))
for u in t[1:]:
ones.append(u)
else:
for u in t:
ones.append(u)
return ones
ans = 0
last_ones, last_groups = one_index(A, 0)
for r in range(1, M):
ones, groups = one_index(A, r)
rep = {}
for i in range(N):
if last_ones[i] != 0 and ones[i] != 0:
v = last_ones[i]
if v in rep:
rv = rep[v]
if ones[i] != rv:
groups -= {ones[i]}
ones[i] = rv
j = i-1
while j >= 0 and ones[j] != rv and ones[j] != 0:
ones[j] = rv
j -= 1
j = i + 1
while j < N and ones[j] != rv and ones[j] != 0:
ones[j] = rv
j += 1
else:
rep[v] = ones[i]
last_groups -= {v}
ans += len(last_groups)
last_ones, last_groups = ones, {i for i in ones if i != 0}
print(ans + len(last_groups))
``` | instruction | 0 | 34,859 | 23 | 69,718 |
No | output | 1 | 34,859 | 23 | 69,719 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,085 | 23 | 70,170 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if not n:
break
ps = [list(map(int,input().split())) for i in range(n)]
dic = set()
for t in ps:
dic.add((t[0],t[1]))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
p1x = p1[0]
p1y = p1[1]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
``` | output | 1 | 35,085 | 23 | 70,171 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,086 | 23 | 70,172 |
"Correct Solution:
```
while True:
n = int(input())
if not n:
break
poles = [tuple(map(int, input().split())) for _ in range(n)]
poles_set = set(poles)
max_square = 0
for i in range(n):
x1, y1 = poles[i]
for j in range(i, n):
x2, y2 = poles[j]
dx, dy = x2 - x1, y2 - y1
if ((x2 + dy, y2 - dx) in poles_set and (x1 + dy, y1 - dx) in poles_set) \
or ((x2 - dy, y2 + dx) in poles_set and (x1 - dy, y1 + dx) in poles_set):
edge = dx ** 2 + dy ** 2
if max_square < edge:
max_square = edge
print(max_square)
``` | output | 1 | 35,086 | 23 | 70,173 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,087 | 23 | 70,174 |
"Correct Solution:
```
def main():
#points = [[False for i in range(5001)] for j in range(5001)]
while True:
n = int(input())
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = map(int,input().split())
dic[(x, y)] = 1;
#points[x][y] = True
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
vx = p2[0] - p1[0]
vy = p2[1] - p1[1]
#if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:
# if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:
if (p1[0] + vy, p1[1] - vx) in dic and (p2[0] + vy, p2[1] - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
#for p in ps:
# points[p[0]][p[1]] = False
print(ans)
main()
``` | output | 1 | 35,087 | 23 | 70,175 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,088 | 23 | 70,176 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if not n:
break
ps = []
dic = {}
for i in range(n):
x, y = map(int,input().split())
dic[(x, y)] = 1;
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
p1x = p1[0]
p1y = p1[1]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
``` | output | 1 | 35,088 | 23 | 70,177 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,089 | 23 | 70,178 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if not n:
break
ps = [list(map(int,input().split())) for i in range(n)]
dic = set()
for t in ps:
dic.add((t[0],t[1]))
ans = 0
for i in range(n):
p1 = ps[i]
p1x = p1[0]
p1y = p1[1]
for j in range(n):
p2 = ps[j]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy, p1y - vx) in dic and (p2x + vy, p2y - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
``` | output | 1 | 35,089 | 23 | 70,179 |
Provide a correct Python 3 solution for this coding contest problem.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None | instruction | 0 | 35,090 | 23 | 70,180 |
"Correct Solution:
```
def main():
while True:
n = int(input())
if not n:
break
ps = [tuple(map(int,input().split())) for i in range(n)]
dic = set()
for t in ps:
dic.add(t)
ans = 0
for i in range(n):
p1 = ps[i]
p1x = p1[0]
p1y = p1[1]
for j in range(n):
p2 = ps[j]
p2x = p2[0]
p2y = p2[1]
vx = p2x - p1x
vy = p2y - p1y
if (p1x + vy , p1y - vx) in dic and (p2x + vy , p2y - vx) in dic:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
``` | output | 1 | 35,090 | 23 | 70,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None
Submitted Solution:
```
n = int(input())
poles = [tuple(map(int, input().split())) for _ in range(n)]
poles_set = set(poles)
max_square = 0
for i in range(n):
x1, y1 = poles[i]
for j in range(i, n):
x2, y2 = poles[j]
dx, dy = x2 - x1, y2 - y1
if ((x2 + dy, y2 - dx) in poles_set and (x1 + dy, y1 - dx) in poles_set) \
or ((x2 - dy, y2 + dx) in poles_set and (x1 - dy, y1 + dx) in poles_set):
edge = dx ** 2 + dy ** 2
if max_square < edge:
max_square = edge
print(max_square)
``` | instruction | 0 | 35,091 | 23 | 70,182 |
No | output | 1 | 35,091 | 23 | 70,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None
Submitted Solution:
```
def main():
while True:
n = int(input())
if not n:
break
points = [[False for i in range(5001)] for j in range(5001)]
ps = []
for i in range(n):
x, y = map(int,input().split())
points[x][y] = True
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
vx = p2[0] - p1[0]
vy = p2[1] - p1[1]
if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:
if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:
ans = max(ans, vx ** 2 + vy ** 2)
print(ans)
main()
``` | instruction | 0 | 35,092 | 23 | 70,184 |
No | output | 1 | 35,092 | 23 | 70,185 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None
Submitted Solution:
```
def main():
points = [[False for i in range(5001)] for j in range(5001)]
while True:
n = int(input())
if not n:
break
ps = []
for i in range(n):
x, y = map(int,input().split())
points[x][y] = True
ps.append((x,y))
ans = 0
for i in range(n):
for j in range(n):
p1 = ps[i]
p2 = ps[j]
vx = p2[0] - p1[0]
vy = p2[1] - p1[1]
if 0 <= p1[0] + vy <= 5000 and 0 <= p1[1] - vx <= 5000 and 0 <= p2[0] + vy <= 5000 and 0 <= p2[1] - vx <= 5000:
if points[p1[0] + vy][p1[1] - vx] and points[p2[0] + vy][p2[1] - vx]:
ans = max(ans, vx ** 2 + vy ** 2)
for p in ps:
points[p[0]][p[1]] = False
print(ans)
main()
``` | instruction | 0 | 35,093 | 23 | 70,186 |
No | output | 1 | 35,093 | 23 | 70,187 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
problem
Once upon a time there were settlements and many people lived there. People built buildings of various shapes and sizes. But those buildings have already been lost, only the literature and the pillars found in the ruins. Was a clue to the location of the building.
There is a description of the temple in the literature. The temple was exactly square when viewed from above, and there were pillars at its four corners. It is unknown which direction the temple was facing. Also, on the sides and inside. I don't know if there were any pillars. Archaeologists believed that among the pillars found in the ruins, the one with the largest square area must be the temple.
Since the coordinates of the position of the pillar are given, find the square with the largest area among the four pillars and write a program to output the area. Note that the sides of the square are not always parallel to the coordinate axes. Be careful.
input
The input consists of multiple datasets. Each dataset is given in the following format. The input ends on a line containing one zero.
On the first line, the number n of pillars found in the ruins is written.
In each of the n lines from the 2nd line to the n + 1st line, the x and y coordinates of the column are written separated by blanks.
A pillar never appears more than once.
n is an integer that satisfies 1 β€ n β€ 3000, and the x and y coordinates of the column are integers greater than or equal to 0 and less than or equal to 5000.
Of the scoring data, 30% of the points satisfy 1 β€ n β€ 100, and 60% of the points satisfy 1 β€ n β€ 500.
The number of datasets does not exceed 10.
output
Outputs one integer for each dataset. If there is a square with four columns, it outputs the area of ββthe largest of those squares, and if no such square exists. Output 0.
Examples
Input
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
10
9 4
4 3
1 1
4 2
2 4
5 8
4 0
5 3
0 5
5 2
0
Output
10
10
Input
None
Output
None
Submitted Solution:
```
while True:
n=int(input())
if n==0:break
pil=[[int(s)for s in input().split(" ")]for i in range(n)]
mS=0
i=0
while i<n:
j=1
while i+j<n:
x1,y1=pil[i]
x2,y2=pil[i+j]
s=x2-x1
t=y2-y1
if [x1-t,y1+s] in pil and [x2-t,y2+s] in pil:mS=max((mS,s**2+t**2))
if [x1+t,y1-s] in pil and [x2+t,y2-s] in pil:mS=max((mS,s**2+t**2))
j+=1
i+=1
print(mS)
``` | instruction | 0 | 35,094 | 23 | 70,188 |
No | output | 1 | 35,094 | 23 | 70,189 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,112 | 23 | 70,224 |
"Correct Solution:
```
from itertools import accumulate
n = int(input())
a = [[0] * 1001 for _ in range(1001)]
for x1, y1, x2, y2 in (map(int, input().split()) for _ in range(n)):
a[x1][y1] += 1
a[x1][y2] -= 1
a[x2][y1] -= 1
a[x2][y2] += 1
print(max(map(max, map(accumulate, zip(*map(accumulate, a))))))
``` | output | 1 | 35,112 | 23 | 70,225 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,113 | 23 | 70,226 |
"Correct Solution:
```
from itertools import accumulate
n=int(input())
size=1005
sheet=[[0for i in range(size)] for i in range(size)]
for i in range(n):
a,b,c,d=map(int,input().split())
sheet[b][a]+=1
sheet[b][c]-=1
sheet[d][a]-=1
sheet[d][c]+=1
for i in range(size):
sheet[i]=list(accumulate(sheet[i]))
mx=max(sheet[0])
for i in range(1,size):
for j in range(size):
sheet[i][j]+=sheet[i-1][j]
mx=max(mx,max(sheet[i]))
print(mx)
``` | output | 1 | 35,113 | 23 | 70,227 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,114 | 23 | 70,228 |
"Correct Solution:
```
from itertools import accumulate
N = int(input())
xys = []
m_x = 0
m_y = 0
for i in range(N):
xy = list(map(int, input().split()))
xys += [xy]
x_1,y_1,x_2,y_2 = xy
m_x = max(x_2, m_x)
m_y = max(y_2, m_y)
im = [[0]*(m_x+1) for i in range(m_y+1)]
for xy in xys:
x_1,y_1,x_2,y_2 = xy
im[y_1][x_1] += 1
im[y_1][x_2] -= 1
im[y_2][x_1] -= 1
im[y_2][x_2] += 1
print(max(map(max, map(accumulate, zip(*map(accumulate, im))))))
``` | output | 1 | 35,114 | 23 | 70,229 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,115 | 23 | 70,230 |
"Correct Solution:
```
#!/usr/bin/env python3
# DSL_5_B: The Maximum Number of Overlaps
from itertools import accumulate
import sys
if __name__ == '__main__':
n = int(input())
ys = [0] * 1001
rects = [None] * 2 * n
i = 0
for line in sys.stdin:
x1, y1, x2, y2 = [int(j) for j in line.split()]
rects[i] = (x2, -1, y1, y2)
rects[i+n] = (x1, 1, y1, y2)
i += 1
rects.sort(key=lambda x: x[0])
max_overlap = 0
for x, t, y1, y2 in rects:
if t > 0:
ys[y1] += 1
ys[y2] -= 1
else:
overlap = max(accumulate(ys))
if overlap > max_overlap:
max_overlap = overlap
ys[y1] -= 1
ys[y2] += 1
print(max_overlap)
``` | output | 1 | 35,115 | 23 | 70,231 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,116 | 23 | 70,232 |
"Correct Solution:
```
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
grid = [[0] * 1002 for _ in range(1002)]
for _ in range(N):
x, y, xx, yy = map(int, input().split())
grid[x][y] += 1
grid[x][yy] -= 1
grid[xx][y] -= 1
grid[xx][yy] += 1
for i in range(1002):
grid[i] = list(accumulate(grid[i]))
for i in range(1001):
for j in range(1002):
grid[i + 1][j] += grid[i][j]
ans = max(max(x) for x in grid)
print(ans)
``` | output | 1 | 35,116 | 23 | 70,233 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,117 | 23 | 70,234 |
"Correct Solution:
```
N = int(input())
xs = set();ys = set()
P = []
for i in range(N):
x1,y1,x2,y2 = map(int, input().split())
xs.add(x1);xs.add(x2)
ys.add(y1);ys.add(y2)
P.append((x1,x2,y1,y2))
X = sorted(xs);Y = sorted(ys)
MX = {x: i for i, x in enumerate(X)}
MY = {y: i for i, y in enumerate(Y)}
H = len(Y);W = len(X)
S = [[0]*(W+1) for i in range(H+1)]
for x1, x2, y1, y2 in P:
p1 = MY[y1]; q1 = MX[x1]
p2 = MY[y2]; q2 = MX[x2]
S[p1][q1] += 1
S[p1][q2] -= 1
S[p2][q1] -= 1
S[p2][q2] += 1
for i in range(H):
for j in range(W):
S[i][j+1] += S[i][j]
ans = 0
for j in range(W):
for i in range(H):
S[i+1][j]+= S[i][j]
ans = max(ans,S[i][j])
print(ans)
``` | output | 1 | 35,117 | 23 | 70,235 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,118 | 23 | 70,236 |
"Correct Solution:
```
from itertools import accumulate
im = [[0]*1001 for i in range(1001)]
for x_1, y_1, x_2, y_2 in (map(int, input().split()) for _ in range(int(input()))):
im[x_1][y_1] += 1
im[x_1][y_2] -= 1
im[x_2][y_1] -= 1
im[x_2][y_2] += 1
print(max(map(max, map(accumulate, zip(*map(accumulate, im))))))
``` | output | 1 | 35,118 | 23 | 70,237 |
Provide a correct Python 3 solution for this coding contest problem.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3 | instruction | 0 | 35,119 | 23 | 70,238 |
"Correct Solution:
```
n = int(input())
lec = [[0 for i in range(1001)] for j in range(1001)]
max_x = 0
max_y = 0
for i in range(n):
x,y,s,t = map(int, input().split(" "))
lec[y][x] += 1
lec[y][s] -= 1
lec[t][x] -= 1
lec[t][s] += 1
max_x = max(max_x, s)
max_y = max(max_y, t)
for i in range(max_y+1):
for j in range(1, max_x+1):
lec[i][j] += lec[i][j-1]
for i in range(1, max_y+1):
for j in range(max_x+1):
lec[i][j] += lec[i-1][j]
ans = 0
for i in range(max_y+1):
for j in range(max_x+1):
ans = max(ans, lec[i][j])
print(ans)
``` | output | 1 | 35,119 | 23 | 70,239 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3
Submitted Solution:
```
N = int(input())
xys = []
"""
m_x = 0
m_y = 0
for i in range(N):
xy = list(map(int, input().split()))
xys += [xy]
x_1,y_1,x_2,y_2 = xy
m_x = max(x_2, m_x)
m_y = max(y_2, m_y)
"""
xys = [list(map(int, input().split())) for i in range(N)]
#im = [[0 for i in range(m_x+1)] for j in range(m_y+1)]
im = [[0]*1010 for i in range(1010)]
for xy in xys:
x_1,y_1,x_2,y_2 = xy
im[y_1][x_1] += 1
im[y_1][x_2] -= 1
im[y_2][x_1] -= 1
im[y_2][x_2] += 1
"""
for y in range(m_y+1):
for x in range(1, m_x+1):
im[y][x] += im[y][x-1]
m = 0
for x in range(m_x+1):
for y in range(1, m_y+1):
im[y][x] += im[y-1][x]
m = max(im[y][x], m)
"""
for y in range(1010):
for x in range(1, 1010):
im[y][x] += im[y][x-1]
m = 0
for x in range(1010):
for y in range(1, 1010):
im[y][x] += im[y-1][x]
m = max(im[y][x], m)
print(m)
``` | instruction | 0 | 35,120 | 23 | 70,240 |
No | output | 1 | 35,120 | 23 | 70,241 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3
Submitted Solution:
```
from itertools import accumulate
n = int(input())
a = [[0] * 10 for _ in range(10)]
for x1, y1, x2, y2 in (map(int, input().split()) for _ in range(n)):
a[x1][y1] += 1
a[x1][y2] -= 1
a[x2][y1] -= 1
a[x2][y2] += 1
print(max(map(max, map(accumulate, zip(*map(accumulate, a))))))
``` | instruction | 0 | 35,121 | 23 | 70,242 |
No | output | 1 | 35,121 | 23 | 70,243 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq 1000 $
* $ x1_i, y1_i, x2_i, y2_i$ are given in integers
Input
The input is given in the following format.
$N$
$x1_1$ $y1_1$ $x2_1$ $y2_1$
$x1_2$ $y1_2$ $x2_2$ $y2_2$
:
$x1_N$ $y1_N$ $x2_N$ $y2_N$
($x1_i, y1_i$) and ($x2_i, y2_i$) are the coordinates of the top-left and the bottom-right corner of the $i$-th seal respectively.
Output
Print the maximum number of overlapped seals in a line.
Examples
Input
2
0 0 3 2
2 1 4 3
Output
2
Input
2
0 0 2 2
2 0 4 2
Output
1
Input
3
0 0 2 2
0 0 2 2
0 0 2 2
Output
3
Submitted Solution:
```
N = int(input())
xys = []
m_x = 0
m_y = 0
for i in range(N):
xy = list(map(int, input().split()))
xys += [xy]
x_1,y_1,x_2,y_2 = xy
m_x = max(x_2, m_x)
m_y = max(y_2, m_y)
im = [[0]*(m_x+1) for i in range(m_y+1)]
for xy in xys:
x_1,y_1,x_2,y_2 = xy
im[y_1][x_1] += 1
im[y_1][x_2] -= 1
im[y_2][x_1] -= 1
im[y_2][x_2] += 1
num = 0
for y in range(m_y+1):
for x in range(1, m_x+1):
im[y][x] += im[y][x-1]
m = 0
for x in range(m_x+1):
for y in range(1, m_y+1):
im[y][x] += im[y-1][x]
m = max(im[y][x], m)
print(m)
``` | instruction | 0 | 35,122 | 23 | 70,244 |
No | output | 1 | 35,122 | 23 | 70,245 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n Γ m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 Γ 1 tiles β each tile costs x burles and covers exactly 1 square;
* 1 Γ 2 tiles β each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 Γ 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 β€ t β€ 500) β the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 β€ n β€ 100; 1 β€ m β€ 1000; 1 β€ x, y β€ 1000) β the size of the Theatre square, the price of the 1 Γ 1 tile and the price of the 1 Γ 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n Γ m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer β the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 Γ 1 tile, even though 1 Γ 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 Γ 1 tiles and spend 20 burles or use a single 1 Γ 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 Γ 2 tiles. You still have to use two 1 Γ 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 Γ 1 tiles everywhere. The total cost is 6 β
3 = 18.
Submitted Solution:
```
for _ in range(int(input())):
n,m,x,y=map(int,input().split())
lis=[]
if(y>2*x):
flag=1
else:
flag=0
cost=0
for i in range(n):
lis=list(input())
if(flag):
cost+=lis.count('.')*x
else:
for i in range(m-1):
if(lis[i]=='.'):
if(lis[i+1]=='.'):
cost+=y
lis[i+1]='*'
else:
cost+=x
lis[i]='*'
if(lis[-1]=='.'):
cost+=x
print(cost)
``` | instruction | 0 | 35,345 | 23 | 70,690 |
Yes | output | 1 | 35,345 | 23 | 70,691 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n Γ m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 Γ 1 tiles β each tile costs x burles and covers exactly 1 square;
* 1 Γ 2 tiles β each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 Γ 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 β€ t β€ 500) β the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 β€ n β€ 100; 1 β€ m β€ 1000; 1 β€ x, y β€ 1000) β the size of the Theatre square, the price of the 1 Γ 1 tile and the price of the 1 Γ 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n Γ m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer β the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 Γ 1 tile, even though 1 Γ 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 Γ 1 tiles and spend 20 burles or use a single 1 Γ 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 Γ 2 tiles. You still have to use two 1 Γ 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 Γ 1 tiles everywhere. The total cost is 6 β
3 = 18.
Submitted Solution:
```
I=lambda:list(map(int,input().split()))
t=I()[0]
while(t):
t-=1
n,m,x,y=I()
grid=[]
ans=0
for i in range(n):
grid.append(input())
ans+=grid[i].count(".")
ans2=0
for i in range(n):
j=1
while(j<m):
if(grid[i][j]=="." and grid[i][j-1]==grid[i][j]):
ans2+=1
j+=1
j+=1
ans2=ans2*y +abs((2*ans2)-ans)*x
ans*=x
print(min(ans,ans2))
``` | instruction | 0 | 35,346 | 23 | 70,692 |
Yes | output | 1 | 35,346 | 23 | 70,693 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n Γ m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 Γ 1 tiles β each tile costs x burles and covers exactly 1 square;
* 1 Γ 2 tiles β each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 Γ 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 β€ t β€ 500) β the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 β€ n β€ 100; 1 β€ m β€ 1000; 1 β€ x, y β€ 1000) β the size of the Theatre square, the price of the 1 Γ 1 tile and the price of the 1 Γ 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n Γ m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer β the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 Γ 1 tile, even though 1 Γ 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 Γ 1 tiles and spend 20 burles or use a single 1 Γ 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 Γ 2 tiles. You still have to use two 1 Γ 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 Γ 1 tiles everywhere. The total cost is 6 β
3 = 18.
Submitted Solution:
```
try:
for _ in range(int(input())):
n,m,x,y=map(int,input().split())
c1 = 0
c2 = 0
for j in range(n):
s = input()
t1 = s.count(".")
t2 = s.count("..")
c1 += t2*y + (t1-2*t2)*x
c2 += t1*x
print(min(c1,c2))
except:
pass
``` | instruction | 0 | 35,347 | 23 | 70,694 |
Yes | output | 1 | 35,347 | 23 | 70,695 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n Γ m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 Γ 1 tiles β each tile costs x burles and covers exactly 1 square;
* 1 Γ 2 tiles β each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 Γ 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 β€ t β€ 500) β the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 β€ n β€ 100; 1 β€ m β€ 1000; 1 β€ x, y β€ 1000) β the size of the Theatre square, the price of the 1 Γ 1 tile and the price of the 1 Γ 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n Γ m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer β the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 Γ 1 tile, even though 1 Γ 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 Γ 1 tiles and spend 20 burles or use a single 1 Γ 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 Γ 2 tiles. You still have to use two 1 Γ 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 Γ 1 tiles everywhere. The total cost is 6 β
3 = 18.
Submitted Solution:
```
import sys
import math
cases = int(input())
for i in range(cases):
n,c,t1,t2 = map(int, input().split())
if 2*t1<=t2:
t2=2*t1
price=0
for i2 in range(n):
s = input()
i=0
while (i<len(s)):
if i+1<len(s) and s[i]==s[i+1]:
if s[i]=='.':
price+=t2
i=i+2
elif s[i]=='.':
price+=t1
i+=1
else:
i+=1
print(price)
``` | instruction | 0 | 35,348 | 23 | 70,696 |
Yes | output | 1 | 35,348 | 23 | 70,697 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
The square still has a rectangular shape of n Γ m meters. However, the picture is about to get more complicated now. Let a_{i,j} be the j-th square in the i-th row of the pavement.
You are given the picture of the squares:
* if a_{i,j} = "*", then the j-th square in the i-th row should be black;
* if a_{i,j} = ".", then the j-th square in the i-th row should be white.
The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
* 1 Γ 1 tiles β each tile costs x burles and covers exactly 1 square;
* 1 Γ 2 tiles β each tile costs y burles and covers exactly 2 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1 Γ 1 tiles.
You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
What is the smallest total price of the tiles needed to cover all the white squares?
Input
The first line contains a single integer t (1 β€ t β€ 500) β the number of testcases. Then the description of t testcases follow.
The first line of each testcase contains four integers n, m, x and y (1 β€ n β€ 100; 1 β€ m β€ 1000; 1 β€ x, y β€ 1000) β the size of the Theatre square, the price of the 1 Γ 1 tile and the price of the 1 Γ 2 tile.
Each of the next n lines contains m characters. The j-th character in the i-th line is a_{i,j}. If a_{i,j} = "*", then the j-th square in the i-th row should be black, and if a_{i,j} = ".", then the j-th square in the i-th row should be white.
It's guaranteed that the sum of n Γ m over all testcases doesn't exceed 10^5.
Output
For each testcase print a single integer β the smallest total price of the tiles needed to cover all the white squares in burles.
Example
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.
Output
10
1
20
18
Note
In the first testcase you are required to use a single 1 Γ 1 tile, even though 1 Γ 2 tile is cheaper. So the total price is 10 burles.
In the second testcase you can either use two 1 Γ 1 tiles and spend 20 burles or use a single 1 Γ 2 tile and spend 1 burle. The second option is cheaper, thus the answer is 1.
The third testcase shows that you can't rotate 1 Γ 2 tiles. You still have to use two 1 Γ 1 tiles for the total price of 20.
In the fourth testcase the cheapest way is to use 1 Γ 1 tiles everywhere. The total cost is 6 β
3 = 18.
Submitted Solution:
```
for t in range(int(input())):
n,m,x,y=map(int,input().split())
cost=0
for i in range(n):
b=input()
j=0
while j<m:
if y<x:
if j!=m-1:
if b[j]==b[j+1]==".":
cost+=y
j+=1
elif b[j]==".":
cost+=x
else:
if b[j]==".":
cost+=x
else:
if b[j]==".":
cost+=x
j+=1
print(cost)
``` | instruction | 0 | 35,349 | 23 | 70,698 |
No | output | 1 | 35,349 | 23 | 70,699 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.