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.
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n).
You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.
Input
First line contains one integer n (1 ≤ n ≤ 10^5).
Each of the next n lines contains two integers x_i and y_i (1 ≤ x_i,y_i ≤ 10^9).
Output
Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.
Examples
Input
3
1 1
1 2
2 1
Output
3
Input
4
1 1
1 2
2 1
2 2
Output
4
Note
Illustration for the first example: <image>
Illustration for the second example: <image>
Submitted Solution:
```
m,n=[],[]
for x in range(int(input())):
a,b=map(int,input().split())
m.append(a)
n.append(b)
m.sort()
n.sort()
if len(m)>1:
if m[-1]+m[-1]>n[-1]+n[-2]:
print(n[-1]+n[-2])
else:
print(m[-1]+m[-1])
else:
print(max(m,n))
``` | instruction | 0 | 43,826 | 23 | 87,652 |
No | output | 1 | 43,826 | 23 | 87,653 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n).
You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.
Input
First line contains one integer n (1 ≤ n ≤ 10^5).
Each of the next n lines contains two integers x_i and y_i (1 ≤ x_i,y_i ≤ 10^9).
Output
Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.
Examples
Input
3
1 1
1 2
2 1
Output
3
Input
4
1 1
1 2
2 1
2 2
Output
4
Note
Illustration for the first example: <image>
Illustration for the second example: <image>
Submitted Solution:
```
n=int(input())
for i in range(n):
sum=0
a,b=map(int,input().split())
if a+b>sum:sum=a+b
print(sum)
``` | instruction | 0 | 43,827 | 23 | 87,654 |
No | output | 1 | 43,827 | 23 | 87,655 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
There are n points on the plane, (x_1,y_1), (x_2,y_2), …, (x_n,y_n).
You need to place an isosceles triangle with two sides on the coordinate axis to cover all points (a point is covered if it lies inside the triangle or on the side of the triangle). Calculate the minimum length of the shorter side of the triangle.
Input
First line contains one integer n (1 ≤ n ≤ 10^5).
Each of the next n lines contains two integers x_i and y_i (1 ≤ x_i,y_i ≤ 10^9).
Output
Print the minimum length of the shorter side of the triangle. It can be proved that it's always an integer.
Examples
Input
3
1 1
1 2
2 1
Output
3
Input
4
1 1
1 2
2 1
2 2
Output
4
Note
Illustration for the first example: <image>
Illustration for the second example: <image>
Submitted Solution:
```
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))
#--------------------------------WhiteHat010--------------------------------#
n = get_int()
matrix = [0]*n
for i in range(n):
matrix[i] = get_int_list()
matrix = sorted(matrix, key = lambda x: x[0]**2 + x[1]**2)
print( matrix[-1][0] + matrix[-1][1] )
``` | instruction | 0 | 43,828 | 23 | 87,656 |
No | output | 1 | 43,828 | 23 | 87,657 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,895 | 23 | 87,790 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
n,m=[int(k) for k in input().split(" ")]
s=[]
for k in range(n):
s+=[input()+1000*"."]
s+=[500*"."]*500
areok=set()
isdone=False
isok=True
for i in range(n):
for j in range(m):
#print(i,j,s[i][j])
if i>0 and s[i][j]=="*" and s[i-1][j]=="*" and j and s[i][j-1]=="*":
#print("cand :",i,j)
areok.add((i,j))
isdone=True
for w in [(1,0),(-1,0),(0,1),(0,-1)]:
howmuch=1
while s[i+w[0]*howmuch][j+w[1]*howmuch]=="*":
areok.add((i+w[0]*howmuch,j+w[1]*howmuch))
howmuch+=1
if howmuch==1:
isok=False
#print(w,howmuch)
break
if isdone:
break
if not isdone:
isok=False
if isok:
for i in range(n):
for j in range(m):
if s[i][j]=="*" and (i,j) not in areok:
# print(i,j)
isok=False
if isok:
print("YES")
else:
print("NO")
``` | output | 1 | 43,895 | 23 | 87,791 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,896 | 23 | 87,792 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
def dfn():
r,c=map(int,input().split())
ar=[]
# for _ in range(r):
# ar.append(input())
if r<3 or c<3:
return -1
ons=[]
mns=-1
ck=0
for i in range(r):
tp=input()
ar.append(tp)
k=tp.count("*")
if k==1:
if ons==[]:
oin=tp.index("*")
elif (ons[-1]!=i-1) or (tp[oin]!='*' ):
return -2
ons+=[i]
elif k==2:
return -3
elif k>2:
if ons==[]:
return -9
if ck==1:
return -4
n=tp.index("*")
while (n<c) and (tp[n]=='*'):
n+=1
for p in range(n+1,c):
if tp[p]=='*':
return -5
ck=1
ons+=[i]
mns=i
if mns==-1 or ons==[]:
return -6
if (ar[mns][oin+1]!='*') or (ar[mns+1][oin]!='*' ) or (ar[mns-1][oin]!='*') or (ar[mns][oin-1]!='*' ):
return -7
return 0
jn="YES" if dfn()==0 else "NO"
# print(dfn())
print(jn)
``` | output | 1 | 43,896 | 23 | 87,793 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,897 | 23 | 87,794 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
n, m = map(int,input().split())
a = [[0] * m for i in range(n)]
for i in range(n):
a[i] = input()
x = -1
y = -1
for i in range(1, n-1):
for j in range(1, m-1):
if(a[i][j]=='*' and a[i-1][j]=='*' and a[i][j-1]=='*' and a[i+1][j]=='*' and a[i][j+1]=='*'):
x = j
y = i
if x==-1 and y==-1:
print("NO")
quit()
for i in range(x, m):
if a[y][i] == '.': break
a[y] = a[y][:i] + '.' + a[y][i+1:]
a[y] = a[y][:x] + '*' + a[y][x+1:]
for i in range(x, -1, -1):
if a[y][i] == '.': break
a[y] = a[y][:i] + '.' + a[y][i+1:]
a[y] = a[y][:x] + '*' + a[y][x+1:]
for i in range(y, n):
if a[i][x] == '.': break
#print(i, x)
a[i] = a[i][:x] + '.' + a[i][x+1:]
a[y] = a[y][:x] + '*' + a[y][x+1:]
for i in range(y, -1, -1):
if a[i][x] == '.': break
a[i] = a[i][:x] + '.' + a[i][x+1:]
for i in range(n):
for j in range(m):
if(a[i][j]=='*'):
print("NO")
quit()
print("YES")
``` | output | 1 | 43,897 | 23 | 87,795 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,898 | 23 | 87,796 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
if __name__=="__main__":
[m,n]=list(map(int,input().split()))
# Accept the matrix
mat=[]
for i in range(m):
temp=list(input())
mat.append(temp)
visited={}
# Now detect the symbols
ans="NO"
# print(mat)
# for i in mat:
# for j in i:
# print(j,end=" ")
# print()
for i in range(1,m-1):
flag=0
for j in range(1,n-1):
# print(i,j)
# print(mat[i][j],mat[i-1][j],mat[i+1][j],mat[i][j-1],mat[i][j+1])
if mat[i][j]=="*" and mat[i+1][j]=="*" and mat[i][j+1]=="*" and mat[i-1][j]=="*" and mat[i][j-1]=="*":
# Mark all those stars as dot
# First all the vertical dots
mat[i][j]="."
vertical=i+1
# print("Running till here")
while vertical<m and mat[vertical][j]=="*":
mat[vertical][j]="."
vertical+=1
verticalR=i-1
while verticalR >=0 and mat[verticalR][j]=="*":
mat[verticalR][j]="."
verticalR-=1
horizontal=j+1
while horizontal<n and mat[i][horizontal]=="*":
mat[i][horizontal]="."
horizontal+=1
horizontalR=j-1
while horizontalR>=0 and mat[i][horizontalR]=="*":
mat[i][horizontalR]="."
horizontalR-=1
ans="YES"
flag=1
break
if flag==1:
break
# for i in mat:
# for j in i:
# print(j,end=" ")
# print()
for i in range(m):
flag=0
for j in range(n):
if mat[i][j]=="*":
ans="NO"
flag=1
break
if flag==1:
break
print(ans)
``` | output | 1 | 43,898 | 23 | 87,797 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,899 | 23 | 87,798 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
"""Template for Python Competitive Programmers prepared by pajengod and many others """
# ////////// SHUBHAM SHARMA \\\\\\\\\\\\\
# to use the print and division function of Python3
from __future__ import division, print_function
"""value of mod"""
MOD = 998244353
mod = 10 ** 9 + 7
"""use resource"""
# import resource
# resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
"""for factorial"""
def prepare_factorial():
fact = [1]
for i in range(1, 100005):
fact.append((fact[-1] * i) % mod)
ifact = [0] * 100005
ifact[100004] = pow(fact[100004], mod - 2, mod)
for i in range(100004, 0, -1):
ifact[i - 1] = (i * ifact[i]) % mod
return fact, ifact
"""uncomment next 4 lines while doing recursion based question"""
# import threading
# threading.stack_size(1<<27)
import sys
# sys.setrecursionlimit(10000)
"""uncomment modules according to your need"""
from bisect import bisect_left, bisect_right, insort
# from itertools import repeat
from math import floor, ceil, sqrt, degrees, atan, pi, log, sin, radians
from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
from collections import Counter, defaultdict, deque
# from copy import deepcopy
# from decimal import *
# import re
# import operator
def modinv(n, p):
return pow(n, p - 2, p)
def ncr(n, r, fact, ifact): # for using this uncomment the lines calculating fact and ifact
t = (fact[n] * (ifact[r] * ifact[n - r]) % mod) % mod
return t
def intarray(): return map(int, sys.stdin.readline().strip().split())
def array(): return list(map(int, sys.stdin.readline().strip().split()))
def input(): return sys.stdin.readline().strip()
"""*****************************************************************************************"""
def GCD(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
return (x * y) // (GCD(x, y))
def get_xor(n):
return [n, 1, n + 1, 0][n % 4]
def fast_expo(a, b):
res = 1
while b:
if b & 1:
res = (res * a)
res %= MOD
b -= 1
else:
a = (a * a)
a %= MOD
b >>= 1
res %= MOD
return res
def get_n(P): # this function returns the maximum n for which Summation(n) <= Sum
ans = (-1 + sqrt(1 + 8 * P)) // 2
return ans
""" ********************************************************************************************* """
"""
array() # for araay
intarray() # for map array
SAMPLE INPUT HERE
5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1
"""
""" OM SAI RAM """
def solve():
n, m = [int(i) for i in input().split()]
arr = [[_ for _ in input()] for i in range(n)]
flag = False
for i in range(1, n - 1):
for j in range(1, m - 1):
if arr[i][j] == '*' and arr[i - 1][j] == '*' and arr[i + 1][j] == '*' and arr[i][j + 1] == '*':
start = (i, j)
flag = True
arr[i][j] = '.'
if flag==False:
return flag
curr = start
for i in range(curr[0] + 1, n):
if arr[i][curr[1]] == '*':
arr[i][curr[1]] = '.'
else:
break
for i in range(curr[0] - 1, -1, -1):
if arr[i][curr[1]] == '*':
arr[i][curr[1]] = '.'
else:
break
for i in range(curr[1] + 1, m):
if arr[curr[0]][i] == '*':
arr[curr[0]][i] = '.'
else:
break
for i in range(curr[1] - 1, -1, -1):
#print(curr[0],i)
if arr[curr[0]][i] == '*':
arr[curr[0]][i] = '.'
else:
break
for i in range(n):
for j in range(m):
if arr[i][j] == '*':
#print(i,j,start)
flag = False
return flag
return flag
def main():
T = 1
while T:
ans = solve()
if ans:
print('YES')
else:
print('NO')
T -= 1
"""OM SAI RAM """
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""
py2 = round(0.5)
if py2:
from future_builtins import ascii, filter, hex, map, oct, zip
range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill(): pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill();
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode('ascii'))
self.read = lambda: self.buffer.read().decode('ascii')
self.readline = lambda: self.buffer.readline().decode('ascii')
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
""" main function"""
if __name__ == '__main__':
main()
# threading.Thread(target=main).start()
``` | output | 1 | 43,899 | 23 | 87,799 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,900 | 23 | 87,800 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
# n = int(input())
# if n & 1 == 1:
# print(0)
# else:
# print(2**(n//2))
h,w = map(int,input().split())
if h < 3 or w < 3:
print('NO')
exit(0)
mat = [[0] * w for _ in range(h)]
for i in range(h):
s = input()
for j in range(w):
if s[j] == '*':
mat[i][j] = 1
for i in range(1,h-1):
for j in range(1,w-1):
if mat[i][j] == 1 and mat[i-1][j] == 1 and mat[i+1][j] == 1 \
and mat[i][j-1] == 1 and mat[i][j+1] == 1:
s = set([(i,j),(i-1,j),(i+1,j),(i,j-1),(i,j+1)])
k = j - 2
while k >= 0:
if mat[i][k] == 1:
s.add((i,k))
k -= 1
else:
break
k = j + 2
while k < w:
if mat[i][k] == 1:
s.add((i,k))
k += 1
else:
break
k = i - 2
while k >= 0:
if mat[k][j] == 1:
s.add((k,j))
k -= 1
else:
break
k = i + 2
while k < h:
if mat[k][j] == 1:
s.add((k,j))
k += 1
else:
break
for p in range(h):
for q in range(w):
if mat[p][q] == 1 and (p,q) not in s:
print('NO')
exit(0)
print('YES')
exit(0)
print('NO')
``` | output | 1 | 43,900 | 23 | 87,801 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,901 | 23 | 87,802 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
a,b=input("").split()
h=int(a)
w=int(b)
dict={}
e=0
g=''
n=502
f=0
min=501
max=-1
z=0
y=True
for i in range(h):
k = input("")
if y:
dict[i]=0
c=0
for j in range(w):
if k[j]=='*':
f+=1
if c==0:
dict[i]=j
u=j
if i<min:
min=i
if i>max:
max=i
c+=1
if c==2:
z+=1
dict[i] =j
start=u
n=i
g=k
if c>0:
if c==2:
y=False
break
elif dict[i]==0 or dict[i]==w-1:
y=False
break
if c>2:
if i==0 and i==h-1:
y=False
break
else:
r=c
e += 1
if e!=1:
y=False
break
if i == n + 1 and i <= h - 1 and i>1:
if dict[i] != dict[i - 2] or dict[i] == 0:
y = False
break
if i != n and i-1 >=min and i<=max and i != n + 1:
if dict[i-1] != dict[i]:
y = False
break
for i in range(i+1,h):
k = input("")
if y:
if f==0 or f==w*h or z==0:
print("NO")
exit()
for p in range(w-1,0,-1):
if g and g[p]=='*':
end=p
break
if start!=dict[n]-1 or end!=dict[n]-2+r:
y=False
print("NO")
elif u<=start or u>=end:
y=False
print("NO")
elif min == n or max == n:
y = False
print("NO")
else:
print("YES")
else:
print("NO")
``` | output | 1 | 43,901 | 23 | 87,803 |
Provide tags and a correct Python 3 solution for this coding contest problem.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape. | instruction | 0 | 43,902 | 23 | 87,804 |
Tags: dfs and similar, implementation, strings
Correct Solution:
```
#author: ankan2526
import math, bisect, heapq
n,m=map(int,input().split())
b=''
a=[]
for i in range(n):
x=input()
b+=x
a.append(list(x))
count=b.count('*')
if count>=n+m:
print('NO')
else:
z=0
for i in range(n):
for j in range(m):
l,r,u,d=0,0,0,0
x,y=i,j
c=0
cc=0
while a[x][y]=='*':
c+=1
y-=1
if y<0:
break
if c<=1:
continue
cc+=c
x,y=i,j
c=0
while a[x][y]=='*':
c+=1
y+=1
if y>=m:
break
if c<=1:
continue
cc+=c
x,y=i,j
c=0
while a[x][y]=='*':
c+=1
x-=1
if x<0:
break
if c<=1:
continue
cc+=c
x,y=i,j
c=0
while a[x][y]=='*':
c+=1
x+=1
if x>=n:
break
if c<=1:
continue
cc+=c
if cc==count+3:
z=1
break
if z==1:
print('YES')
else:
print('NO')
``` | output | 1 | 43,902 | 23 | 87,805 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
dr = [0,0,-1,1]
dc = [-1,1,0,0]
maxx = 501
class Cell:
def __init__(self,r,c):
self.c = c
self.r = r
if __name__ == '__main__':
matrix = [] * maxx
cnt = 0
count = 0
m, n = map(int, input().split())
for i in range(m):
tmp = list(input())
matrix.append(tmp)
for i in range(1,m-1):
for j in range(1,n-1):
if matrix[i][j] == '*' and matrix[i][j-1] == '*' and matrix[i][j+1] == '*' and matrix[i-1][j] == '*' and matrix[i+1][j] == '*':
# print(i, j)
up = i - 1
while up >= 0 and matrix[up][j] == '*':
cnt += 1
up -= 1
down = i +1
while down < m and matrix[down][j] == '*':
cnt += 1
down += 1
left = j -1
while left >= 0 and matrix[i][left] == '*':
cnt += 1
left -= 1
right = j + 1
while right < n and matrix[i][right] == '*':
cnt += 1
right += 1
cnt += 1
if cnt > 0:
break
if cnt > 0:
break
for i in range(m):
for j in range(n):
if matrix[i][j] == '*':
count += 1
if cnt == count and count != 0:
print('YES')
else: print('NO')
``` | instruction | 0 | 43,903 | 23 | 87,806 |
Yes | output | 1 | 43,903 | 23 | 87,807 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
from collections import *
import bisect
import heapq
import sys
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
h, w = rl()
grid = [[x for x in "."*w] for _ in range(h)]
stars_row = [0]*h
for i in range(h):
grid[i] = [x for x in input()]
C = Counter(grid[i])
stars_row[i] = C['*']
Cr = Counter(stars_row)
if Cr[0] + Cr[1] != h - 1:
print("NO")
sys.exit()
stars_col = [0]*w
for j in range(w):
for i in range(h):
if grid[i][j] == "*":
stars_col[j] += 1
Cc = Counter(stars_col)
if Cc[0] + Cc[1] != w - 1:
print("NO")
sys.exit()
degrees = [[-1]*w for _ in range(h)]
d0 = 0
d1 = 0
d2 = 0
d4 = 0
d_ = 0
for i in range(h):
for j in range(w):
if grid[i][j] == "*":
degrees[i][j] = 0
for di, dj in [(-1,0), (1,0),(0,-1), (0,1)]:
ni = i + di
nj = j + dj
if ni >= 0 and ni < h and nj >= 0 and nj < w:
if grid[ni][nj] == "*":
degrees[i][j] += 1
if degrees[i][j] == 1:
d1 += 1
elif degrees[i][j] == 2:
d2 += 1
elif degrees[i][j] == 4:
d4 += 1
elif degrees[i][j] == 0:
d0 += 1
else:
d_ += 1
# print(d4, d1, d2, d0, d_)
# print(degrees)
if d4 == 1 and d1 == 4 and d0 == 0 and d_ == 0:
print("YES")
else:
print("NO")
``` | instruction | 0 | 43,904 | 23 | 87,808 |
Yes | output | 1 | 43,904 | 23 | 87,809 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
n, m = map(int, input().split())
f = []
all_dots = set()
horizontals = []
for i in range(n):
row = input()
line = []
for j in range(m):
if row[j] == '*':
all_dots.add((i, j))
line.append((i, j))
else:
if line:
if len(line) > 1:
horizontals.append(line)
line = []
if line and len(line) > 1:
horizontals.append(line)
f.append(row)
verticals = []
for j in range(m):
line = []
for i in range(n):
if f[i][j] == '*':
line.append((i, j))
else:
if line:
if len(line) > 1:
verticals.append(line)
line = []
if line and len(line) > 1:
verticals.append(line)
if len(horizontals) > 1 or len(horizontals) == 0:
print('NO')
exit()
if len(verticals) > 1 or len(verticals) == 0:
print('NO')
exit()
h = set(horizontals[0])
v = set(verticals[0])
cross_dots = h|v
cross = h & v
if cross:
if all_dots - cross_dots:
print('NO')
exit()
if len(verticals[0]) < 3 or len(horizontals[0]) < 3:
print('NO')
exit()
i, j = cross.pop()
if f[i][j] == '*' and f[i+1][j] == '*' and f[i][j+1] == '*' and f[i][j-1] == '*' and f[i+1][j] == '*':
print('YES')
exit()
print('NO')
``` | instruction | 0 | 43,905 | 23 | 87,810 |
Yes | output | 1 | 43,905 | 23 | 87,811 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
w, h = map(int, input().split())
sas = -4
f = 0
G = 0
U = 0
z = 0
popa = 0
Rer = 0
d1 = 10 ** 4
A = [input().split() for _ in range(w)]
for S in A:
x = (''.join(S)).find('*')
y = (''.join(S)).rfind('*')
if not x == -1:
for elem in range(x, y+1):
if S[0][elem] == '.':
print('NO')
exit(0)
if x == y and not x == -1:
if G:
Rer = 1
z = 1
popa = 1
if f:
print('NO')
exit(0)
if sas == -4 and U <= x <= d1:
sas = x
elif not sas == x:
print('NO')
exit(0)
elif x == -1 and y == -1:
if not sas == -4:
f = 1
else:
if z == 0:
print('NO')
exit(0)
popa = 1
U, d1 = x, y
if G:
print('NO')
exit(0)
G = 1
if popa and d1 - U >= 2 and Rer:
print('YES')
else:
print('NO')
``` | instruction | 0 | 43,906 | 23 | 87,812 |
Yes | output | 1 | 43,906 | 23 | 87,813 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
h,w=map(int,input().split())
a=[0]*h
for i in range(h):
a[i]=input()
e=0
f=0
c=0
for i in range(0,h):
for j in range(0,w):
if a[i][j]=="*":
e+=1
if i==0 or j==0 or i==h-1 or j==w-1:
continue
if f==0 and a[i][j]=="*" and a[i+1][j]=="*" and a[i-1][j]=="*" and a[i][j+1]=="*" and a[i][j-1]=="*":
t=1
f=1
while(a[t+i][j]=="*"):
c+=1
t+=1
if t+i==h:
break
t=1
while(a[i-t][j]=="*"):
c+=1
t+=1
if i-t==-1:
print(t)
break
t=1
while(a[i][j+t]=="*"):
c+=1
t+=1
if j+t==w:
break
t=1
while(a[i][j-t]=="*"):
c+=1
t+=1
if j-t==-1:
break
if c+1==e and f==1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 43,907 | 23 | 87,814 |
No | output | 1 | 43,907 | 23 | 87,815 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
from collections import Counter
def solve(q1, q2):
m_x = q1.most_common(1)[0]
m_y = q2.most_common(1)[0]
if m_x[1] < 3:
return "NO"
q1.pop(m_x[0])
l = [m_x[0]]
m = q1.most_common(1)[0]
if m[1] != 1:
return "NO"
l.extend(q1.keys())
l.sort()
if l != list(range(l[0], l[-1]+1)):
return "NO"
if not ( l[0] < m_x[0] < l[-1]):
return "NO"
if m_y[1] < 3:
return "NO"
q2.pop(m_y[0])
l = [m_y[0]]
m = q2.most_common(1)[0]
if m[1] != 1:
return "NO"
l.extend(q2.keys())
l.sort()
if l != list(range(l[0], l[-1]+1)):
return "NO"
if not ( l[0] < m_y[0] < l[-1]):
return "NO"
return "YES"
h, w = map(int, input().split())
c1 = Counter()
c2 = Counter()
for i in range (h):
s = input()
for j, c in enumerate(s):
if c == '*':
c1[i] += 1
c2[j] += 1
print(solve(c1, c2))
``` | instruction | 0 | 43,908 | 23 | 87,816 |
No | output | 1 | 43,908 | 23 | 87,817 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
a=[input()for _ in[0]*int(input().split()[0])]
def f(a):
try:(x,y,z,_),u={(x.index('*'),x[::-1].index('*'),x.count('*'),-len(x)):0for x in a if'*'in x}
except:z=2
return z>1or x<=u[0]or y<=u[1]or sum(u)
print('YNEOS'[f(a)|f(zip(*a))::2])
``` | instruction | 0 | 43,909 | 23 | 87,818 |
No | output | 1 | 43,909 | 23 | 87,819 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You have a given picture with size w × h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
* A "+" shape has one center nonempty cell.
* There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
* All other cells are empty.
Find out if the given picture has single "+" shape.
Input
The first line contains two integers h and w (1 ≤ h, w ≤ 500) — the height and width of the picture.
The i-th of the next h lines contains string s_{i} of length w consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.
Output
If the given picture satisfies all conditions, print "YES". Otherwise, print "NO".
You can output each letter in any case (upper or lower).
Examples
Input
5 6
......
..*...
.****.
..*...
..*...
Output
YES
Input
3 5
..*..
****.
.*...
Output
NO
Input
7 7
.......
...*...
..****.
...*...
...*...
.......
.*.....
Output
NO
Input
5 6
..**..
..**..
******
..**..
..**..
Output
NO
Input
3 7
.*...*.
***.***
.*...*.
Output
NO
Input
5 10
..........
..*.......
.*.******.
..*.......
..........
Output
NO
Note
In the first example, the given picture contains one "+".
In the second example, two vertical branches are located in a different column.
In the third example, there is a dot outside of the shape.
In the fourth example, the width of the two vertical branches is 2.
In the fifth example, there are two shapes.
In the sixth example, there is an empty space inside of the shape.
Submitted Solution:
```
h,w=map(int,input().split())
arr=[input() for _ in range(h)]
cnt_center=0
pos_center_x=0
pos_center_y=0
cnt_plus=0
cnt_black=0
if h>=3 and w>=3:
for i in range(1,h-1):
for j in range(1,w-1):
if arr[i][j]=='*':
if arr[i-1][j]=='*' and arr[i+1][j]=='*' and arr[i][j-1]=='*' and arr[i][j+1]=='*':
cnt_center+=1
pos_center_y=i
pos_center_x=j
if cnt_center!=1:
print('NO')
else:
for i in range(pos_center_x-1,-1,-1):
if arr[pos_center_y][i]=='*':
cnt_plus+=1
else:
break
for i in range(pos_center_x+1,w):
if arr[pos_center_y][i]=='*':
cnt_plus+=1
else:
break
for i in range(pos_center_y-1,-1,-1):
if arr[i][pos_center_x]=='*':
cnt_plus+=1
else:
break
for i in range(pos_center_y+1,h):
if arr[i][pos_center_x]=='*':
cnt_plus+=1
else:
break
for i in range(h):
for j in range(w):
if arr[i][j]=='*':
cnt_black+=1
if cnt_plus==cnt_black:
print('YES')
else:
print('NO')
else:
print('NO')
``` | instruction | 0 | 43,910 | 23 | 87,820 |
No | output | 1 | 43,910 | 23 | 87,821 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
def list_sum(list, shift, step):
sum = 0
for i in range(int(len(list)) // step):
sum += a[i*step + shift]
return sum
n = int(input())
a = [int(i) for i in input().split()]
max_sum = list_sum(a, 0, 1)
#print('max_sum =', max_sum)
for div in range(3, n//2+1):
#print('div =', div)
if n % div == 0:
step = n//div
#print('step =', step)
for shift in range(n // div):
sum = list_sum(a, shift, step)
#print('sum =', sum)
if sum > max_sum:
max_sum = sum
print(max_sum)
``` | instruction | 0 | 44,084 | 23 | 88,168 |
Yes | output | 1 | 44,084 | 23 | 88,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
# _
#####################################################################################################################
from math import sqrt, ceil
def factorsOf(n):
yield 1
squareRoot_n = sqrt(n)
limit = ceil(squareRoot_n)
if n%2:
step = 2
else:
yield 2
step = 1
for value in range(3, limit, step):
if not n%value:
yield value
yield n//value
if squareRoot_n == limit:
yield limit
def maxAttractiveness(nSculptures, sculptures_attractiveness):
if nSculptures < 6:
return sum(sculptures_attractiveness)
return sorted((sorted((sum(sculptures_attractiveness[iFirst: nSculptures: i])
for iFirst in range(i)), reverse=True)[0]
for i in factorsOf(nSculptures)), reverse=True)[0]
print(maxAttractiveness(int(input()), list(map(int, input().split()))))
``` | instruction | 0 | 44,085 | 23 | 88,170 |
Yes | output | 1 | 44,085 | 23 | 88,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
n=int(input())
s,a=0,[]
for i in input().split():
j=int(i)
s+=j
a.append(j)
if n>5:
for i in range(3, n):
if n%i==0:
k=n//i
for j in range(k):
z=0
for f in range(j, n, k):
z+=a[f]
s=z if z>s else s
print(s)
``` | instruction | 0 | 44,086 | 23 | 88,172 |
Yes | output | 1 | 44,086 | 23 | 88,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
n=int(input())
a=[0] + list(map(int,input().split()))
m=sum(a)
for i in range(2,int(n**0.5)+ 1):
# print(i)
if n%i==0:
x=i
y=n//i
a1=0
# a2=0
if n//x>=3:
for j in range(1,x+1):
a1=0
for k in range(j,n+1,x):
a1+=a[k]
m=max(m,a1)
# print(a1,x)
if n//y>=3:
for j in range(1,y+1):
a1=0
for k in range(j,n+1,y):
a1+=a[k]
m=max(m,a1)
# print(a1,y)
print(m)
``` | instruction | 0 | 44,087 | 23 | 88,174 |
Yes | output | 1 | 44,087 | 23 | 88,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
import sys
import math
n = int(sys.stdin.readline())
ti = [int(x) for x in (sys.stdin.readline()).split()]
k = 1
x = n
vmax = -1000 * 20000
while(n > 2):
for i in range(k):
v = 0
for j in range(i, x, k):
v += ti[j]
if(v > vmax):
vmax = v
v = 0
k *= 2
n = int(n / 2)
print(vmax)
``` | instruction | 0 | 44,089 | 23 | 88,178 |
No | output | 1 | 44,089 | 23 | 88,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
# _
#####################################################################################################################
from math import sqrt, ceil
def factorsOf(n):
if n == 1:
yield 1
return
factorsStorage, squareRoot_n = [], sqrt(n)
limit = ceil(squareRoot_n)
step = 1 + n%2
for value in range(1, limit, step):
if not n%value:
yield n//value
factorsStorage.append(value)
if squareRoot_n == limit:
yield limit
factorsStorage.reverse()
for factor in factorsStorage:
yield factor
def maxAttractiveness(nSculptures, sculptures_attractiveness):
return max(max(sum(sculptures_attractiveness[x]
for x in range(iFirst, nSculptures, i))
for iFirst in range(i)) for i in factorsOf(nSculptures))
print(maxAttractiveness(int(input()), list(map(int, input().split()))))
``` | instruction | 0 | 44,090 | 23 | 88,180 |
No | output | 1 | 44,090 | 23 | 88,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.
The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.
When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:
* the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),
* the sum of the ti values of the remaining sculptures is maximized.
Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.
Input
The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.
Output
Print the required maximum sum of the sculptures' attractiveness.
Examples
Input
8
1 2 -3 4 -5 5 2 3
Output
14
Input
6
1 -2 3 -4 5 -6
Output
9
Input
6
1 2 3 4 5 6
Output
21
Note
In the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.
Submitted Solution:
```
n = int(input())
marks = [int(i) for i in input().split(' ')]
cnt = init_cnt = len(marks)
maxim = sum(marks)
init_angle = 360 / cnt
cnt -= 1
while cnt >= 3:
part = (360 / cnt) / init_angle
if part.is_integer():
part = int(part)
maxim = max(maxim,
sum([m for idx, m in enumerate(marks) if idx % part == 0])
)
cnt -= 1
print(maxim)
``` | instruction | 0 | 44,091 | 23 | 88,182 |
No | output | 1 | 44,091 | 23 | 88,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archer’s fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A.
<image>
Find the number of cells that are under fire for some archer.
Input
The first and only line of input contains a single positive integer k — the archer's shot range (1 ≤ k ≤ 106).
Output
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Examples
Input
3
Output
7
Input
4
Output
13
Input
5
Output
19
Submitted Solution:
```
import math
k = int(input())
n = int(k/math.sqrt(3))
# print('n', n)
point_to_check = (n+2)//2
# print('p', point_to_check)
x = 0.0
y = n*math.sqrt(3)
# print('r', math.sqrt((x**2+y**2)))
# p1
x -= 0.5
y += math.sqrt(3) * 0.5
# print('r', math.sqrt((x**2+y**2)))
count = -1
for i in range(point_to_check):
# print('r', math.sqrt((x**2+y**2)))
if ((x**2+y**2)<=k**2):
count = i
break
x -= 1.5
y -= math.sqrt(3)/2
extra = 0
if count != -1:
extra = point_to_check - count
if (n+1)%2==0:
extra *= 2
else:
extra = extra*2 -1
# print('extra', extra)
ans = 0
if extra == n+1:
ans = (extra-1)*6
else:
ans = extra*6
for i in range(n):
if i==0:
ans += 1
else:
ans += i*6
print(ans)
# R = 1
# r = sqrt(3)*0.5*R
# full_cycle_count = k / (math.sqrt(3)) - 0.5
# print(full_cycle_count)
# full_cycle_count = int(full_cycle_count)
# print(full_cycle_count)
#
# half_cycle_count = int((k - 1) / 3) * 2
# print(half_cycle_count)
#
# ans = 1
# last_add = 0
# for i in range(1, full_cycle_count+1):
# last_add +=6
# ans += last_add
#
# print(last_add)
#
# if half_cycle_count>full_cycle_count:
# ans += (last_add+6) / 2
#
# print(int(ans))
``` | instruction | 0 | 44,329 | 23 | 88,658 |
No | output | 1 | 44,329 | 23 | 88,659 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,348 | 23 | 88,696 |
Tags: brute force, implementation
Correct Solution:
```
import sys
input=sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left,bisect
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
n,a,b=map(int,input().split())
l=[]
for _ in range(n):
l.append(list(map(int,input().split())))
m=0
for i in range(n):
for j in range(i+1,n):
if (l[i][0]+l[j][0]<=a and max(l[i][1],l[j][1])<=b) or (l[i][0]+l[j][1]<=a and max(l[i][1],l[j][0])<=b) or (l[i][1]+l[j][0]<=a and max(l[i][0],l[j][1])<=b) or (l[i][1]+l[j][1]<=a and max(l[i][0],l[j][0])<=b) or (l[i][0]+l[j][0]<=b and max(l[i][1],l[j][1])<=a) or (l[i][0]+l[j][1]<=b and max(l[i][1],l[j][0])<=a) or (l[i][1]+l[j][0]<=b and max(l[i][0],l[j][1])<=a) or (l[i][1]+l[j][1]<=b and max(l[i][0],l[j][0])<=a):
m=max(m,l[i][0]*l[i][1]+l[j][0]*l[j][1])
print(m)
``` | output | 1 | 44,348 | 23 | 88,697 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,349 | 23 | 88,698 |
Tags: brute force, implementation
Correct Solution:
```
n, a, b = map(int, input().split())
A = []
for i in range(n):
A.append(list(map(int, input().split())))
def sqr(f, s):
for i in range(3):
if (a >= f[0] + s[0] and b >= max(f[1], s[1])) or (b >= f[0] + s[0] and a >= max(f[1], s[1])):
return f[0]*f[1] + s[0]*s[1]
elif (a >= max(f[0], s[0]) and b >= f[1] + s[1]) or (b >= max(f[0], s[0]) and a >= f[1] + s[1]):
return f[0] * f[1] + s[0] * s[1]
elif(i == 0):
f[0], f[1] = f[1], f[0]
elif (i == 1):
f[0], f[1] = f[1], f[0]
s[0], s[1] = s[1], s[0]
return 0
maxi = 0
for i in range(n):
for j in range(n):
if i != j:
maxi = max(maxi, sqr(A[i], A[j]))
print(maxi)
``` | output | 1 | 44,349 | 23 | 88,699 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,350 | 23 | 88,700 |
Tags: brute force, implementation
Correct Solution:
```
n,a,b=map(int,input().split())
t=[]
for i in range(n):
t.append(list(map(int,input().split())))
m=0
for i in range(n-1):
for j in range(i+1,n):
x1,y1=t[i][0],t[i][1]
x2,y2=t[j][0],t[j][1]
c=x1+x2
d=max(y1,y2)
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
c=max(x1,x2)
d=y1+y2
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
x2,y2=y2,x2
c=x1+x2
d=max(y1,y2)
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
c=max(x1,x2)
d=y1+y2
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
x1,y1=y1,x1
x2,y2=t[j][0],t[j][1]
c=x1+x2
d=max(y1,y2)
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
c=max(x1,x2)
d=y1+y2
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
x2,y2=y2,x2
c=x1+x2
d=max(y1,y2)
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
c=max(x1,x2)
d=y1+y2
if c<=a and d<=b:
if x1*y1+x2*y2>m:
m=x1*y1+x2*y2
print(m)
``` | output | 1 | 44,350 | 23 | 88,701 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,351 | 23 | 88,702 |
Tags: brute force, implementation
Correct Solution:
```
#RAVENS#TEAM_2#ESSI-DAYI_MOHSEN-LORENZO
import sys
input=sys.stdin.readline
def cal(r1,r2,a,b):
# 8 state
if r1[0]<=a and r1[1]<=b: #a,b
if (r2[0] <=a-r1[0] and r2[1]<=b) or (r2[1] <=a-r1[0] and r2[0]<=b):
return (r1[0]*r1[1]) + (r2[0]*r2[1])
if (r2[0] <=a and r2[1]<=b-r1[1]) or (r2[1] <=a and r2[0]<=b-r1[1]):
return (r1[0]*r1[1]) + (r2[0]*r2[1])
a,b = b,a
if r1[0]<=a and r1[1]<=b: #a,b
if (r2[0] <=a-r1[0] and r2[1]<=b) or (r2[1] <=a-r1[0] and r2[0]<=b):
return (r1[0]*r1[1]) + (r2[0]*r2[1])
if (r2[0] <=a and r2[1]<=b-r1[1]) or (r2[1] <=a and r2[0]<=b-r1[1]):
return (r1[0]*r1[1]) + (r2[0]*r2[1])
return 0
n,a,b = map(int,input().split())
arr = []
MAX = 0
for i in range(n):arr.append(list(map(int,input().split())))
for i in range(n):
for j in range(i+1,n):
MAX = max(MAX,cal(arr[i],arr[j],a,b))
print(MAX)
``` | output | 1 | 44,351 | 23 | 88,703 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,352 | 23 | 88,704 |
Tags: brute force, implementation
Correct Solution:
```
def ldc( nt, mt, a, b ):
index = 0
if( nt >= a and mt >= b ):
index = 1
elif( nt >= b and mt >= a ):
index = 1
if( index == 1 ):
return 1
else:
return 0
t, n ,m = map(int,input().split())
list_a = []
list_b = []
list_s = []
max_s = 0
for i in range( t ):
a, b = map(int,input().split())
list_a.append( a )
list_b.append( b )
list_s.append( a*b )
for i in range( t ):
if( ldc( n, m, list_a[i], list_b[i] ) == 1 ):
for j in range( t ):
if( i != j ):
index_t = 0
if( n >= list_a[i] and m >= list_b[i] ):
if( ldc( n-list_a[i], m, list_a[j], list_b[j] ) == 1 ):
index_t = 1
if( ldc( n, m-list_b[i], list_a[j], list_b[j] ) == 1 ):
index_t = 1
if( n >= list_b[i] and m >= list_a[i] ):
if( ldc( n-list_b[i], m, list_a[j], list_b[j] ) == 1 ):
index_t = 1
if( ldc( n, m-list_a[i], list_a[j], list_b[j] ) == 1 ):
index_t = 1
if(index_t == 1 ):
s = list_s[i] + list_s[j]
if( max_s < s and s <= n*m ):
max_s = s
print( max_s )
``` | output | 1 | 44,352 | 23 | 88,705 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,353 | 23 | 88,706 |
Tags: brute force, implementation
Correct Solution:
```
k, n, m = map(int,input().split())
x, y = [],[]
for i in range(k):
q, p = map(int, input().split())
x.append(min(q, p))
y.append(max(q, p))
MAX = 0
for i in range(k):
for j in range(i+1,k):
ok = False
if x[i] + x[j] <= n and y[i] <= m and y[j] <= m:
ok = True
elif x[i] + y[j] <= n and y[i] <= m and x[j] <= m:
ok = True
elif y[i] + y[j] <= m and x[i] <= n and x[j] <= n:
ok = True
elif y[i] + x[j] <= m and x[i] <= n and y[j] <= n:
ok = True
elif y[i] + y[j] <= n and x[i] <= m and x[j] <= m:
ok = True
elif y[i] + x[j] <= n and x[i] <= m and y[j] <= m:
ok = True
elif x[i] + x[j] <= m and y[i] <= n and y[j] <= n:
ok = True
elif x[i] + y[j] <= m and y[i] <= n and x[j] <= n:
ok = True
if ok:
MAX = max(MAX, x[i]*y[i] + x[j]*y[j])
print(MAX)
``` | output | 1 | 44,353 | 23 | 88,707 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,354 | 23 | 88,708 |
Tags: brute force, implementation
Correct Solution:
```
from sys import stdin as fin
# fin = open("ecr26c.in", "r")
def check_place(x1, y1, x2, y2, x, y):
return (
# (x1 + x2 <= x and y1 + y2 >= y) or
(x1 + x2 <= x and max(y1, y2) <= y) or
(max(x1, x2) <= x and y1 + y2 <= y)
)
n, a, b = map(int, fin.readline().split())
# m = int(fin.readline())
maxs = 0
rects = tuple(tuple(map(int, fin.readline().split())) for i in range(n))
for i in range(n):
for j in range(n):
if i != j:
(x1, y1), (x2, y2) = rects[i], rects[j]
if (
check_place(x1, y1, x2, y2, a, b) or
check_place(x1, y1, y2, x2, a, b) or
check_place(y1, x1, x2, y2, a, b) or
check_place(y1, x1, y2, x2, a, b)
):
maxs = max(maxs, x1*y1 + x2*y2)
pass
print(maxs)
``` | output | 1 | 44,354 | 23 | 88,709 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper. | instruction | 0 | 44,355 | 23 | 88,710 |
Tags: brute force, implementation
Correct Solution:
```
import sys
def check(a, b, x, y, q, w):
if x + q <= a and max(y, w) <= b:
return True
if y + w <= b and max(x, q) <= a:
return True
return False
def main():
n, a, b = map(int, sys.stdin.readline().split())
t = []
for i in range(n):
x, y = map(int, sys.stdin.readline().split())
if (x > a or y > b) and (x > b or y > a):
pass
else:
t.append((x, y))
ans = 0
for i in range(len(t)):
for j in range(i + 1, len(t)):
if check(a, b, t[i][0], t[i][1], t[j][0], t[j][1]) or check(a, b, t[i][0], t[i][1], t[j][1], t[j][0]) \
or check(a, b, t[i][1], t[i][0], t[j][1], t[j][0]) or check(a, b, t[i][1], t[i][0], t[j][0],
t[j][1]):
c = t[i][0] * t[i][1] + t[j][0] * t[j][1]
if c > ans:
ans = c
print(ans)
main()
``` | output | 1 | 44,355 | 23 | 88,711 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
n,a,b = map(int,input().split())
lst,res = [],0
for i in range(n):
lst.append(list(map(int,input().split())))
for i,x in enumerate(lst):
for j,y in enumerate(lst):
if i!=j:
a1,b1,a2,b2=x[0],x[1],y[0],y[1]
if max(a1,a2)<=a and b1+b2<=b:
res=max(res,a1*b1+a2*b2);continue
if max(a1,a2)<=b and b1+b2<=a:
res=max(res,a1*b1+a2*b2);continue
if max(b1,b2)<=a and a1+a2<=b:
res=max(res,a1*b1+a2*b2);continue
if max(b1,b2)<=b and a1+a2<=a:
res=max(res,a1*b1+a2*b2);continue
if max(a1,b2)<=a and b1+a2<=b:
res=max(res,a1*b1+a2*b2);continue
if max(a1,b2)<=b and b1+a2<=a:
res=max(res,a1*b1+a2*b2);continue
if max(b1,a2)<=a and a1+b2<=b:
res=max(res,a1*b1+a2*b2);continue
if max(b1,a2)<=b and a1+b2<=a:
res=max(res,a1*b1+a2*b2)
print(res)
``` | instruction | 0 | 44,356 | 23 | 88,712 |
Yes | output | 1 | 44,356 | 23 | 88,713 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
import sys
n, a, b = map(int, input().split())
x = []
y = []
for i in range(n):
x1, y1 = map(int, input().split())
x.append(x1)
y.append(y1)
ans = 0
for i in range(n):
for j in range(i + 1, n):
s = x[i] * y[i] + x[j] * y[j]
if x[i] + x[j] <= a and max(y[i], y[j]) <= b:
ans = max(ans, s)
if x[i] + x[j] <= b and max(y[i], y[j]) <= a:
ans = max(ans, s)
if x[i] + y[j] <= a and max(y[i], x[j]) <= b:
ans = max(ans, s)
if x[i] + y[j] <= b and max(y[i], x[j]) <= a:
ans = max(ans, s)
if y[i] + y[j] <= a and max(x[i], x[j]) <= b:
ans = max(ans, s)
if y[i] + y[j] <= b and max(x[i], x[j]) <= a:
ans = max(ans, s)
if y[i] + x[j] <= a and max(x[i], y[j]) <= b:
ans = max(ans, s)
if y[i] + x[j] <= b and max(x[i], y[j]) <= a:
ans = max(ans, s)
print(ans)
``` | instruction | 0 | 44,357 | 23 | 88,714 |
Yes | output | 1 | 44,357 | 23 | 88,715 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
n,a,b=map(int,input().split())
seal=[]
for i in range(n):
seal.append(list(map(int,input().split())))
ma=0
for i in range(n-1):
j=i+1
while j<n:
l=[]
m=seal[i][0]*seal[i][1]+seal[j][0]*seal[j][1]
x,y=seal[i][0]+seal[j][0],max(seal[i][1],seal[j][1])
if max(x,y)<=max(a,b) and min(x,y)<=min(a,b):
ma=max(ma,m)
x,y=seal[i][0]+seal[j][1],max(seal[i][1],seal[j][0])
if max(x,y)<=max(a,b) and min(x,y)<=min(a,b):
ma=max(ma,m)
x,y=seal[i][1]+seal[j][0],max(seal[i][0],seal[j][1])
if max(x,y)<=max(a,b) and min(x,y)<=min(a,b):
ma=max(ma,m)
x,y=seal[i][1]+seal[j][1],max(seal[i][0],seal[j][0])
if max(x,y)<=max(a,b) and min(x,y)<=min(a,b):
ma=max(ma,m)
j+=1
print(ma)
``` | instruction | 0 | 44,358 | 23 | 88,716 |
Yes | output | 1 | 44,358 | 23 | 88,717 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
import sys
n, a, b = map(int, input().split())
p = []
for i in range(n):
p.append(list(map(int, input().split())))
sMax = 0
for i in range(n-1):
j = i+1
while j < n:
l = []
nSq = p[i][0]*p[i][1]+p[j][0]*p[j][1]
s1, s2 = p[i][0]+p[j][0], max(p[i][1],p[j][1])
if max(s1,s2) <= max(a,b) and min(s1,s2) <= min(a,b):
sMax = max(sMax,nSq)
s1, s2 = p[i][0]+p[j][1], max(p[i][1],p[j][0])
if max(s1,s2) <= max(a,b) and min(s1,s2) <= min(a,b):
sMax = max(sMax,nSq)
s1, s2 = p[i][1]+p[j][0], max(p[i][0],p[j][1])
if max(s1,s2) <= max(a,b) and min(s1,s2) <= min(a,b):
sMax = max(sMax,nSq)
s1, s2 = p[i][1]+p[j][1], max(p[i][0],p[j][0])
if max(s1,s2) <= max(a,b) and min(s1,s2) <= min(a,b):
sMax = max(sMax,nSq)
j += 1
print(sMax)
``` | instruction | 0 | 44,359 | 23 | 88,718 |
Yes | output | 1 | 44,359 | 23 | 88,719 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
# Task3 Codeforces 837c
def sm(obj1,obj2):
return obj1[0]*obj1[1]+obj2[0]*obj2[1]
def can_add(x,y,obj1,obj2):
if obj1[1]+obj2[1] <= y and obj2[0]<=x:
return True
elif obj1[0]+obj2[0] <= x and obj2[1]<=y:
return True
else:
return False
def add(x, y, obj1, obj2, ms):
lm = sm(obj1,obj2)
if lm>x*y or lm<ms:
return False
if can_add(x, y, obj1, obj2):
return True
elif can_add(x, y, obj1, obj2[::-1]):
return True
else:
return False
lst,m = [],0
n,a,b=map(int, input().split())
for i in range(n):
lst += [[int(j) for j in input().split()]]
for i in range(n-1):
for j in range(i+1,n):
if add(a, b, lst[i], lst[j], m):
m = sm(lst[i],lst[j])
print(m)
``` | instruction | 0 | 44,360 | 23 | 88,720 |
No | output | 1 | 44,360 | 23 | 88,721 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
n,a,b=list(map(int,input().split()))
x=[]
y=[]
for i in range(n):
h,m=list(map(int,input().split()))
x.append(h)
y.append(m)
k=0
a,b=min(a,b),max(a,b)
for i in range(n):
for j in range(i+1,n):
h1,m1=min(x[i],y[i]),max(x[i],y[i])
h2,m2=min(x[j],y[j]),max(x[j],y[j])
if max(h1,h2)<=a and m1+m2<=b:
k=max(k,h1*m1+h2*m2)
break
if (max(m1,h2)<=a and h1+m2<=b) or (max(m1,h2)<=b and h1+m2<=a):
k=max(k,h1*m1+h2*m2)
break
if (max(h1,m2)<=a and m1+h2<=b) or (max(h1,m2)<=b and m1+h2<=a):
k=max(k,h1*m1+h2*m2)
break
if (max(m1,m2)<=a and h1+h2<=b) or (max(m1,m2)<=b and h1+h2<=a):
k=max(k,h1*m1+h2*m2)
break
print(k)
``` | instruction | 0 | 44,361 | 23 | 88,722 |
No | output | 1 | 44,361 | 23 | 88,723 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
n, a, b = map(int, input().split())
s = [0] * n
for i in range(n):
s[i] = tuple(map(int, input().split()))
ans = 0
for i in range(n):
if s[i][0] > a and s[i][1] > b or\
s[i][0] > a and s[i][1] > a:
continue
cur = [s[i][0], s[i][1]]
for orientation in range(2):
cur[0], cur[1] = cur[1], cur[0]
rest = [(a - cur[0], b), (a, b - cur[1])]
if s[i][0] <= a and s[i][1] <= b:
for j in range(i + 1, n):
cur2 = [s[j][0], s[j][1]]
for orientation2 in range(2):
cur2[0], cur2[1] = cur2[1], cur2[0]
for pair in rest:
if cur2[0] <= pair[0] and cur2[1] <= pair[1]:
res = cur[0] * cur[1] + cur2[0] * cur2[1]
ans = max(ans, res)
print(ans)
``` | instruction | 0 | 44,362 | 23 | 88,724 |
No | output | 1 | 44,362 | 23 | 88,725 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
Input
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Output
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
Examples
Input
2 2 2
1 2
2 1
Output
4
Input
4 10 9
2 3
1 1
5 10
9 11
Output
56
Input
3 10 10
6 6
7 7
20 5
Output
0
Note
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
Submitted Solution:
```
n,a,b=list(map(int,input().split()))
x=[]
y=[]
for i in range(n):
h,m=list(map(int,input().split()))
x.append(h)
y.append(m)
k=0
a,b=min(a,b),max(a,b)
for i in range(n):
l=0
for j in range(i+1,n):
h1,m1=min(x[i],y[i]),max(x[i],y[i])
h2,m2=min(x[j],y[j]),max(x[j],y[j])
if h1+h2<=a and max(m1,m2)<=b:
l=(m1*h1)+(h2*m2)
k=max(k,l)
print(k)
``` | instruction | 0 | 44,363 | 23 | 88,726 |
No | output | 1 | 44,363 | 23 | 88,727 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,405 | 23 | 88,810 |
"Correct Solution:
```
n = int(input())
p, q = [], []
for _ in range(n):
x, y = map(int, input().split())
p.append(x + y)
q.append(x - y)
p.sort()
q.sort()
print(max(max(p) - min(p), max(q) - min(q)))
``` | output | 1 | 44,405 | 23 | 88,811 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,406 | 23 | 88,812 |
"Correct Solution:
```
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
z = []
w = []
for i in range(N):
x,y = xy[i]
z.append(x+y)
w.append(x-y)
ans = max(max(z)-min(z),max(w)-min(w))
print(ans)
``` | output | 1 | 44,406 | 23 | 88,813 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,407 | 23 | 88,814 |
"Correct Solution:
```
n = int(input())
z,w = [],[]
for _ in range(n):
x,y = map(int,input().split())
z.append(x+y)
w.append(x-y)
print(max(max(z)-min(z),max(w)-min(w)))
``` | output | 1 | 44,407 | 23 | 88,815 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,408 | 23 | 88,816 |
"Correct Solution:
```
import sys
input=sys.stdin.readline
n=int(input())
ab=[]
A=-1e20
B=-1e20
C=1e20
D=1e20
for i in range(n):
x,y=map(int,input().split())
A=max(A,x+y)
B=max(B,x-y)
C=min(C,x+y)
D=min(D,x-y)
print(max(A-C,B-D))
``` | output | 1 | 44,408 | 23 | 88,817 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,409 | 23 | 88,818 |
"Correct Solution:
```
N = int(input())
x = [0]* N
y = [0] * N
for i in range(N):
a , b = map(int,input().split())
x[i] = a+b
y[i] = a-b
ans = max([max(x) - min(x),max(y) - min(y)])
print(ans)
``` | output | 1 | 44,409 | 23 | 88,819 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,410 | 23 | 88,820 |
"Correct Solution:
```
n=int(input())
z=[]
c=[]
for j in range(n):
x1,y1=[int(j) for j in input().split()]
z.append(x1+y1)
c.append(x1-y1)
za=max(z)
zi=min(z)
ca=max(c)
ci=min(c)
mx=max(za-zi,ca-ci)
print(mx)
``` | output | 1 | 44,410 | 23 | 88,821 |
Provide a correct Python 3 solution for this coding contest problem.
There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points?
Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.
Constraints
* 2 \leq N \leq 2 \times 10^5
* 1 \leq x_i,y_i \leq 10^9
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N
Output
Print the answer.
Examples
Input
3
1 1
2 4
3 2
Output
4
Input
2
1 1
1 1
Output
0 | instruction | 0 | 44,411 | 23 | 88,822 |
"Correct Solution:
```
N = int(input())
a = []
b = []
for i in range(N):
x,y = (list(map(int,input().split())))
a.append(x+y)
b.append(x-y)
a.sort()
b.sort()
ans = max(a[-1]-a[0],b[-1]-b[0])
print(ans)
``` | output | 1 | 44,411 | 23 | 88,823 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.