message stringlengths 2 28.7k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 21 109k | cluster float64 7 7 | __index_level_0__ int64 42 217k |
|---|---|---|---|---|---|
Provide tags and a correct Python 3 solution for this coding contest problem.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them. | instruction | 0 | 26,991 | 7 | 53,982 |
Tags: implementation
Correct Solution:
```
import sys
import math
import itertools as it
import operator as op
import fractions as fr
n = int(sys.stdin.readline().strip())
T = list(map(int,sys.stdin.readline().split()))
cnt = [0 for _ in range(n+1)]
for i in range(n):
dom_col = T[i]
D = [0 for _ in range(n+1)]
D[dom_col] = 1
cnt[dom_col] += 1
for j in range(i+1,n):
col = T[j]
D[col] += 1
if D[dom_col] < D[col]:
dom_col = col
elif D[dom_col] == D[col]:
if dom_col > col:
dom_col = col
cnt[dom_col] += 1
print(' '.join(map(str, cnt[1:])))
``` | output | 1 | 26,991 | 7 | 53,983 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them. | instruction | 0 | 26,992 | 7 | 53,984 |
Tags: implementation
Correct Solution:
```
n=int(input())
a=list(map(int,input().split()))
r=[0]*(n+1)
for i in range(n):
d={}
v=-1
for j in range(i,n):
t=d.get(a[j],0)+1
d[a[j]]=t
if t>v or t==v and a[j]<m:
v=t
m=a[j]
r[m]+=1
print(' '.join(map(str,r[1:])))
``` | output | 1 | 26,992 | 7 | 53,985 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
def main():
n = int(input())
a = [int(i) for i in input().strip().split()]
res = [0] * n
for st in range(n):
cnt = [0] * n
x = 0
y = 0
for ed in range(st, n):
cnt[a[ed] - 1] += 1
if (cnt[a[ed] - 1] > x) or (cnt[a[ed] - 1] == x and a[ed] - 1 < y):
x = cnt[a[ed] - 1]
y = a[ed] - 1
res[y] += 1
print(" ".join(map(str, res)))
if __name__ == "__main__":
main()
``` | instruction | 0 | 26,993 | 7 | 53,986 |
Yes | output | 1 | 26,993 | 7 | 53,987 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
n = int(input())
t = [int(q) - 1 for q in input().split()]
k = [0] * n
for i in range(n):
s = [0] * n
b = 0
for a in t[i:]:
s[a] += 1
if s[a] > s[b] or a < b and s[a] == s[b]: b = a
k[b] += 1
print(*k)
``` | instruction | 0 | 26,994 | 7 | 53,988 |
Yes | output | 1 | 26,994 | 7 | 53,989 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
n = int(input())
s = [int(i) for i in input().split()]
answer = [0 for i in range(n)]
p = n
for j in range(n):
a = [0] * p
domin = s[0]
answer[domin - 1] += 1
a[domin - 1] += 1
for i in range(1, n):
a[s[i] - 1] += 1
if a[s[i] - 1] > a[domin - 1] or (a[s[i] - 1] == a[domin - 1] and s[i] < domin):
domin = s[i]
answer[domin - 1] += 1
s.pop(0)
n -= 1
print(*answer)
``` | instruction | 0 | 26,995 | 7 | 53,990 |
Yes | output | 1 | 26,995 | 7 | 53,991 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
import math
import sys
from collections import Counter
def solve():
n = int(input())
T = [int(x) - 1 for x in input().split()]
M = [[0]*n for i in range(n)]
curmin, ans = [0]*n, [0]*n
for i in range(n):
ans[T[i]] += 1
curmin[i] = T[i]
M[i][T[i]] = 1
for i in range(n):
for j in range(i + 1, n):
M[i][T[j]] += 1
if (M[i][T[j]] > M[i][curmin[i]] or
M[i][T[j]] == M[i][curmin[i]] and T[j] < curmin[i]):
curmin[i] = T[j]
ans[curmin[i]] += 1
return ans
print(' '.join(map(str, solve())))
``` | instruction | 0 | 26,996 | 7 | 53,992 |
Yes | output | 1 | 26,996 | 7 | 53,993 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
def findargmax(n, rest):
argmax = 1
for i in range(1,n+1,1):
if rest[i]>rest[argmax]:
argmax=i
return argmax
def solve(n, data):
res={}
sol=[0]*(n+1)
argmax=1
tmp={}
for i in range(1,n+1,1):
res[i]=0
for i in data:
res[i]+=1
for i in range(1,n+1,1):
if res[i]>res[argmax]:
argmax=i
sol[argmax]+=1
for j in range(n-1,0,-1):
res[data[j]]-=1
for i in range(1,n+1,1):
tmp[i]=res[i]
argmax=findargmax(n, res)
sol[argmax]+=1
for k in range(n-j):
res[data[k]]-=1
res[data[k+j]]+=1
if data[k]==argmax:
argmax=findargmax(n, res)
elif res[data[k+j]]>res[argmax]:
argmax=k+j
sol[argmax]+=1
for i in range(1,n+1,1):
res[i]=tmp[i]
return sol
n=int(input())
data=[int(x) for x in input().split()]
solv = solve(n,data)
for x in solv[1:-1]:
print(x,end=' ')
print(solv[-1])
``` | instruction | 0 | 26,997 | 7 | 53,994 |
No | output | 1 | 26,997 | 7 | 53,995 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
def readInts(): return map(int, input().split())
n = int(input())
good = [False]*90
for i in readInts():
good[i-1] = True
ans = 0
badCnt = 0
for g in good:
ans += 1
if g: badCnt = 0
else:
badCnt += 1
if badCnt == 15:
break
print(ans)
``` | instruction | 0 | 26,998 | 7 | 53,996 |
No | output | 1 | 26,998 | 7 | 53,997 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
def f():
n = int(input())
inputStrings = input().split(' ')
colors = [int(s) for s in inputStrings]
dominants = [0 for i in range(n+1)]
lowestIndex = [-1 for i in range(n+1)]
for i in range(n):
if lowestIndex[colors[i]] == -1:
lowestIndex[colors[i]] = i
for i in range(n):
counters = [0 for k in range(n+1)]
dominantColor = 0
for j in range(i,n):
counters[colors[j]] += 1
if counters[colors[j]] > counters[dominantColor] \
or lowestIndex[colors[j]] < lowestIndex[dominantColor]:
dominantColor = colors[j]
dominants[dominantColor] += 1
printStr = ""
for i in range(1,n):
printStr += str(dominants[i])+" "
print(printStr + str(dominants[n]))
f()
``` | instruction | 0 | 26,999 | 7 | 53,998 |
No | output | 1 | 26,999 | 7 | 53,999 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.
For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.
There are <image> non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls.
The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.
Output
Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.
Examples
Input
4
1 2 1 2
Output
7 3 0 0
Input
3
1 1 1
Output
6 0 0
Note
In the first sample, color 2 is dominant in three intervals:
* An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.
* An interval [4, 4] contains one ball, with color 2 again.
* An interval [2, 4] contains two balls of color 2 and one ball of color 1.
There are 7 more intervals and color 1 is dominant in all of them.
Submitted Solution:
```
n = int(input())
T = list(map(int, input().split()))
M = [[0 for _ in range(5000)] for _ in range(5000)]
print(1)
def solution(T):
if len(T) == 1:
return {T[0]:1},T[0]
``` | instruction | 0 | 27,000 | 7 | 54,000 |
No | output | 1 | 27,000 | 7 | 54,001 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.
A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type.
Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change.
We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.
Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0.
<image>
The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing.
The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data.
For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.
Input
The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below.
* "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units.
* "HBox [name]" — create a new widget [name] of the type HBox.
* "VBox [name]" — create a new widget [name] of the type VBox.
* "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox.
* "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox.
* "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox.
All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.
The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data.
All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive
It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.
Output
For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator)
Examples
Input
12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)
Output
brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20
Input
15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)
Output
dummy 0 0
pack 10 10
x 40 10
y 10 10
Note
In the first sample the widgets are arranged as follows:
<image> | instruction | 0 | 27,088 | 7 | 54,176 |
Tags: dp, expression parsing, graphs, implementation
Correct Solution:
```
n = int(input())
widgets = {}
class Widget:
def __init__(self, w, h):
self.w = w
self.h = h
def calc_size(self):
return (self.w, self.h)
class Box:
def __init__(self, direction):
self.dir = direction
self.packed = []
self.border = 0
self.spacing = 0
self.size = None
def calc_size(self):
if self.size is not None: return self.size
if not len(self.packed):
self.size = (0, 0)
return self.size
child_sizes = []
for kid in self.packed:
child_sizes.append(kid.calc_size())
s = 0
for kid in child_sizes: s += kid[self.dir=='V']
s += self.spacing*max(0, len(self.packed)-1)
mx = 0
for kid in child_sizes: mx = max(mx, kid[self.dir=='H'])
self.size = (mx + 2*self.border, s + 2*self.border)
if self.dir == 'H':
self.size = (self.size[1], self.size[0])
return self.size
for _ in range(n):
s = input().strip()
spacespl = s.split(' ')
if len(spacespl) > 1:
cmd, rest = spacespl
if cmd == 'Widget':
name, rest = rest.split('(')
w, h = map(int, rest[:-1].split(','))
widgets[name] = Widget(w, h)
elif cmd == 'HBox':
widgets[rest] = Box('H')
elif cmd == 'VBox':
widgets[rest] = Box('V')
else:
name1, rest = s.split('.')
method, args = rest[:-1].split('(')
if method == 'pack':
widgets[name1].packed.append(widgets[args])
elif method == 'set_border':
widgets[name1].border = int(args)
elif method == 'set_spacing':
widgets[name1].spacing = int(args)
for name, thing in sorted(widgets.items()):
print(name, *thing.calc_size())
``` | output | 1 | 27,088 | 7 | 54,177 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other.
A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type.
Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change.
We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.
Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0.
<image>
The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing.
The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data.
For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.
Input
The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below.
* "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units.
* "HBox [name]" — create a new widget [name] of the type HBox.
* "VBox [name]" — create a new widget [name] of the type VBox.
* "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox.
* "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox.
* "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox.
All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.
The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data.
All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive
It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.
Output
For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.
Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator)
Examples
Input
12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)
Output
brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20
Input
15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)
Output
dummy 0 0
pack 10 10
x 40 10
y 10 10
Note
In the first sample the widgets are arranged as follows:
<image> | instruction | 0 | 27,089 | 7 | 54,178 |
Tags: dp, expression parsing, graphs, implementation
Correct Solution:
```
import sys
from array import array # noqa: F401
import re
def input():
return sys.stdin.buffer.readline().decode('utf-8')
class Widget(object):
def __init__(self, x, y):
self.x = x
self.y = y
class Box(object):
def __init__(self):
self.children = []
self.border = 0
self.spacing = 0
self._x = -1
self._y = -1
def set_border(self, size):
self.border = size
def set_spacing(self, size):
self.spacing = size
def pack(self, widget):
self.children.append(widget)
@property
def x(self):
if self._x == -1:
self._x = (max(child.x for child in self.children) + self.border * 2
if self.children else 0)
return self._x
@property
def y(self):
if self._y == -1:
self._y = (max(child.y for child in self.children) + self.border * 2
if self.children else 0)
return self._y
class HBox(Box):
@property
def x(self):
if self._x == -1:
if not self.children:
return 0
a = [child.x for child in self.children]
self._x = self.border * 2 + sum(a) + self.spacing * (len(a) - 1)
return self._x
class VBox(Box):
@property
def y(self):
if self._y == -1:
if not self.children:
return 0
a = [child.y for child in self.children]
self._y = self.border * 2 + sum(a) + self.spacing * (len(a) - 1)
return self._y
if __name__ == '__main__':
n = int(input())
namespace = {}
pattern = re.compile(r'([^(]+?)\(([^)]+?)\)')
def parse(s):
return re.search(pattern, s).groups()
for _ in range(n):
command = input().split()
if command[0] == 'Widget':
name, args = parse(command[1])
namespace[name] = Widget(*tuple(map(int, args.split(','))))
elif command[0] == 'VBox':
namespace[command[1]] = VBox()
elif command[0] == 'HBox':
namespace[command[1]] = HBox()
else:
name, method = command[0].split('.')
method, args = parse(method)
if method == 'set_border':
namespace[name].set_border(int(args))
elif method == 'set_spacing':
namespace[name].set_spacing(int(args))
elif method == 'pack':
namespace[name].pack(namespace[args])
for name in sorted(namespace.keys()):
print(f'{name} {namespace[name].x} {namespace[name].y}')
``` | output | 1 | 27,089 | 7 | 54,179 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,429 | 7 | 54,858 |
Tags: implementation
Correct Solution:
```
def get_colors(x1, y1, x2, y2):
w = x2 - x1 + 1
h = y2 - y1 + 1
if w % 2 == 0 or h % 2 == 0:
black = w * h // 2
white = w * h // 2
else:
oddx = w // 2
if x1 % 2 == 1 and x2 % 2 == 1:
oddx += 1
oddy = h // 2
if y1 % 2 == 1 and y2 % 2 == 1:
oddy += 1
evenx = w // 2
if x1 % 2 == 0 and x2 % 2 == 0:
evenx += 1
eveny = h // 2
if y1 % 2 == 0 and y2 % 2 == 0:
eveny += 1
white = oddx * oddy + evenx * eveny
black = w * h - white
return white, black
def get_intersection(ax1, ay1, ax2, ay2, bx1, by1, bx2, by2):
if ax1 > bx2:
return None, None, None, None
if bx1 > ax2:
return None, None, None, None
if ay1 > by2:
return None, None, None, None
if by1 > ay2:
return None, None, None, None
return max(ax1, bx1), max(ay1, by1), min(ax2, bx2), min(ay2, by2)
t = int(input())
for i in range(t):
n, m = map(int, input().split())
white, black = get_colors(1, 1, m, n)
wx1, wy1, wx2, wy2 = map(int, input().split())
w, b = get_colors(wx1, wy1, wx2, wy2)
white += b
black -= b
bx1, by1, bx2, by2 = map(int, input().split())
ix1, iy1, ix2, iy2 = get_intersection(wx1, wy1, wx2, wy2, bx1, by1, bx2, by2)
if ix1 is not None:
w, b = get_colors(ix1, iy1, ix2, iy2)
white -= b
black += b
w, b = get_colors(bx1, by1, bx2, by2)
white -= w
black += w
print(white, black)
``` | output | 1 | 27,429 | 7 | 54,859 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,430 | 7 | 54,860 |
Tags: implementation
Correct Solution:
```
import math
def w(a,b):
return math.ceil(a/2) * math.ceil(b/2) + math.floor(a/2) * math.floor(b/2)
def W(x1,y1,x2,y2):
return w(x2,y2) - w(x2,y1-1) - w(x1-1,y2) + w(x1-1,y1-1)
def B(x1,y1,x2,y2):
return (y2-y1+1) * (x2-x1+1) - W(x1,y1,x2,y2)
t = int(input())
while t>0:
n, m = map(int, input().split())
x1,y1,x2,y2 = map(int, input().split())
x3,y3,x4,y4 = map(int, input().split())
white = W(1,1,m,n)
black = B(1,1,m,n)
white += B(x1,y1,x2,y2)
black -= B(x1,y1,x2,y2)
white -= W(x3,y3,x4,y4)
black += W(x3,y3,x4,y4)
if(max(x1,x3) <= min(x2,x4) and max(y1,y3) <= min(y2,y4)):
white -= B(max(x1,x3), max(y1,y3), min(x2,x4), min(y2,y4))
black += B(max(x1,x3), max(y1,y3), min(x2,x4), min(y2,y4))
print(white, black)
t-=1
``` | output | 1 | 27,430 | 7 | 54,861 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,431 | 7 | 54,862 |
Tags: implementation
Correct Solution:
```
def ww(x,y): # whites in (1,1) to (x,y)
return ((x)*(y)+1)//2
def bb(x,y): # blacks in (1,1) to (x,y)
return ((x)*(y)) - ww(x,y)
def w(x1,y1,x2,y2):
return ww(x2,y2) - ww(x1-1,y2) - ww(x2,y1-1) + ww(x1-1,y1-1)
def b(x1,y1,x2,y2):
return (x2-x1+1) * (y2-y1+1) - w(x1,y1,x2,y2)
for _ in range(int(input().strip())):
n,m = map(int,input().split())
x1,y1,x2,y2 = map(int,input().split())
x3,y3,x4,y4 = map(int,input().split())
nw,nb = ww(m,n),bb(m,n)
#print(nw,nb)
x = b(x1,y1,x2,y2)
nw+=x
nb-=x
y = w(x3,y3,x4,y4)
nw-=y
nb+=y
if not ( x3>x2 or x4<x1 or y4<y1 or y2<y3 ):
X1,Y1 = max(x1,x3),max(y1,y3)
X2,Y2 = min(x2,x4),min(y2,y4)
c = b(X1,Y1,X2,Y2)
nw-=c
nb+=c
print(nw,nb)
``` | output | 1 | 27,431 | 7 | 54,863 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,432 | 7 | 54,864 |
Tags: implementation
Correct Solution:
```
def w(x1,y1,x2,y2):
if (x2-x1+1)*(y2-y1+1)%2==0:
return (x2-x1+1)*(y2-y1+1)//2
elif (x1+y1)%2==0:
return (x2-x1+1)*(y2-y1+1)//2+1
else:
return (x2-x1+1)*(y2-y1+1)//2
def bl(x1,y1,x2,y2):
if (x2-x1+1)*(y2-y1+1)%2==0:
return (x2-x1+1)*(y2-y1+1)//2
elif (x1+y1)%2==0:
return (x2-x1+1)*(y2-y1+1)//2
else:
return (x2-x1+1)*(y2-y1+1)//2+1
t = int(input())
for _ in ' '*t:
n, m = map(int, input().split())
x1,y1,x2,y2=map(int, input().split())
x3,y3,x4,y4=map(int, input().split())
a,b,c,d=max(x1,x3),max(y1,y3),min(x2,x4),min(y2,y4)
if a>c or b>d:
black=bl(1,1,m,n)-bl(x1,y1,x2,y2)+w(x3,y3,x4,y4)
else:
black=bl(1,1,m,n)-bl(x1,y1,x2,y2)+w(x3,y3,x4,y4)+bl(a,b,c,d)
print(n*m-black,black)
``` | output | 1 | 27,432 | 7 | 54,865 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,433 | 7 | 54,866 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import itertools
import sys
"""
created by shhuan at 2018/11/24 15:29
"""
T = int(input())
def interact(rect1, rect2):
x1, y1, x2, y2 = rect1
x3, y3, x4, y4 = rect2
ans = (-1, -1, -1, -1)
if x2 < x3 or x4 < x1:
return 0, ans
if y2 < y3 or y4 < y1:
return 0, ans
ans = (max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4))
return area(ans), ans
def area(rect):
return (rect[2] - rect[0] + 1) * (rect[3] - rect[1] + 1)
def winrect(rect):
a = area(rect)
if a % 2 == 0:
return a // 2
x1, y1, x2, y2 = rect
e1, e2 = x1 % 2 == 0, y1 % 2 == 0
ow = (e1 and e2) or (not e1 and not e2)
return a // 2 + 1 if ow else a // 2
ans = []
for ti in range(T):
N, M = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
w = winrect((1, 1, N, M))
a, b = (x1, y1, x2, y2), (x3, y3, x4, y4)
s, c = interact(a, b)
if s == 0:
w -= winrect(a) + winrect(b)
w += area(a)
elif s == area(a):
w -= winrect(b)
elif s == area(b):
w -= winrect(b)
w += area(a) - area(b) - (winrect(a) - winrect(b))
else:
w += area(a) - winrect(a)
w -= winrect(b)
w -= area(c) - winrect(c)
ans.append((w, N*M-w))
print('\n'.join(['{} {}'.format(a, b) for a, b in ans]))
``` | output | 1 | 27,433 | 7 | 54,867 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,434 | 7 | 54,868 |
Tags: implementation
Correct Solution:
```
k = int(input())
grid_size = []
white_rec = []
black_rec = []
for i in range(k):
grid = [int(x) for x in input().split()]
white = [int(x) for x in input().split()]
black = [int(x) for x in input().split()]
grid_size.append(grid)
white_rec.append(white)
black_rec.append(black)
def count_white(a, b):
return ((a + 1) // 2) * ((b + 1) // 2) + (a//2) * (b//2)
def count_white_range(a, b, c, d):
return count_white(c, d) - count_white(a - 1, d) - count_white(c, b - 1) + count_white(a-1, b-1)
def count_black_range(a, b, c, d):
return (c + 1 -a) * (d +1 - b) - count_white_range(a, b, c, d)
def count_black_white(grid, whites, blacks):
m, n = grid
white_count = count_white(m, n)
w_a, w_b, w_c, w_d = whites
# color all the blacks in range whites black
white_count += count_black_range(w_a, w_b, w_c, w_d)
b_a, b_b, b_c, b_d = blacks
# color all the whites in the black section black
white_count -= count_white_range(b_a, b_b, b_c, b_d)
#check if overlap
if max(w_a, b_a) > min(w_c, b_c) or max(w_b, b_b) > min(w_d, b_d):
return white_count, m*n - white_count
white_count -= count_black_range(max(w_a, b_a), max(w_b, b_b), min(w_c, b_c), min(w_d, b_d))
return white_count, m*n - white_count
for i in range(k):
white, black = count_black_white(grid_size[i], white_rec[i], black_rec[i])
print('{} {}'.format(white, black))
``` | output | 1 | 27,434 | 7 | 54,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,435 | 7 | 54,870 |
Tags: implementation
Correct Solution:
```
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#-------------------game starts now-----------------------------------------------------
for _ in range (int(input())):
n,m=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
a1,b1,a2,b2=map(int,input().split())
black=(n*m)//2
white=(n*m)//2
if n%2==1 and m%2==1:
white+=1
#print(black,white)
white+=((x2-x1+1)*(y2-y1+1))//2
black-=((x2-x1+1)*(y2-y1+1))//2
if (x2-x1+1)%2==1 and (y2-y1+1)%2==1 and (x1+y1)%2==1:
white+=1
black-=1
#print(white,black)
black+=((a2-a1+1)*(b2-b1+1))//2
white-=((a2-a1+1)*(b2-b1+1))//2
if (a2-a1+1)%2==1 and (b2-b1+1)%2==1 and (a1+b1)%2==0:
black+=1
white-=1
#print(white,black)
startx=max(x1,a1)
starty=max(y1,b1)
h=min(y2,b2)-max(b1,y1)+1
w=min(x2,a2)-max(a1,x1)+1
if w>0 and h>0:
white-=h*w//2
black+=h*w//2
if (startx+starty)%2==1 and w%2==1 and h%2==1:
white-=1
black+=1
#print(startx,starty)
print(white,black)
``` | output | 1 | 27,435 | 7 | 54,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image> | instruction | 0 | 27,436 | 7 | 54,872 |
Tags: implementation
Correct Solution:
```
def area(rect):
if rect is None:
return 0
x1, y1, x2, y2 = rect
return (x2-x1+1) * (y2-y1+1)
def get_w(rect):
if rect is None:
return 0#, 0
x1, y1, x2, y2 = rect
ra = area(rect)
more, less = (ra + 1) // 2, ra // 2
if (x1 + y1) % 2 == 0:
return more #, less
else:
return less #, more
def intersect_rects(r1, r2):
out = []
for i, a, b in zip(range(4), r1, r2):
out.append(max(a,b) if i < 2 else min(a,b))
if out[0] > out[2] or out[1] > out[3]:
return None
return out
def main():
n, m = list(map(int, input().split()))
rect1 = list(map(int, input().split()))
rect2 = list(map(int, input().split()))
rect12 = intersect_rects(rect1, rect2)
w_start = get_w([1,1,n,m])
w1 = get_w(rect1)
w2 = get_w(rect2)
w12 = get_w(rect12)
w = w_start - w1 - w2 + w12 + area(rect1) - area(rect12)
print(w, n*m-w)
q = int(input())
for i in range(q):
main()
``` | output | 1 | 27,436 | 7 | 54,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
def solve(n, m, white, black):
w, b = tiles(1, 1, m, n)
_, b2w = tiles(*white)
w2b, _ = tiles(*black)
w += b2w
b -= b2w
w -= w2b
b += w2b
x1, y1 , x2, y2 = max(white[0], black[0]), max(white[1], black[1]), min(white[2], black[2]), min(white[3], black[3])
if (x1 <= x2 and y1 <= y2):
_, b2 = tiles(x1, y1, x2, y2)
w -= b2
b += b2
return w, b
def tiles(x1, y1, x2, y2):
n = y2 - y1 + 1
m = x2 - x1 + 1
black = (x1 + y1) % 2
w = (n//2) * m + (m+(not black))//2 * (n%2)
b = (n//2) * m + (m+(black))//2 * (n%2)
return w, b
def read(): return list(map(int, input().split()))
q = int(input())
for _ in range(q):
print(*solve(*read(), read(), read()), sep=' ')
``` | instruction | 0 | 27,437 | 7 | 54,874 |
Yes | output | 1 | 27,437 | 7 | 54,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
def call(x,y):
if x>=1 and y>=1:
w=(x+1)//2
b=x-w
if w==b:
w*=y
b*=y
else:
w-=1
w*=y
b*=y
w+=(y+1)//2
b+=y//2
return w,b
else:
return 0,0
def repo(x,y,x1,y1):
w,b=call(x1,y1)
w1,b1=call(x-1,y-1)
w2,b2=call(x1,y-1)
w3,b3=call(x-1,y1)
w=w-w2-w3+w1
b=b-b2-b3+b1
return w,b
def fun(x,y,x1,y1,X,Y,X1,Y1):
if X<=x<=X1:
xx=x
if X<=x1<=X1:
xx2=x1
if x<=X<=x1:
xx=X
if x<=X1<=x1:
xx2=X1
if Y<=y<=Y1:
yy=y
if Y<=y1<=Y1:
yy2=y1
if y<=Y<=y1:
yy=Y
if y<=Y1<=y1:
yy2=Y1
return repo(xx,yy,xx2,yy2)
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
x,y,x1,y1=map(int,input().split())
X,Y,X1,Y1=map(int,input().split())
w,b=call(m,n)
w1,b1=repo(x,y,x1,y1)
w2,b2=repo(X,Y,X1,Y1)
if X1<x or x1<X or Y1<y or y1<Y :
w3=0
b3=0
else:
w3,b3=fun(x,y,x1,y1,X,Y,X1,Y1)
print(w+b1-w2-b3,b-b1+w2+b3)
``` | instruction | 0 | 27,438 | 7 | 54,876 |
Yes | output | 1 | 27,438 | 7 | 54,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
def getBW(x1, y1, x2, y2):
if (x2 - x1) % 2 == 1 or (y2 - y1) % 2 == 1:
return [(y2 + 1 - y1) * (x2 + 1 - x1) // 2, (y2 + 1 - y1) * (x2 + 1 - x1) // 2]
else:
if (x1 % 2 == 0 and y1 % 2 == 0) or (x1 % 2 == 1 and y1 % 2 == 1):
return [(y2 + 1 - y1) * (x2 + 1 - x1) // 2, 1 + (y2 + 1 - y1) * (x2 + 1 - x1) // 2]
else:
return [1 + (y2 + 1 - y1) * (x2 + 1 - x1) // 2, (y2 + 1 - y1) * (x2 + 1 - x1) // 2]
cs = int(input())
for c in range(cs):
m, n = map(int, input().split())
BW = getBW(1, 1, n, m)
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
BW1 = getBW(x1, y1, x2, y2)
BW2 = getBW(x3, y3, x4, y4)
BWO =[0, 0]
#if x1 > x3: (x1, y1, x2, y2), (x3, y3, x4, y4) = (x3, y3, x4, y4), (x1, y1, x2, y2)
#xO1, xO2 = x1, min(x2, x4)
xo1 = max(x1, x3)
xo2 = min(x2, x4)
yo1 = max(y1, y3)
yo2 = min(y2, y4)
if (xo2 >= xo1 and yo2 >= yo1):
BWO = getBW(xo1, yo1, xo2, yo2)
'''
print(BW1)
print(BW2)
print(BWO)
print(BW)'''
B = BW[0] - BW1[0] + BW2[1] + BWO[0]
W = BW[1] + BW1[0] - BW2[1] - BWO[0]
print(W, end = " ")
print(B)
``` | instruction | 0 | 27,439 | 7 | 54,878 |
Yes | output | 1 | 27,439 | 7 | 54,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
for i in range(int(input())):
m, n = map(int, input().split())
s0 = s1 = n * m // 2
if n * m % 2 == 1:
s0 += 1
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
d1, d2 = x4 - x3 + 1, y4 - y3 + 1
if d1 * d2 % 2 == 1 and (x3 + y3) % 2 == 0:
s0 -= d1 * d2 // 2 + 1
s1 += d1 * d2 // 2 + 1
else:
s0 -= d1 * d2 // 2
s1 += d1 * d2 // 2
a = []
a.append([1, 1, x3 - 1, y3 - 1])
a.append([1, y3, x3 - 1, y4])
a.append([1, y4 + 1, x3 - 1, m])
a.append([x3, 1, x4, y3 - 1])
a.append([x3, y4 + 1, x4, m])
a.append([x4 + 1, 1, n, y3 - 1])
a.append([x4 + 1, y3, n, y4])
a.append([x4 + 1, y4 + 1, n, m])
for b in a:
nx1, ny1, nx2, ny2 = max(b[0], x1), max(b[1], y1), min(b[2], x2), min(b[3],y2)
if nx1 > nx2 or ny1 > ny2: continue
d1, d2 = nx2 - nx1 + 1, ny2 - ny1 + 1
if d1 * d2 % 2 == 1 and (nx1 + ny1) % 2 == 1:
s0 += d1 * d2 // 2 + 1
s1 -= d1 * d2 // 2 + 1
else:
s0 += d1 * d2 // 2
s1 -= d1 * d2 // 2
print(s0, s1)
``` | instruction | 0 | 27,440 | 7 | 54,880 |
Yes | output | 1 | 27,440 | 7 | 54,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
from math import ceil
t = int( input() )
for tc in range( t ):
n, m = map( int, input().split() )
w = ceil( n * m / 2 )
x1,y1,x2,y2 = map(int,input().split())
x3,y3,x4,y4 = map(int,input().split())
c = (x1+y1)%2
c *= -1
c += 0.5
sz = (x2-x1+1)*(y2-y1+1)
c *= sz%2
tw = sz/2 - c
tw = int(tw)
c = (x3+y3)%2
c *= -1
c += 0.5
sz = (x4-x3+1)*(y4-y3+1)
c *= sz%2
tb = sz/2 + c
tb = int( tb )
x1 = max( x1,x3 )
x2 = min( x2, x4 )
y1 = max( y1, y3 )
y2 = min( y2, y4 )
c = (x1+y1)%2
c *= -1
c += 0.5
sz = (x2-x1+1)*(y2-y1+1)
c *= sz%2
ctw = sz/2 - c
ctw = int( ctw )
if x1 > x2 or y1 > y2 or ctw < 0:
ctw = 0
w += tw - tb - ctw
print( w, n * m - w )
``` | instruction | 0 | 27,441 | 7 | 54,882 |
No | output | 1 | 27,441 | 7 | 54,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
def white(x1,y1,x2,y2):
h = y2-y1+1
w = x2-x1+1
if ((h % 2 == 0) or (w % 2 == 0)):
return int((h*w)/2)
else:
if x1+y1 == 0:
return int((h*w+1)/2)
else:
return int((h*w-1)/2)
def black(x1,y1,x2,y2):
h = y2-y1+1
w = x2-x1+1
if ((h % 2 == 0) or (w % 2 == 0)):
return int((h*w)/2)
else:
if x1+y1 == 0:
return int((h*w-1)/2)
else:
return int((h*w+1)/2)
t = int(input())
for i in range(0,t):
n, m = [int(x) for x in input().split()]
x1,y1,x2,y2 = [int(x) for x in input().split()]
x3,y3,x4,y4 = [int(x) for x in input().split()]
if ((y2 < y3) or (y4<y1) or (x2<x3) or (x4<x1)):
print(int(white(1,1,m,n)+black(x1,y1,x2,y2)-white(x3,y3,x4,y4)),int(black(1,1,m,n)-black(x1,y1,x2,y2)+white(x3,y3,x4,y4)))
else:
X = [x1,x2,x3,x4]
Y = [y1,y2,y3,y4]
X.sort()
Y.sort()
A1 = white(1,1,m,n)+black(x1,y1,x2,y2)-white(x3,y3,x4,y4)-black(X[1],Y[1],X[2],Y[2])
A2 = black(1,1,m,n)-black(x1,y1,x2,y2)+white(x3,y3,x4,y4)+black(X[1],Y[1],X[2],Y[2])
print(int(A1),int(A2))
``` | instruction | 0 | 27,442 | 7 | 54,884 |
No | output | 1 | 27,442 | 7 | 54,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
# cook your dish here
def color(x1,y1,x2,y2):
dx = max((x2-x1+1), 0)
dy = max((y2-y1+1), 0)
b=w=dx*dy//2
if dx%2 or dy%2:
if (x1+y1)%2==0:
w+=1
else:
b+=1
return w,b
for _ in range(int(input())):
n,m=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
x3,y3,x4,y4=map(int,input().split())
w,b=color(1,1,n,m)
w1,b1=color(x1,y1,x2,y2)
w2,b2=color(x3,y3,x4,y4)
w3,b3=color(max(x1,x3),max(y1,y3),min(x2,x4),min(y2,y4))
W=w+b1-w2-b3
print(W,n*m-W)
``` | instruction | 0 | 27,443 | 7 | 54,886 |
No | output | 1 | 27,443 | 7 | 54,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Recently, Masha was presented with a chessboard with a height of n and a width of m.
The rows on the chessboard are numbered from 1 to n from bottom to top. The columns are numbered from 1 to m from left to right. Therefore, each cell can be specified with the coordinates (x,y), where x is the column number, and y is the row number (do not mix up).
Let us call a rectangle with coordinates (a,b,c,d) a rectangle lower left point of which has coordinates (a,b), and the upper right one — (c,d).
The chessboard is painted black and white as follows:
<image> An example of a chessboard.
Masha was very happy with the gift and, therefore, invited her friends Maxim and Denis to show off. The guys decided to make her a treat — they bought her a can of white and a can of black paint, so that if the old board deteriorates, it can be repainted. When they came to Masha, something unpleasant happened: first, Maxim went over the threshold and spilled white paint on the rectangle (x_1,y_1,x_2,y_2). Then after him Denis spilled black paint on the rectangle (x_3,y_3,x_4,y_4).
To spill paint of color color onto a certain rectangle means that all the cells that belong to the given rectangle become color. The cell dyeing is superimposed on each other (if at first some cell is spilled with white paint and then with black one, then its color will be black).
Masha was shocked! She drove away from the guests and decided to find out how spoiled the gift was. For this, she needs to know the number of cells of white and black color. Help her find these numbers!
Input
The first line contains a single integer t (1 ≤ t ≤ 10^3) — the number of test cases.
Each of them is described in the following format:
The first line contains two integers n and m (1 ≤ n,m ≤ 10^9) — the size of the board.
The second line contains four integers x_1, y_1, x_2, y_2 (1 ≤ x_1 ≤ x_2 ≤ m, 1 ≤ y_1 ≤ y_2 ≤ n) — the coordinates of the rectangle, the white paint was spilled on.
The third line contains four integers x_3, y_3, x_4, y_4 (1 ≤ x_3 ≤ x_4 ≤ m, 1 ≤ y_3 ≤ y_4 ≤ n) — the coordinates of the rectangle, the black paint was spilled on.
Output
Output t lines, each of which contains two numbers — the number of white and black cells after spilling paint, respectively.
Example
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
Note
Explanation for examples:
The first picture of each illustration shows how the field looked before the dyes were spilled. The second picture of each illustration shows how the field looked after Maxim spoiled white dye (the rectangle on which the dye was spilled is highlighted with red). The third picture in each illustration shows how the field looked after Denis spoiled black dye (the rectangle on which the dye was spilled is highlighted with red).
In the first test, the paint on the field changed as follows:
<image>
In the second test, the paint on the field changed as follows:
<image>
In the third test, the paint on the field changed as follows:
<image>
In the fourth test, the paint on the field changed as follows:
<image>
In the fifth test, the paint on the field changed as follows:
<image>
Submitted Solution:
```
import math
n=int(input())
for i in range(n):
size=list(map(int, input().rstrip().split()))
whites=list(map(int, input().rstrip().split()))
blacks=list(map(int, input().rstrip().split()))
whitexmin=whites[0]
whiteymin=whites[1]
whitexmax=whites[2]
whiteymax=whites[3]
blackxmin=blacks[0]
blackymin=blacks[1]
blackxmax=blacks[2]
blackymax=blacks[3]
whitearea=(whitexmax-whitexmin+1)*(whiteymax-whiteymin+1)
blackarea=(blackxmax-blackxmin+1)*(blackymax-blackymin+1)
xintersect=0
if whitexmin<=blackxmin and whitexmax<=blackxmax:
xintersect=max(0,whitexmax-blackxmin+1)
if blackxmin<=whitexmin and blackxmax<=whitexmax:
xintersect=max(0, blackxmax-whitexmin+1)
if whitexmin<=blackxmin and blackxmax<=whitexmax:
xintersect=max(0,blackxmax-blackxmin+1)
if blackxmin<=whitexmin and whitexmax<=blackxmax:
xintersect=max(0,whitexmax-whitexmin+1)
yintersect=0
if whiteymin<=blackymin and whiteymax<=blackymax:
yintersect=max(0,whiteymax-blackymin+1)
if blackymin<=whiteymin and blackymax<=whiteymax:
yintersect=max(0, blackymax-whiteymin+1)
if whiteymin<=blackymin and blackymax<=whiteymax:
yintersect=max(0,blackymax-blackymin+1)
if blackymin<=whiteymin and whiteymax<=blackymax:
yintersect=max(0,whiteymax-whiteymin+1)
overlaparea=xintersect*yintersect
whitemod=0
blackmod=0
fullmod=0
#whitemod=(whitexmin+whiteymin)%2
#blackmod=(blackxmin+blackymin)%2
if size[1]%2==1 and size[0]%2==1 :
fullmod=1
if (blackymax-blackymin)%2==0 and (blackxmax-blackxmin)%2==0:
blackmod=(blackxmin+blackymin)%2
if (whiteymax-whiteymin)%2==0 and (whitexmax-whitexmin)%2==0 :
whitemod=(whitexmin+whiteymin)%2
whitesquares=size[0]*size[1]//2+fullmod+whitearea//2+whitemod-blackarea//2+blackmod-math.ceil(overlaparea/2)
blacksquares=size[0]*size[1]-whitesquares
print(whitesquares, blacksquares)
``` | instruction | 0 | 27,444 | 7 | 54,888 |
No | output | 1 | 27,444 | 7 | 54,889 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,522 | 7 | 57,044 |
Tags: implementation
Correct Solution:
```
n, m = list(map(int, input().split()))
f, x = False, []
for i in range(n):
a = input()
b = set(a)
x.append(int(a))
if len(b) != 1:
f = True
if i > 0 and x[i] == x[i-1]:
f = True
if f:
print('NO')
else:
print('YES')
``` | output | 1 | 28,522 | 7 | 57,045 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,523 | 7 | 57,046 |
Tags: implementation
Correct Solution:
```
n, m = [int(item) for item in input().split()]
prev, current, ans = '', '', 'YES'
for i in range(n):
current = input()
if current != current[0] * m or current == prev:
ans = "NO"
break
prev = current
print(ans)
``` | output | 1 | 28,523 | 7 | 57,047 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,524 | 7 | 57,048 |
Tags: implementation
Correct Solution:
```
n,m=map(int,(input().split()))
f='0'
d=1
for i in range(n):
s=input()
if i==0:
f=s[0]
for j in range(len(s)-1):
if s[j]!=s[j+1]:
print('NO')
d=0
break
elif i!=0:
if s[0]==f:
print('NO')
d=0
break
else:
f=s[0]
for j in range(len(s)-1):
if s[j]!=s[j+1]:
print('NO')
d=0
break
if d==0:
break
if d==1:
print('YES')
``` | output | 1 | 28,524 | 7 | 57,049 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,525 | 7 | 57,050 |
Tags: implementation
Correct Solution:
```
n=[int(i) for i in input().split(' ')]
a=[]
while n[0]>0:
n[0]-=1
s=set(input())
a.append(s)
pr=set('r')
res='YES'
for i in a:
if len(i)!=1 or i==pr:
res='NO'
pr=i
print(res)
``` | output | 1 | 28,525 | 7 | 57,051 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,526 | 7 | 57,052 |
Tags: implementation
Correct Solution:
```
# -*- coding: utf-8 -*-
n,m = map(int,input().split())
a = list(input() for i in range(n))
def Flag(n,a):
if a[0].count(a[0][0]) != len(a[0]): return 'NO'
for i in range(1,n):
if a[i].count(a[i][0]) != len(a[i]): return 'NO'
if a[i][0] == a[i-1][0]: return 'NO'
return 'YES'
print(Flag(n,a))
``` | output | 1 | 28,526 | 7 | 57,053 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,527 | 7 | 57,054 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
def solve():
ans = "YES"
for i in range(n):
row = input()
for j in range(1, len(row)):
if row[0] != row[j]:
ans = 'NO'
if i > 0 and pre == row:
ans = "NO"
pre = row
return ans
print(solve())
``` | output | 1 | 28,527 | 7 | 57,055 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,528 | 7 | 57,056 |
Tags: implementation
Correct Solution:
```
def checkIndiRow(rows, columns):
for n in range(0, len(rows)):
if(rows[n].count(rows[n][0])==columns):
continue
else:
return 0
for n in range(0,len(rows)-1):
if(rows[n][0]==rows[n+1][0]):
return 0
else:
continue
return 1
def flagmain():
rowColumn = list(map(int, input().split()))
rows=[]
for n in range(0,rowColumn[0]):
rows.append(input())
check=checkIndiRow(rows, rowColumn[1])
if(check==1):
print("YES")
else:
print("NO")
flagmain()
``` | output | 1 | 28,528 | 7 | 57,057 |
Provide tags and a correct Python 3 solution for this coding contest problem.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO | instruction | 0 | 28,529 | 7 | 57,058 |
Tags: implementation
Correct Solution:
```
n,m=list(map(int,input().split()))
ans="YES"
for i in range(n):
str=input()
for j in range(1,len(str)):
if str[0]!=str[j]:
ans="NO"
if i>0 and pre==str:
ans="NO"
pre=str
print(ans)
``` | output | 1 | 28,529 | 7 | 57,059 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
from sys import exit
info = input().split()
n = int(info[0])
m = int(info[1])
list = []
for i in range(n):
list.append(input())
for i in range(n-1):
if list[i] == list[i + 1]:
print("NO")
exit(0)
for i in range(n):
clr = list[i][0]
str = f"{clr}"* m
if str != list[i]:
print("NO")
exit(0)
print("YES")
``` | instruction | 0 | 28,530 | 7 | 57,060 |
Yes | output | 1 | 28,530 | 7 | 57,061 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
n, m = list(map(int, input().split()))
prev = ''
ans = "YES"
for i in range(n):
current = input()
if current != current[0] * m or current == prev:
ans = "NO"
break
prev = current
print(ans)
``` | instruction | 0 | 28,531 | 7 | 57,062 |
Yes | output | 1 | 28,531 | 7 | 57,063 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
n,m=map(int,input().split())
l=[]
f=0
while(n):
n-=1
e=0
k=list(input())
for i in range(m):
if(k[i]!=k[0]):
e=1
break
if(k in l or e==1):
print("NO")
f=1
break
if(len(l)==0):
l.append(k)
else:
l.append(k)
l.remove(l[0])
if(f==0):
print("YES")
``` | instruction | 0 | 28,532 | 7 | 57,064 |
Yes | output | 1 | 28,532 | 7 | 57,065 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
e = input().split(' ')
n = int(e[0])
m = int(e[1])
result = "YES"
prev_row_color = ""
i = 0
while i < n:
j = 0
row = input()
while j < m:
curr = row[j]
if j+1 == len(row):
break
nxt = row[j+1]
if curr != nxt:
result = "NO"
j += 1
row_color = curr
if row_color == prev_row_color:
result = "NO"
prev_row_color = row_color
i += 1
print(result)
``` | instruction | 0 | 28,533 | 7 | 57,066 |
Yes | output | 1 | 28,533 | 7 | 57,067 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
n,m = map(int,input().split())
l=[]
for i in range(n):
a = list(set(map(int,input())))
l.append(a)
# print(l)
for i in range(len(l)):
if len(l[i]) != 1:
print("NO")
exit()
flag = 0
for i in range(len(l)-1):
if l[i] == l[i+1]:
flag = 1
if flag == 1:
print("NO")
break
else:
print("YES")
break
``` | instruction | 0 | 28,534 | 7 | 57,068 |
No | output | 1 | 28,534 | 7 | 57,069 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
n,m=map(int,input().split())
h=0
v=1
l=[]
for i in range(0,n):
a=list(input())
a=[int(u) for u in a]
l.append(a[0])
if len(list(set(a)))==1:
h=h+1
for x,y in zip(l,l[1:]):
if x==y:
v=0
break
if v==1 and h==m:
print("YES")
else:
print("NO")
``` | instruction | 0 | 28,535 | 7 | 57,070 |
No | output | 1 | 28,535 | 7 | 57,071 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
r, c = input().split(" ")
rows = int(r)
columns = int(c)
flag = [""]*rows
for i in range(0, rows):
flag[i] = input()
false = 0
if columns < 10:
for i in range(rows):
letter = flag[i][0]
for j in range(columns):
if letter != flag[i][j]:
false = 1
if i != 0:
if row == letter:
false = 1
row = flag[i][0]
if false:
print("NO")
else:
print("YES")
else:
print("NO")
``` | instruction | 0 | 28,536 | 7 | 57,072 |
No | output | 1 | 28,536 | 7 | 57,073 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input
The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Examples
Input
3 3
000
111
222
Output
YES
Input
3 3
000
000
111
Output
NO
Input
3 3
000
111
002
Output
NO
Submitted Solution:
```
s = str(input())
m = int(s[0])
ans = 0
ans=1
s = str(input())
temp=s[0]
if len(s) == s.count(s[0]):
for i in range(m-1):
s = str(input())
if len(s) == s.count(s[0]):
if temp!=s[0]:
ans = 1
temp = s[0]
else:
ans = 0
break
else:
ans = 0
break
else:
ans =0
if ans==1:
print("YES")
else:
print("NO")
``` | instruction | 0 | 28,537 | 7 | 57,074 |
No | output | 1 | 28,537 | 7 | 57,075 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,860 | 7 | 57,720 |
"Correct Solution:
```
n,a,b = map(int,input().split())
print((int)(n/(a+b))*a+min(a,(int)(n%(a+b))))
``` | output | 1 | 28,860 | 7 | 57,721 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,861 | 7 | 57,722 |
"Correct Solution:
```
n,a,b = map(int,input().split())
m = a+b
print(a*(n//m)+min(a,n-((n//m)*m)))
``` | output | 1 | 28,861 | 7 | 57,723 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,863 | 7 | 57,726 |
"Correct Solution:
```
N,A,B = map(int, input().split())
a = N//(A+B)
b = N%(A+B)
print(A*a + min(A,b))
``` | output | 1 | 28,863 | 7 | 57,727 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,864 | 7 | 57,728 |
"Correct Solution:
```
n,a,b=map(int,input().split())
print(min(n%(a+b),a)+n//(a+b)*a)
``` | output | 1 | 28,864 | 7 | 57,729 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,865 | 7 | 57,730 |
"Correct Solution:
```
N,A,B=map(int,input().split())
print(A*(N//(A+B))+min(A,N%(A+B)))
``` | output | 1 | 28,865 | 7 | 57,731 |
Provide a correct Python 3 solution for this coding contest problem.
Takahashi has many red balls and blue balls. Now, he will place them in a row.
Initially, there is no ball placed.
Takahashi, who is very patient, will do the following operation 10^{100} times:
* Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row.
How many blue balls will be there among the first N balls in the row of balls made this way?
Constraints
* 1 \leq N \leq 10^{18}
* A, B \geq 0
* 0 < A + B \leq 10^{18}
* All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of blue balls that will be there among the first N balls in the row of balls.
Examples
Input
8 3 4
Output
4
Input
8 0 4
Output
0
Input
6 2 4
Output
2 | instruction | 0 | 28,866 | 7 | 57,732 |
"Correct Solution:
```
n,a,b=map(int,input().split())
c=a+b
print(a*(n//c)+min(a,n%c))
``` | output | 1 | 28,866 | 7 | 57,733 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.